Skip to content

Commit

Permalink
Merge pull request #3316 from navikt/feature/pdl-forvalter-historiske…
Browse files Browse the repository at this point in the history
…-opplysninger

Feature/pdl forvalter historiske opplysninger
  • Loading branch information
stigus authored Oct 25, 2023
2 parents 5f445cf + 88cfa11 commit df4e84b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 53 deletions.
5 changes: 3 additions & 2 deletions apps/pdl-forvalter/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
env:
- name: SPRING_PROFILES_ACTIVE
value: dev
image: {{ image }}
image: {{image}}
webproxy: true
tokenx:
enabled: true
Expand All @@ -26,10 +26,11 @@ spec:
- "https://testnav-pdl-forvalter-dev.intern.dev.nav.no"
liveness:
path: /internal/isAlive
periodSeconds: 30
periodSeconds: 60
initialDelay: 60
readiness:
path: /internal/isReady
periodSeconds: 60
initialDelay: 60
prometheus:
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import no.nav.pdl.forvalter.exception.InvalidRequestException;
import no.nav.pdl.forvalter.exception.NotFoundException;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
Expand Down Expand Up @@ -45,7 +44,6 @@ public Object beforeBodyWrite(final Object body,
final Class<? extends HttpMessageConverter<?>> selectedConverterType,
final ServerHttpRequest request,
final ServerHttpResponse response) {
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json;charset=utf-8");
return body;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.pdl.forvalter.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;
import no.nav.pdl.forvalter.database.repository.PersonRepository;
import no.nav.pdl.forvalter.exception.InvalidRequestException;
Expand All @@ -19,6 +20,7 @@

import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;

import static java.util.Objects.nonNull;
Expand All @@ -35,6 +37,7 @@
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Service
@Slf4j
@RequiredArgsConstructor
public class IdenttypeService implements Validation<IdentRequestDTO> {

Expand All @@ -54,64 +57,19 @@ public class IdenttypeService implements Validation<IdentRequestDTO> {
private final MapperFacade mapperFacade;
private final PersonRepository personRepository;

private static Identtype getIdenttype(IdentRequestDTO request, String ident) {

if (nonNull(request.getIdenttype())) {
return request.getIdenttype();
}
return nonNull(ident) ? IdenttypeFraIdentUtility.getIdenttype(ident) : FNR;
}

private static Kjoenn getTilfeldigKjoenn() {

return secureRandom.nextBoolean() ? MANN : KVINNE;
}

private static Kjoenn getKjoenn(IdentRequestDTO request, String ident) {

if (nonNull(request.getKjoenn()) && request.getKjoenn() != UKJENT) {
return request.getKjoenn();
}
return nonNull(ident) ? KjoennFraIdentUtility.getKjoenn(ident) : getTilfeldigKjoenn();
}

private static LocalDateTime getFoedtFoer(IdentRequestDTO request, String ident) {

if (nonNull(request.getFoedtFoer())) {
return request.getFoedtFoer();
} else if (nonNull(request.getAlder())) {
return LocalDateTime.now().minusYears(request.getAlder()).minusMonths(3);
}
return (nonNull(ident)) ? DatoFraIdentUtility.getDato(ident).plusMonths(1).atStartOfDay() :
LocalDateTime.now().minusYears(18);
}

private static LocalDateTime getFoedtEtter(IdentRequestDTO request, String ident) {

if (nonNull(request.getFoedtEtter())) {
return request.getFoedtEtter();
} else if (nonNull(request.getAlder())) {
return LocalDateTime.now().minusYears(request.getAlder()).minusYears(1);
}
return (nonNull(ident)) ? DatoFraIdentUtility.getDato(ident).minusMonths(1).atStartOfDay() :
LocalDateTime.now().minusYears(67);
}

private static boolean isSyntetisk(IdentRequestDTO request, String ident) {
return nonNull(request.getSyntetisk()) ? request.getSyntetisk() :
SyntetiskFraIdentUtility.isSyntetisk(ident);
}

public PersonDTO convert(PersonDTO person) {

var nyPerson = person;
for (var type : person.getNyident()) {
List<IdentRequestDTO> nyident = person.getNyident();
for (int index = 0; index < nyident.size(); index++) {
var type = nyident.get(index);

if (isTrue(type.getIsNew())) {

nyPerson = handle(type, nyPerson);
type.setKilde(isNotBlank(type.getKilde()) ? type.getKilde() : "Dolly");
type.setMaster(nonNull(type.getMaster()) ? type.getMaster() : DbVersjonDTO.Master.FREG);
type.setFoedtEtter(person.getFoedsel().getFirst().getFoedselsdato().plusDays(index + 1L));
}
}
return nyPerson;
Expand Down Expand Up @@ -170,4 +128,52 @@ private PersonDTO handle(IdentRequestDTO request, PersonDTO person) {

return nonNull(oppdatertPerson) ? oppdatertPerson : person;
}

private static Identtype getIdenttype(IdentRequestDTO request, String ident) {

if (nonNull(request.getIdenttype())) {
return request.getIdenttype();
}
return nonNull(ident) ? IdenttypeFraIdentUtility.getIdenttype(ident) : FNR;
}

private static Kjoenn getTilfeldigKjoenn() {

return secureRandom.nextBoolean() ? MANN : KVINNE;
}

private static Kjoenn getKjoenn(IdentRequestDTO request, String ident) {

if (nonNull(request.getKjoenn()) && request.getKjoenn() != UKJENT) {
return request.getKjoenn();
}
return nonNull(ident) ? KjoennFraIdentUtility.getKjoenn(ident) : getTilfeldigKjoenn();
}

private static LocalDateTime getFoedtFoer(IdentRequestDTO request, String ident) {

if (nonNull(request.getFoedtFoer())) {
return request.getFoedtFoer();
} else if (nonNull(request.getAlder())) {
return LocalDateTime.now().minusYears(request.getAlder()).minusMonths(3);
}
return (nonNull(ident)) ? DatoFraIdentUtility.getDato(ident).plusMonths(1).atStartOfDay() :
LocalDateTime.now().minusYears(18);
}

private static LocalDateTime getFoedtEtter(IdentRequestDTO request, String ident) {

if (nonNull(request.getFoedtEtter())) {
return request.getFoedtEtter();
} else if (nonNull(request.getAlder())) {
return LocalDateTime.now().minusYears(request.getAlder()).plusDays(1);
}
return (nonNull(ident)) ? DatoFraIdentUtility.getDato(ident).plusMonths(1).atStartOfDay() :
LocalDateTime.now().minusYears(67);
}

private static boolean isSyntetisk(IdentRequestDTO request, String ident) {
return nonNull(request.getSyntetisk()) ? request.getSyntetisk() :
SyntetiskFraIdentUtility.isSyntetisk(ident);
}
}

0 comments on commit df4e84b

Please sign in to comment.