|
| 1 | +package no.nav.vedtak.sikkerhet.tilgang; |
| 2 | + |
| 3 | +import java.time.LocalDate; |
| 4 | +import java.util.List; |
| 5 | +import java.util.Optional; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; |
| 8 | + |
| 9 | +public record TilgangPersondataEnkelDto(String aktoerId, Person person, Identer identer) { |
| 10 | + |
| 11 | + public record Person(List<Adressebeskyttelse> adressebeskyttelse) { |
| 12 | + } |
| 13 | + |
| 14 | + public record Adressebeskyttelse(Gradering gradering) { } |
| 15 | + |
| 16 | + public record Identer(List<Ident> identer) { } |
| 17 | + |
| 18 | + public record Ident(String ident, Boolean historisk, IdentGruppe gruppe) { } |
| 19 | + |
| 20 | + public enum Gradering { STRENGT_FORTROLIG_UTLAND, STRENGT_FORTROLIG, FORTROLIG, @JsonEnumDefaultValue UDEFINERT } |
| 21 | + |
| 22 | + public enum IdentGruppe { AKTORID, FOLKEREGISTERIDENT, NPID, @JsonEnumDefaultValue UDEFINERT } |
| 23 | + |
| 24 | + public boolean harStrengAdresseBeskyttelse() { |
| 25 | + return Optional.ofNullable(person()).map(Person::adressebeskyttelse).orElse(List.of()).stream() |
| 26 | + .map(Adressebeskyttelse::gradering) |
| 27 | + .anyMatch(g -> Gradering.STRENGT_FORTROLIG.equals(g) || Gradering.STRENGT_FORTROLIG_UTLAND.equals(g)); |
| 28 | + } |
| 29 | + |
| 30 | + public boolean harAdresseBeskyttelse() { |
| 31 | + return Optional.ofNullable(person()).map(Person::adressebeskyttelse).orElse(List.of()).stream() |
| 32 | + .map(Adressebeskyttelse::gradering) |
| 33 | + .anyMatch(g -> g != null && !Gradering.UDEFINERT.equals(g)); |
| 34 | + } |
| 35 | + |
| 36 | + public String personIdent() { |
| 37 | + return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream() |
| 38 | + .filter(i -> IdentGruppe.FOLKEREGISTERIDENT.equals(i.gruppe())) |
| 39 | + .filter(i -> !i.historisk()) |
| 40 | + .map(Ident::ident) |
| 41 | + .findFirst().orElse(null); |
| 42 | + } |
| 43 | + |
| 44 | + public List<String> personIdenter(boolean medHistoriske) { |
| 45 | + return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream() |
| 46 | + .filter(i -> IdentGruppe.FOLKEREGISTERIDENT.equals(i.gruppe())) |
| 47 | + .filter(i -> medHistoriske || !i.historisk()) |
| 48 | + .map(Ident::ident) |
| 49 | + .toList(); |
| 50 | + } |
| 51 | + |
| 52 | + public String aktørId(boolean medHistoriske) { |
| 53 | + return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream() |
| 54 | + .filter(i -> IdentGruppe.AKTORID.equals(i.gruppe())) |
| 55 | + .filter(i -> medHistoriske || !i.historisk()) |
| 56 | + .map(Ident::ident) |
| 57 | + .findFirst().orElse(null); |
| 58 | + } |
| 59 | + |
| 60 | + public List<String> alleIdenter(boolean medHistoriske) { |
| 61 | + return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream() |
| 62 | + .filter(i -> medHistoriske || !i.historisk()) |
| 63 | + .map(Ident::ident) |
| 64 | + .toList(); |
| 65 | + } |
| 66 | +} |
0 commit comments