Skip to content

Commit

Permalink
Refactor config files and improve response status handling #deploy-tp…
Browse files Browse the repository at this point in the history
…s-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.
  • Loading branch information
krharum committed Mar 6, 2024
1 parent 43ca9da commit 3d4fd07
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +51,6 @@ public DoedsmeldingResponse annulerDoedsmelding(PersonDTO person, List<String> m

private void prepareStatus(Map<String, String> sentStatus) {

sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ExtractErrorStatus.extract(status));
sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ResponseStatus.extract(status));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,6 +35,6 @@ public FoedselsmeldingResponse sendFoedselsmelding(FoedselsmeldingRequest person

private void prepareStatus(Map<String, String> sentStatus) {

sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ExtractErrorStatus.extract(status));
sentStatus.replaceAll((env, status) -> status.matches("^00.*") ? "OK" : ResponseStatus.extract(status));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,13 +56,16 @@ public List<PersonhistorikkDTO> 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();
}

Expand Down Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions apps/tps-messaging-service/src/main/resources/bootstrap.yaml

This file was deleted.

0 comments on commit 3d4fd07

Please sign in to comment.