From 3d4fd07a6777fd3f3cc05ad811051a2e4e224039 Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Wed, 6 Mar 2024 14:46:08 +0100 Subject: [PATCH] Refactor config files and improve response status handling #deploy-tps-messaging-service Removed bootstrap.yaml and re-structured application.yaml and application-prod.yaml to better manage configuration across environments. The code for handling TPS response status was improved by creating the ResponseStatus class, which deciphers the status and extracts error details if necessary. These changes aim to increase clarity and maintainability of YAML configurations and status handling. --- .../service/DoedsmeldingService.java | 4 +-- .../service/FoedselsmeldingService.java | 4 +-- .../service/PersonHistorikkService.java | 26 +++++++++++-------- ...ctErrorStatus.java => ResponseStatus.java} | 13 +++++++++- .../src/main/resources/application-prod.yaml | 12 +++++++++ .../src/main/resources/application.yaml | 5 +--- .../src/main/resources/bootstrap.yaml | 4 --- 7 files changed, 44 insertions(+), 24 deletions(-) rename apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/{ExtractErrorStatus.java => ResponseStatus.java} (52%) create mode 100644 apps/tps-messaging-service/src/main/resources/application-prod.yaml delete mode 100644 apps/tps-messaging-service/src/main/resources/bootstrap.yaml diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/DoedsmeldingService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/DoedsmeldingService.java index db7fea47a78..f0ab4f71682 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/DoedsmeldingService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/DoedsmeldingService.java @@ -4,7 +4,7 @@ import no.nav.testnav.apps.tpsmessagingservice.service.skd.DoedsmeldingAnnulleringBuilderService; import no.nav.testnav.apps.tpsmessagingservice.service.skd.DoedsmeldingBuilderService; import no.nav.testnav.apps.tpsmessagingservice.service.skd.SendSkdMeldinger; -import no.nav.testnav.apps.tpsmessagingservice.utils.ExtractErrorStatus; +import no.nav.testnav.apps.tpsmessagingservice.utils.ResponseStatus; import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO; import no.nav.testnav.libs.data.tpsmessagingservice.v1.DoedsmeldingResponse; import org.springframework.stereotype.Service; @@ -51,6 +51,6 @@ public DoedsmeldingResponse annulerDoedsmelding(PersonDTO person, List m private void prepareStatus(Map sentStatus) { - sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ExtractErrorStatus.extract(status)); + sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ResponseStatus.extract(status)); } } diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/FoedselsmeldingService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/FoedselsmeldingService.java index 5e000e51ec6..45edef11a07 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/FoedselsmeldingService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/FoedselsmeldingService.java @@ -4,7 +4,7 @@ import no.nav.testnav.apps.tpsmessagingservice.dto.endringsmeldinger.SkdMeldingTrans1; import no.nav.testnav.apps.tpsmessagingservice.service.skd.FoedselsmeldingBuilderService; import no.nav.testnav.apps.tpsmessagingservice.service.skd.SendSkdMeldinger; -import no.nav.testnav.apps.tpsmessagingservice.utils.ExtractErrorStatus; +import no.nav.testnav.apps.tpsmessagingservice.utils.ResponseStatus; import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingRequest; import no.nav.testnav.libs.data.tpsmessagingservice.v1.FoedselsmeldingResponse; import org.springframework.stereotype.Service; @@ -35,6 +35,6 @@ public FoedselsmeldingResponse sendFoedselsmelding(FoedselsmeldingRequest person private void prepareStatus(Map sentStatus) { - sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ExtractErrorStatus.extract(status)); + sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ResponseStatus.extract(status)); } } diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/PersonHistorikkService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/PersonHistorikkService.java index 219afe8fc6e..b6f2951cb77 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/PersonHistorikkService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/PersonHistorikkService.java @@ -12,6 +12,7 @@ import no.nav.testnav.apps.tpsmessagingservice.dto.TpsServicerutineAksjonsdatoRequest; import no.nav.testnav.apps.tpsmessagingservice.dto.TpsServicerutineS018Response; import no.nav.testnav.apps.tpsmessagingservice.utils.EndringsmeldingUtil; +import no.nav.testnav.apps.tpsmessagingservice.utils.ResponseStatus; import no.nav.testnav.apps.tpsmessagingservice.utils.ServiceRutineUtil; import no.nav.testnav.libs.data.tpsmessagingservice.v1.PersonhistorikkDTO; import no.nav.tps.xjc.ctg.domain.s018.SRnavnType; @@ -55,13 +56,16 @@ public List hentIdent(String ident, LocalDate aksjonsdato, L var tpsPersoner = readFromTps(ident, aksjonsdato, miljoer); return tpsPersoner.entrySet().stream() - .map(entry -> PersonhistorikkDTO.builder() - .miljoe(entry.getKey()) - .status(mapperFacade.map(entry.getValue().getTpsSvar(), PersonhistorikkDTO.TpsMeldingResponse.class)) - .persondata("OK".equals(entry.getValue().getTpsSvar().getSvarStatus().getReturStatus()) ? - mapperFacade.map(entry.getValue().getTpsSvar().getPersondataS018(), PersonhistorikkDTO.PersonData.class) : - null) - .build()) + .map(entry -> { + var status = ResponseStatus.decodeStatus(entry.getValue().getTpsSvar().getSvarStatus()); + return PersonhistorikkDTO.builder() + .miljoe(entry.getKey()) + .status(mapperFacade.map(status, PersonhistorikkDTO.TpsMeldingResponse.class)) + .persondata("OK".equals(status.getReturStatus()) ? + mapperFacade.map(entry.getValue().getTpsSvar().getPersondataS018(), PersonhistorikkDTO.PersonData.class) : + null) + .build(); + }) .toList(); } @@ -94,10 +98,10 @@ private TpsServicerutineS018Response unmarshallFromXml(String endringsmeldingRes if (TpsMeldingCommand.NO_RESPONSE.equals(endringsmeldingResponse)) { return TpsServicerutineS018Response.builder() - .tpsSvar(TpsServicerutineS018Response.TpsSvar.builder() - .svarStatus(EndringsmeldingUtil.getNoAnswerStatus()) - .build()) - .build(); + .tpsSvar(TpsServicerutineS018Response.TpsSvar.builder() + .svarStatus(EndringsmeldingUtil.getNoAnswerStatus()) + .build()) + .build(); } else { diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/ExtractErrorStatus.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/ResponseStatus.java similarity index 52% rename from apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/ExtractErrorStatus.java rename to apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/ResponseStatus.java index 01951eda8fc..090d8c46cfd 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/ExtractErrorStatus.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/utils/ResponseStatus.java @@ -1,14 +1,16 @@ package no.nav.testnav.apps.tpsmessagingservice.utils; import lombok.experimental.UtilityClass; +import no.nav.testnav.apps.tpsmessagingservice.dto.TpsMeldingResponse; import static java.lang.String.format; import static java.util.Objects.nonNull; @UtilityClass -public final class ExtractErrorStatus { +public final class ResponseStatus { public static String extract(String status) { + if (nonNull(status) && status.contains("FEIL")) { return status; } else if (nonNull(status) && status.length() > 3) { @@ -17,4 +19,13 @@ public static String extract(String status) { return "STATUS: TIDSAVBRUDD"; } } + + public static TpsMeldingResponse decodeStatus(TpsMeldingResponse response) { + + return TpsMeldingResponse.builder() + .returStatus("00".equals(response.getReturStatus()) || "04".equals(response.getReturStatus()) ? "OK" : "FEIL") + .returMelding(response.getReturMelding()) + .utfyllendeMelding(response.getUtfyllendeMelding()) + .build(); + } } \ No newline at end of file diff --git a/apps/tps-messaging-service/src/main/resources/application-prod.yaml b/apps/tps-messaging-service/src/main/resources/application-prod.yaml new file mode 100644 index 00000000000..d13db0f94c7 --- /dev/null +++ b/apps/tps-messaging-service/src/main/resources/application-prod.yaml @@ -0,0 +1,12 @@ + +spring: + security: + oauth2: + resourceserver: + tokenx: + issuer-uri: ${TOKEN_X_ISSUER} + jwk-set-uri: ${TOKEN_X_JWKS_URI} + accepted-audience: ${TOKEN_X_CLIENT_ID} + cloud: + vault: + enabled: false diff --git a/apps/tps-messaging-service/src/main/resources/application.yaml b/apps/tps-messaging-service/src/main/resources/application.yaml index d55c85176d4..2fd513cf407 100644 --- a/apps/tps-messaging-service/src/main/resources/application.yaml +++ b/apps/tps-messaging-service/src/main/resources/application.yaml @@ -12,10 +12,7 @@ spring: issuer-uri: ${AAD_ISSUER_URI}/v2.0 jwk-set-uri: ${AAD_ISSUER_URI}/discovery/v2.0/keys accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} - tokenx: - issuer-uri: ${TOKEN_X_ISSUER} - jwk-set-uri: ${TOKEN_X_JWKS_URI} - accepted-audience: ${TOKEN_X_CLIENT_ID} + cloud: vault: enabled: false diff --git a/apps/tps-messaging-service/src/main/resources/bootstrap.yaml b/apps/tps-messaging-service/src/main/resources/bootstrap.yaml deleted file mode 100644 index 0451449ca23..00000000000 --- a/apps/tps-messaging-service/src/main/resources/bootstrap.yaml +++ /dev/null @@ -1,4 +0,0 @@ -spring: - cloud: - vault: - enabled: false \ No newline at end of file