Skip to content

Commit 64a7aec

Browse files
committed
feat: add new queries and DTOs for mal-bestilling management
#deploy-test-dolly-backend #deploy-dolly-backend
1 parent 0b6d36c commit 64a7aec

9 files changed

+203
-54
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package no.nav.dolly.domain.resultset.entity.bestilling;
2+
3+
public interface MalBestilling {
4+
5+
Long getId();
6+
String getMalNavn();
7+
String getMalBestilling();
8+
String getMiljoer();
9+
String getSistOppdatert();
10+
String getBrukernavn();
11+
String getBrukerId();
12+
}

apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestilling.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
import lombok.Builder;
66
import lombok.Data;
77
import lombok.NoArgsConstructor;
8-
import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter;
9-
10-
import java.time.LocalDateTime;
118

129
@Data
1310
@Builder
14-
@AllArgsConstructor
1511
@NoArgsConstructor
12+
@AllArgsConstructor
1613
public class RsMalBestilling {
1714

1815
private Long id;
19-
private JsonNode bestilling;
20-
private String miljoer;
2116
private String malNavn;
22-
private RsBrukerUtenFavoritter bruker;
23-
private LocalDateTime sistOppdatert;
17+
private JsonNode malBestilling;
18+
private String miljoer;
19+
private String sistOppdatert;
20+
private String brukernavn;
21+
private String brukerId;
2422
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package no.nav.dolly.domain.resultset.entity.bestilling;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter;
9+
10+
import java.time.LocalDateTime;
11+
12+
@Data
13+
@Builder
14+
@AllArgsConstructor
15+
@NoArgsConstructor
16+
public class RsMalBestillingUtenFavoritter {
17+
18+
private Long id;
19+
private JsonNode bestilling;
20+
private String miljoer;
21+
private String malNavn;
22+
private RsBrukerUtenFavoritter bruker;
23+
private LocalDateTime sistOppdatert;
24+
}

apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
@AllArgsConstructor
2020
public class RsMalBestillingWrapper {
2121

22-
private Map<String, List<RsMalBestilling>> malbestillinger;
22+
private Map<String, List<RsMalBestillingUtenFavoritter>> malbestillinger;
2323

24-
public Map<String, List<RsMalBestilling>> getMalbestillinger() {
24+
public Map<String, List<RsMalBestillingUtenFavoritter>> getMalbestillinger() {
2525

2626
if (isNull(malbestillinger)) {
2727
malbestillinger = new TreeMap<>();

apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/MalBestillingMappingStrategy.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import ma.glasnost.orika.CustomMapper;
88
import ma.glasnost.orika.MapperFactory;
99
import ma.glasnost.orika.MappingContext;
10-
import no.nav.dolly.domain.jpa.BestillingMal;
10+
import no.nav.dolly.domain.resultset.entity.bestilling.MalBestilling;
1111
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling;
12-
import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter;
1312
import no.nav.dolly.mapper.MappingStrategy;
1413
import org.springframework.http.HttpStatus;
1514
import org.springframework.stereotype.Component;
@@ -24,18 +23,19 @@ public class MalBestillingMappingStrategy implements MappingStrategy {
2423

2524
@Override
2625
public void register(MapperFactory factory) {
27-
factory.classMap(BestillingMal.class, RsMalBestilling.class)
26+
factory.classMap(MalBestilling.class, RsMalBestilling.class)
2827
.customize(new CustomMapper<>() {
2928
@Override
30-
public void mapAtoB(BestillingMal kilde, RsMalBestilling destinasjon, MappingContext context) {
29+
public void mapAtoB(MalBestilling kilde, RsMalBestilling destinasjon, MappingContext context) {
3130

31+
destinasjon.setId(kilde.getId());
32+
destinasjon.setMalNavn(kilde.getMalNavn());
33+
destinasjon.setMiljoer(kilde.getMiljoer());
34+
destinasjon.setSistOppdatert(kilde.getSistOppdatert());
35+
destinasjon.setBrukernavn(kilde.getBrukernavn());
36+
destinasjon.setBrukerId(kilde.getBrukerId());
3237
try {
33-
destinasjon.setId(kilde.getId());
34-
destinasjon.setMiljoer(kilde.getMiljoer());
35-
destinasjon.setMalNavn(kilde.getMalNavn());
36-
destinasjon.setBestilling(objectMapper.readTree(kilde.getBestKriterier()));
37-
destinasjon.setBruker(mapperFacade.map(kilde.getBruker(), RsBrukerUtenFavoritter.class));
38-
destinasjon.setSistOppdatert(kilde.getSistOppdatert());
38+
destinasjon.setMalBestilling(objectMapper.readTree(kilde.getMalBestilling()));
3939

4040
} catch (JsonProcessingException e) {
4141
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package no.nav.dolly.mapper.strategy;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
7+
import ma.glasnost.orika.CustomMapper;
8+
import ma.glasnost.orika.MapperFactory;
9+
import ma.glasnost.orika.MappingContext;
10+
import no.nav.dolly.domain.jpa.BestillingMal;
11+
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingUtenFavoritter;
12+
import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter;
13+
import no.nav.dolly.mapper.MappingStrategy;
14+
import org.springframework.http.HttpStatus;
15+
import org.springframework.stereotype.Component;
16+
import org.springframework.web.server.ResponseStatusException;
17+
18+
@Slf4j
19+
@Component
20+
@RequiredArgsConstructor
21+
public class MalBestillingUtenFavoritterMappingStrategy implements MappingStrategy {
22+
23+
private final ObjectMapper objectMapper;
24+
25+
@Override
26+
public void register(MapperFactory factory) {
27+
factory.classMap(BestillingMal.class, RsMalBestillingUtenFavoritter.class)
28+
.customize(new CustomMapper<>() {
29+
@Override
30+
public void mapAtoB(BestillingMal kilde, RsMalBestillingUtenFavoritter destinasjon, MappingContext context) {
31+
32+
try {
33+
destinasjon.setId(kilde.getId());
34+
destinasjon.setMiljoer(kilde.getMiljoer());
35+
destinasjon.setMalNavn(kilde.getMalNavn());
36+
destinasjon.setBestilling(objectMapper.readTree(kilde.getBestKriterier()));
37+
destinasjon.setBruker(mapperFacade.map(kilde.getBruker(), RsBrukerUtenFavoritter.class));
38+
destinasjon.setSistOppdatert(kilde.getSistOppdatert());
39+
40+
} catch (JsonProcessingException e) {
41+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
42+
}
43+
}
44+
})
45+
.register();
46+
}
47+
}

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lombok.RequiredArgsConstructor;
55
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling;
66
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingSimple;
7+
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingUtenFavoritter;
78
import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper;
89
import no.nav.dolly.service.MalBestillingService;
910
import org.springframework.cache.annotation.CacheEvict;
@@ -18,6 +19,8 @@
1819
import org.springframework.web.bind.annotation.RequestParam;
1920
import org.springframework.web.bind.annotation.RestController;
2021

22+
import java.util.List;
23+
2124
import static no.nav.dolly.config.CachingConfig.CACHE_BESTILLING_MAL;
2225
import static org.apache.commons.lang3.StringUtils.isBlank;
2326

@@ -31,8 +34,8 @@ public class MalBestillingController {
3134
@CacheEvict(value = { CACHE_BESTILLING_MAL }, allEntries = true)
3235
@PostMapping(value = "/ident/{ident}")
3336
@Operation(description = "Opprett ny mal-bestilling fra ident")
34-
public RsMalBestilling createTemplateFromIdent(@PathVariable String ident,
35-
@RequestParam String malNavn) {
37+
public RsMalBestillingUtenFavoritter createTemplateFromIdent(@PathVariable String ident,
38+
@RequestParam String malNavn) {
3639

3740
return malBestillingService.createFromIdent(ident, malNavn);
3841
}
@@ -47,6 +50,15 @@ public RsMalBestillingWrapper getMalBestillinger(@RequestParam(required = false)
4750
malBestillingService.getMalBestillinger() : malBestillingService.getMalbestillingByUser(brukerId);
4851
}
4952

53+
@Cacheable(value = CACHE_BESTILLING_MAL)
54+
@GetMapping("/brukerId/{brukerId}")
55+
@Transactional
56+
@Operation(description = "Hent mal-bestilling, for angitt brukerId, evt ALLE eller FELLES")
57+
public List<RsMalBestilling> getMalBestillingerBrukerId(@PathVariable("brukerId") String brukerId) {
58+
59+
return malBestillingService.getMalBestillingerBrukerId(brukerId);
60+
}
61+
5062
@GetMapping("/oversikt")
5163
@Transactional(readOnly = true)
5264
@Operation(description = "Hent oversikt bestillinger")
@@ -59,7 +71,7 @@ public RsMalBestillingSimple getMalBestillinger() {
5971
@PostMapping
6072
@Operation(description = "Opprett ny mal-bestilling fra bestillingId")
6173
@Transactional
62-
public RsMalBestilling opprettMalbestilling(@RequestParam Long bestillingId, @RequestParam String malNavn) {
74+
public RsMalBestillingUtenFavoritter opprettMalbestilling(@RequestParam Long bestillingId, @RequestParam String malNavn) {
6375

6476
return malBestillingService.saveBestillingMalFromBestillingId(bestillingId, malNavn);
6577
}
@@ -77,7 +89,7 @@ public void deleteMalBestilling(@PathVariable Long id) {
7789
@PutMapping("/id/{id}")
7890
@Operation(description = "Rediger mal-bestilling")
7991
@Transactional
80-
public RsMalBestilling redigerMalBestilling(@PathVariable Long id, @RequestParam String malNavn) {
92+
public RsMalBestillingUtenFavoritter redigerMalBestilling(@PathVariable Long id, @RequestParam String malNavn) {
8193

8294
return malBestillingService.updateMalNavnById(id, malNavn);
8395
}

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

+32-3
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.MalBestilling;
56
import no.nav.dolly.domain.resultset.entity.bestilling.MalBestillingFragment;
67
import org.springframework.data.jpa.repository.Modifying;
78
import org.springframework.data.jpa.repository.Query;
@@ -20,12 +21,40 @@ public interface BestillingMalRepository extends CrudRepository<BestillingMal, L
2021

2122
List<BestillingMal> findByBruker(Bruker bruker);
2223

24+
@Query(value = """
25+
select bm.id, bm.mal_navn malNavn, bm.best_kriterier malBestilling, bm.miljoer,
26+
bm.sist_oppdatert sistOppdatert, b.brukernavn, b.bruker_id brukerId
27+
from bestilling_mal bm
28+
join bruker b on bm.bruker_id = b.id
29+
where b.bruker_id = :brukerId
30+
order by bm.mal_navn;
31+
""", nativeQuery = true)
32+
List<MalBestilling> findAllByBrukerId(@Param("brukerId") String brukerId);
33+
34+
@Query(value = """
35+
select bm.id, bm.mal_navn malNavn, bm.best_kriterier malBestilling, bm.miljoer,
36+
bm.sist_oppdatert sistOppdatert
37+
from bestilling_mal bm
38+
where bm.bruker_id is null
39+
order by bm.mal_navn;
40+
""", nativeQuery = true)
41+
List<MalBestilling> findAllByBrukerIsNull();
42+
43+
@Query(value = """
44+
select bm.id, bm.mal_navn malNavn, bm.best_kriterier malBestilling, bm.miljoer,
45+
bm.sist_oppdatert sistOppdatert, b.brukernavn, b.bruker_id brukerId
46+
from bestilling_mal bm
47+
left outer join bruker b on bm.bruker_id = b.id
48+
order by bm.mal_navn, b.brukernavn
49+
""", nativeQuery = true)
50+
List<MalBestilling> findAllBy();
51+
2352
@Query(value = """
2453
select (b.brukernavn || ':' || b.bruker_id) malBruker from bruker b
2554
join bestilling_mal bm on b.id = bm.bruker_id
26-
and b.brukertype = 'AZURE'
55+
and b.brukertype = 'AZURE'
2756
group by malBruker
28-
order by malBruker
57+
order by malBruker
2958
""", nativeQuery = true)
3059
List<MalBestillingFragment> findAllByBrukertypeAzure();
3160

@@ -34,7 +63,7 @@ public interface BestillingMalRepository extends CrudRepository<BestillingMal, L
3463
join bestilling_mal bm on b.id = bm.bruker_id
3564
and b.bruker_id in :brukerIds
3665
group by malBruker
37-
order by malBruker
66+
order by malBruker
3867
""", nativeQuery = true)
3968
List<MalBestillingFragment> findAllByBrukerIdIn(@Param("brukerIds") List<String> brukerIds);
4069
}

0 commit comments

Comments
 (0)