1
1
package no .nav .k9 .søknad ;
2
2
3
3
import java .io .IOException ;
4
+ import java .time .OffsetDateTime ;
4
5
import java .time .ZonedDateTime ;
5
6
import java .util .AbstractMap .SimpleEntry ;
6
7
import java .util .Collections ;
9
10
import java .util .stream .Collectors ;
10
11
11
12
import javax .validation .Valid ;
13
+ import javax .validation .constraints .AssertTrue ;
12
14
import javax .validation .constraints .NotNull ;
13
15
14
16
import com .fasterxml .jackson .annotation .JsonAlias ;
@@ -43,17 +45,22 @@ public class LegacySøknad implements Innsending {
43
45
@ JsonProperty (value = "søknadId" , required = true )
44
46
private SøknadId søknadId ;
45
47
48
+ @ JsonInclude (value = Include .NON_EMPTY )
46
49
@ Valid
47
- @ NotNull
48
- @ JsonProperty (value = "versjon" , required = true )
50
+ @ JsonProperty (value = "versjon" )
49
51
private Versjon versjon ;
50
52
51
- @ Valid
52
- @ NotNull
53
+ @ JsonInclude ( value = Include . NON_EMPTY )
54
+ @ JsonProperty ( value = "mottattDato" )
53
55
@ JsonFormat (shape = JsonFormat .Shape .STRING , pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX" , timezone = "UTC" )
54
- @ JsonProperty ( value = "mottattDato" , required = true )
56
+ @ Valid
55
57
private ZonedDateTime mottattDato ;
56
58
59
+ @ JsonInclude (value = Include .NON_EMPTY )
60
+ @ JsonProperty (value = "mottatt" )
61
+ @ Valid
62
+ private OffsetDateTime mottatt ;
63
+
57
64
@ Valid
58
65
@ NotNull
59
66
@ JsonProperty (value = "søker" , required = true )
@@ -72,8 +79,8 @@ public class LegacySøknad implements Innsending {
72
79
private Map <Periode , Dummy > perioder ;
73
80
74
81
public LegacySøknad (@ JsonProperty (value = "søknadId" , required = true ) @ Valid @ NotNull SøknadId søknadId ,
75
- @ JsonProperty (value = "versjon" , required = true ) @ Valid @ NotNull Versjon versjon ,
76
- @ JsonProperty (value = "mottattDato" , required = true ) @ Valid @ NotNull ZonedDateTime mottattDato ,
82
+ @ JsonProperty (value = "versjon" ) @ Valid Versjon versjon ,
83
+ @ JsonProperty (value = "mottattDato" ) @ Valid @ NotNull ZonedDateTime mottattDato ,
77
84
@ JsonProperty (value = "søker" , required = true ) @ Valid @ NotNull Søker søker ) {
78
85
this .søknadId = søknadId ;
79
86
this .versjon = versjon ;
@@ -83,19 +90,26 @@ public class LegacySøknad implements Innsending {
83
90
84
91
@ JsonCreator
85
92
public LegacySøknad (@ JsonProperty (value = "søknadId" , required = true ) @ Valid @ NotNull SøknadId søknadId ,
86
- @ JsonProperty (value = "versjon" , required = true ) @ Valid @ NotNull Versjon versjon ,
87
- @ JsonProperty (value = "mottattDato" , required = true ) @ Valid @ NotNull ZonedDateTime mottattDato ,
93
+ @ JsonProperty (value = "versjon" ) @ Valid Versjon versjon ,
94
+ @ JsonProperty (value = "mottattDato" ) @ Valid ZonedDateTime mottattDato ,
95
+ @ JsonProperty (value = "mottatt" ) @ Valid OffsetDateTime mottattDato2 ,
88
96
@ JsonProperty (value = "søker" , required = true ) @ Valid @ NotNull Søker søker ,
89
97
@ JsonAlias (value = { "fosterbarn" }) @ JsonProperty (value = "barn" , required = true ) List <Barn > barn ,
90
98
@ JsonProperty (value = "perioder" , required = false ) Map <Periode , Dummy > perioder ) {
91
99
this .søknadId = søknadId ;
92
100
this .versjon = versjon ;
93
101
this .mottattDato = mottattDato ;
102
+ this .mottatt = mottattDato2 ;
94
103
this .søker = søker ;
95
104
this .barn = barn ;
96
105
this .perioder = perioder ;
97
106
}
98
107
108
+ @ AssertTrue (message = "trenger enten mottatDato eller mottatt" )
109
+ private boolean isOk () {
110
+ return mottattDato != null || mottatt != null ;
111
+ }
112
+
99
113
@ Override
100
114
public SøknadId getSøknadId () {
101
115
return søknadId ;
@@ -112,7 +126,7 @@ public List<Barn> getBarn() {
112
126
public void setBarn (List <Barn > barn ) {
113
127
this .barn = barn == null ? null : List .copyOf (barn );
114
128
}
115
-
129
+
116
130
public void setPerioder (List <Periode > perioder ) {
117
131
this .perioder = perioder .stream ().map (p -> new SimpleEntry <>(p , new Dummy ())).collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
118
132
}
@@ -124,7 +138,7 @@ public Versjon getVersjon() {
124
138
125
139
@ Override
126
140
public ZonedDateTime getMottattDato () {
127
- return mottattDato ;
141
+ return mottattDato == null ? mottatt . toZonedDateTime () : mottattDato ;
128
142
}
129
143
130
144
public List <Periode > getPerioder () {
@@ -147,7 +161,7 @@ public static String serialize(LegacySøknad søknad) {
147
161
public static LegacySøknad deserialize (String søknad ) {
148
162
return JsonUtils .fromString (søknad , LegacySøknad .class );
149
163
}
150
-
164
+
151
165
public static LegacySøknad deserialize (ObjectNode node ) {
152
166
try {
153
167
return JsonUtils .getObjectMapper ().treeToValue (node , LegacySøknad .class );
0 commit comments