From 0022bfde9037e1797152b795a816b0330e577cfa Mon Sep 17 00:00:00 2001 From: Betsy Carina Traran Date: Wed, 10 Apr 2024 18:09:04 +0200 Subject: [PATCH 01/82] Fix visning av valgte egenskaper --- .../stegVelger/steg/steg1/Steg1Person.tsx | 9 ++- .../steg/steg1/paneler/Personinformasjon.tsx | 60 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/Steg1Person.tsx b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/Steg1Person.tsx index 5c19ac21c4f..5df1f2958c3 100644 --- a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/Steg1Person.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/Steg1Person.tsx @@ -53,11 +53,10 @@ export const Steg1Person = ({ stateModifier }: any) => { ] .map((panel) => ({ label: panel.heading, - values: stateModifier(panel.initialValues).checked, - })) - .map((v) => ({ - ...v, - values: v?.values.filter((val) => !personFoerLeggTil && !leggTil && val !== 'Alder'), + values: stateModifier(panel.initialValues).checked?.filter( + (val: string) => + (!personFoerLeggTil && !leggTil) || ((personFoerLeggTil || leggTil) && val !== 'Alder'), + ), })) .filter((v) => v.values.length) diff --git a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/paneler/Personinformasjon.tsx b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/paneler/Personinformasjon.tsx index 6ab6d2896db..c8668f85329 100644 --- a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/paneler/Personinformasjon.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg1/paneler/Personinformasjon.tsx @@ -180,6 +180,8 @@ PersoninformasjonPanel.initialValues = ({ set, opts, setMulti, del, has }) => { skjerming: 'skjerming.egenAnsattDatoTom', }, skjermetFra: 'skjermingsregister.skjermetFra', + norskBankkonto: 'bankkonto.norskBankkonto', + utenlandskBankkonto: 'bankkonto.utenlandskBankkonto', telefonnummer: { pdl: 'pdldata.person.telefonnummer', tpsM: 'tpsMessaging.telefonnummer', @@ -188,8 +190,6 @@ PersoninformasjonPanel.initialValues = ({ set, opts, setMulti, del, has }) => { fullmakt: 'pdldata.person.fullmakt', sikkerhetstiltak: 'pdldata.person.sikkerhetstiltak', tilrettelagtKommunikasjon: 'pdldata.person.tilrettelagtKommunikasjon', - utenlandskBankkonto: 'bankkonto.utenlandskBankkonto', - norskBankkonto: 'bankkonto.norskBankkonto', } return { @@ -301,6 +301,34 @@ PersoninformasjonPanel.initialValues = ({ set, opts, setMulti, del, has }) => { del('skjerming') }, }, + norskBankkonto: { + label: 'Norsk bank', + checked: has(paths.norskBankkonto), + add: () => + set(paths.norskBankkonto, { + kontonummer: '', + tilfeldigKontonummer: opts.antall && opts.antall > 1, + }), + remove: () => del(paths.norskBankkonto), + }, + utenlandskBankkonto: { + label: 'Utenlandsk bank', + checked: has(paths.utenlandskBankkonto), + add: () => + set(paths.utenlandskBankkonto, { + kontonummer: '', + tilfeldigKontonummer: false, + swift: 'BANKXX11222', + landkode: null, + banknavn: '', + iban: '', + valuta: null, + bankAdresse1: '', + bankAdresse2: '', + bankAdresse3: '', + }), + remove: () => del(paths.utenlandskBankkonto), + }, telefonnummer: { label: 'Telefonnummer', checked: has(paths.telefonnummer.pdl), @@ -369,33 +397,5 @@ PersoninformasjonPanel.initialValues = ({ set, opts, setMulti, del, has }) => { del(paths.tilrettelagtKommunikasjon) }, }, - utenlandskBankkonto: { - label: 'Utenlandsk bank', - checked: has(paths.utenlandskBankkonto), - add: () => - set(paths.utenlandskBankkonto, { - kontonummer: '', - tilfeldigKontonummer: false, - swift: 'BANKXX11222', - landkode: null, - banknavn: '', - iban: '', - valuta: null, - bankAdresse1: '', - bankAdresse2: '', - bankAdresse3: '', - }), - remove: () => del(paths.utenlandskBankkonto), - }, - norskBankkonto: { - label: 'Norsk bank', - checked: has(paths.norskBankkonto), - add: () => - set(paths.norskBankkonto, { - kontonummer: '', - tilfeldigKontonummer: opts.antall && opts.antall > 1, - }), - remove: () => del(paths.norskBankkonto), - }, } } From 8a4b858ecad8bfdbe8116ef42fda52774b186659 Mon Sep 17 00:00:00 2001 From: Betsy Carina Traran Date: Thu, 11 Apr 2024 14:18:47 +0200 Subject: [PATCH 02/82] Omskrivning henting av arenadata --- .../bestillingsveileder/Bestillingsveileder.tsx | 4 ++-- .../bestillingsveileder/options/options.tsx | 11 ----------- .../src/pages/gruppe/PersonVisning/PersonVisning.tsx | 3 +++ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/Bestillingsveileder.tsx b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/Bestillingsveileder.tsx index 9123fe97ced..c73b96cce67 100644 --- a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/Bestillingsveileder.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/Bestillingsveileder.tsx @@ -14,7 +14,7 @@ export const Bestillingsveileder = ({ error, sendBestilling }) => { const navigate = useNavigate() const [showError, setShowError] = useState(false) const [navigateRoot, setNavigateRoot] = useState(false) - const { gruppeId, personId } = useParams() + const { gruppeId } = useParams() const erOrganisasjon = location?.state?.opprettOrganisasjon const importPersoner = location?.state?.importPersoner @@ -46,7 +46,7 @@ export const Bestillingsveileder = ({ error, sendBestilling }) => { return null } - const options = BVOptions(location.state, gruppeId, personId) + const options = BVOptions(location.state, gruppeId) const handleSubmit = (values) => { sendBestilling(values, options, gruppeId, navigate) } diff --git a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/options/options.tsx b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/options/options.tsx index 7f84f5973a1..d65dc99ee3f 100644 --- a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/options/options.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/options/options.tsx @@ -1,6 +1,4 @@ import { initialValuesBasedOnMal } from '@/components/bestillingsveileder/options/malOptions' -import { useArenaData } from '@/utils/hooks/useFagsystemer' -import { harArenaBestilling } from '@/utils/SjekkBestillingFagsystem' const TYPE = Object.freeze({ NY_BESTILLING: 'NY_BESTILLING', @@ -29,7 +27,6 @@ export const BVOptions = ( gruppe, } = {}, gruppeId, - personId, ) => { let initialValues = { antall: antall || 1, @@ -114,14 +111,6 @@ export const BVOptions = ( initialValues = initialValuesLeggTil } - if (personFoerLeggTil) { - const bestillinger = tidligereBestillinger?.map((best) => best?.data) - const { arenaData } = useArenaData(personId, harArenaBestilling(bestillinger)) - if (arenaData && arenaData.length > 0) { - personFoerLeggTil.arenaforvalteren = arenaData - } - } - if (leggTilPaaGruppe) { bestType = TYPE.LEGG_TIL_PAA_GRUPPE initialValues = initialValuesLeggTilPaaGruppe diff --git a/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx b/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx index be1e792ae3f..987613e8892 100644 --- a/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx +++ b/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx @@ -371,6 +371,9 @@ export default ({ if (arbeidsplassencvData) { personData.arbeidsplassenCV = { harHjemmel: getArbeidsplassencvHjemmel() } } + if (arenaData) { + personData.arenaforvalteren = arenaData + } leggTilPaaPerson( personData, bestillingListe, From 302fad22dcb35e94e2e44f5bdba1389c2aaa5258 Mon Sep 17 00:00:00 2001 From: Betsy Carina Traran Date: Fri, 12 Apr 2024 13:51:08 +0200 Subject: [PATCH 03/82] Fikset miljoe-validering som ikke oppdaterte --- .../bestillingsveileder/stegVelger/steg/steg3/Steg3.tsx | 1 + .../src/main/js/src/components/miljoVelger/MiljoVelger.tsx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg3/Steg3.tsx b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg3/Steg3.tsx index 760e86fc6d2..1015f43bd26 100644 --- a/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg3/Steg3.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/bestillingsveileder/stegVelger/steg/steg3/Steg3.tsx @@ -81,6 +81,7 @@ export const Steg3 = () => { if (harRelatertPersonVedSivilstand || harEksisterendeNyIdent || harRelatertPersonBarn) { formMethods.setValue('malBestillingNavn', undefined) } + formMethods.trigger('environments') }, []) const visMiljoeVelger = formMethods.watch('environments') diff --git a/apps/dolly-frontend/src/main/js/src/components/miljoVelger/MiljoVelger.tsx b/apps/dolly-frontend/src/main/js/src/components/miljoVelger/MiljoVelger.tsx index 49067d80154..63d721634ed 100644 --- a/apps/dolly-frontend/src/main/js/src/components/miljoVelger/MiljoVelger.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/miljoVelger/MiljoVelger.tsx @@ -96,6 +96,7 @@ export const MiljoVelger = ({ isChecked(id) ? values.filter((value) => value !== id) : values.concat(id), ) } + formMethods.trigger('environments') } return ( @@ -110,7 +111,7 @@ export const MiljoVelger = ({ )}
- Miljøer + Miljøer
{filteredEnvironments.map((env) => ( Date: Fri, 12 Apr 2024 15:57:08 +0200 Subject: [PATCH 04/82] Update maler api --- .../src/main/js/src/service/services/dolly/DollyEndpoints.tsx | 4 ++-- apps/dolly-frontend/src/main/js/src/utils/hooks/useMaler.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/dolly-frontend/src/main/js/src/service/services/dolly/DollyEndpoints.tsx b/apps/dolly-frontend/src/main/js/src/service/services/dolly/DollyEndpoints.tsx index ca892189c71..3b6e2486654 100644 --- a/apps/dolly-frontend/src/main/js/src/service/services/dolly/DollyEndpoints.tsx +++ b/apps/dolly-frontend/src/main/js/src/service/services/dolly/DollyEndpoints.tsx @@ -182,11 +182,11 @@ export default class DollyEndpoints { } static malBestillingMedId(malId, malNavn) { - return `${bestillingBase}/malbestilling/${malId}?malNavn=${malNavn}` + return `${uri}/malbestilling/id/${malId}?malNavn=${malNavn}` } static malBestillingMedBestillingId(bestillingId, malNavn) { - return `${bestillingBase}/malbestilling?bestillingId=${bestillingId}&malNavn=${malNavn}` + return `${uri}/malbestilling?bestillingId=${bestillingId}&malNavn=${malNavn}` } static organisasjonMalBestillingMedBestillingId(bestillingId, malNavn) { diff --git a/apps/dolly-frontend/src/main/js/src/utils/hooks/useMaler.tsx b/apps/dolly-frontend/src/main/js/src/utils/hooks/useMaler.tsx index 446d00a8dbc..7ab0e019db1 100644 --- a/apps/dolly-frontend/src/main/js/src/utils/hooks/useMaler.tsx +++ b/apps/dolly-frontend/src/main/js/src/utils/hooks/useMaler.tsx @@ -1,7 +1,7 @@ import useSWR from 'swr' import { fetcher } from '@/api' -const getMalerUrl = '/dolly-backend/api/v1/bestilling/malbestilling' +const getMalerUrl = '/dolly-backend/api/v1/malbestilling' const getOrganisasjonMalerUrl = '/dolly-backend/api/v1/organisasjon/bestilling/malbestilling' export type Mal = { From e0a4a65a54d4aab4c51e812d82bb50930da12b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristen=20H=C3=A6rum?= Date: Mon, 15 Apr 2024 09:46:41 +0200 Subject: [PATCH 05/82] Oppdaterer personstatus ved doedsfall (#3467) #deploy-pdl-forvalter #deploy-test-pdl-forvalter --- .../FolkeregisterPersonstatusService.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/FolkeregisterPersonstatusService.java b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/FolkeregisterPersonstatusService.java index 362717f3556..765bf7046f1 100644 --- a/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/FolkeregisterPersonstatusService.java +++ b/apps/pdl-forvalter/src/main/java/no/nav/pdl/forvalter/service/FolkeregisterPersonstatusService.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import static java.util.Objects.nonNull; import static no.nav.pdl.forvalter.utils.ArtifactUtils.getKilde; @@ -37,6 +38,8 @@ public class FolkeregisterPersonstatusService implements BiValidation convert(PersonDTO person) { + var touched = new AtomicBoolean(false); + person.getFolkeregisterPersonstatus() .forEach(status -> { @@ -45,6 +48,7 @@ public List convert(PersonDTO person) { handle(status, person); status.setKilde(getKilde(status)); status.setMaster(getMaster(status, person)); + touched.set(true); } }); @@ -59,6 +63,12 @@ public List convert(PersonDTO person) { .build(), person) ); + touched.set(true); + } + + if (!touched.get() && !person.getFolkeregisterPersonstatus().isEmpty()) { + + handle(person.getFolkeregisterPersonstatus().getFirst(), person); } return person.getFolkeregisterPersonstatus(); @@ -113,18 +123,18 @@ private FolkeregisterPersonstatusDTO handle(FolkeregisterPersonstatusDTO persons } else if (!person.getBostedsadresse().isEmpty()) { - if (person.getBostedsadresse().get(0).isAdresseUtland()) { + if (person.getBostedsadresse().getFirst().isAdresseUtland()) { personstatus.setStatus(IKKE_BOSATT); - } else if (nonNull(person.getBostedsadresse().get(0).getUkjentBosted())) { + } else if (nonNull(person.getBostedsadresse().getFirst().getUkjentBosted())) { personstatus.setStatus(FOEDSELSREGISTRERT); } else { personstatus.setStatus(BOSATT); } - personstatus.setGyldigFraOgMed(nonNull(person.getBostedsadresse().get(0).getGyldigFraOgMed()) ? - person.getBostedsadresse().get(0).getGyldigFraOgMed() : + personstatus.setGyldigFraOgMed(nonNull(person.getBostedsadresse().getFirst().getGyldigFraOgMed()) ? + person.getBostedsadresse().getFirst().getGyldigFraOgMed() : DatoFraIdentUtility.getDato(person.getIdent()).atStartOfDay()); } else if (FNR != getIdenttype(person.getIdent()) && From 8fc72b4cd0e3e7e507126e621f8cf622fbdfadfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristen=20H=C3=A6rum?= Date: Mon, 15 Apr 2024 10:08:18 +0200 Subject: [PATCH 06/82] Add MalBestilling functionality (#3463) * Lagt til opprett mal fra person Co-authored-by: Betsy Carina Traran --- .../dolly/DollyBackendApplicationStarter.java | 2 +- .../no/nav/dolly/config/CachingConfig.java | 2 + .../java/no/nav/dolly/domain/jpa/Bruker.java | 2 + .../entity/bestilling/RsBestillingStatus.java | 57 +--- .../entity/bestilling/RsMalBestilling.java | 24 ++ .../bestilling/RsMalBestillingWrapper.java | 71 ----- .../{strategy => }/BestillingMapper.java | 2 +- .../BestillingStatusMappingStrategy.java | 54 +--- ...yRequest2MalBestillingMappingStrategy.java | 201 +++++++++++++ .../mapper/strategy/JsonBestillingMapper.java | 10 - .../MalBestillingMappingStrategy.java | 33 ++- .../provider/api/BestillingController.java | 41 --- .../provider/api/MalBestillingController.java | 74 +++++ .../dolly/service/BestillingMalService.java | 177 ------------ .../nav/dolly/service/BestillingService.java | 8 +- .../dolly/service/MalBestillingService.java | 273 ++++++++++++++++++ .../OrganisasjonBestillingMalService.java | 2 +- .../dolly/service/SplittGruppeService.java | 2 +- .../api/BestillingControllerTest.java | 18 +- .../api/MalBestillingControllerTest.java} | 36 ++- ...OrganisasjonMalBestillingServiceTest.java} | 2 +- .../src/main/js/cypress/e2e/Minside.cy.ts | 2 +- .../src/main/js/cypress/support/e2e.ts | 4 +- .../detaljer/BestillingDetaljer.tsx | 12 +- .../gruppe/PersonVisning/PersonVisning.tsx | 12 + .../js/src/pages/minSide/maler/MalModal.tsx | 46 ++- .../js/src/pages/minSide/maler/MalPanel.tsx | 5 +- .../service/services/dolly/DollyEndpoints.tsx | 8 +- .../service/services/dolly/DollyService.tsx | 4 + .../src/main/js/src/utils/hooks/useMaler.tsx | 2 +- .../v1/ArbeidsplassenCVDTO.java | 31 +- 31 files changed, 753 insertions(+), 464 deletions(-) create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestilling.java rename apps/dolly-backend/src/main/java/no/nav/dolly/mapper/{strategy => }/BestillingMapper.java (97%) create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/DollyRequest2MalBestillingMappingStrategy.java create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/MalBestillingController.java delete mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingMalService.java create mode 100644 apps/dolly-backend/src/main/java/no/nav/dolly/service/MalBestillingService.java rename apps/dolly-backend/src/test/java/no/nav/dolly/{service/BestillingMalServiceTest.java => provider/api/MalBestillingControllerTest.java} (86%) rename apps/dolly-backend/src/test/java/no/nav/dolly/service/{OrganisasjonBestillingMalServiceTest.java => OrganisasjonMalBestillingServiceTest.java} (99%) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java b/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java index 6af8668f777..f0ef428e58d 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/DollyBackendApplicationStarter.java @@ -10,4 +10,4 @@ public static void main(String[] args) { SpringApplication.run(DollyBackendApplicationStarter.class, args); } -} \ No newline at end of file +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/config/CachingConfig.java b/apps/dolly-backend/src/main/java/no/nav/dolly/config/CachingConfig.java index 769530033ad..b3e918603dd 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/config/CachingConfig.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/config/CachingConfig.java @@ -17,6 +17,7 @@ public class CachingConfig { public static final String CACHE_BESTILLING = "bestilling"; + public static final String CACHE_BESTILLING_MAL = "bestilling-mal"; public static final String CACHE_BRUKER = "bruker"; public static final String CACHE_GRUPPE = "gruppe"; public static final String CACHE_HELSEPERSONELL = "helsepersonell"; @@ -25,6 +26,7 @@ public class CachingConfig { @Profile({ "dev", "prod" }) public CacheManager cacheManager(Caffeine caffeine) { var caffeineCacheManager = new CaffeineCacheManager(CACHE_BESTILLING, + CACHE_BESTILLING_MAL, CACHE_BRUKER, CACHE_GRUPPE, CACHE_HELSEPERSONELL diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/Bruker.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/Bruker.java index 3b07d184c96..58441a7da19 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/Bruker.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/Bruker.java @@ -1,5 +1,6 @@ package no.nav.dolly.domain.jpa; +import com.fasterxml.jackson.annotation.JsonInclude; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -36,6 +37,7 @@ @NoArgsConstructor @AllArgsConstructor @Table(name = "BRUKER") +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class Bruker implements Serializable { @Id diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java index e0fdc364c23..21db02dc4fc 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsBestillingStatus.java @@ -1,32 +1,12 @@ package no.nav.dolly.domain.resultset.entity.bestilling; -import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonNode; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import no.nav.dolly.domain.resultset.RsStatusRapport; -import no.nav.dolly.domain.resultset.aareg.RsAareg; -import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata; -import no.nav.dolly.domain.resultset.breg.RsBregdata; -import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv; import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; -import no.nav.dolly.domain.resultset.histark.RsHistark; -import no.nav.dolly.domain.resultset.inntektsmeldingstub.RsInntektsmelding; -import no.nav.dolly.domain.resultset.inntektstub.InntektMultiplierWrapper; -import no.nav.dolly.domain.resultset.inst.RsInstdata; -import no.nav.dolly.domain.resultset.kontoregister.BankkontoData; -import no.nav.dolly.domain.resultset.krrstub.RsDigitalKontaktdata; -import no.nav.dolly.domain.resultset.medl.RsMedl; -import no.nav.dolly.domain.resultset.pdldata.PdlPersondata; -import no.nav.dolly.domain.resultset.pensjon.PensjonData; -import no.nav.dolly.domain.resultset.sigrunstub.RsLignetInntekt; -import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden; -import no.nav.dolly.domain.resultset.skjerming.RsSkjerming; -import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding; -import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging; -import no.nav.dolly.domain.resultset.udistub.model.RsUdiPerson; -import no.nav.testnav.libs.data.arbeidsplassencv.v1.ArbeidsplassenCVDTO; import java.time.LocalDateTime; import java.util.ArrayList; @@ -39,7 +19,6 @@ @Data @NoArgsConstructor @AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_EMPTY) @Builder public class RsBestillingStatus { @@ -58,7 +37,7 @@ public class RsBestillingStatus { private Long opprettetFraId; private Long opprettetFraGruppeId; private Long gjenopprettetFraIdent; - private RsBestilling bestilling; + private JsonNode bestilling; private String opprettFraIdenter; public Set getEnvironments() { @@ -74,36 +53,4 @@ public List getStatus() { } return status; } - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @JsonInclude(JsonInclude.Include.NON_EMPTY) - public static class RsBestilling { - - private Boolean navSyntetiskIdent; - private List importFraPdl; - private String kildeMiljoe; - private RsDigitalKontaktdata krrstub; - private List instdata; - private List aareg; - private List sigrunstub; - private List sigrunstubPensjonsgivende; - private InntektMultiplierWrapper inntektstub; - private Arenadata arenaforvalter; - private RsUdiPerson udistub; - private PensjonData pensjonforvalter; - private RsInntektsmelding inntektsmelding; - private RsBregdata brregstub; - private RsDokarkiv dokarkiv; - private RsMedl medl; - private RsHistark histark; - private RsSykemelding sykemelding; - private PdlPersondata pdldata; - private RsTpsMessaging tpsMessaging; - private BankkontoData bankkonto; - private RsSkjerming skjerming; - private ArbeidsplassenCVDTO arbeidsplassenCV; - } } \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestilling.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestilling.java new file mode 100644 index 00000000000..cfcbaf8bc8e --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestilling.java @@ -0,0 +1,24 @@ +package no.nav.dolly.domain.resultset.entity.bestilling; + +import com.fasterxml.jackson.databind.JsonNode; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; + +import java.time.LocalDateTime; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class RsMalBestilling { + + private Long id; + private JsonNode bestilling; + private String miljoer; + private String malNavn; + private RsBrukerUtenFavoritter bruker; + private LocalDateTime sistOppdatert; +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java index 5033027879a..7bb94900566 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/entity/bestilling/RsMalBestillingWrapper.java @@ -1,36 +1,13 @@ package no.nav.dolly.domain.resultset.entity.bestilling; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import no.nav.dolly.domain.resultset.aareg.RsAareg; -import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata; -import no.nav.dolly.domain.resultset.breg.RsBregdata; -import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv; -import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; -import no.nav.dolly.domain.resultset.histark.RsHistark; -import no.nav.dolly.domain.resultset.inntektsmeldingstub.RsInntektsmelding; -import no.nav.dolly.domain.resultset.inntektstub.InntektMultiplierWrapper; -import no.nav.dolly.domain.resultset.inst.RsInstdata; -import no.nav.dolly.domain.resultset.kontoregister.BankkontoData; -import no.nav.dolly.domain.resultset.krrstub.RsDigitalKontaktdata; -import no.nav.dolly.domain.resultset.medl.RsMedl; -import no.nav.dolly.domain.resultset.pdldata.PdlPersondata; -import no.nav.dolly.domain.resultset.pensjon.PensjonData; -import no.nav.dolly.domain.resultset.sigrunstub.RsLignetInntekt; -import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden; -import no.nav.dolly.domain.resultset.skjerming.RsSkjerming; -import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding; -import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging; -import no.nav.dolly.domain.resultset.udistub.model.RsUdiPerson; -import no.nav.testnav.libs.data.arbeidsplassencv.v1.ArbeidsplassenCVDTO; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import static java.util.Objects.isNull; @@ -51,52 +28,4 @@ public Map> getMalbestillinger() { } return malbestillinger; } - - @Getter - @Setter - @Builder - @NoArgsConstructor - @AllArgsConstructor - @JsonInclude(JsonInclude.Include.NON_EMPTY) - public static class RsMalBestilling { - - private Long id; - private String malNavn; - private RsBestilling bestilling; - private RsBrukerUtenFavoritter bruker; - } - - @Getter - @Setter - @Builder - @NoArgsConstructor - @AllArgsConstructor - @JsonInclude(JsonInclude.Include.NON_EMPTY) - public static class RsBestilling { - - private Integer antallIdenter; - private Boolean navSyntetiskIdent; - private String opprettFraIdenter; - private Set environments; - private PdlPersondata pdldata; - private RsDigitalKontaktdata krrstub; - private List instdata; - private List aareg; - private List sigrunstub; - private List sigrunstubPensjonsgivende; - private InntektMultiplierWrapper inntektstub; - private Arenadata arenaforvalter; - private RsUdiPerson udistub; - private RsInntektsmelding inntektsmelding; - private PensjonData pensjonforvalter; - private RsBregdata brregstub; - private RsDokarkiv dokarkiv; - private RsMedl medl; - private RsHistark histark; - private RsSykemelding sykemelding; - private RsTpsMessaging tpsMessaging; - private RsSkjerming skjerming; - private BankkontoData bankkonto; - private ArbeidsplassenCVDTO arbeidsplassenCV; - } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingMapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingMapper.java similarity index 97% rename from apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingMapper.java rename to apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingMapper.java index ef7c5ea975d..9e805136d87 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingMapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/BestillingMapper.java @@ -1,4 +1,4 @@ -package no.nav.dolly.mapper.strategy; +package no.nav.dolly.mapper; import lombok.experimental.UtilityClass; import no.nav.dolly.domain.jpa.Bestilling; diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java index e7b03e9a9f3..11d9d610bdc 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java @@ -1,5 +1,6 @@ package no.nav.dolly.mapper.strategy; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -9,16 +10,14 @@ import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.jpa.BestillingProgress; import no.nav.dolly.domain.jpa.OrganisasjonBestilling; -import no.nav.dolly.domain.resultset.RsDollyBestillingRequest; import no.nav.dolly.domain.resultset.entity.bestilling.RsBestillingStatus; import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; import no.nav.dolly.mapper.MappingStrategy; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import org.springframework.web.server.ResponseStatusException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - +import static java.util.Objects.isNull; import static no.nav.dolly.bestilling.service.DollyBestillingService.getEnvironments; import static no.nav.dolly.mapper.AnnenFeilStatusMapper.buildAnnenFeilStatusMap; import static no.nav.dolly.mapper.ArbeidsplassenCVStatusMapper.buildArbeidsplassenCVStatusMap; @@ -44,14 +43,13 @@ import static no.nav.dolly.mapper.BestillingTpsMessagingStatusMapper.buildTpsMessagingStatusMap; import static no.nav.dolly.mapper.BestillingUdiStubStatusMapper.buildUdiStubStatusMap; import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; @Slf4j @Component @RequiredArgsConstructor public class BestillingStatusMappingStrategy implements MappingStrategy { - private final JsonBestillingMapper jsonBestillingMapper; + private static final String EMPTY_JSON = "{}"; private final ObjectMapper objectMapper; @Override @@ -62,12 +60,21 @@ public void register(MapperFactory factory) { public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus, MappingContext context) { var ident = (String) context.getProperty("ident"); + try { + bestillingStatus.setBestilling( + objectMapper.readTree(isNull(bestilling.getBestKriterier()) || + EMPTY_JSON.equals(bestilling.getBestKriterier()) ? EMPTY_JSON : + bestilling.getBestKriterier())); + } catch (JsonProcessingException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); + } + + bestillingStatus.setBruker(mapperFacade.map(bestilling.getBruker(), RsBrukerUtenFavoritter.class)); + var progresser = bestilling.getProgresser().stream() .filter(progress -> isBlank(ident) || ident.equals(progress.getIdent())) .toList(); - RsDollyBestillingRequest bestillingRequest = jsonBestillingMapper - .mapBestillingRequest(bestilling.getId(), bestilling.getBestKriterier()); bestillingStatus.setAntallLevert((int) progresser.stream() .filter(BestillingProgress::isIdentGyldig) .count()); @@ -97,32 +104,6 @@ public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus, bestillingStatus.getStatus().addAll(buildKontoregisterStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildArbeidsplassenCVStatusMap(progresser)); bestillingStatus.getStatus().addAll(buildAnnenFeilStatusMap(progresser)); - bestillingStatus.setBestilling(RsBestillingStatus.RsBestilling.builder() - .pdldata(bestillingRequest.getPdldata()) - .aareg(bestillingRequest.getAareg()) - .krrstub(bestillingRequest.getKrrstub()) - .medl(bestillingRequest.getMedl()) - .arenaforvalter(bestillingRequest.getArenaforvalter()) - .instdata(bestillingRequest.getInstdata()) - .inntektstub(bestillingRequest.getInntektstub()) - .sigrunstub(bestillingRequest.getSigrunstub()) - .sigrunstubPensjonsgivende(bestillingRequest.getSigrunstubPensjonsgivende()) - .udistub(bestillingRequest.getUdistub()) - .pensjonforvalter(bestillingRequest.getPensjonforvalter()) - .inntektsmelding(bestillingRequest.getInntektsmelding()) - .brregstub(bestillingRequest.getBrregstub()) - .dokarkiv(bestillingRequest.getDokarkiv()) - .histark(bestillingRequest.getHistark()) - .sykemelding(bestillingRequest.getSykemelding()) - .skjerming(bestillingRequest.getSkjerming()) - .tpsMessaging(bestillingRequest.getTpsMessaging()) - .bankkonto(bestillingRequest.getBankkonto()) - .arbeidsplassenCV(bestillingRequest.getArbeidsplassenCV()) - .importFraPdl(mapIdents(bestilling.getPdlImport())) - .kildeMiljoe(bestilling.getKildeMiljoe()) - .navSyntetiskIdent(bestilling.getNavSyntetiskIdent()) - .build()); - bestillingStatus.setBruker(mapperFacade.map(bestilling.getBruker(), RsBrukerUtenFavoritter.class)); } }) .exclude("bruker") @@ -139,9 +120,6 @@ public void mapAtoB(OrganisasjonBestilling bestilling, RsBestillingStatus bestil }) .byDefault() .register(); - } - private static List mapIdents(String idents) { - return isNotBlank(idents) ? Arrays.asList(idents.split(",")) : Collections.emptyList(); } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/DollyRequest2MalBestillingMappingStrategy.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/DollyRequest2MalBestillingMappingStrategy.java new file mode 100644 index 00000000000..484f5dd7757 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/DollyRequest2MalBestillingMappingStrategy.java @@ -0,0 +1,201 @@ +package no.nav.dolly.mapper.strategy; + +import ma.glasnost.orika.CustomMapper; +import ma.glasnost.orika.MapperFactory; +import ma.glasnost.orika.MappingContext; +import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling; +import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata; +import no.nav.dolly.domain.resultset.inntektstub.InntektMultiplierWrapper; +import no.nav.dolly.domain.resultset.kontoregister.BankkontoData; +import no.nav.dolly.domain.resultset.krrstub.RsDigitalKontaktdata; +import no.nav.dolly.domain.resultset.pdldata.PdlPersondata; +import no.nav.dolly.domain.resultset.pensjon.PensjonData; +import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding; +import no.nav.dolly.mapper.MappingStrategy; +import no.nav.testnav.libs.data.arbeidsplassencv.v1.ArbeidsplassenCVDTO; +import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO; +import org.springframework.stereotype.Component; + +@Component +public class DollyRequest2MalBestillingMappingStrategy implements MappingStrategy { + + @Override + public void register(MapperFactory factory) { + factory.classMap(RsDollyUtvidetBestilling.class, RsDollyUtvidetBestilling.class) + .mapNulls(false) + .field("arbeidsplassenCV", "arbeidsplassenCV") + .field("arenaforvalter", "arenaforvalter") + .field("bankkonto", "bankkonto") + .field("brregstub", "brregstub") + .field("dokarkiv", "dokarkiv") + .field("environments", "environments") + .field("histark", "histark") + .field("inntektsmelding", "inntektsmelding") + .field("inntektstub", "inntektstub") + .field("krrstub", "krrstub") + .field("medl", "medl") + .field("navSyntetiskIdent", "navSyntetiskIdent") + .field("pdldata", "pdldata") + .field("pensjonforvalter", "pensjonforvalter") + .field("sigrunstub", "sigrunstub") + .field("sigrunstubPensjonsgivende", "sigrunstubPensjonsgivende") + .field("skjerming", "skjerming") + .field("sykemelding", "sykemelding") + .field("tpsMessaging", "tpsMessaging") + .field("udistub", "udistub") + + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(RsDollyUtvidetBestilling request, RsDollyUtvidetBestilling akkumulert, MappingContext context) { + + akkumulert.getAareg().addAll(request.getAareg()); + akkumulert.getEnvironments().addAll(request.getEnvironments()); + akkumulert.getInstdata().addAll(request.getInstdata()); + akkumulert.getSigrunstub().addAll(request.getSigrunstub()); + akkumulert.getSigrunstubPensjonsgivende().addAll(request.getSigrunstubPensjonsgivende()); + } + }) + .register(); + + factory.classMap(ArbeidsplassenCVDTO.Jobboensker.class, ArbeidsplassenCVDTO.Jobboensker.class) + .mapNulls(false) + .field("active", "active") + .field("startOption", "startOption") + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(ArbeidsplassenCVDTO.Jobboensker jobboensker, ArbeidsplassenCVDTO.Jobboensker akkumulert, MappingContext context) { + akkumulert.getLocations().addAll(jobboensker.getLocations()); + akkumulert.getOccupationDrafts().addAll(jobboensker.getOccupationDrafts()); + akkumulert.getOccupationTypes().addAll(jobboensker.getOccupationTypes()); + akkumulert.getOccupations().addAll(jobboensker.getOccupations()); + akkumulert.getWorkLoadTypes().addAll(jobboensker.getWorkLoadTypes()); + akkumulert.getWorkScheduleTypes().addAll(jobboensker.getWorkScheduleTypes()); + } + }) + .register(); + + factory.classMap(ArbeidsplassenCVDTO.class, ArbeidsplassenCVDTO.class) + .mapNulls(false) + .field("harHjemmel", "harHjemmel") + .field("harBil", "harBil") + .field("sammendrag", "sammendrag") + .field("jobboensker", "jobboensker") + .field("sistEndretAvNav", "sistEndretAvNav") + .field("sistEndret", "sistEndret") + + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(ArbeidsplassenCVDTO arbeidsplassenCV, ArbeidsplassenCVDTO akkumulert, MappingContext context) { + akkumulert.getAndreGodkjenninger().addAll(arbeidsplassenCV.getAndreGodkjenninger()); + akkumulert.getAnnenErfaring().addAll(arbeidsplassenCV.getAnnenErfaring()); + akkumulert.getArbeidserfaring().addAll(arbeidsplassenCV.getArbeidserfaring()); + akkumulert.getFagbrev().addAll(arbeidsplassenCV.getFagbrev()); + akkumulert.getFoererkort().addAll(arbeidsplassenCV.getFoererkort()); + akkumulert.getKompetanser().addAll(arbeidsplassenCV.getKompetanser()); + akkumulert.getKurs().addAll(arbeidsplassenCV.getKurs()); + akkumulert.getOffentligeGodkjenninger().addAll(arbeidsplassenCV.getOffentligeGodkjenninger()); + akkumulert.getSpraak().addAll(arbeidsplassenCV.getSpraak()); + akkumulert.getUtdanning().addAll(arbeidsplassenCV.getUtdanning()); + } + }) + .register(); + + factory.classMap(RsDigitalKontaktdata.class, RsDigitalKontaktdata.class) + .mapNulls(false) + .byDefault() + .register(); + + factory.classMap(RsSykemelding.class, RsSykemelding.class) + .mapNulls(false) + .byDefault() + .register(); + + factory.classMap(BankkontoData.class, BankkontoData.class) + .mapNulls(false) + .byDefault() + .register(); + + factory.classMap(InntektMultiplierWrapper.class, InntektMultiplierWrapper.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(InntektMultiplierWrapper inntekt, InntektMultiplierWrapper akkumlert, MappingContext context) { + akkumlert.getInntektsinformasjon().addAll(inntekt.getInntektsinformasjon()); + } + }) + .register(); + + factory.classMap(PensjonData.class, PensjonData.class) + .mapNulls(false) + .field("inntekt", "inntekt") + .field("alderspensjon", "alderspensjon") + .field("uforetrygd", "uforetrygd") + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(PensjonData pensjonData, PensjonData akkumulert, MappingContext context) { + akkumulert.getTp().addAll(pensjonData.getTp()); + } + }) + .register(); + + factory.classMap(Arenadata.class, Arenadata.class) + .mapNulls(false) + .field("aktiveringDato", "aktiveringDato") + .field("arenaBrukertype", "arenaBrukertype") + .field("automatiskInnsendingAvMeldekort", "automatiskInnsendingAvMeldekort") + .field("inaktiveringDato", "inaktiveringDato") + .field("kvalifiseringsgruppe", "kvalifiseringsgruppe") + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(Arenadata arenadata, Arenadata akkumulert, MappingContext context) { + akkumulert.getAap115().addAll(arenadata.getAap115()); + akkumulert.getAap().addAll(arenadata.getAap()); + akkumulert.getDagpenger().addAll(arenadata.getDagpenger()); + } + }) + .register(); + + factory.classMap(PdlPersondata.class, PdlPersondata.class) + .mapNulls(false) + .byDefault() + .register(); + + factory.classMap(PersonDTO.class, PersonDTO.class) + .mapNulls(false) + .field("ident", "ident") + .field("identtype", "identtype") + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(PersonDTO personDTO, PersonDTO akkumulertDTO, MappingContext context) { + akkumulertDTO.getAdressebeskyttelse().addAll(personDTO.getAdressebeskyttelse()); + akkumulertDTO.getBostedsadresse().addAll(personDTO.getBostedsadresse()); + akkumulertDTO.getBostedsadresse().addAll(personDTO.getBostedsadresse()); + akkumulertDTO.getDeltBosted().addAll(personDTO.getDeltBosted()); + akkumulertDTO.getDoedfoedtBarn().addAll(personDTO.getDoedfoedtBarn()); + akkumulertDTO.getDoedsfall().addAll(personDTO.getDoedsfall()); + akkumulertDTO.getFalskIdentitet().addAll(personDTO.getFalskIdentitet()); + akkumulertDTO.getFoedsel().addAll(personDTO.getFoedsel()); + akkumulertDTO.getFolkeregisterPersonstatus().addAll(personDTO.getFolkeregisterPersonstatus()); + akkumulertDTO.getForelderBarnRelasjon().addAll(personDTO.getForelderBarnRelasjon()); + akkumulertDTO.getForeldreansvar().addAll(personDTO.getForeldreansvar()); + akkumulertDTO.getFullmakt().addAll(personDTO.getFullmakt()); + akkumulertDTO.getInnflytting().addAll(personDTO.getInnflytting()); + akkumulertDTO.getKjoenn().addAll(personDTO.getKjoenn()); + akkumulertDTO.getKontaktadresse().addAll(personDTO.getKontaktadresse()); + akkumulertDTO.getKontaktinformasjonForDoedsbo().addAll(personDTO.getKontaktinformasjonForDoedsbo()); + akkumulertDTO.getNavn().addAll(personDTO.getNavn()); + akkumulertDTO.getNyident().addAll(personDTO.getNyident()); + akkumulertDTO.getOpphold().addAll(personDTO.getOpphold()); + akkumulertDTO.getOppholdsadresse().addAll(personDTO.getOppholdsadresse()); + akkumulertDTO.getSikkerhetstiltak().addAll(personDTO.getSikkerhetstiltak()); + akkumulertDTO.getSivilstand().addAll(personDTO.getSivilstand()); + akkumulertDTO.getStatsborgerskap().addAll(personDTO.getStatsborgerskap()); + akkumulertDTO.getTelefonnummer().addAll(personDTO.getTelefonnummer()); + akkumulertDTO.getTilrettelagtKommunikasjon().addAll(personDTO.getTilrettelagtKommunikasjon()); + akkumulertDTO.getUtenlandskIdentifikasjonsnummer().addAll(personDTO.getUtenlandskIdentifikasjonsnummer()); + akkumulertDTO.getUtflytting().addAll(personDTO.getUtflytting()); + akkumulertDTO.getVergemaal().addAll(personDTO.getVergemaal()); + } + }) + .register(); + } +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/JsonBestillingMapper.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/JsonBestillingMapper.java index 8ab5a101263..da7247007ee 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/JsonBestillingMapper.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/JsonBestillingMapper.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import no.nav.dolly.domain.resultset.RsDollyBestillingRequest; import no.nav.dolly.domain.resultset.RsOrganisasjonBestilling.SyntetiskOrganisasjon; import org.springframework.stereotype.Component; @@ -18,15 +17,6 @@ public class JsonBestillingMapper { private final ObjectMapper objectMapper; - public RsDollyBestillingRequest mapBestillingRequest(Long bestillingId, String jsonInput) { - try { - return objectMapper.readValue(nonNull(jsonInput) ? jsonInput : "{}", RsDollyBestillingRequest.class); - } catch (IOException e) { - log.error("Mapping av JSON fra database bestKriterier, bestId: {} feilet. {}", bestillingId, e.getMessage(), e); - } - return new RsDollyBestillingRequest(); - } - public SyntetiskOrganisasjon mapOrganisasjonBestillingRequest(String jsonInput) { try { return objectMapper.readValue(nonNull(jsonInput) ? jsonInput : "{}", SyntetiskOrganisasjon.class); diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/MalBestillingMappingStrategy.java b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/MalBestillingMappingStrategy.java index ae69562e82e..78262ddf95b 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/MalBestillingMappingStrategy.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/MalBestillingMappingStrategy.java @@ -1,40 +1,47 @@ package no.nav.dolly.mapper.strategy; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import ma.glasnost.orika.CustomMapper; import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.MappingContext; import no.nav.dolly.domain.jpa.BestillingMal; -import no.nav.dolly.domain.resultset.RsDollyBestillingRequest; -import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper; +import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling; +import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; import no.nav.dolly.mapper.MappingStrategy; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; - -import static no.nav.dolly.bestilling.service.DollyBestillingService.getEnvironments; +import org.springframework.web.server.ResponseStatusException; @Slf4j @Component @RequiredArgsConstructor public class MalBestillingMappingStrategy implements MappingStrategy { - private final JsonBestillingMapper jsonBestillingMapper; + private final ObjectMapper objectMapper; @Override public void register(MapperFactory factory) { - factory.classMap(BestillingMal.class, RsMalBestillingWrapper.RsBestilling.class) + factory.classMap(BestillingMal.class, RsMalBestilling.class) .customize(new CustomMapper<>() { @Override - public void mapAtoB(BestillingMal bestilling, RsMalBestillingWrapper.RsBestilling malBestilling, MappingContext context) { + public void mapAtoB(BestillingMal kilde, RsMalBestilling destinasjon, MappingContext context) { + + try { + destinasjon.setId(kilde.getId()); + destinasjon.setMiljoer(kilde.getMiljoer()); + destinasjon.setMalNavn(kilde.getMalNavn()); + destinasjon.setBestilling(objectMapper.readTree(kilde.getBestKriterier())); + destinasjon.setBruker(mapperFacade.map(kilde.getBruker(), RsBrukerUtenFavoritter.class)); + destinasjon.setSistOppdatert(kilde.getSistOppdatert()); - RsDollyBestillingRequest bestillingRequest = jsonBestillingMapper - .mapBestillingRequest(bestilling.getId(), bestilling.getBestKriterier()); - mapperFacade.map(bestillingRequest, malBestilling); - malBestilling.setEnvironments(getEnvironments(bestilling.getMiljoer())); - malBestilling.setNavSyntetiskIdent(true); + } catch (JsonProcessingException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); + } } }) - .byDefault() .register(); } } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/BestillingController.java b/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/BestillingController.java index 63569c8aa9d..39ea45abcd1 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/BestillingController.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/BestillingController.java @@ -7,9 +7,7 @@ import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.resultset.entity.bestilling.RsBestillingFragment; import no.nav.dolly.domain.resultset.entity.bestilling.RsBestillingStatus; -import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper; import no.nav.dolly.domain.resultset.entity.testident.RsWhereAmI; -import no.nav.dolly.service.BestillingMalService; import no.nav.dolly.service.BestillingService; import no.nav.dolly.service.NavigasjonService; import no.nav.dolly.service.OrganisasjonBestillingService; @@ -21,7 +19,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -34,7 +31,6 @@ import static no.nav.dolly.config.CachingConfig.CACHE_BESTILLING; import static no.nav.dolly.config.CachingConfig.CACHE_GRUPPE; import static org.apache.commons.lang3.BooleanUtils.isTrue; -import static org.apache.commons.lang3.StringUtils.isBlank; @Transactional @RestController @@ -46,7 +42,6 @@ public class BestillingController { private final BestillingService bestillingService; private final OrganisasjonBestillingService organisasjonBestillingService; private final NavigasjonService navigasjonService; - private final BestillingMalService bestillingMalService; private final GjenopprettBestillingService gjenopprettBestillingService; @Cacheable(value = CACHE_BESTILLING) @@ -123,40 +118,4 @@ public RsBestillingStatus gjenopprettBestilling(@PathVariable("bestillingId") Lo gjenopprettBestillingService.executeAsync(bestilling); return mapperFacade.map(bestilling, RsBestillingStatus.class); } - - @Cacheable(value = CACHE_BESTILLING) - @GetMapping("/malbestilling") - @Operation(description = "Hent mal-bestilling, kan filtreses på en bruker") - public RsMalBestillingWrapper getMalBestillinger(@RequestParam(required = false, value = "brukerId") String brukerId) { - - return isBlank(brukerId) ? - bestillingMalService.getMalBestillinger() : bestillingMalService.getMalbestillingByUser(brukerId); - } - - @CacheEvict(value = { CACHE_BESTILLING }, allEntries = true) - @PostMapping("/malbestilling") - @Operation(description = "Opprett ny mal-bestilling fra bestillingId") - @Transactional - public void opprettMalbestilling(@RequestParam(value = "bestillingId") Long bestillingId, @RequestParam(value = "malNavn") String malNavn) { - - bestillingMalService.saveBestillingMalFromBestillingId(bestillingId, malNavn); - } - - @CacheEvict(value = { CACHE_BESTILLING }, allEntries = true) - @DeleteMapping("/malbestilling/{id}") - @Operation(description = "Slett mal-bestilling") - @Transactional - public void deleteMalBestilling(@PathVariable Long id) { - - bestillingMalService.deleteMalBestillingByID(id); - } - - @CacheEvict(value = { CACHE_BESTILLING }, allEntries = true) - @PutMapping("/malbestilling/{id}") - @Operation(description = "Rediger mal-bestilling") - @Transactional - public void redigerMalBestilling(@PathVariable Long id, @RequestParam(value = "malNavn") String malNavn) { - - bestillingMalService.updateMalNavnById(id, malNavn); - } } \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/MalBestillingController.java b/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/MalBestillingController.java new file mode 100644 index 00000000000..cdc4812ed7d --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/provider/api/MalBestillingController.java @@ -0,0 +1,74 @@ +package no.nav.dolly.provider.api; + +import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; +import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling; +import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper; +import no.nav.dolly.service.MalBestillingService; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import static no.nav.dolly.config.CachingConfig.CACHE_BESTILLING_MAL; +import static org.apache.commons.lang3.StringUtils.isBlank; + +@RequestMapping(value = "/api/v1/malbestilling") +@RestController +@RequiredArgsConstructor +public class MalBestillingController { + + private final MalBestillingService malBestillingService; + + @CacheEvict(value = { CACHE_BESTILLING_MAL }, allEntries = true) + @PostMapping(value = "/ident/{ident}") + @Operation(description = "Opprett ny mal-bestilling fra ident") + public RsMalBestilling createTemplateFromIdent(@PathVariable String ident, + @RequestParam String malNavn) { + + return malBestillingService.createFromIdent(ident, malNavn); + } + + @Cacheable(value = CACHE_BESTILLING_MAL) + @GetMapping + @Operation(description = "Hent mal-bestilling, kan filtreres på en bruker") + public RsMalBestillingWrapper getMalBestillinger(@RequestParam(required = false) String brukerId) { + + return isBlank(brukerId) ? + malBestillingService.getMalBestillinger() : malBestillingService.getMalbestillingByUser(brukerId); + } + + @CacheEvict(value = { CACHE_BESTILLING_MAL }, allEntries = true) + @PostMapping + @Operation(description = "Opprett ny mal-bestilling fra bestillingId") + @Transactional + public RsMalBestilling opprettMalbestilling(@RequestParam Long bestillingId, @RequestParam String malNavn) { + + return malBestillingService.saveBestillingMalFromBestillingId(bestillingId, malNavn); + } + + @CacheEvict(value = { CACHE_BESTILLING_MAL }, allEntries = true) + @DeleteMapping("/id/{id}") + @Operation(description = "Slett mal-bestilling") + @Transactional + public void deleteMalBestilling(@PathVariable Long id) { + + malBestillingService.deleteMalBestillingByID(id); + } + + @CacheEvict(value = { CACHE_BESTILLING_MAL }, allEntries = true) + @PutMapping("/id/{id}") + @Operation(description = "Rediger mal-bestilling") + @Transactional + public RsMalBestilling redigerMalBestilling(@PathVariable Long id, @RequestParam String malNavn) { + + return malBestillingService.updateMalNavnById(id, malNavn); + } +} diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingMalService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingMalService.java deleted file mode 100644 index 22260a5ed3c..00000000000 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingMalService.java +++ /dev/null @@ -1,177 +0,0 @@ -package no.nav.dolly.service; - -import lombok.RequiredArgsConstructor; -import ma.glasnost.orika.MapperFacade; -import no.nav.dolly.domain.jpa.Bestilling; -import no.nav.dolly.domain.jpa.BestillingMal; -import no.nav.dolly.domain.jpa.Bruker; -import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper; -import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper.RsBestilling; -import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper.RsMalBestilling; -import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; -import no.nav.dolly.exceptions.NotFoundException; -import no.nav.dolly.repository.BestillingMalRepository; -import no.nav.dolly.repository.BestillingRepository; -import no.nav.testnav.libs.servletsecurity.action.GetUserInfo; -import org.apache.commons.collections4.IterableUtils; -import org.springframework.stereotype.Service; - -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.util.Objects.isNull; -import static java.util.Objects.nonNull; -import static no.nav.dolly.util.CurrentAuthentication.getUserId; - -@Service -@RequiredArgsConstructor -public class BestillingMalService { - - private static final String ANONYM = "FELLES"; - private static final String ALLE = "ALLE"; - - private final BestillingMalRepository bestillingMalRepository; - private final BestillingRepository bestillingRepository; - private final BrukerService brukerService; - private final MapperFacade mapperFacade; - private final GetUserInfo getUserInfo; - - public RsMalBestillingWrapper getMalBestillinger() { - - var malBestillingWrapper = new RsMalBestillingWrapper(); - - var malBestillinger = IterableUtils.toList(bestillingMalRepository.findAll()) - .stream() - .collect(Collectors.groupingBy(bestilling -> getBruker(bestilling.getBruker()))) - .entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() - .stream() - .map(bestillingMal -> RsMalBestilling.builder() - .bestilling(mapperFacade.map(bestillingMal, RsBestilling.class)) - .malNavn(bestillingMal.getMalNavn()) - .id(bestillingMal.getId()) - .bruker(mapperFacade.map(nonNull(bestillingMal.getBruker()) ? - bestillingMal.getBruker() : - Bruker.builder().brukerId(ANONYM).brukernavn(ANONYM).build(), RsBrukerUtenFavoritter.class)) - .build()) - .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) - .toList())); - - malBestillingWrapper.getMalbestillinger().putAll(malBestillinger); - malBestillingWrapper.getMalbestillinger().put(ALLE, malBestillinger.values().stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) - .toList()); - - return malBestillingWrapper; - } - - public List getMalbestillingByUserAndNavn(String brukerId, String malNavn) { - - var bruker = brukerService.fetchOrCreateBruker(brukerId); - - return bestillingMalRepository.findByBrukerAndMalNavn(bruker, malNavn) - .stream() - .map(bestilling -> RsMalBestilling.builder() - .malNavn(bestilling.getMalNavn()) - .id(bestilling.getId()) - .bestilling(mapperFacade.map(bestilling, RsBestilling.class)) - .build()) - .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) - .toList(); - } - - public RsMalBestillingWrapper getMalbestillingByUser(String brukerId) { - - var bruker = brukerService.fetchOrCreateBruker(brukerId); - - var malBestillinger = bestillingMalRepository.findByBruker(bruker) - .stream() - .collect(Collectors.groupingBy(bestilling -> getBruker(bestilling.getBruker()))) - .entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() - .stream() - .map(bestillingMal -> RsMalBestilling.builder() - .bestilling(mapperFacade.map(bestillingMal, RsBestilling.class)) - .malNavn(bestillingMal.getMalNavn()) - .id(bestillingMal.getId()) - .bruker(mapperFacade.map(nonNull(bestillingMal.getBruker()) ? - bestillingMal.getBruker() : - Bruker.builder().brukerId(ANONYM).brukernavn(ANONYM).build(), RsBrukerUtenFavoritter.class)) - .build()) - .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) - .toList())); - - return RsMalBestillingWrapper.builder() - .malbestillinger(malBestillinger) - .build(); - } - - public void saveBestillingMal(Bestilling bestilling, String malNavn, Bruker bruker) { - - var eksisterende = bestillingMalRepository.findByBrukerAndMalNavn(bruker, malNavn); - if (eksisterende.isEmpty()) { - bestillingMalRepository.save(BestillingMal.builder() - - .bestKriterier(bestilling.getBestKriterier()) - .bruker(bruker) - .malNavn(malNavn) - .miljoer(bestilling.getMiljoer()) - .build()); - } else { - eksisterende.stream() - .findFirst() - .ifPresent(malbestilling -> { - malbestilling.setBestKriterier(bestilling.getBestKriterier()); - malbestilling.setMiljoer(bestilling.getMiljoer()); - }); - } - } - - public void saveBestillingMalFromBestillingId(Long bestillingId, String malNavn) { - - Bruker bruker = brukerService.fetchOrCreateBruker(getUserId(getUserInfo)); - - var bestilling = bestillingRepository.findById(bestillingId) - .orElseThrow(() -> new NotFoundException(bestillingId + " finnes ikke")); - - overskrivDuplikateMalbestillinger(malNavn, bruker); - bestillingMalRepository.save(BestillingMal.builder() - .bestKriterier(bestilling.getBestKriterier()) - .bruker(bruker) - .malNavn(malNavn) - .miljoer(bestilling.getMiljoer()) - .build()); - } - - public void deleteMalBestillingByID(Long id) { - - bestillingMalRepository.deleteById(id); - } - - public void updateMalNavnById(Long id, String nyttMalNavn) { - - bestillingMalRepository.updateMalNavnById(id, nyttMalNavn); - } - - public static String getBruker(Bruker bruker) { - - if (isNull(bruker)) { - return ANONYM; - } - return switch (bruker.getBrukertype()) { - case AZURE, BANKID -> bruker.getBrukernavn(); - case BASIC -> bruker.getNavIdent(); - }; - } - - void overskrivDuplikateMalbestillinger(String malNavn, Bruker bruker) { - - var gamleMalBestillinger = getMalbestillingByUserAndNavn(bruker.getBrukerId(), malNavn); - gamleMalBestillinger.forEach(malBestilling -> - bestillingMalRepository.deleteById(malBestilling.getId())); - } -} \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java index 1474ca5f181..5066ec21607 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/BestillingService.java @@ -68,7 +68,7 @@ public class BestillingService { private static final String SEARCH_STRING = "info:"; private static final String DEFAULT_VALUE = null; private final BestillingRepository bestillingRepository; - private final BestillingMalService bestillingMalService; + private final MalBestillingService malBestillingService; private final BestillingKontrollRepository bestillingKontrollRepository; private final IdentRepository identRepository; private final BestillingProgressRepository bestillingProgressRepository; @@ -209,7 +209,7 @@ public Bestilling saveBestilling(RsDollyUpdateRequest request, String ident) { .build(); if (isNotBlank(request.getMalBestillingNavn())) { - bestillingMalService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker); + malBestillingService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker); } return saveBestillingToDB(bestilling); } @@ -245,7 +245,7 @@ public Bestilling saveBestilling(Long gruppeId, RsDollyBestilling request, Integ .build(); fixAaregAbstractClassProblem(request.getAareg()); if (isNotBlank(request.getMalBestillingNavn())) { - bestillingMalService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker); + malBestillingService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker); } return saveBestillingToDB(bestilling); } @@ -331,7 +331,7 @@ public Bestilling saveBestilling(Long gruppeId, RsDollyImportFraPdlRequest reque fixAaregAbstractClassProblem(request.getAareg()); if (isNotBlank(request.getMalBestillingNavn())) { - bestillingMalService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker); + malBestillingService.saveBestillingMal(bestilling, request.getMalBestillingNavn(), bruker); } return saveBestillingToDB(bestilling); } diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/MalBestillingService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/MalBestillingService.java new file mode 100644 index 00000000000..8cb32a303e1 --- /dev/null +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/MalBestillingService.java @@ -0,0 +1,273 @@ +package no.nav.dolly.service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import ma.glasnost.orika.MapperFacade; +import no.nav.dolly.domain.jpa.Bestilling; +import no.nav.dolly.domain.jpa.BestillingMal; +import no.nav.dolly.domain.jpa.Bruker; +import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling; +import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestilling; +import no.nav.dolly.domain.resultset.entity.bestilling.RsMalBestillingWrapper; +import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter; +import no.nav.dolly.exceptions.NotFoundException; +import no.nav.dolly.repository.BestillingMalRepository; +import no.nav.dolly.repository.BestillingRepository; +import no.nav.testnav.libs.servletsecurity.action.GetUserInfo; +import org.apache.commons.collections4.IterableUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; +import static no.nav.dolly.util.CurrentAuthentication.getUserId; + +@Service +@RequiredArgsConstructor +public class MalBestillingService { + + private static final String ANONYM = "FELLES"; + private static final String ALLE = "ALLE"; + private static final String EMPTY_JSON = "{}"; + + private final BestillingMalRepository bestillingMalRepository; + private final BestillingRepository bestillingRepository; + private final BrukerService brukerService; + private final MapperFacade mapperFacade; + private final GetUserInfo getUserInfo; + private final ObjectMapper objectMapper; + + @Transactional(readOnly = true) + public RsMalBestillingWrapper getMalBestillinger() { + + var malBestillingWrapper = new RsMalBestillingWrapper(); + + var malBestillinger = IterableUtils.toList(bestillingMalRepository.findAll()) + .stream() + .collect(Collectors.groupingBy(bestilling -> getBruker(bestilling.getBruker()))) + .entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() + .stream() + .map(bestillingMal -> { + try { + return RsMalBestilling.builder() + .bestilling(objectMapper.readTree(bestillingMal.getBestKriterier())) + .malNavn(bestillingMal.getMalNavn()) + .id(bestillingMal.getId()) + .bruker(mapperFacade.map(nonNull(bestillingMal.getBruker()) ? + bestillingMal.getBruker() : + Bruker.builder().brukerId(ANONYM).brukernavn(ANONYM).build(), RsBrukerUtenFavoritter.class)) + .build(); + } catch (JsonProcessingException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); + } + }) + .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) + .toList())); + + malBestillingWrapper.getMalbestillinger().putAll(malBestillinger); + malBestillingWrapper.getMalbestillinger().put(ALLE, malBestillinger.values().stream() + .flatMap(Collection::stream) + .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) + .toList()); + + return malBestillingWrapper; + } + + @Transactional(readOnly = true) + public RsMalBestillingWrapper getMalbestillingByUser(String brukerId) { + + var bruker = brukerService.fetchBruker(brukerId); + + var malBestillinger = bestillingMalRepository.findByBruker(bruker) + .stream() + .collect(Collectors.groupingBy(bestilling -> getBruker(bestilling.getBruker()))) + .entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue() + .stream() + .map(bestillingMal -> { + try { + return RsMalBestilling.builder() + .bestilling(objectMapper.readTree(bestillingMal.getBestKriterier())) + .malNavn(bestillingMal.getMalNavn()) + .id(bestillingMal.getId()) + .bruker(mapperFacade.map(nonNull(bestillingMal.getBruker()) ? + bestillingMal.getBruker() : + Bruker.builder().brukerId(ANONYM).brukernavn(ANONYM).build(), RsBrukerUtenFavoritter.class)) + .build(); + } catch (JsonProcessingException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); + } + }) + .sorted(Comparator.comparing(RsMalBestilling::getMalNavn)) + .toList())); + + return RsMalBestillingWrapper.builder() + .malbestillinger(malBestillinger) + .build(); + } + + public void saveBestillingMal(Bestilling bestilling, String malNavn, Bruker bruker) { + + var eksisterende = bestillingMalRepository.findByBrukerAndMalNavn(bruker, malNavn); + + if (eksisterende.isEmpty()) { + bestillingMalRepository.save(BestillingMal.builder() + + .bestKriterier(bestilling.getBestKriterier()) + .bruker(bruker) + .malNavn(malNavn) + .miljoer(bestilling.getMiljoer()) + .build()); + } else { + + var oppdateEksisterende = eksisterende.getFirst(); + oppdateEksisterende.setBestKriterier(bestilling.getBestKriterier()); + oppdateEksisterende.setMiljoer(bestilling.getMiljoer()); + } + } + + @Transactional + public RsMalBestilling saveBestillingMalFromBestillingId(Long bestillingId, String malNavn) { + + var bruker = brukerService.fetchBruker(getUserId(getUserInfo)); + + var bestilling = bestillingRepository.findById(bestillingId) + .orElseThrow(() -> new NotFoundException(bestillingId + " finnes ikke")); + + BestillingMal malbestilling; + var maler = bestillingMalRepository.findByBrukerAndMalNavn(bruker, malNavn); + if (maler.isEmpty()) { + malbestilling = bestillingMalRepository.save(BestillingMal.builder() + .bestKriterier(bestilling.getBestKriterier()) + .bruker(bruker) + .malNavn(malNavn) + .miljoer(bestilling.getMiljoer()) + .build()); + } else { + malbestilling = maler.getFirst(); + } + + return mapperFacade.map(malbestilling, RsMalBestilling.class); + } + + @Transactional + public void deleteMalBestillingByID(Long id) { + + bestillingMalRepository.findById(id) + .orElseThrow(() -> + new ResponseStatusException(HttpStatus.NOT_FOUND, "Malbestilling med id %d ble ikke funnet".formatted(id))); + bestillingMalRepository.deleteById(id); + } + + @Transactional + public RsMalBestilling updateMalNavnById(Long id, String nyttMalNavn) { + + bestillingMalRepository.findById(id) + .orElseThrow(() -> + new ResponseStatusException(HttpStatus.NOT_FOUND, "Malbestilling med id %d ble ikke funnet".formatted(id))); + + bestillingMalRepository.updateMalNavnById(id, nyttMalNavn); + var oppdatertMalBestilling = new AtomicReference(); + + bestillingMalRepository.findById(id) + .ifPresentOrElse(malBestilling -> + oppdatertMalBestilling.set(mapperFacade.map(malBestilling, RsMalBestilling.class)), null); + return oppdatertMalBestilling.get(); + } + + @Transactional + public RsMalBestilling createFromIdent(String ident, String name) { + + var bruker = brukerService.fetchBruker(getUserId(getUserInfo)); + + var bestillinger = bestillingRepository.findBestillingerByIdent(ident); + if (bestillinger.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ingen bestillinger funnet på ident %s".formatted(ident)); + } + + var aggregertRequest = new RsDollyUtvidetBestilling(); + + bestillinger.stream() + .filter(bestilling -> nonNull(bestilling.getBestKriterier()) && + !EMPTY_JSON.equals(bestilling.getBestKriterier())) + .filter(bestilling -> isNull(bestilling.getOpprettetFraGruppeId()) && + isNull(bestilling.getGjenopprettetFraIdent()) && + isNull(bestilling.getOpprettetFraId())) + .forEach(bestilling -> { + var dollyBestilling = fromJson(bestilling.getBestKriterier()); + dollyBestilling.getEnvironments().addAll(toSet(bestilling.getMiljoer())); + dollyBestilling.setNavSyntetiskIdent(bestilling.getNavSyntetiskIdent()); + mapperFacade.map(dollyBestilling, aggregertRequest); + }); + + BestillingMal akkumulertMal; + var maler = bestillingMalRepository.findByBrukerAndMalNavn(bruker, name); + if (maler.isEmpty()) { + + akkumulertMal = bestillingMalRepository.save(BestillingMal.builder() + .bruker(bruker) + .malNavn(name) + .miljoer(String.join(",", aggregertRequest.getEnvironments())) + .bestKriterier(toJson(aggregertRequest)) + .build()); + } else { + + akkumulertMal = maler.getFirst(); + akkumulertMal.setMiljoer(String.join(",", aggregertRequest.getEnvironments())); + akkumulertMal.setBestKriterier(toJson(aggregertRequest)); + } + + return mapperFacade.map(akkumulertMal, RsMalBestilling.class); + } + + public static String getBruker(Bruker bruker) { + + if (isNull(bruker)) { + return ANONYM; + } + return switch (bruker.getBrukertype()) { + case AZURE, BANKID -> bruker.getBrukernavn(); + case BASIC -> bruker.getNavIdent(); + }; + } + + private static Set toSet(String miljoer) { + + return StringUtils.isNotBlank(miljoer) ? + Arrays.stream(miljoer.split(",")) + .collect(Collectors.toSet()) : + Collections.emptySet(); + } + + private String toJson(RsDollyUtvidetBestilling bestilling) { + + try { + return objectMapper.writeValueAsString(bestilling); + } catch (JsonProcessingException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); + } + } + + private RsDollyUtvidetBestilling fromJson(String json) { + + try { + return objectMapper.readValue(json, RsDollyUtvidetBestilling.class); + } catch (JsonProcessingException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); + } + } +} \ No newline at end of file diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/OrganisasjonBestillingMalService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/OrganisasjonBestillingMalService.java index 49df018d294..c576d6bd5c3 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/OrganisasjonBestillingMalService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/OrganisasjonBestillingMalService.java @@ -23,7 +23,7 @@ import java.util.stream.Collectors; import static java.util.Objects.nonNull; -import static no.nav.dolly.service.BestillingMalService.getBruker; +import static no.nav.dolly.service.MalBestillingService.getBruker; import static no.nav.dolly.util.CurrentAuthentication.getUserId; @Service diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/service/SplittGruppeService.java b/apps/dolly-backend/src/main/java/no/nav/dolly/service/SplittGruppeService.java index 05bcf05dabf..c5618670b90 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/service/SplittGruppeService.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/service/SplittGruppeService.java @@ -6,7 +6,7 @@ import no.nav.dolly.domain.jpa.Testgruppe; import no.nav.dolly.domain.jpa.Testident; import no.nav.dolly.exceptions.NotFoundException; -import no.nav.dolly.mapper.strategy.BestillingMapper; +import no.nav.dolly.mapper.BestillingMapper; import no.nav.dolly.repository.BestillingKontrollRepository; import no.nav.dolly.repository.BestillingProgressRepository; import no.nav.dolly.repository.BestillingRepository; diff --git a/apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/BestillingControllerTest.java b/apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/BestillingControllerTest.java index ea7b9a628f6..f56d00aa621 100644 --- a/apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/BestillingControllerTest.java +++ b/apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/BestillingControllerTest.java @@ -1,10 +1,8 @@ package no.nav.dolly.provider.api; import ma.glasnost.orika.MapperFacade; -import no.nav.dolly.bestilling.service.DollyBestillingService; import no.nav.dolly.domain.jpa.Bestilling; import no.nav.dolly.domain.resultset.entity.bestilling.RsBestillingStatus; -import no.nav.dolly.service.BestillingMalService; import no.nav.dolly.service.BestillingService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -34,12 +32,6 @@ class BestillingControllerTest { @Mock private BestillingService bestillingService; - @Mock - private DollyBestillingService dollyBestillingService; - - @Mock - private BestillingMalService bestillingMalService; - @InjectMocks private BestillingController bestillingController; @@ -60,7 +52,7 @@ void getBestillingerOk() { when(mapperFacade.mapAsList(anyList(), eq(RsBestillingStatus.class))) .thenReturn(singletonList(RsBestillingStatus.builder().id(BESTILLING_ID).build())); - RsBestillingStatus bestilling = bestillingController.getBestillinger(GRUPPE_ID, 0, 10).get(0); + RsBestillingStatus bestilling = bestillingController.getBestillinger(GRUPPE_ID, 0, 10).getFirst(); verify(bestillingService).getBestillingerFromGruppeIdPaginert(GRUPPE_ID, 0, 10); verify(mapperFacade).mapAsList(anyList(), eq(RsBestillingStatus.class)); @@ -76,12 +68,4 @@ void stopBestillingProgressOk() { verify(bestillingService).cancelBestilling(BESTILLING_ID); verify(mapperFacade).map(any(Bestilling.class), eq(RsBestillingStatus.class)); } - - @Test - void malBestillingNavnOk() { - - bestillingController.getMalBestillinger(null); - - verify(bestillingMalService).getMalBestillinger(); - } } diff --git a/apps/dolly-backend/src/test/java/no/nav/dolly/service/BestillingMalServiceTest.java b/apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/MalBestillingControllerTest.java similarity index 86% rename from apps/dolly-backend/src/test/java/no/nav/dolly/service/BestillingMalServiceTest.java rename to apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/MalBestillingControllerTest.java index 3397428469a..2879d3ae1ba 100644 --- a/apps/dolly-backend/src/test/java/no/nav/dolly/service/BestillingMalServiceTest.java +++ b/apps/dolly-backend/src/test/java/no/nav/dolly/provider/api/MalBestillingControllerTest.java @@ -1,4 +1,4 @@ -package no.nav.dolly.service; +package no.nav.dolly.provider.api; import no.nav.dolly.MockedJwtAuthenticationTokenUtils; import no.nav.dolly.domain.jpa.Bestilling; @@ -30,9 +30,13 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasSize; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -42,7 +46,7 @@ @EnableAutoConfiguration @ComponentScan("no.nav.dolly") @AutoConfigureMockMvc(addFilters = false) -class BestillingMalServiceTest { +class MalBestillingControllerTest { @MockBean @SuppressWarnings("unused") @@ -54,7 +58,7 @@ class BestillingMalServiceTest { private final static String MALNAVN = "test"; private final static String NYTT_MALNAVN = "nyttMalnavn"; - private final static String BEST_KRITERIER = "Testeteste"; + private final static String BEST_KRITERIER = "{\"test\":true}"; private static final Bruker DUMMY_EN = Bruker.builder() .brukerId("testbruker_en") .brukernavn("test_en") @@ -67,6 +71,12 @@ class BestillingMalServiceTest { .brukertype(Bruker.Brukertype.AZURE) .epost("epost@test_to") .build(); + private static final Bruker DUMMY_TRE = Bruker.builder() + .brukerId("123") + .brukernavn("test_tre") + .brukertype(Bruker.Brukertype.AZURE) + .epost("epost@test_tre") + .build(); private static final String IDENT = "12345678912"; private static final String BESKRIVELSE = "Teste"; private static final String TESTGRUPPE = "Testgruppe"; @@ -92,6 +102,7 @@ public void beforeEach() { flyway.migrate(); saveDummyBruker(DUMMY_EN); saveDummyBruker(DUMMY_TO); + saveDummyBruker(DUMMY_TRE); MockedJwtAuthenticationTokenUtils.setJwtAuthenticationToken(); } @@ -111,14 +122,13 @@ void shouldCreateAndGetMaler() saveDummyBestillingMal(bruker_en); saveDummyBestillingMal(bruker_to); - mockMvc.perform(get("/api/v1/bestilling/malbestilling")) + mockMvc.perform(get("/api/v1/malbestilling")) .andExpect(status().isOk()) .andExpect(jsonPath("$.malbestillinger.ALLE", hasSize(2))) .andExpect(jsonPath("$.malbestillinger.test_en", hasSize(1))) .andExpect(jsonPath("$.malbestillinger.test_to", hasSize(1))) .andExpect(jsonPath("$.malbestillinger.test_en[0].malNavn").value(MALNAVN)) .andExpect(jsonPath("$.malbestillinger.test_en[0].bruker.brukerId").value(bruker_en.getBrukerId())) - .andExpect(jsonPath("$.malbestillinger.test_en[0].bestilling.navSyntetiskIdent", is(true))) .andExpect(jsonPath("$.malbestillinger.test_to[0].bruker.brukerId").value(bruker_to.getBrukerId())); } @@ -132,12 +142,12 @@ void shouldCreateMalerFromExistingOrder() var testgruppe = saveDummyGruppe(); var bestilling = saveDummyBestilling(bruker_en, testgruppe); - mockMvc.perform(post("/api/v1/bestilling/malbestilling") + mockMvc.perform(post("/api/v1/malbestilling") .queryParam("bestillingId", String.valueOf(bestilling.getId())) .queryParam("malNavn", MALNAVN)) .andExpect(status().isOk()); - mockMvc.perform(post("/api/v1/bestilling/malbestilling") + mockMvc.perform(post("/api/v1/malbestilling") .queryParam("bestillingId", UGYLDIG_BESTILLINGID) .queryParam("malNavn", MALNAVN)) .andExpect(status().is4xxClientError()); @@ -152,18 +162,18 @@ void shouldCreateUpdateAndDeleteMal() var bruker_en = brukerRepository.findBrukerByBrukerId(DUMMY_EN.getBrukerId()).orElseThrow(); var bestillingMal = saveDummyBestillingMal(bruker_en); - mockMvc.perform(put("/api/v1/bestilling/malbestilling/{id}", bestillingMal.getId()) + mockMvc.perform(put("/api/v1/malbestilling/id/{id}", bestillingMal.getId()) .queryParam("malNavn", NYTT_MALNAVN)) .andExpect(status().isOk()); - mockMvc.perform(get("/api/v1/bestilling/malbestilling")) + mockMvc.perform(get("/api/v1/malbestilling")) .andExpect(status().isOk()) .andExpect(jsonPath("$.malbestillinger.test_en", hasSize(1))); - mockMvc.perform(delete("/api/v1/bestilling/malbestilling/{id}", bestillingMal.getId())) + mockMvc.perform(delete("/api/v1/malbestilling/id/{id}", bestillingMal.getId())) .andExpect(status().isOk()); - mockMvc.perform(get("/api/v1/bestilling/malbestilling")) + mockMvc.perform(get("/api/v1/malbestilling")) .andExpect(status().isOk()) .andExpect(jsonPath("$.malbestillinger.ALLE", empty())); } diff --git a/apps/dolly-backend/src/test/java/no/nav/dolly/service/OrganisasjonBestillingMalServiceTest.java b/apps/dolly-backend/src/test/java/no/nav/dolly/service/OrganisasjonMalBestillingServiceTest.java similarity index 99% rename from apps/dolly-backend/src/test/java/no/nav/dolly/service/OrganisasjonBestillingMalServiceTest.java rename to apps/dolly-backend/src/test/java/no/nav/dolly/service/OrganisasjonMalBestillingServiceTest.java index 2caa2dc8316..fe745d24d26 100644 --- a/apps/dolly-backend/src/test/java/no/nav/dolly/service/OrganisasjonBestillingMalServiceTest.java +++ b/apps/dolly-backend/src/test/java/no/nav/dolly/service/OrganisasjonMalBestillingServiceTest.java @@ -44,7 +44,7 @@ @EnableAutoConfiguration @ComponentScan("no.nav.dolly") @AutoConfigureMockMvc(addFilters = false) -class OrganisasjonBestillingMalServiceTest { +class OrganisasjonMalBestillingServiceTest { @MockBean @SuppressWarnings("unused") diff --git a/apps/dolly-frontend/src/main/js/cypress/e2e/Minside.cy.ts b/apps/dolly-frontend/src/main/js/cypress/e2e/Minside.cy.ts index 4b15e3bb817..e91e36559b3 100644 --- a/apps/dolly-frontend/src/main/js/cypress/e2e/Minside.cy.ts +++ b/apps/dolly-frontend/src/main/js/cypress/e2e/Minside.cy.ts @@ -1,7 +1,7 @@ import { CypressSelector } from '../mocks/Selectors' import { brukerMalerEndretMock } from '../mocks/BasicMocks' -const brukerMaler = new RegExp(/dolly-backend\/api\/v1\/bestilling\/malbestilling\?brukerId/) +const brukerMaler = new RegExp(/dolly-backend\/api\/v1\/malbestilling\?brukerId/) describe('Minside mal testing', () => { it('passes', () => { diff --git a/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts b/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts index eab8ae75428..99d64061da0 100644 --- a/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts +++ b/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts @@ -81,8 +81,8 @@ const udistub = new RegExp(/testnav-udistub-proxy\/api\/v1/) const brregstub = new RegExp(/testnav-brregstub/) const medl = new RegExp(/testnav-medl-proxy/) const sigrunstub = new RegExp(/testnav-sigrunstub-proxy\/api\/v1\/lignetinntekt/) -const alleMaler = new RegExp(/dolly-backend\/api\/v1\/bestilling\/malbestilling$/) -const brukerMaler = new RegExp(/dolly-backend\/api\/v1\/bestilling\/malbestilling\?brukerId/) +const alleMaler = new RegExp(/dolly-backend\/api\/v1\/malbestilling$/) +const brukerMaler = new RegExp(/dolly-backend\/api\/v1\/malbestilling\?brukerId/) const oppsummeringsdokService = new RegExp( /oppsummeringsdokument-service\/api\/v1\/oppsummeringsdokumenter/, ) diff --git a/apps/dolly-frontend/src/main/js/src/components/bestilling/detaljer/BestillingDetaljer.tsx b/apps/dolly-frontend/src/main/js/src/components/bestilling/detaljer/BestillingDetaljer.tsx index d9e1b06ba86..1d66ae3213a 100644 --- a/apps/dolly-frontend/src/main/js/src/components/bestilling/detaljer/BestillingDetaljer.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/bestilling/detaljer/BestillingDetaljer.tsx @@ -4,7 +4,7 @@ import BestillingSammendrag from '@/components/bestilling/sammendrag/BestillingS import GjenopprettConnector from '@/components/bestilling/gjenopprett/GjenopprettBestillingConnector' import './BestillingDetaljer.less' -import { MalModal } from '@/pages/minSide/maler/MalModal' +import { MalModal, malTyper } from '@/pages/minSide/maler/MalModal' import _ from 'lodash' import { SlettButton } from '@/components/ui/button/SlettButton/SlettButton' import React from 'react' @@ -65,7 +65,7 @@ export default function BestillingDetaljer({ bestilling, iLaastGruppe, brukerId, kind={'maler'} className="svg-icon-blue" > - OPPRETT NY MAL + OPPRETT MAL )}
)} @@ -109,7 +109,11 @@ export default function BestillingDetaljer({ bestilling, iLaastGruppe, brukerId, )} {isMalModalOpen && ( - + )} ) diff --git a/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx b/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx index be1e792ae3f..975c570ae80 100644 --- a/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx +++ b/apps/dolly-frontend/src/main/js/src/pages/gruppe/PersonVisning/PersonVisning.tsx @@ -86,6 +86,8 @@ import { import { usePensjonEnvironments } from '@/utils/hooks/useEnvironments' import { SigrunstubPensjonsgivendeVisning } from '@/components/fagsystem/sigrunstubPensjonsgivende/visning/Visning' import { useUdistub } from '@/utils/hooks/useUdistub' +import useBoolean from '@/utils/hooks/useBoolean' +import { MalModal, malTyper } from '@/pages/minSide/maler/MalModal' import { useTenorOversikt } from '@/utils/hooks/useTenorSoek' import { SkatteetatenVisning } from '@/components/fagsystem/skatteetaten/visning/SkatteetatenVisning' @@ -114,6 +116,8 @@ export default ({ }) => { const { gruppeId } = ident + const [isMalModalOpen, openMalModal, closeMalModal] = useBoolean(false) + const { organisasjonTilgang } = useOrganisasjonTilgang() const tilgjengeligMiljoe = organisasjonTilgang?.miljoe @@ -394,6 +398,11 @@ export default ({ master={ident?.master} /> )} + {bestillingIdListe?.length > 0 && ( + + )} {!iLaastGruppe && ident.master !== 'PDL' && ( @@ -531,6 +540,9 @@ export default ({ /> + {isMalModalOpen && ( + + )} ) diff --git a/apps/dolly-frontend/src/main/js/src/pages/minSide/maler/MalModal.tsx b/apps/dolly-frontend/src/main/js/src/pages/minSide/maler/MalModal.tsx index 7587f2ca1ba..06c879586eb 100644 --- a/apps/dolly-frontend/src/main/js/src/pages/minSide/maler/MalModal.tsx +++ b/apps/dolly-frontend/src/main/js/src/pages/minSide/maler/MalModal.tsx @@ -7,25 +7,59 @@ import { Label } from '@/components/ui/form/inputs/label/Label' import { DollyApi } from '@/service/Api' import { REGEX_BACKEND_BESTILLINGER, + REGEX_BACKEND_GRUPPER, REGEX_BACKEND_ORGANISASJONER, useMatchMutate, } from '@/utils/hooks/useMutate' import { FormProvider, useForm } from 'react-hook-form' import { CypressSelector } from '../../../../cypress/mocks/Selectors' -export const MalModal = ({ id, erOrganisasjon, closeModal }) => { +export const malTyper = { + ORGANISASJON: 'ORGANISASJON', + BESTILLING: 'BESTILLING', + PERSON: 'PERSON', +} + +export const MalModal = ({ id, malType, closeModal }) => { const [nyttMalnavn, setMalnavn] = useState('') const matchMutate = useMatchMutate() const formMethods = useForm() + const lagreMal = () => { - erOrganisasjon - ? DollyApi.lagreOrganisasjonMalFraBestillingId(id, nyttMalnavn).then(() => + switch (malType) { + case malTyper.ORGANISASJON: + DollyApi.lagreOrganisasjonMalFraBestillingId(id, nyttMalnavn).then(() => matchMutate(REGEX_BACKEND_ORGANISASJONER), ) - : DollyApi.lagreMalFraBestillingId(id, nyttMalnavn).then(() => + closeModal() + break + case malTyper.BESTILLING: + DollyApi.lagreMalFraBestillingId(id, nyttMalnavn).then(() => matchMutate(REGEX_BACKEND_BESTILLINGER), ) - closeModal() + closeModal() + break + case malTyper.PERSON: + DollyApi.opprettMalFraPerson(id, nyttMalnavn).then(() => matchMutate(REGEX_BACKEND_GRUPPER)) + closeModal() + break + default: + closeModal() + break + } + } + + let topic + switch (malType) { + case malTyper.ORGANISASJON: + topic = 'organisasjon' + break + case malTyper.BESTILLING: + topic = 'bestilling' + break + case malTyper.PERSON: + topic = 'person' + break } return ( @@ -33,7 +67,7 @@ export const MalModal = ({ id, erOrganisasjon, closeModal }) => {
-

Opprett ny mal

+

Opprett mal fra {topic}