Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Historikk for personstatus #3636

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public static void main(String[] args) {

SpringApplication.run(PdlForvalterApplicationStarter.class, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import no.nav.testnav.libs.data.pdlforvalter.v1.DoedsfallDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FalskIdentitetDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus;
import no.nav.testnav.libs.data.pdlforvalter.v1.PersonDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.UtflyttingDTO;
import org.springframework.stereotype.Service;
Expand All @@ -25,12 +26,10 @@
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.DOED;
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.FOEDSELSREGISTRERT;
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.IKKE_BOSATT;
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.INAKTIV;
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.MIDLERTIDIG;
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.OPPHOERT;
import static no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO.FolkeregisterPersonstatus.UTFLYTTET;
import static no.nav.testnav.libs.data.pdlforvalter.v1.Identtype.DNR;
import static no.nav.testnav.libs.data.pdlforvalter.v1.Identtype.FNR;
import static no.nav.testnav.libs.data.pdlforvalter.v1.Identtype.NPID;
import static org.apache.commons.lang3.BooleanUtils.isTrue;

Expand All @@ -42,6 +41,10 @@ public List<FolkeregisterPersonstatusDTO> convert(PersonDTO person) {

var touched = new AtomicBoolean(false);

if (person.isNotChanged() || isTestnorgeIdent(person.getIdent()) || person.getIdenttype() == NPID) {
return person.getFolkeregisterPersonstatus();
}

person.getFolkeregisterPersonstatus()
.forEach(status -> {

Expand All @@ -54,26 +57,21 @@ public List<FolkeregisterPersonstatusDTO> convert(PersonDTO person) {
}
});

if (person.getFolkeregisterPersonstatus().isEmpty() &&
!person.getFalskIdentitet().isEmpty() &&
person.getIdenttype() != NPID &&
!isTestnorgeIdent(person.getIdent())) {

person.getFolkeregisterPersonstatus().add(handle(FolkeregisterPersonstatusDTO.builder()
.id(1)
.kilde("Dolly")
.master(Master.FREG)
.build(),
person)
);
touched.set(true);
}
if (!touched.get()) {

if (!touched.get() && !person.getFolkeregisterPersonstatus().isEmpty()) {
var status = handle(FolkeregisterPersonstatusDTO.builder()
.id(person.getFolkeregisterPersonstatus().size() + 1)
.isNew(true)
.kilde("Dolly")
.master(Master.FREG)
.build(), person);

handle(person.getFolkeregisterPersonstatus().getFirst(), person);
if (nonNull(status.getStatus())) {
person.getFolkeregisterPersonstatus().addFirst(status);
}
}

setGyldigTilOgMed(person.getFolkeregisterPersonstatus());
return person.getFolkeregisterPersonstatus();
}

Expand All @@ -94,72 +92,80 @@ private FolkeregisterPersonstatusDTO handle(FolkeregisterPersonstatusDTO persons
if (person.getFolkeregisterPersonstatus()
.stream().anyMatch(status -> isTrue(status.getIsNew()) && nonNull(status.getStatus()))) {

// Status allerede satt
return personstatus;

} else if (!person.getDoedsfall().isEmpty()) {

personstatus.setStatus(DOED);
personstatus.setGyldigFraOgMed(person.getDoedsfall().stream()
.map(DoedsfallDTO::getDoedsdato)
.findFirst()
.orElse(LocalDateTime.now()));
if (isNotCurrentStatus(DOED, person)) {
personstatus.setStatus(DOED);
personstatus.setGyldigFraOgMed(person.getDoedsfall().stream()
.map(DoedsfallDTO::getDoedsdato)
.findFirst()
.orElse(LocalDateTime.now()));
}
return personstatus;

} else if (person.getFalskIdentitet().stream().anyMatch(FalskIdentitetDTO::isFalskIdentitet)) {

personstatus.setStatus(OPPHOERT);
personstatus.setGyldigFraOgMed(person.getFalskIdentitet().stream()
.filter(FalskIdentitetDTO::isFalskIdentitet)
.map(FalskIdentitetDTO::getGyldigFraOgMed)
.filter(Objects::nonNull)
.findFirst()
.orElse(LocalDateTime.now()));
if (isNotCurrentStatus(OPPHOERT, person)) {
personstatus.setStatus(OPPHOERT);
personstatus.setGyldigFraOgMed(person.getFalskIdentitet().stream()
.filter(FalskIdentitetDTO::isFalskIdentitet)
.map(FalskIdentitetDTO::getGyldigFraOgMed)
.filter(Objects::nonNull)
.findFirst()
.orElse(LocalDateTime.now()));
}
return personstatus;

} else if (!person.getUtflytting().isEmpty() && person.getUtflytting().stream()
.noneMatch(utflytting -> person.getInnflytting().stream()
.anyMatch(innflytting ->
innflytting.getInnflyttingsdato().isAfter(utflytting.getUtflyttingsdato())))) {

personstatus.setStatus(UTFLYTTET);
personstatus.setGyldigFraOgMed(person.getUtflytting().stream()
.map(UtflyttingDTO::getUtflyttingsdato)
.filter(Objects::nonNull)
.findFirst()
.orElse(LocalDateTime.now()));
if (isNotCurrentStatus(UTFLYTTET, person)) {
personstatus.setStatus(UTFLYTTET);
personstatus.setGyldigFraOgMed(person.getUtflytting().stream()
.map(UtflyttingDTO::getUtflyttingsdato)
.filter(Objects::nonNull)
.findFirst()
.orElse(LocalDateTime.now()));
}
return personstatus;

} else if (!person.getOpphold().isEmpty() || DNR == getIdenttype(person.getIdent())) {

personstatus.setStatus(MIDLERTIDIG);
if (isNotCurrentStatus(MIDLERTIDIG, person)) {
personstatus.setStatus(MIDLERTIDIG);
personstatus.setGyldigFraOgMed(FoedselsdatoUtility.getFoedselsdato(person));
}
return personstatus;

} else if (!person.getBostedsadresse().isEmpty()) {

if (person.getBostedsadresse().getFirst().isAdresseUtland()) {
personstatus.setStatus(IKKE_BOSATT);

if (isNotCurrentStatus(IKKE_BOSATT, person)) {
personstatus.setStatus(IKKE_BOSATT);
personstatus.setGyldigFraOgMed(getBoadresseGyldigFraDato(person));
}

} else if (nonNull(person.getBostedsadresse().getFirst().getUkjentBosted())) {
personstatus.setStatus(FOEDSELSREGISTRERT);

} else {
personstatus.setStatus(BOSATT);
}
if (isNotCurrentStatus(FOEDSELSREGISTRERT, person)) {
personstatus.setStatus(FOEDSELSREGISTRERT);
personstatus.setGyldigFraOgMed(getBoadresseGyldigFraDato(person));
}

personstatus.setGyldigFraOgMed(person.getBostedsadresse().stream()
.map(BostedadresseDTO::getGyldigFraOgMed)
.filter(Objects::nonNull)
.findFirst()
.orElse(FoedselsdatoUtility.getFoedselsdato(person)));
} else if (isNotCurrentStatus(BOSATT, person)) {

} else if (FNR != getIdenttype(person.getIdent()) &&
person.getBostedsadresse().stream().findFirst().orElse(new BostedadresseDTO()).countAdresser() == 0 ||
nonNull(person.getBostedsadresse().stream().findFirst().orElse(new BostedadresseDTO()).getUtenlandskAdresse())) {
personstatus.setStatus(BOSATT);
personstatus.setGyldigFraOgMed(getBoadresseGyldigFraDato(person));
}

personstatus.setStatus(INAKTIV);
personstatus.setGyldigFraOgMed(person.getBostedsadresse().stream()
.map(BostedadresseDTO::getGyldigFraOgMed)
.filter(Objects::nonNull)
.findFirst()
.orElse(FoedselsdatoUtility.getFoedselsdato(person)));
return personstatus;

} else {
} else if (isNotCurrentStatus(FOEDSELSREGISTRERT, person)) {

personstatus.setStatus(FOEDSELSREGISTRERT);
personstatus.setGyldigFraOgMed(FoedselsdatoUtility.getFoedselsdato(person));
Expand All @@ -168,9 +174,34 @@ private FolkeregisterPersonstatusDTO handle(FolkeregisterPersonstatusDTO persons
return personstatus;
}

private static boolean isNotCurrentStatus(FolkeregisterPersonstatus status, PersonDTO person) {

return person.getFolkeregisterPersonstatus().isEmpty() ||
person.getFolkeregisterPersonstatus().getFirst().getStatus() != status;
}

@Override
public void validate(FolkeregisterPersonstatusDTO artifact, PersonDTO person) {

// Ingen validering
}

private static LocalDateTime getBoadresseGyldigFraDato(PersonDTO person) {

return person.getBostedsadresse().stream()
.map(BostedadresseDTO::getGyldigFraOgMed)
.filter(Objects::nonNull)
.findFirst()
.orElse(FoedselsdatoUtility.getFoedselsdato(person));
}

private static void setGyldigTilOgMed(List<FolkeregisterPersonstatusDTO> folkeregisterPersonstatus) {

for (var i = 0; i < folkeregisterPersonstatus.size(); i++) {
if (i + 1 < folkeregisterPersonstatus.size() && nonNull(folkeregisterPersonstatus.get(i).getGyldigFraOgMed())) {
folkeregisterPersonstatus.get(i + 1)
.setGyldigTilOgMed(folkeregisterPersonstatus.get(i).getGyldigFraOgMed().minusDays(1));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void mergeElements(java.lang.reflect.Field field, List<DbVersjonDTO> inf
if (isNull(requestElement.getFolkeregistermetadata())) {
requestElement.setFolkeregistermetadata(new FolkeregistermetadataDTO());
}
infoElementDbPerson.add(0, mapperFacade.map(requestElement, requestElement.getClass()));
infoElementDbPerson.addFirst(mapperFacade.map(requestElement, requestElement.getClass()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ public PersonDTO buildPerson(PersonDTO person, Boolean relaxed) {
person.setForeldreansvar(foreldreansvarService.convert(person));
person.setDoedfoedtBarn(doedfoedtBarnService.convert(person.getDoedfoedtBarn()));
person.setSikkerhetstiltak(sikkerhetstiltakService.convert(person));
person.setFolkeregisterPersonstatus(folkeregisterPersonstatusService.convert(person));
person.setNavPersonIdentifikator(navPersonIdentifikatorService.convert(person));

person = identtypeService.convert(person);

person.setFolkeregisterPersonstatus(folkeregisterPersonstatusService.convert(person));

return person;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import no.nav.testnav.libs.data.pdlforvalter.v1.BostedadresseDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FoedestedDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FoedselsdatoDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FolkeregisterPersonstatusDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.ForeldreansvarDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.FullPersonDTO;
import no.nav.testnav.libs.data.pdlforvalter.v1.Identtype;
Expand Down Expand Up @@ -237,10 +236,6 @@ public String createPerson(BestillingRequestDTO request) {
if (request.getPerson().getSivilstand().stream().noneMatch(SivilstandDTO::isUgift)) {
request.getPerson().getSivilstand().addFirst(new SivilstandDTO());
}
if (request.getPerson().getFolkeregisterPersonstatus().isEmpty() &&
Identtype.NPID != getIdenttype(request.getPerson().getIdent())) {
request.getPerson().getFolkeregisterPersonstatus().add(new FolkeregisterPersonstatusDTO());
}
if (Identtype.NPID == getIdenttype(request.getPerson().getIdent())) {
request.getPerson().getNavPersonIdentifikator().add(new NavPersonIdentifikatorDTO());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private void swopOpplysninger(DbPerson person1, DbPerson person2) {
person1.getPerson().getInnflytting().addAll(person2.getPerson().getInnflytting());
person1.getPerson().setAdressebeskyttelse(person2.getPerson().getAdressebeskyttelse());
person1.getPerson().setNavPersonIdentifikator(person2.getPerson().getNavPersonIdentifikator());
person1.getPerson().setFolkeregisterPersonstatus(person2.getPerson().getFolkeregisterPersonstatus());

if (person1.getPerson().isStrengtFortrolig() || person2.getPerson().isStrengtFortrolig()) {
person1.getPerson().setBostedsadresse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static java.lang.Integer.parseInt;
import static java.util.Collections.emptyList;
import static java.util.Objects.isNull;
import static no.nav.testnav.libs.data.pdlforvalter.v1.Identtype.DNR;
import static no.nav.testnav.libs.data.pdlforvalter.v1.Identtype.FNR;
Expand Down Expand Up @@ -265,7 +269,7 @@ public List<FoedselsdatoDTO> getFoedselsdato() {
}

public List<NavPersonIdentifikatorDTO> getNavPersonIdentifikator() {
if(isNull(navPersonIdentifikator)) {
if (isNull(navPersonIdentifikator)) {
navPersonIdentifikator = new ArrayList<>();
}
return navPersonIdentifikator;
Expand Down Expand Up @@ -296,4 +300,22 @@ public boolean isStandalone() {

return isTrue(standalone);
}

@JsonIgnore
public boolean isNotChanged() {

return Arrays.stream(this.getClass().getMethods())
.filter(method -> method.getName().startsWith("get"))
.filter(method -> method.getReturnType().equals(List.class))
.map(method -> {
try {
return method.invoke(this);
} catch (IllegalAccessException | InvocationTargetException e) {
return emptyList();
}
})
.map(result -> (List<? extends DbVersjonDTO>) result)
.flatMap(Collection::stream)
.noneMatch(entity -> isTrue(entity.getIsNew()));
}
}
Loading