5
5
import no .nav .pdl .forvalter .consumer .GenererNavnServiceConsumer ;
6
6
import no .nav .pdl .forvalter .exception .InvalidRequestException ;
7
7
import no .nav .pdl .forvalter .utils .IdenttypeUtility ;
8
+ import no .nav .testnav .libs .data .pdlforvalter .v1 .AdressebeskyttelseDTO ;
8
9
import no .nav .testnav .libs .data .pdlforvalter .v1 .OppholdsadresseDTO ;
9
10
import no .nav .testnav .libs .data .pdlforvalter .v1 .PersonDTO ;
10
11
import no .nav .testnav .libs .data .pdlforvalter .v1 .StatsborgerskapDTO ;
22
23
import static java .util .Objects .nonNull ;
23
24
import static no .nav .pdl .forvalter .utils .ArtifactUtils .getKilde ;
24
25
import static no .nav .pdl .forvalter .utils .ArtifactUtils .getMaster ;
26
+ import static no .nav .testnav .libs .data .pdlforvalter .v1 .AdressebeskyttelseDTO .AdresseBeskyttelse .STRENGT_FORTROLIG ;
25
27
import static no .nav .testnav .libs .data .pdlforvalter .v1 .Identtype .FNR ;
26
28
import static org .apache .commons .lang3 .BooleanUtils .isTrue ;
27
29
import static org .apache .logging .log4j .util .Strings .isNotBlank ;
@@ -31,6 +33,8 @@ public class OppholdsadresseService extends AdresseService<OppholdsadresseDTO, P
31
33
32
34
private static final String VALIDATION_AMBIGUITY_ERROR = "Oppholdsadresse: kun én adresse skal være satt (vegadresse, " +
33
35
"matrikkeladresse, utenlandskAdresse)" ;
36
+ private static final String VALIDATION_PROTECTED_ADDRESS = "Oppholdsadresse: Personer med adressebeskyttelse == " +
37
+ "STRENGT_FORTROLIG skal ikke ha oppholdsadresse" ;
34
38
35
39
private final AdresseServiceConsumer adresseServiceConsumer ;
36
40
private final MapperFacade mapperFacade ;
@@ -66,6 +70,12 @@ public void validate(OppholdsadresseDTO adresse, PersonDTO person) {
66
70
throw new InvalidRequestException (VALIDATION_AMBIGUITY_ERROR );
67
71
68
72
}
73
+ if (FNR == IdenttypeUtility .getIdenttype (person .getIdent ()) &&
74
+ STRENGT_FORTROLIG == person .getAdressebeskyttelse ().stream ()
75
+ .findFirst ().orElse (new AdressebeskyttelseDTO ()).getGradering () &&
76
+ adresse .countAdresser () > 0 ) {
77
+ throw new InvalidRequestException (VALIDATION_PROTECTED_ADDRESS );
78
+ }
69
79
70
80
if (nonNull (adresse .getVegadresse ()) && isNotBlank (adresse .getVegadresse ().getBruksenhetsnummer ())) {
71
81
validateBruksenhet (adresse .getVegadresse ().getBruksenhetsnummer ());
@@ -86,7 +96,12 @@ protected void handle(OppholdsadresseDTO oppholdsadresse, PersonDTO person) {
86
96
87
97
if (FNR == IdenttypeUtility .getIdenttype (person .getIdent ())) {
88
98
89
- if (oppholdsadresse .countAdresser () == 0 ) {
99
+ if (STRENGT_FORTROLIG == person .getAdressebeskyttelse ().stream ()
100
+ .findFirst ().orElse (new AdressebeskyttelseDTO ()).getGradering ()) {
101
+
102
+ return ;
103
+
104
+ } else if (oppholdsadresse .countAdresser () == 0 ) {
90
105
oppholdsadresse .setVegadresse (new VegadresseDTO ());
91
106
}
92
107
0 commit comments