Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/inntekt altinn joark #3508

Merged
merged 11 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/inntektsmelding-generator-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {

test {
useJUnitPlatform()
jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
}

sonarqube {
Expand All @@ -26,6 +27,7 @@ sonarqube {
}
bootJar {
archiveFileName = "app.jar"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

dependencyManagement {
Expand Down Expand Up @@ -57,18 +59,17 @@ dependencies {

implementation 'org.aspectj:aspectjweaver:1.9.22'

implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
implementation 'javax.json.bind:javax.json.bind-api:1.0'
implementation 'javax.activation:activation:1.1.1'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.2'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.5'
implementation 'com.sun.xml.bind:jaxb-impl:4.0.5'
implementation 'com.sun.xml.bind:jaxb-core:4.0.5'

implementation 'ma.glasnost.orika:orika-core:1.5.4'

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
implementation 'org.apache.commons:commons-text:1.11.0'

implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation 'no.nav.tjenestespesifikasjoner:nav-altinn-inntektsmelding:1.2019.09.25-00.21-49b69f0625e0'
stigus marked this conversation as resolved.
Show resolved Hide resolved


testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package no.nav.registre.inntektsmeldinggeneratorservice.provider;

import io.swagger.v3.core.util.Json;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.registre.inntektsmeldinggeneratorservice.exception.JaxbToXmlException;
Expand All @@ -11,9 +14,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package no.nav.registre.inntektsmeldinggeneratorservice.provider;
stigus marked this conversation as resolved.
Show resolved Hide resolved

import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLInntektsmeldingM;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLSkjemainnhold;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlSeeAlso;
import no.nav.registre.inntektsmeldinggeneratorservice.xml.InntektsmeldingM;
import no.nav.registre.inntektsmeldinggeneratorservice.xml.Skjemainnhold;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.namespace.QName;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -15,13 +15,13 @@

@XmlRootElement(name = "melding")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({ XMLInntektsmeldingM.class, LocalDate.class, LocalDateTime.class })
public class Melding extends XMLInntektsmeldingM {
@XmlSeeAlso({ InntektsmeldingM.class, LocalDate.class, LocalDateTime.class })
public class Melding extends InntektsmeldingM {

public Melding() {
}

public Melding(XMLSkjemainnhold skjemainnhold, Map<QName, String> otherAttributes) {
public Melding(Skjemainnhold skjemainnhold, Map<QName, String> otherAttributes) {
super(skjemainnhold, otherAttributes);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package no.nav.registre.inntektsmeldinggeneratorservice.util;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
import lombok.extern.slf4j.Slf4j;
import no.nav.registre.inntektsmeldinggeneratorservice.exception.JaxbToXmlException;
import org.apache.commons.text.CaseUtils;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
Expand All @@ -27,16 +27,17 @@ private XmlConverter() {

public static <T> String toXml(JAXBElement<T> value, Class<T> clazz) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
JAXBContext jaxbContext = JAXBContext.newInstance("no.nav.registre.inntektsmeldinggeneratorservice.v20181211.adapter", clazz.getClassLoader());
stigus marked this conversation as resolved.
Show resolved Hide resolved

Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);


StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(value, sw);

String xmlContent = sw.toString();
String xmlContent = sw.toString().replace("ns2:", "").replace(":ns2", "");
stigus marked this conversation as resolved.
Show resolved Hide resolved

log.debug("Opprettet xml: {}", xmlContent);
return xmlContent;
Expand All @@ -55,21 +56,6 @@ public static <T> boolean validate(String xml, Class<T> clazz) {
}
}


@SuppressWarnings("unchecked")
private static <T> T toObject(String xml, Class<T> clazz) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);

Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

return (T) unmarshaller.unmarshal(new StringReader(xml));

} catch (JAXBException e) {
throw new JaxbToXmlException("klarte ikke å konvertere Jaxb element til Objekt", e);
}
}

public static BigDecimal toBigDecimal(Double value) {

return nonNull(value) ? BigDecimal.valueOf(value) : null;
Expand All @@ -89,4 +75,18 @@ public static LocalDate toLocalDate(LocalDateTime localDateTime) {

return nonNull(localDateTime) ? localDateTime.toLocalDate() : null;
}

@SuppressWarnings("unchecked")
private static <T> void toObject(String xml, Class<T> clazz) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance("no.nav.registre.inntektsmeldinggeneratorservice.v20181211.adapter");

Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

unmarshaller.unmarshal(new StringReader(xml));

} catch (JAXBException e) {
throw new JaxbToXmlException("klarte ikke å konvertere Jaxb element til Objekt", e);
}
}
}
Loading