Skip to content

Commit 11fa0ab

Browse files
committed
feature: Refactor Instdata handling and introduce KDI support
1 parent ea41837 commit 11fa0ab

17 files changed

Lines changed: 139 additions & 122 deletions

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/InstdataClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Mono<BestillingProgress> gjenopprett(RsDollyUtvidetBestilling bestilling,
4242
.filter(rsInstdata -> !rsInstdata.isEmpty())
4343
.flatMap(rsInstdata -> Mono.just(mapperFacade.mapAsList(rsInstdata, Instdata.class, context)))
4444
.flatMap(instdata -> instdataConsumer.getMiljoer()
45-
.flatMap(miljoer -> Flux.fromIterable(miljoer)
45+
.flatMap(miljoer -> Flux.fromIterable(miljoer.getInstitusjonsoppholdEnvironments())
4646
.filter(miljoe -> bestilling.getEnvironments().contains(miljoe))
4747
.flatMap(miljoe -> postInstdata(isOpprettEndre, instdata, miljoe))
4848
.collect(Collectors.joining(",")))

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/InstdataConsumer.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import no.nav.dolly.bestilling.instdata.command.InstdataKdiDeleteCommand;
99
import no.nav.dolly.bestilling.instdata.command.InstdataKdiPostCommand;
1010
import no.nav.dolly.bestilling.instdata.command.InstdataPostCommand;
11-
import no.nav.dolly.bestilling.instdata.domain.DeleteResponse;
12-
import no.nav.dolly.bestilling.instdata.domain.InstdataKdiPostRequest;
11+
import no.nav.dolly.bestilling.instdata.domain.InstdataKdiDTO;
1312
import no.nav.dolly.bestilling.instdata.domain.InstdataResponse;
14-
import no.nav.dolly.bestilling.instdata.domain.InstitusjonsoppholdRespons;
1513
import no.nav.dolly.bestilling.instdata.domain.MiljoerResponse;
1614
import no.nav.dolly.config.Consumers;
1715
import no.nav.dolly.domain.resultset.inst.Instdata;
@@ -54,14 +52,14 @@ public Mono<MiljoerResponse> getMiljoer() {
5452
}
5553

5654
@Timed(name = "providers", tags = {"operation", "inst_getInstdata"})
57-
public Mono<InstitusjonsoppholdRespons> getInstdata(String ident, String environment) {
55+
public Mono<InstdataResponse> getInstdata(String ident, String environment) {
5856

5957
return tokenService.exchange(serverProperties)
6058
.flatMap(token -> new InstdataGetCommand(webClient, ident, environment, token.getTokenValue()).call());
6159
}
6260

6361
@Timed(name = "providers", tags = {"operation", "inst_deleteInstdata"})
64-
public Mono<List<DeleteResponse>> deleteInstdata(List<String> identer) {
62+
public Mono<List<InstdataResponse>> deleteInstdata(List<String> identer) {
6563

6664
return tokenService.exchange(serverProperties)
6765
.flatMap(token -> new InstdataGetMiljoerCommand(webClient, token.getTokenValue()).call()
@@ -84,13 +82,12 @@ public Flux<InstdataResponse> postInstdata(List<Instdata> instdata, String envir
8482
}
8583

8684
@Timed(name = "providers", tags = {"operation", "inst_postInstdataKdi"})
87-
public Flux<InstdataResponse> postInstdataKdi(InstdataKdiPostRequest instdata) {
85+
public Mono<InstdataResponse> postInstdataKdi(InstdataKdiDTO instdata, String ident, String environment) {
8886

8987
log.info("Instdata KDI oppretting {}", instdata);
9088
return tokenService.exchange(serverProperties)
91-
.flatMapMany(token -> Flux.fromIterable(instdata)
92-
.flatMap(opphold -> new InstdataKdiPostCommand(webClient, opphold,
93-
token.getTokenValue()).call()));
89+
.flatMap(token -> new InstdataKdiPostCommand(webClient, ident, instdata,
90+
token.getTokenValue()).call());
9491
}
9592

9693
@Override

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/command/InstdataDeleteCommand.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.slf4j.Slf4j;
5-
import no.nav.dolly.bestilling.instdata.domain.DeleteResponse;
65
import no.nav.dolly.bestilling.instdata.domain.InstdataRequest;
6+
import no.nav.dolly.bestilling.instdata.domain.InstdataResponse;
77
import no.nav.testnav.libs.reactivecore.web.WebClientError;
88
import no.nav.testnav.libs.reactivecore.web.WebClientHeader;
99
import org.springframework.http.HttpStatus;
@@ -16,7 +16,7 @@
1616

1717
@RequiredArgsConstructor
1818
@Slf4j
19-
public class InstdataDeleteCommand implements Callable<Mono<DeleteResponse>> {
19+
public class InstdataDeleteCommand implements Callable<Mono<InstdataResponse>> {
2020

2121
private static final String INSTDATA_URL = "/inst/api/v1/institusjonsopphold/person/slett";
2222

@@ -26,7 +26,7 @@ public class InstdataDeleteCommand implements Callable<Mono<DeleteResponse>> {
2626
private final String token;
2727

2828
@Override
29-
public Mono<DeleteResponse> call() {
29+
public Mono<InstdataResponse> call() {
3030

3131
return webClient
3232
.post()
@@ -40,14 +40,15 @@ public Mono<DeleteResponse> call() {
4040
.build())
4141
.retrieve()
4242
.toBodilessEntity()
43-
.map(resultat -> DeleteResponse.builder()
44-
.ident(ident)
43+
.map(resultat -> InstdataResponse.builder()
4544
.status(HttpStatus.valueOf(resultat.getStatusCode().value()))
45+
.personident(ident)
46+
.environments(miljoer)
4647
.build())
4748
.doOnError(
4849
throwable -> !(throwable instanceof WebClientResponseException.BadRequest),
4950
WebClientError.logTo(log))
5051
.retryWhen(WebClientError.is5xxException())
51-
.onErrorResume(throwable -> DeleteResponse.of(WebClientError.describe(throwable), ident));
52+
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable), ident, miljoer));
5253
}
5354
}

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/command/InstdataGetCommand.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.slf4j.Slf4j;
55
import no.nav.dolly.bestilling.instdata.domain.InstdataRequest;
6-
import no.nav.dolly.bestilling.instdata.domain.InstitusjonsoppholdRespons;
6+
import no.nav.dolly.bestilling.instdata.domain.InstdataResponse;
77
import no.nav.dolly.domain.resultset.inst.Instdata;
88
import no.nav.testnav.libs.reactivecore.web.WebClientError;
99
import no.nav.testnav.libs.reactivecore.web.WebClientHeader;
1010
import org.springframework.core.ParameterizedTypeReference;
1111
import org.springframework.http.HttpHeaders;
12+
import org.springframework.http.HttpStatus;
1213
import org.springframework.web.reactive.function.client.WebClient;
1314
import reactor.core.publisher.Mono;
1415

@@ -18,7 +19,7 @@
1819

1920
@Slf4j
2021
@RequiredArgsConstructor
21-
public class InstdataGetCommand implements Callable<Mono<InstitusjonsoppholdRespons>> {
22+
public class InstdataGetCommand implements Callable<Mono<InstdataResponse>> {
2223

2324
private static final String INSTDATA_URL = "/inst/api/v1/institusjonsopphold/person/soek";
2425

@@ -28,7 +29,7 @@ public class InstdataGetCommand implements Callable<Mono<InstitusjonsoppholdResp
2829
private final String token;
2930

3031
@Override
31-
public Mono<InstitusjonsoppholdRespons> call() {
32+
public Mono<InstdataResponse> call() {
3233
return webClient
3334
.post()
3435
.uri(builder -> builder.path(INSTDATA_URL)
@@ -42,11 +43,15 @@ public Mono<InstitusjonsoppholdRespons> call() {
4243
.retrieve()
4344
.bodyToMono(new ParameterizedTypeReference<Map<String, List<Instdata>>>() {
4445
})
45-
.map(resultat -> InstitusjonsoppholdRespons.builder()
46+
.map(resultat -> InstdataResponse.builder()
47+
.status(HttpStatus.OK)
48+
.personident(ident)
49+
.environments(List.of(miljoe))
4650
.institusjonsopphold(resultat)
4751
.build())
4852
.doOnError(error -> log.error("Henting av institusjonsopphold feilet", error))
4953
.retryWhen(WebClientError.is5xxException())
50-
.onErrorResume(error -> Mono.just(new InstitusjonsoppholdRespons()));
54+
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable),
55+
ident, List.of(miljoe)));
5156
}
5257
}

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/command/InstdataKdiDeleteCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.slf4j.Slf4j;
5-
import no.nav.dolly.bestilling.instdata.domain.DeleteResponse;
65
import no.nav.dolly.bestilling.instdata.domain.InstdataRequest;
6+
import no.nav.dolly.bestilling.instdata.domain.InstdataResponse;
77
import no.nav.testnav.libs.reactivecore.web.WebClientError;
88
import no.nav.testnav.libs.reactivecore.web.WebClientHeader;
99
import org.springframework.http.HttpMethod;
@@ -17,7 +17,7 @@
1717

1818
@RequiredArgsConstructor
1919
@Slf4j
20-
public class InstdataKdiDeleteCommand implements Callable<Mono<DeleteResponse>> {
20+
public class InstdataKdiDeleteCommand implements Callable<Mono<InstdataResponse>> {
2121

2222
private static final String INSTDATA_KDI_URL = "/inst/api/v2/kdi/person";
2323

@@ -27,7 +27,7 @@ public class InstdataKdiDeleteCommand implements Callable<Mono<DeleteResponse>>
2727
private final String token;
2828

2929
@Override
30-
public Mono<DeleteResponse> call() {
30+
public Mono<InstdataResponse> call() {
3131

3232
return webClient
3333
.method(HttpMethod.DELETE)
@@ -41,14 +41,14 @@ public Mono<DeleteResponse> call() {
4141
.build())
4242
.retrieve()
4343
.toBodilessEntity()
44-
.map(resultat -> DeleteResponse.builder()
45-
.ident(ident)
44+
.map(resultat -> InstdataResponse.builder()
45+
.personident(ident)
4646
.status(HttpStatus.valueOf(resultat.getStatusCode().value()))
4747
.build())
4848
.doOnError(
4949
throwable -> !(throwable instanceof WebClientResponseException.BadRequest),
5050
WebClientError.logTo(log))
5151
.retryWhen(WebClientError.is5xxException())
52-
.onErrorResume(throwable -> DeleteResponse.of(WebClientError.describe(throwable), ident));
52+
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable), ident, miljoer));
5353
}
5454
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package no.nav.dolly.bestilling.instdata.command;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import no.nav.dolly.bestilling.instdata.domain.InstdataKdiDTO;
6+
import no.nav.dolly.bestilling.instdata.domain.InstdataKdiResponse;
7+
import no.nav.dolly.bestilling.instdata.domain.InstdataRequest;
8+
import no.nav.testnav.libs.reactivecore.web.WebClientError;
9+
import no.nav.testnav.libs.reactivecore.web.WebClientHeader;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.web.reactive.function.client.WebClient;
12+
import reactor.core.publisher.Mono;
13+
14+
import java.util.concurrent.Callable;
15+
16+
@RequiredArgsConstructor
17+
@Slf4j
18+
public class InstdataKdiGetCommand implements Callable<Mono<InstdataKdiResponse>> {
19+
20+
private static final String INSTDATA_URL = "/inst/api/v2/kdi/person/soek";
21+
22+
private final WebClient webClient;
23+
private final String ident;
24+
private final String miljoe;
25+
private final String token;
26+
27+
@Override
28+
public Mono<InstdataKdiResponse> call() {
29+
return webClient
30+
.post()
31+
.uri(uriBuilder -> uriBuilder
32+
.path(INSTDATA_URL)
33+
.build())
34+
.headers(WebClientHeader.bearer(token))
35+
.bodyValue(InstdataRequest.builder()
36+
.norskident(ident)
37+
.environment(miljoe)
38+
.build())
39+
.retrieve()
40+
.bodyToMono(InstdataKdiDTO.class)
41+
.map(resultat -> InstdataKdiResponse.builder()
42+
.status(HttpStatus.OK)
43+
.norskident(ident)
44+
.environment(miljoe)
45+
.instdataKdi(resultat)
46+
.build())
47+
.doOnError(WebClientError.logTo(log))
48+
.retryWhen(WebClientError.is5xxException())
49+
.onErrorResume(throwable -> InstdataKdiResponse.of(WebClientError.describe(throwable), ident, miljoe));
50+
}
51+
}

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/command/InstdataKdiPostCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.slf4j.Slf4j;
5-
import no.nav.dolly.bestilling.instdata.domain.InstdataKdiPostRequest;
5+
import no.nav.dolly.bestilling.instdata.domain.InstdataKdiDTO;
66
import no.nav.dolly.bestilling.instdata.domain.InstdataResponse;
77
import no.nav.testnav.libs.reactivecore.web.WebClientError;
88
import no.nav.testnav.libs.reactivecore.web.WebClientHeader;
@@ -21,7 +21,7 @@ public class InstdataKdiPostCommand implements Callable<Mono<InstdataResponse>>
2121

2222
private final WebClient webClient;
2323
private final String ident;
24-
private final InstdataKdiPostRequest instdata;
24+
private final InstdataKdiDTO instdata;
2525
private final String token;
2626

2727
@Override
@@ -42,6 +42,6 @@ public Mono<InstdataResponse> call() {
4242
.build())
4343
.doOnError(WebClientError.logTo(log))
4444
.retryWhen(WebClientError.is5xxException())
45-
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable), instdata, List.of(instdata.getEnvironment())));
45+
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable), ident, List.of(instdata.getEnvironment())));
4646
}
4747
}

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/command/InstdataPostCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public Mono<InstdataResponse> call() {
3939
.toBodilessEntity()
4040
.map(resultat -> InstdataResponse.builder()
4141
.personident(instdata.getNorskident())
42-
.instdata(instdata)
4342
.status(HttpStatus.valueOf(resultat.getStatusCode().value()))
4443
.environments(List.of(miljoe))
4544
.build())
4645
.doOnError(WebClientError.logTo(log))
4746
.retryWhen(WebClientError.is5xxException())
48-
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable), instdata, List.of(miljoe)));
47+
.onErrorResume(throwable -> InstdataResponse.of(WebClientError.describe(throwable),
48+
instdata.getNorskident(), List.of(miljoe)));
4949
}
5050
}

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/domain/DeleteResponse.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/domain/InstdataKdiPostRequest.java renamed to apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/instdata/domain/InstdataKdiDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@Builder
1313
@NoArgsConstructor
1414
@AllArgsConstructor
15-
public class InstdataKdiPostRequest {
15+
public class InstdataKdiDTO {
1616

1717
private String environment;
1818
private Data data;

0 commit comments

Comments
 (0)