diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/dto/TpsServicerutineM201Response.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/dto/TpsServicerutineM201Response.java index b76558092d7..ec19307221e 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/dto/TpsServicerutineM201Response.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/dto/TpsServicerutineM201Response.java @@ -3,6 +3,9 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -18,26 +21,19 @@ @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) +@XmlRootElement(name = "tpsPersonData") +@XmlType(propOrder = {"tpsServiceRutine", "tpsSvar"}) public class TpsServicerutineM201Response { - private TpsPersonData tpsPersonData; - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - @JsonInclude(JsonInclude.Include.NON_EMPTY) - public static class TpsPersonData { - - private TpsServiceRutineType tpsServiceRutine; - private TpsSvar tpsSvar; - } + private TpsServiceRutineType tpsServiceRutine; + private TpsSvar tpsSvar; @Data @Builder @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) + @XmlType(propOrder = {"svarStatus", "personDataM201"}) public static class TpsSvar { private TpsMeldingResponse svarStatus; @@ -49,10 +45,11 @@ public static class TpsSvar { @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) + @XmlType(propOrder = {"antallFM201", "AFnr"}) public static class PersondataFraTpsM201 { private int antallFM201; - private AFnr AFnr; + private AFnr aFnr; } @Data @@ -60,17 +57,19 @@ public static class PersondataFraTpsM201 { @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) + @XmlType(propOrder = "EFnr") public static class AFnr { @JacksonXmlCData @JacksonXmlElementWrapper(useWrapping = false) - private List EFnr; + @JacksonXmlProperty(localName = "eFnr") + private List eFnr; public List getEFnr() { - if (Objects.isNull(EFnr)) { - EFnr = new ArrayList<>(); + if (Objects.isNull(eFnr)) { + eFnr = new ArrayList<>(); } - return EFnr; + return eFnr; } } @@ -79,6 +78,7 @@ public List getEFnr() { @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_EMPTY) + @XmlType(propOrder = {"fnr", "sp", "kn", "fn", "mn", "en", "svarStatus"}) public static class EFnr { private String fnr; @@ -89,4 +89,4 @@ public static class EFnr { private String en; private TpsMeldingResponse svarStatus; } -} +} \ No newline at end of file diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java index 19ec3173274..ea4dfcb36d3 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java @@ -1,6 +1,9 @@ package no.nav.testnav.apps.tpsmessagingservice.service; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import no.nav.testnav.apps.tpsmessagingservice.consumer.ServicerutineConsumer; @@ -10,7 +13,6 @@ import no.nav.testnav.apps.tpsmessagingservice.exception.BadRequestException; import no.nav.testnav.apps.tpsmessagingservice.utils.EndringsmeldingUtil; import no.nav.testnav.libs.data.tpsmessagingservice.v1.TpsIdentStatusDTO; -import org.json.XML; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -33,15 +35,22 @@ public class IdentService { private final ServicerutineConsumer servicerutineConsumer; private final TestmiljoerServiceConsumer testmiljoerServiceConsumer; - private final ObjectMapper objectMapper; + private final XmlMapper xmlMapper; public IdentService(ServicerutineConsumer servicerutineConsumer, - TestmiljoerServiceConsumer testmiljoerServiceConsumer, - ObjectMapper objectMapper) { + TestmiljoerServiceConsumer testmiljoerServiceConsumer) { this.servicerutineConsumer = servicerutineConsumer; this.testmiljoerServiceConsumer = testmiljoerServiceConsumer; - this.objectMapper = objectMapper; + this.xmlMapper = XmlMapper + .builder() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) + .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true) + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .build(); } public List getIdenter(List identer, List miljoer, Boolean includeProd) { @@ -74,10 +83,10 @@ public List getIdenter(List identer, List mil private boolean exists(String ident, TpsServicerutineM201Response response) { - return nonNull(response.getTpsPersonData()) && nonNull(response.getTpsPersonData().getTpsSvar()) && - nonNull(response.getTpsPersonData().getTpsSvar().getPersonDataM201()) && - nonNull(response.getTpsPersonData().getTpsSvar().getPersonDataM201().getAFnr()) && - response.getTpsPersonData().getTpsSvar().getPersonDataM201().getAFnr().getEFnr().stream() + return nonNull(response.getTpsSvar()) && + nonNull(response.getTpsSvar().getPersonDataM201()) && + nonNull(response.getTpsSvar().getPersonDataM201().getAFnr()) && + response.getTpsSvar().getPersonDataM201().getAFnr().getEFnr().stream() .anyMatch(eFnr -> ident.equals(eFnr.getFnr()) && isNull(eFnr.getSvarStatus())); } @@ -102,16 +111,13 @@ private TpsServicerutineM201Response unmarshallFromXml(String endringsmeldingRes if (TpsMeldingCommand.NO_RESPONSE.equals(endringsmeldingResponse)) { return TpsServicerutineM201Response.builder() - .tpsPersonData(TpsServicerutineM201Response.TpsPersonData.builder() - .tpsSvar(TpsServicerutineM201Response.TpsSvar.builder() - .svarStatus(EndringsmeldingUtil.getNoAnswerStatus()) - .build()) + .tpsSvar(TpsServicerutineM201Response.TpsSvar.builder() + .svarStatus(EndringsmeldingUtil.getNoAnswerStatus()) .build()) .build(); } else { - var jsonRoot = XML.toJSONObject(endringsmeldingResponse); - return objectMapper.readValue(jsonRoot.toString(), TpsServicerutineM201Response.class); + return xmlMapper.readValue(endringsmeldingResponse, TpsServicerutineM201Response.class); } }