Skip to content

Commit cb5b3c8

Browse files
Feature/npe protection utbetalingspost (#480)
* fix: NPE protection utbetalt ytelse * fix: javax.valdation feil i mapping for enum verdier
1 parent 284571a commit cb5b3c8

26 files changed

+72
-133
lines changed

domenetjenester/iay/src/main/java/no/nav/foreldrepenger/abakus/domene/iay/Inntektspost.java

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ void setInntekt(Inntekt inntekt) {
167167
}
168168

169169
void setYtelse(UtbetaltYtelseType ytelse) {
170+
if (ytelse == null) {
171+
ytelse = UtbetaltYtelseFraOffentligeType.UDEFINERT;
172+
}
170173
this.ytelseType = ytelse.getKodeverk();
171174
this.ytelse = ytelse.getKode();
172175
}

kodeverk/src/main/java/no/nav/abakus/iaygrunnlag/kodeverk/Kodeverk.java

-67
This file was deleted.

kodeverk/src/main/java/no/nav/abakus/iaygrunnlag/kodeverk/Landkode.java

+24-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import java.util.Map;
88
import java.util.Objects;
99

10+
import javax.validation.constraints.Pattern;
11+
import javax.validation.constraints.Size;
12+
1013
import com.fasterxml.jackson.annotation.JsonAutoDetect;
1114
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
1215
import com.fasterxml.jackson.annotation.JsonCreator;
@@ -20,7 +23,7 @@ public class Landkode implements Kodeverdi {
2023
private static final String KODEVERK = "LANDKODER";
2124

2225
private static final Map<String, Landkode> KODER = initKoder();
23-
26+
2427
public static final Landkode NOR = fraKode("NOR"); //$NON-NLS-1$
2528
public static final Landkode DNK = fraKode("DNK"); //$NON-NLS-1$
2629
public static final Landkode SWE = fraKode("SWE"); //$NON-NLS-1$
@@ -30,24 +33,26 @@ public class Landkode implements Kodeverdi {
3033
public static final Landkode FIN = fraKode("FIN"); //$NON-NLS-1$
3134
public static final Landkode CAN = fraKode("CAN"); //$NON-NLS-1$
3235
public static final Landkode ESP = fraKode("ESP"); //$NON-NLS-1$
33-
36+
3437
/** Kodeverkklient spesifikk konstant. Statsløs bruker */
3538
public static final Landkode STATSLØS = fraKode("XXX");
36-
37-
/** Kodeverkklient spesifikk konstant. Bruker oppgir ikke land*/
39+
40+
/** Kodeverkklient spesifikk konstant. Bruker oppgir ikke land */
3841
public static final Landkode UOPPGITT_UKJENT = fraKode("???");
39-
42+
4043
/** Egendefinert konstant - ikke definert (null object pattern) for bruk i modeller som krever non-null. */
41-
public static final Landkode UDEFINERT = fraKode("-");
42-
44+
public static final Landkode UDEFINERT = fraKode("-");
45+
4346
public static final Landkode NORGE = NOR;
4447
public static final Landkode SVERIGE = SWE;
4548
public static final Landkode DANMARK = DNK;
46-
49+
4750
/** ISO 3166 alpha 3-letter code. */
48-
@JsonProperty(value="kode")
51+
@JsonProperty(value = "kode")
52+
@Size(max = 3)
53+
@Pattern(regexp = "^[\\p{Alnum}]+$", message = "'${validatedValue}' matcher ikke tillatt pattern '{regexp}'")
4954
private String kode;
50-
55+
5156
Landkode() {
5257
}
5358

@@ -59,7 +64,7 @@ private Landkode(String kode) {
5964
public String getOffisiellKode() {
6065
return kode;
6166
}
62-
67+
6368
@Override
6469
public String getNavn() {
6570
return kode;
@@ -70,15 +75,15 @@ public String getKode() {
7075
return kode;
7176
}
7277

73-
@JsonProperty(value="kodeverk", access = JsonProperty.Access.READ_ONLY)
78+
@JsonProperty(value = "kodeverk", access = JsonProperty.Access.READ_ONLY)
7479
@Override
7580
public String getKodeverk() {
7681
return KODEVERK;
7782
}
78-
83+
7984
@Override
8085
public boolean equals(Object obj) {
81-
if(obj==this) {
86+
if (obj == this) {
8287
return true;
8388
} else if (obj == null || obj.getClass() != this.getClass()) {
8489
return false;
@@ -91,7 +96,7 @@ public boolean equals(Object obj) {
9196
public int hashCode() {
9297
return Objects.hash(kode);
9398
}
94-
99+
95100
@JsonCreator
96101
public static Landkode fraKode(@JsonProperty("kode") String kode) {
97102
if (kode == null) {
@@ -103,15 +108,15 @@ public static Landkode fraKode(@JsonProperty("kode") String kode) {
103108
}
104109
return ad;
105110
}
106-
111+
107112
@Override
108113
public String toString() {
109114
return kode;
110115
}
111116

112117
private static Map<String, Landkode> initKoder() {
113118
var map = new LinkedHashMap<String, Landkode>();
114-
for(var iso2cc : Locale.getISOCountries(IsoCountryCode.PART1_ALPHA2)) {
119+
for (var iso2cc : Locale.getISOCountries(IsoCountryCode.PART1_ALPHA2)) {
115120
Locale locale = new Locale("", iso2cc);
116121
String iso3cc = locale.getISO3Country().toUpperCase();
117122
Landkode landkode = new Landkode(iso3cc);
@@ -121,10 +126,10 @@ private static Map<String, Landkode> initKoder() {
121126
map.put("-", new Landkode("-"));
122127
map.put("???", new Landkode("???"));
123128
map.put("XXX", new Landkode("XXX"));
124-
129+
125130
return Collections.unmodifiableMap(map);
126131
}
127-
132+
128133
public static boolean erNorge(String kode) {
129134
return NOR.getKode().equals(kode);
130135
}

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/ArbeidsforholdRefDto.java

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.Objects;
44

5-
import javax.validation.Valid;
65
import javax.validation.constraints.NotNull;
76
import javax.validation.constraints.Pattern;
87

@@ -25,7 +24,6 @@ public class ArbeidsforholdRefDto {
2524

2625
@JsonProperty(value = "eksternReferanseSystem", index = 1)
2726
@NotNull
28-
@Valid
2927
private Fagsystem eksternReferanseSystem;
3028

3129
@JsonProperty(value = "abakusReferanse", index = 2)

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/arbeid/v1/PermisjonDto.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class PermisjonDto {
3131

3232
/** Permisjon type, hvis oppgitt. Kan være null. */
3333
@JsonProperty(value = "type", required = true)
34-
@Valid
3534
private PermisjonsbeskrivelseType type;
3635

3736
/**
@@ -48,7 +47,7 @@ public class PermisjonDto {
4847
protected PermisjonDto() {
4948
}
5049

51-
public PermisjonDto(@NotNull @Valid Periode periode, @NotNull @Valid PermisjonsbeskrivelseType type) {
50+
public PermisjonDto(@NotNull @Valid Periode periode, @NotNull PermisjonsbeskrivelseType type) {
5251
Objects.requireNonNull(periode, "periode");
5352
this.periode = periode;
5453
this.type = type;

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/arbeid/v1/YrkesaktivitetDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class YrkesaktivitetDto {
3434
private ArbeidsforholdRefDto arbeidsforholdId;
3535

3636
@JsonProperty("arbeidType")
37-
@Valid
3837
@NotNull
3938
private ArbeidType arbeidType;
4039

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/arbeidsforhold/v1/ArbeidsforholdDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class ArbeidsforholdDto {
2828
private Aktør arbeidsgiver;
2929

3030
@JsonProperty(value = "arbeidType", required = true)
31-
@Valid
3231
@NotNull
3332
private ArbeidType type;
3433

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/arbeidsforhold/v1/ArbeidsforholdOverstyringDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public class ArbeidsforholdOverstyringDto {
4848
private ArbeidsforholdRefDto nyArbeidsforholdRef;
4949

5050
@JsonProperty(value = "arbeidsforholdHandlingType", required = true)
51-
@Valid
5251
@NotNull
5352
private ArbeidsforholdHandlingType handling;
5453

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/arbeidsforhold/v1/BekreftetPermisjon.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class BekreftetPermisjon {
2424

2525
@JsonProperty(value = "status")
2626
@NotNull
27-
@Valid
2827
private BekreftetPermisjonStatus status;
2928

3029
@JsonProperty("periode")
@@ -34,7 +33,7 @@ public class BekreftetPermisjon {
3433

3534
@JsonCreator
3635
public BekreftetPermisjon(@JsonProperty("periode") @Valid @NotNull Periode periode,
37-
@JsonProperty(value = "status") @Valid @NotNull BekreftetPermisjonStatus status) {
36+
@JsonProperty(value = "status") @NotNull BekreftetPermisjonStatus status) {
3837
Objects.requireNonNull(periode, "periode");
3938
this.periode = periode;
4039
this.status = status;

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/inntekt/v1/UtbetalingDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class UtbetalingDto {
2828

2929
@JsonProperty(value = "inntektsKilde", required = true)
3030
@NotNull
31-
@Valid
3231
private InntektskildeType kilde;
3332

3433
@JsonProperty(value = "utbetalingsPoster", required = true)

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/inntekt/v1/UtbetalingsPostDto.java

+29-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import javax.validation.Valid;
88
import javax.validation.constraints.NotNull;
9+
import javax.validation.constraints.Pattern;
10+
import javax.validation.constraints.Size;
911

1012
import com.fasterxml.jackson.annotation.JsonAutoDetect;
1113
import com.fasterxml.jackson.annotation.JsonCreator;
@@ -25,7 +27,6 @@
2527
public class UtbetalingsPostDto {
2628

2729
@JsonProperty(value = "inntektspostType", required = true)
28-
@Valid
2930
@NotNull
3031
private InntektspostType inntektspostType;
3132

@@ -35,7 +36,6 @@ public class UtbetalingsPostDto {
3536
private Periode periode;
3637

3738
@JsonProperty("skattAvgiftType")
38-
@Valid
3939
private SkatteOgAvgiftsregelType skattAvgiftType;
4040

4141
/** Tillater her både positive og negative beløp (korreksjoner). Min/max verdi håndteres av mottager og avsender. */
@@ -72,7 +72,7 @@ public void setSkattAvgiftType(SkatteOgAvgiftsregelType skattAvgiftType) {
7272
}
7373

7474
public void setUtbetaltYtelseType(UtbetaltYtelseType ytelseType) {
75-
this.ytelseType = new WrapUtbetaltYtelse(ytelseType.getKode(), ytelseType.getKodeverk());
75+
this.ytelseType = ytelseType == null ? null : new WrapUtbetaltYtelse(ytelseType.getKode(), ytelseType.getKodeverk());
7676
}
7777

7878
public UtbetalingsPostDto medUtbetaltYtelseType(UtbetaltYtelseType ytelseType) {
@@ -141,10 +141,14 @@ static class WrapUtbetaltYtelse {
141141

142142
@JsonProperty(value = "kode", required = true)
143143
@NotNull
144+
@Size(max = 50)
145+
@Pattern(regexp = "^[\\p{Alnum}ÆØÅæøå_\\.\\-]+$", message = "'${validatedValue}' matcher ikke tillatt pattern '{regexp}'")
144146
private String kode;
145147

146148
@JsonProperty(value = "kodeverk", required = true)
147149
@NotNull
150+
@Size(max = 50)
151+
@Pattern(regexp = "^[\\p{Alnum}ÆØÅæøå_\\\\.\\\\-]+$", message = "'${validatedValue}' matcher ikke tillatt pattern '{regexp}'")
148152
private String kodeverk;
149153

150154
@JsonCreator
@@ -158,6 +162,28 @@ UtbetaltYtelseType getUtbetaltYtelseType() {
158162
return UtbetaltYtelseType.getUtbetaltYtelseType(kode, kodeverk);
159163
}
160164

165+
@Override
166+
public boolean equals(Object obj) {
167+
if (obj == this)
168+
return true;
169+
if (obj == null || obj.getClass() != this.getClass())
170+
return false;
171+
var other = (WrapUtbetaltYtelse) obj;
172+
173+
return Objects.equals(kode, other.kode)
174+
&& Objects.equals(kodeverk, other.kodeverk);
175+
}
176+
177+
@Override
178+
public int hashCode() {
179+
return Objects.hash(kode, kodeverk);
180+
}
181+
182+
@Override
183+
public String toString() {
184+
return "ytelseType<" + kode + ", " + kodeverk + ">";
185+
}
186+
161187
}
162188

163189
}

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/inntektsmelding/v1/InntektsmeldingDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public class InntektsmeldingDto {
103103
private List<RefusjonDto> refusjonEndringer;
104104

105105
@JsonProperty(value = "innsendingsårsak", required = true)
106-
@Valid
107106
@NotNull
108107
private InntektsmeldingInnsendingsårsakType innsendingsårsak;
109108

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/inntektsmelding/v1/NaturalytelseDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class NaturalytelseDto {
2929
private Periode periode;
3030

3131
@JsonProperty(value = "naturalytelseType", required = true, index = 1)
32-
@Valid
3332
@NotNull
3433
private NaturalytelseType type;
3534

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/inntektsmelding/v1/UtsettelsePeriodeDto.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class UtsettelsePeriodeDto {
2626
private Periode periode;
2727

2828
@JsonProperty(value = "utsettelseÅrsak")
29-
@Valid
3029
private UtsettelseÅrsakType utsettelseÅrsak;
3130

3231
protected UtsettelsePeriodeDto() {

kontrakt/src/main/java/no/nav/abakus/iaygrunnlag/oppgittopptjening/v1/OppgittAnnenAktivitetDto.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ public class OppgittAnnenAktivitetDto {
2727
private Periode periode;
2828

2929
@JsonProperty(value = "arbeidType", required = true)
30-
@Valid
3130
@NotNull
3231
private ArbeidType arbeidTypeDto;
3332

3433
@JsonCreator
3534
public OppgittAnnenAktivitetDto(@JsonProperty(value = "periode", required = true) @Valid @NotNull Periode periode,
36-
@JsonProperty(value = "arbeidType", required = true) @Valid @NotNull ArbeidType arbeidType) {
35+
@JsonProperty(value = "arbeidType", required = true) @NotNull ArbeidType arbeidType) {
3736
Objects.requireNonNull(periode, "periode");
3837
Objects.requireNonNull(arbeidType, "arbeidType");
3938
this.periode = periode;

0 commit comments

Comments
 (0)