Skip to content

Commit

Permalink
Add error handling and logging updates
Browse files Browse the repository at this point in the history
Included a new JsonNode for errors in PdlPersonDTO and added Jackson codecs in PdlConsumer. Enhanced logging in SokPersonCommand for debugging purposes.
  • Loading branch information
krharum committed Oct 17, 2024
1 parent 49b255e commit 1036b3f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.testnav.levendearbeidsforholdansettelse.consumers;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import no.nav.testnav.levendearbeidsforholdansettelse.config.Consumers;
Expand All @@ -11,8 +12,12 @@
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.netty.http.client.HttpClient;
Expand All @@ -37,12 +42,21 @@ public class PdlConsumer {
public PdlConsumer(
TokenExchange tokenService,
Consumers consumers,
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getPdlProxy();
this.tokenService = tokenService;
webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(config -> {
config.defaultCodecs()
.jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON));
config.defaultCodecs()
.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
})
.build())
.clientConnector(
new ReactorClientHttpConnector(
HttpClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.testnav.levendearbeidsforholdansettelse.consumers.command.pdl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.levendearbeidsforholdansettelse.domain.dto.PdlPersonDTO;
import no.nav.testnav.levendearbeidsforholdansettelse.domain.pdl.GraphqlVariables;
import no.nav.testnav.levendearbeidsforholdansettelse.provider.PdlMiljoer;
Expand All @@ -25,7 +24,6 @@
import static no.nav.testnav.levendearbeidsforholdansettelse.domain.pdl.CommonKeysAndUtils.HEADER_NAV_CONSUMER_ID;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

@Slf4j
@RequiredArgsConstructor
public class SokPersonCommand implements Callable<Flux<PdlPersonDTO>> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.testnav.levendearbeidsforholdansettelse.domain.dto;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -20,6 +21,8 @@
@AllArgsConstructor
public class PdlPersonDTO {

private JsonNode errors;

private Data data;

public enum Gruppe {AKTORID, FOLKEREGISTERIDENT, NPID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class PdlService {

private static final Random RANDOM = new SecureRandom();
private static final String CONTAINS = "contains";

private final PdlConsumer pdlConsumer;

Expand All @@ -38,6 +39,7 @@ public Flux<PdlPersonDTO.Person> getPerson(DatoIntervall datoIntervall, String p
return pdlConsumer.getSokPerson(lagSokPersonPaging(1),
lagSokPersonCriteria(datoIntervall, postnummer),
PdlMiljoer.Q2)
.filter(data -> nonNull(data.getData()))
.map(PdlPersonDTO::getData)
.filter(data -> nonNull(data.getSokPerson()))
.map(PdlPersonDTO.Data::getSokPerson)
Expand Down Expand Up @@ -71,17 +73,17 @@ private GraphqlVariables.Criteria lagSokPersonCriteria(DatoIntervall intervall,

GraphqlVariables.Filter testnorge = GraphqlVariables.Filter.builder()
.fieldName("tags")
.searchRule(Map.of("contains", "TESTNORGE"))
.searchRule(Map.of(CONTAINS, "TESTNORGE"))
.build();

GraphqlVariables.Filter dolly = GraphqlVariables.Filter.builder()
.fieldName("tags")
.searchRule(Map.of("contains", "DOLLY"))
.searchRule(Map.of(CONTAINS, "DOLLY"))
.build();

GraphqlVariables.Filter arenasynt = GraphqlVariables.Filter.builder()
.fieldName("tags")
.searchRule(Map.of("contains", "ARENASYNT"))
.searchRule(Map.of(CONTAINS, "ARENASYNT"))
.build();

var or = Map.of("or", List.of(filterBostedPostnr, filterOppholdPostnr));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ type Navn {
originaltNavn: OriginaltNavn
}

type Navspersonidentifikator {
identifikasjonsnummer: String!
metadata: Metadata!
}

type Opphold {
folkeregistermetadata: Folkeregistermetadata!
metadata: Metadata!
Expand Down Expand Up @@ -479,6 +484,7 @@ type Person {
kontaktadresse(historikk: Boolean = false): [Kontaktadresse!]!
kontaktinformasjonForDoedsbo(historikk: Boolean = false): [KontaktinformasjonForDoedsbo!]!
navn(historikk: Boolean = false): [Navn!]!
navspersonidentifikator(historikk: Boolean = false): [Navspersonidentifikator!]!
opphold(historikk: Boolean = false): [Opphold!]!
oppholdsadresse(historikk: Boolean = false): [Oppholdsadresse!]!
rettsligHandleevne(historikk: Boolean = false): [RettsligHandleevne!]!
Expand Down Expand Up @@ -893,7 +899,7 @@ input SearchRule {
" Begrenser treff til kun de hvor felt har input verdi"
equals: String
" Sjekker om feltet finnes / at det ikke har en null verdi."
exists: String
exists: Boolean
"""
Søk fra og med (se fromExcluding for bare fra men ikke med)
Expand All @@ -915,7 +921,7 @@ input SearchRule {
" Filtrerer bort treff hvor felt inneholder input verdi"
notEquals: String
" Søk som gir tilfeldig poengsum til hvert treff (kun ment til generering av testdata)"
random: String
random: Float
" Regex søk for spesielle situasjoner (Dette er en treg opprasjon og bør ikke brukes)"
regex: String
" Gir treff når opgitt feltstarter med opgitt verdi."
Expand Down

0 comments on commit 1036b3f

Please sign in to comment.