Skip to content

Commit

Permalink
Begynt på oppsett for ny pdl-fullmakt i dolly-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
stigus committed Sep 10, 2024
1 parent 2a8cb64 commit 687ea84
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package no.nav.dolly.bestilling.fullmakt;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MappingContext;
import no.nav.dolly.bestilling.ClientFuture;
import no.nav.dolly.bestilling.ClientRegister;
import no.nav.dolly.bestilling.fullmakt.dto.FullmaktResponse;
import no.nav.dolly.domain.jpa.BestillingProgress;
import no.nav.dolly.domain.resultset.RsDollyUtvidetBestilling;
import no.nav.dolly.domain.resultset.dolly.DollyPerson;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.dolly.util.TransactionHelperService;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.util.List;

import static java.util.Objects.nonNull;

@Slf4j
@Service
@RequiredArgsConstructor
public class FullmaktClient implements ClientRegister {

private final MapperFacade mapperFacade;
private final ErrorStatusDecoder errorStatusDecoder;
private final TransactionHelperService transactionHelperService;
private final FullmaktConsumer fullmaktConsumer;

@Override
public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, DollyPerson dollyPerson, BestillingProgress progress, boolean isOpprettEndre) {

if (nonNull(bestilling.getFullmakt())) {

var context = new MappingContext.Factory().getContext();
context.setProperty("ident", dollyPerson.getIdent());
context.setProperty("bestilling", bestilling);

return Flux.from(fullmaktConsumer.createFullmaktData(bestilling.getFullmakt()))
.map(this::getStatus)
.map(status -> futurePersist(progress, status));
}

//TODO: Kunne opprette fullmakt ved gjeldende person i gruppen eller lage ny gjennom pdl-forvalter
//TODO: Fjerne trygdeetaten fra proxy og informere PDL om dette
//TODO: Fullmakt-proxy - bruke oppsett fra cv-proxy som legger på tokenX fra header mot fakedings
//TODO: Fullmektig get og Post er på helt samme endepunkt-url
//TODO: Lage ny fullmektig option i dolly-bestilling, prøve å få det bakoverkompatibelt

return Flux.empty();
}

@Override
public void release(List<String> identer) {

//TODO: Legge til sletting dersom det trengs
// fullmaktConsumer.deleteKontaktdata(identer)
// .collectList()
// .subscribe(resp -> log.info("Slettet antall {} identer fra Krrstub", resp.size()));
}

private ClientFuture futurePersist(BestillingProgress progress, String status) {

return () -> {
transactionHelperService.persister(progress, BestillingProgress::setFullmaktStatus, status);
return progress;
};
}

private String getStatus(FullmaktResponse response) {

return response.getStatus().is2xxSuccessful() ? "OK" :
errorStatusDecoder.getErrorText(response.getStatus(), response.getMelding());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package no.nav.dolly.bestilling.fullmakt;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.ConsumerStatus;
import no.nav.dolly.bestilling.fullmakt.command.GetFullmaktDataCommand;
import no.nav.dolly.bestilling.fullmakt.dto.FullmaktResponse;
import no.nav.dolly.config.Consumers;
import no.nav.dolly.domain.resultset.fullmakt.RsFullmakt;
import no.nav.dolly.metrics.Timed;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;

import static no.nav.dolly.util.JacksonExchangeStrategyUtil.getJacksonStrategy;

@Slf4j
@Service
public class FullmaktConsumer implements ConsumerStatus {

private final WebClient webClient;
private final TokenExchange tokenService;
private final ServerProperties serverProperties;

public FullmaktConsumer(
TokenExchange tokenService,
Consumers consumers,
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder
) {
this.tokenService = tokenService;
serverProperties = consumers.getTestnavFullmaktProxy();
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.exchangeStrategies(getJacksonStrategy(objectMapper))
.build();
}

@Timed(name = "providers", tags = { "operation", "fullmakt_createData" })
public Mono<FullmaktResponse> createFullmaktData(RsFullmakt fullmakt) {

log.info("Fullmakt opprett {}", fullmakt);
return tokenService.exchange(serverProperties)
.flatMap(token -> new FullmaktDataPostCommand(webClient, fullmakt, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "fullmakt_getData" })
public Flux<FullmaktResponse> getFullmaktData(List<String> identer) {

return tokenService.exchange(serverProperties)
.flatMapMany(token -> Flux.range(0, identer.size())
.delayElements(Duration.ofMillis(100))
.flatMap(idx -> new GetFullmaktDataCommand(webClient, identer.get(idx),
token.getTokenValue()).call()));
}

@Override
public String serviceUrl() {
return serverProperties.getUrl();
}

@Override
public String consumerName() {
return "testnav-fullmakt-proxy";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package no.nav.dolly.bestilling.fullmakt.command;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.fullmakt.dto.FullmaktResponse;
import no.nav.dolly.util.RequestHeaderUtil;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import no.nav.testnav.libs.securitycore.config.UserConstant;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.util.retry.Retry;

import java.time.Duration;
import java.util.concurrent.Callable;

import static no.nav.dolly.domain.CommonKeysAndUtils.CONSUMER;
import static no.nav.dolly.domain.CommonKeysAndUtils.HEADER_NAV_CALL_ID;
import static no.nav.dolly.domain.CommonKeysAndUtils.HEADER_NAV_CONSUMER_ID;
import static no.nav.dolly.domain.CommonKeysAndUtils.HEADER_NAV_PERSON_IDENT;
import static no.nav.dolly.util.TokenXUtil.getUserJwt;

@Slf4j
@RequiredArgsConstructor
public class GetFullmaktDataCommand implements Callable<Flux<FullmaktResponse>> {

private static final String HENT_FULLMAKT_URL = "/api/v1/fullmakt/fullmektig";

private final WebClient webClient;
private final String ident;
private final String token;

public Flux<FullmaktResponse> call() {

return webClient.get()
.uri(uriBuilder -> uriBuilder
.path(HENT_FULLMAKT_URL)
.build())
.header(HEADER_NAV_CALL_ID, RequestHeaderUtil.getNavCallId())
.header(HEADER_NAV_CONSUMER_ID, CONSUMER)
.header(HEADER_NAV_PERSON_IDENT, ident)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.header(UserConstant.USER_HEADER_JWT, getUserJwt())
.retrieve()
.bodyToFlux(FullmaktResponse.class)
.doOnError(WebClientFilter::logErrorMessage)
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5))
.filter(WebClientFilter::is5xxException))
.doOnError(WebClientFilter::logErrorMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package no.nav.dolly.bestilling.fullmakt.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FullmaktResponse {

private HttpStatus status;
private String melding;
private List<Fullmakt> fullmakt;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Fullmakt {

private Integer fullmaktId;
private LocalDateTime registrert;
private String registrertAv;
private LocalDateTime endret;
private String endretAv;
private Boolean opphoert;
private String fullmaktsgiver;
private String fullmektig;
private List<Omraade> omraade;
private LocalDate gyldigFraOgMed;
private LocalDate gyldigTilOgMed;
private String fullmaktUuid;
private String opplysningsId;
private Integer endringsId;
private String status;
private String kilde;
private String fullmaktsgiverNavn;
private String fullmektigsNavn;
}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Omraade {
private String tema;
private List<String> handling;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Consumers {
private ServerProperties testnavInstProxy;
private ServerProperties testnavKodeverkService;
private ServerProperties testnavKontoregisterPersonProxy;
private ServerProperties testnavFullmaktProxy;
private ServerProperties testnavKrrstubProxy;
private ServerProperties testnavMedlProxy;
private ServerProperties testnavMiljoerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class BestillingProgress implements Serializable {
@Column(name = "KRRSTUB_STATUS")
private String krrstubStatus;

@Column(name = "FULLMAKT_STATUS")
private String fullmaktStatus;

@Column(name = "MEDL_STATUS")
private String medlStatus;

Expand Down Expand Up @@ -170,6 +173,7 @@ public boolean equals(Object o) {
.append(getBestilling(), that.getBestilling())
.append(getIdent(), that.getIdent())
.append(getSigrunstubStatus(), that.getSigrunstubStatus())
.append(getFullmaktStatus(), that.getFullmaktStatus())
.append(getKrrstubStatus(), that.getKrrstubStatus())
.append(getMedlStatus(), that.getMedlStatus())
.append(getUdistubStatus(), that.getUdistubStatus())
Expand Down Expand Up @@ -205,6 +209,7 @@ public int hashCode() {
.append(getIdent())
.append(getSigrunstubStatus())
.append(getKrrstubStatus())
.append(getFullmaktStatus())
.append(getMedlStatus())
.append(getUdistubStatus())
.append(getAaregStatus())
Expand Down Expand Up @@ -239,6 +244,7 @@ public String toString() {
", ident='" + ident + '\'' +
", sigrunstubStatus='" + sigrunstubStatus + '\'' +
", krrstubStatus='" + krrstubStatus + '\'' +
", fullmaktStatus='" + fullmaktStatus + '\'' +
", medlStatus='" + medlStatus + '\'' +
", udistubStatus='" + udistubStatus + '\'' +
", aaregStatus='" + aaregStatus + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata;
import no.nav.dolly.domain.resultset.breg.RsBregdata;
import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv;
import no.nav.dolly.domain.resultset.fullmakt.RsFullmakt;
import no.nav.dolly.domain.resultset.histark.RsHistark;
import no.nav.dolly.domain.resultset.inntektsmeldingstub.RsInntektsmelding;
import no.nav.dolly.domain.resultset.inntektstub.InntektMultiplierWrapper;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class BestilteKriterier {
private RsInntektsmelding inntektsmelding;
private RsBregdata brregstub;
private RsDokarkiv dokarkiv;
private RsFullmakt fullmakt;
private RsMedl medl;
private RsHistark histark;
private RsTpsMessaging tpsMessaging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import no.nav.dolly.domain.resultset.arenaforvalter.Arenadata;
import no.nav.dolly.domain.resultset.breg.RsBregdata;
import no.nav.dolly.domain.resultset.dokarkiv.RsDokarkiv;
import no.nav.dolly.domain.resultset.fullmakt.RsFullmakt;
import no.nav.dolly.domain.resultset.histark.RsHistark;
import no.nav.dolly.domain.resultset.inntektsmeldingstub.RsInntektsmelding;
import no.nav.dolly.domain.resultset.inntektstub.InntektMultiplierWrapper;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class RsDollyBestilling {
private String malBestillingNavn;
private PdlPersondata pdldata;
private RsDigitalKontaktdata krrstub;
private RsFullmakt fullmakt;
private RsMedl medl;
private List<RsInstdata> instdata;
private List<RsAareg> aareg;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package no.nav.dolly.domain.resultset.fullmakt;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RsFullmakt {

@Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second, pattern = "uuuu-MM-dd'T'HH:mm:ss")
private LocalDateTime gyldigFraOgMed;
@Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second, pattern = "uuuu-MM-dd'T'HH:mm:ss")
private LocalDateTime gyldigTilOgMed;
private String fullmektig;
private String fullmaktsgiver;
private List<String> omraader;
}
Loading

0 comments on commit 687ea84

Please sign in to comment.