Skip to content

Commit

Permalink
Refactor Inntektsmelding generation code #deploy-inntektsmelding-gene…
Browse files Browse the repository at this point in the history
…rator-service

Simplified and improved the code for Inntektsmelding generation by removing unnecessary Optional wrappers in various classes. Replaced uses of the Objects.isNull method with direct comparison to null for readability. Also consolidated commonly used conversions in XmlInntektsmelding201812 to helper methods in the XmlConverter class.
  • Loading branch information
krharum committed Feb 6, 2024
1 parent 86b391c commit da668df
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.Map;

import static java.util.Objects.isNull;

@Component
public class XML201809Validator {

Expand All @@ -18,7 +20,7 @@ public static void validate(RsInntektsmelding inntektsmelding) throws Validation

Map<String, Boolean> rules = new HashMap<>();

rules.put("Må ha en arbeidsgiver.", inntektsmelding.getArbeidsgiver().isEmpty());
rules.put("Må ha en arbeidsgiver.", isNull(inntektsmelding.getArbeidsgiver()));

List<String> errors = rules.entrySet().stream()
.filter(s -> s.getValue().equals(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -10,6 +11,10 @@
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.BigInteger;

import static java.util.Objects.nonNull;

@Slf4j
public class XmlConverter {
Expand Down Expand Up @@ -62,4 +67,19 @@ private static <T> T toObject(String xml, Class<T> clazz) {
throw new JaxbToXmlException("klarte ikke å konvertere Jaxb element til Objekt", e);
}
}

public static BigDecimal toBigDecimal(Double value) {

return nonNull(value) ? BigDecimal.valueOf(value) : null;
}

public static BigInteger toBigInteger(Integer value) {

return nonNull(value) ? BigInteger.valueOf(value) : null;
}

public static String toCamelCase(String value) {

return nonNull(value) ? CaseUtils.toCamelCase(value, true, '_') : null;
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.Value;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.enums.YtelseKodeListe;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.enums.AarsakInnsendingKodeListe;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.enums.YtelseKodeListe;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsArbeidsforhold;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsArbeidsgiver;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsArbeidsgiverPrivat;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsAvsendersystem;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsNaturalytelseDetaljer;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsOmsorgspenger;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsPeriode;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsRefusjon;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsSykepengerIArbeidsgiverperioden;
import no.nav.testnav.libs.dto.inntektsmeldinggeneratorservice.v1.rs.RsNaturalytelseDetaljer;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Objects;


@Value
Expand Down Expand Up @@ -72,10 +71,6 @@ public class RsInntektsmeldingRequest {
@JsonProperty
private List<RsPeriode> pleiepengerPerioder;

public RsAvsendersystem getAvsendersystem() {
return Objects.requireNonNullElse(avsendersystem, new RsAvsendersystem());
}

public List<RsNaturalytelseDetaljer> getOpphoerAvNaturalytelseListe() {
return Objects.requireNonNullElse(opphoerAvNaturalytelseListe, Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -27,18 +26,6 @@ public class RsArbeidsforhold {
@JsonProperty
private List<RsGraderingIForeldrepenger> graderingIForeldrepengerListe;

public Optional<String> getArbeidsforholdId() {
return Optional.ofNullable(arbeidsforholdId);
}

public Optional<LocalDate> getFoersteFravaersdag() {
return Optional.ofNullable(foersteFravaersdag);
}

public Optional<RsInntekt> getBeregnetInntekt() {
return Optional.ofNullable(beregnetInntekt);
}

public List<RsPeriode> getAvtaltFerieListe() {
return Objects.requireNonNullElse(avtaltFerieListe, Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -15,12 +14,4 @@ public class RsDelvisFravaer {
private LocalDate dato;
@JsonProperty
private Double timer;

public Optional<LocalDate> getDato() {
return Optional.ofNullable(dato);
}

public Optional<Double> getTimer() {
return Optional.ofNullable(timer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -17,12 +16,4 @@ public class RsEndringIRefusjon {
private LocalDate endringsdato;
@JsonProperty
private Double refusjonsbeloepPrMnd;

public Optional<LocalDate> getEndringsdato() {
return Optional.ofNullable(endringsdato);
}

public Optional<Double> getRefusjonsbeloepPrMnd() {
return Optional.ofNullable(refusjonsbeloepPrMnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

@Data
@NoArgsConstructor
public class RsGraderingIForeldrepenger {
Expand All @@ -14,12 +12,4 @@ public class RsGraderingIForeldrepenger {
private RsPeriode periode;
@JsonProperty
private Integer arbeidstidprosent;

public Optional<RsPeriode> getPeriode() {
return Optional.ofNullable(periode);
}

public Optional<Integer> getArbeidstidprosent() {
return Optional.ofNullable(arbeidstidprosent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

@Data
@NoArgsConstructor
public class RsInntekt {
Expand All @@ -14,12 +12,4 @@ public class RsInntekt {
private Double beloep;
@JsonProperty
private String aarsakVedEndring;

public Optional<Double> getBeloep() {
return Optional.ofNullable(beloep);
}

public Optional<String> getAarsakVedEndring() {
return Optional.ofNullable(aarsakVedEndring);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Data
@Builder
Expand Down Expand Up @@ -54,22 +53,6 @@ public class RsInntektsmelding {
@JsonProperty
private List<RsPeriode> pleiepengerPerioder;

public Optional<RsArbeidsgiver> getArbeidsgiver() {
return Optional.ofNullable(arbeidsgiver);
}

public Optional<RsArbeidsgiverPrivat> getArbeidsgiverPrivat() {
return Optional.ofNullable(arbeidsgiverPrivat);
}

public Optional<RsRefusjon> getRefusjon() {
return Optional.ofNullable(refusjon);
}

public Optional<RsOmsorgspenger> getOmsorgspenger() {
return Optional.ofNullable(omsorgspenger);
}

public RsAvsendersystem getAvsendersystem() {
return Objects.requireNonNullElse(avsendersystem, new RsAvsendersystem());
}
Expand All @@ -85,12 +68,4 @@ public List<RsNaturalytelseDetaljer> getGjenopptakelseNaturalytelseListe() {
public List<RsPeriode> getPleiepengerPerioder() {
return Objects.requireNonNullElse(pleiepengerPerioder, Collections.emptyList());
}

public Optional<RsSykepengerIArbeidsgiverperioden> getSykepengerIArbeidsgiverPerioden() {
return Optional.ofNullable(sykepengerIArbeidsgiverperioden);
}

public Optional<LocalDate> getStartdatoForeldrepengeperiode() {
return Optional.ofNullable(startdatoForeldrepengeperiode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -17,16 +16,4 @@ public class RsNaturalytelseDetaljer {
private LocalDate fom;
@JsonProperty
private Double beloepPrMnd;

public Optional<String> getNaturaytelseType() {
return Optional.ofNullable(naturaytelseType);
}

public Optional<LocalDate> getFom() {
return Optional.ofNullable(fom);
}

public Optional<Double> getBeloepPrMnd() {
return Optional.ofNullable(beloepPrMnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -20,10 +19,6 @@ public class RsOmsorgspenger {
@JsonProperty
private List<RsDelvisFravaer> delvisFravaersListe;

public Optional<Boolean> getHarUtbetaltPliktigeDager() {
return Optional.ofNullable(harUtbetaltPliktigeDager);
}

public List<RsPeriode> getFravaersPerioder() {
return Objects.requireNonNullElse(fravaersPerioder, Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -15,12 +14,4 @@ public class RsPeriode {
private LocalDate fom;
@JsonProperty
private LocalDate tom;

public Optional<LocalDate> getFom() {
return Optional.ofNullable(fom);
}

public Optional<LocalDate> getTom() {
return Optional.ofNullable(tom);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -21,14 +20,6 @@ public class RsRefusjon {
@JsonProperty
private List<RsEndringIRefusjon> endringIRefusjonListe;

public Optional<Double> getRefusjonsbeloepPrMnd() {
return Optional.ofNullable(refusjonsbeloepPrMnd);
}

public Optional<LocalDate> getRefusjonsopphoersdato() {
return Optional.ofNullable(refusjonsopphoersdato);
}

public List<RsEndringIRefusjon> getEndringIRefusjonListe() {
return Objects.requireNonNullElse(endringIRefusjonListe, Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Optional;

@Data
@NoArgsConstructor
Expand All @@ -17,16 +16,4 @@ public class RsSykepengerIArbeidsgiverperioden {
private Double bruttoUtbetalt;
@JsonProperty
private String begrunnelseForReduksjonEllerIkkeUtbetalt;

public Optional<List<RsPeriode>> getArbeidsgiverperiodeListe() {
return Optional.ofNullable(arbeidsgiverperiodeListe);
}

public Optional<Double> getBruttoUtbetalt() {
return Optional.ofNullable(bruttoUtbetalt);
}

public Optional<String> getBegrunnelseForReduksjonEllerIkkeUtbetalt() {
return Optional.ofNullable(begrunnelseForReduksjonEllerIkkeUtbetalt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

@Data
@NoArgsConstructor
public class RsUtsettelseAvForeldrepenger {
Expand All @@ -14,12 +12,4 @@ public class RsUtsettelseAvForeldrepenger {
private RsPeriode periode;
@JsonProperty
private String aarsakTilUtsettelse;

public Optional<RsPeriode> getPeriode() {
return Optional.ofNullable(periode);
}

public Optional<String> getAarsakTilUtsettelse() {
return Optional.ofNullable(aarsakTilUtsettelse);
}
}

0 comments on commit da668df

Please sign in to comment.