Skip to content

Commit 0b6d36c

Browse files
committed
feat: add new endpoints for fetching mal-bestilling overview and fragments #deploy-test-dolly-backend #deploy-dolly-backend
1 parent 9eb385e commit 0b6d36c

File tree

7 files changed

+100
-3
lines changed

7 files changed

+100
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package no.nav.dolly.domain.resultset.entity.bestilling;
2+
3+
public interface MalBestillingFragment {
4+
5+
String getMalBruker();
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package no.nav.dolly.domain.resultset.entity.bestilling;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.List;
9+
10+
@Data
11+
@Builder
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
public class RsMalBestillingSimple {
15+
16+
private List<MalBruker> brukereMedMaler;
17+
18+
@Data
19+
@Builder
20+
@AllArgsConstructor
21+
@NoArgsConstructor
22+
public static class MalBruker {
23+
24+
private String brukernavn;
25+
private String brukerId;
26+
}
27+
}

apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bruker/RsBrukerUtenFavoritter.java

-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ public class RsBrukerUtenFavoritter {
2020
private String brukernavn;
2121
private Brukertype brukertype;
2222
private String epost;
23-
private String navIdent;
2423
}

apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/MalBestillingController.java

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.swagger.v3.oas.annotations.Operation;
44
import lombok.RequiredArgsConstructor;
55
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling;
6+
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingSimple;
67
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper;
78
import no.nav.dolly.service.MalBestillingService;
89
import org.springframework.cache.annotation.CacheEvict;
@@ -38,13 +39,22 @@ public RsMalBestilling createTemplateFromIdent(@PathVariable String ident,
3839

3940
@Cacheable(value = CACHE_BESTILLING_MAL)
4041
@GetMapping
42+
@Transactional
4143
@Operation(description = "Hent mal-bestilling, kan filtreres på en bruker")
4244
public RsMalBestillingWrapper getMalBestillinger(@RequestParam(required = false) String brukerId) {
4345

4446
return isBlank(brukerId) ?
4547
malBestillingService.getMalBestillinger() : malBestillingService.getMalbestillingByUser(brukerId);
4648
}
4749

50+
@GetMapping("/oversikt")
51+
@Transactional(readOnly = true)
52+
@Operation(description = "Hent oversikt bestillinger")
53+
public RsMalBestillingSimple getMalBestillinger() {
54+
55+
return malBestillingService.getMalBestillingOversikt();
56+
}
57+
4858
@CacheEvict(value = { CACHE_BESTILLING_MAL }, allEntries = true)
4959
@PostMapping
5060
@Operation(description = "Opprett ny mal-bestilling fra bestillingId")

apps/dolly-backend/src/main/java/no/nav/dolly/repository/BestillingMalRepository.java

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import no.nav.dolly.domain.jpa.BestillingMal;
44
import no.nav.dolly.domain.jpa.Bruker;
5+
import no.nav.dolly.domain.resultset.entity.bestilling.MalBestillingFragment;
56
import org.springframework.data.jpa.repository.Modifying;
67
import org.springframework.data.jpa.repository.Query;
78
import org.springframework.data.repository.CrudRepository;
@@ -10,11 +11,30 @@
1011
import java.util.List;
1112

1213
public interface BestillingMalRepository extends CrudRepository<BestillingMal, Long> {
14+
1315
@Modifying
1416
@Query("update BestillingMal b set b.malNavn = :malNavn where b.id = :id")
1517
void updateMalNavnById(@Param("id") Long id, @Param("malNavn") String malNavn);
1618

1719
List<BestillingMal> findByBrukerAndMalNavn(Bruker bruker, String navn);
1820

1921
List<BestillingMal> findByBruker(Bruker bruker);
22+
23+
@Query(value = """
24+
select (b.brukernavn || ':' || b.bruker_id) malBruker from bruker b
25+
join bestilling_mal bm on b.id = bm.bruker_id
26+
and b.brukertype = 'AZURE'
27+
group by malBruker
28+
order by malBruker
29+
""", nativeQuery = true)
30+
List<MalBestillingFragment> findAllByBrukertypeAzure();
31+
32+
@Query(value = """
33+
select (b.brukernavn || ':' || b.bruker_id) malBruker from bruker b
34+
join bestilling_mal bm on b.id = bm.bruker_id
35+
and b.bruker_id in :brukerIds
36+
group by malBruker
37+
order by malBruker
38+
""", nativeQuery = true)
39+
List<MalBestillingFragment> findAllByBrukerIdIn(@Param("brukerIds") List<String> brukerIds);
2040
}

apps/dolly-backend/src/main/java/no/nav/dolly/service/BrukerService.java

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public Bruker fjernFavoritt(Long gruppeId) {
9090
public List<Bruker> fetchBrukere() {
9191

9292
var brukeren = fetchOrCreateBruker();
93-
log.info("Hentet current bruker: id {} brukertype {}", brukeren.getBrukerId(), brukeren.getBrukertype());
94-
9593
if (brukeren.getBrukertype() == AZURE) {
9694
return brukerRepository.findAllByOrderById();
9795

apps/dolly-backend/src/main/java/no/nav/dolly/service/MalBestillingService.java

+37
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import lombok.RequiredArgsConstructor;
66
import lombok.extern.slf4j.Slf4j;
77
import ma.glasnost.orika.MapperFacade;
8+
import no.nav.dolly.consumer.brukerservice.BrukerServiceConsumer;
9+
import no.nav.dolly.consumer.brukerservice.dto.TilgangDTO;
810
import no.nav.dolly.domain.jpa.Bestilling;
911
import no.nav.dolly.domain.jpa.BestillingMal;
1012
import no.nav.dolly.domain.jpa.Bruker;
1113
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
14+
import no.nav.dolly.domain.resultset.entity.bestilling.MalBestillingFragment;
1215
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling;
16+
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingSimple;
1317
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper;
1418
import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter;
1519
import no.nav.dolly.exceptions.NotFoundException;
@@ -29,14 +33,17 @@
2933
import java.util.Collection;
3034
import java.util.Collections;
3135
import java.util.Comparator;
36+
import java.util.List;
3237
import java.util.Map;
38+
import java.util.Objects;
3339
import java.util.Set;
3440
import java.util.concurrent.atomic.AtomicReference;
3541
import java.util.stream.Collectors;
3642

3743
import static java.util.Objects.isNull;
3844
import static java.util.Objects.nonNull;
3945
import static no.nav.dolly.config.CachingConfig.CACHE_BESTILLING_MAL;
46+
import static no.nav.dolly.domain.jpa.Bruker.Brukertype.AZURE;
4047
import static no.nav.dolly.util.CurrentAuthentication.getUserId;
4148

4249
@Service
@@ -49,6 +56,7 @@ public class MalBestillingService {
4956
private static final String EMPTY_JSON = "{}";
5057

5158
private final BestillingMalRepository bestillingMalRepository;
59+
private final BrukerServiceConsumer brukerServiceConsumer;
5260
private final BestillingRepository bestillingRepository;
5361
private final BrukerService brukerService;
5462
private final MapperFacade mapperFacade;
@@ -286,4 +294,33 @@ private static Set<String> toSet(String miljoer) {
286294
.collect(Collectors.toSet()) :
287295
Collections.emptySet();
288296
}
297+
298+
public RsMalBestillingSimple getMalBestillingOversikt() {
299+
300+
List<MalBestillingFragment> maler;
301+
var brukeren = brukerService.fetchOrCreateBruker();
302+
if (brukeren.getBrukertype() == AZURE) {
303+
maler = bestillingMalRepository.findAllByBrukertypeAzure();
304+
305+
} else {
306+
var brukere = brukerServiceConsumer.getKollegaerIOrganisasjon(brukeren.getBrukerId())
307+
.map(TilgangDTO::getBrukere)
308+
.block();
309+
310+
maler = bestillingMalRepository.findAllByBrukerIdIn(brukere);
311+
}
312+
313+
return RsMalBestillingSimple.builder()
314+
.brukereMedMaler(
315+
maler.stream()
316+
.map(MalBestillingFragment::getMalBruker)
317+
.filter(Objects::nonNull)
318+
.map(malBruker -> malBruker.split(":"))
319+
.map(malBruker -> RsMalBestillingSimple.MalBruker.builder()
320+
.brukernavn(malBruker[0])
321+
.brukerId(malBruker[1])
322+
.build())
323+
.toList())
324+
.build();
325+
}
289326
}

0 commit comments

Comments
 (0)