-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begynt på oppsett for ny pdl-fullmakt i dolly-backend
- Loading branch information
Showing
12 changed files
with
318 additions
and
10 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/fullmakt/FullmaktClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/fullmakt/FullmaktConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...ackend/src/main/java/no/nav/dolly/bestilling/fullmakt/command/GetFullmaktDataCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/fullmakt/dto/FullmaktResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
apps/dolly-backend/src/main/java/no/nav/dolly/domain/resultset/fullmakt/RsFullmakt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.