-
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.
Feature/dolly sok inkluder opprettede personer (#3724)
- Loading branch information
Showing
58 changed files
with
2,370 additions
and
12 deletions.
There are no files selected for viewing
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,25 @@ | ||
name: dolly-search-service | ||
|
||
on: | ||
push: | ||
paths: | ||
- "plugins/**" | ||
- "libs/data-transfer-search-objects/**" | ||
- "libs/reactive-core/**" | ||
- "libs/security-core/**" | ||
- "libs/servlet-core/**" | ||
- "libs/servlet-security/**" | ||
- "libs/testing/**" | ||
- "apps/dolly-search-service/**" | ||
- ".github/workflows/app.dolly-search-service.yml" | ||
|
||
jobs: | ||
workflow: | ||
uses: ./.github/workflows/common.workflow.backend.yml | ||
with: | ||
working-directory: "apps/dolly-search-service" | ||
deploy-tag: "#deploy-dolly-search-service" | ||
permissions: | ||
contents: read | ||
id-token: write | ||
secrets: inherit |
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
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
39 changes: 39 additions & 0 deletions
39
apps/dolly-backend/src/main/java/no/nav/dolly/opensearch/DollySearchServiceConsumer.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,39 @@ | ||
package no.nav.dolly.opensearch; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.dolly.config.Consumers; | ||
import no.nav.dolly.opensearch.command.DollySearchServicePostCommand; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.SearchRequest; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.SearchResponse; | ||
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.Mono; | ||
|
||
@Service | ||
@Slf4j | ||
public class DollySearchServiceConsumer { | ||
|
||
private final TokenExchange tokenService; | ||
private final WebClient webClient; | ||
private final ServerProperties serverProperties; | ||
|
||
public DollySearchServiceConsumer( | ||
TokenExchange tokenService, | ||
Consumers consumers, | ||
WebClient.Builder webClientBuilder) { | ||
|
||
this.tokenService = tokenService; | ||
serverProperties = consumers.getDollySearchService(); | ||
this.webClient = webClientBuilder | ||
.baseUrl(serverProperties.getUrl()) | ||
.build(); | ||
} | ||
|
||
public Mono<SearchResponse> doPersonSearch(SearchRequest request) { | ||
|
||
return tokenService.exchange(serverProperties) | ||
.flatMap(token -> new DollySearchServicePostCommand(webClient, request, token.getTokenValue()).call()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...-backend/src/main/java/no/nav/dolly/opensearch/command/DollySearchServicePostCommand.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,40 @@ | ||
package no.nav.dolly.opensearch.command; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.SearchRequest; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.SearchResponse; | ||
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
import reactor.util.retry.Retry; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.Callable; | ||
|
||
@RequiredArgsConstructor | ||
public class DollySearchServicePostCommand implements Callable<Mono<SearchResponse>> { | ||
|
||
private static final String SEARCH_URL = "/api/v1/opensearch"; | ||
|
||
private final WebClient webClient; | ||
private final SearchRequest request; | ||
private final String token; | ||
|
||
@Override | ||
public Mono<SearchResponse> call() { | ||
|
||
return webClient.post() | ||
.uri(uriBuilder -> uriBuilder.path(SEARCH_URL).build()) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token) | ||
.bodyValue(request) | ||
.retrieve() | ||
.bodyToMono(SearchResponse.class) | ||
.doOnError(WebClientFilter::logErrorMessage) | ||
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) | ||
.filter(WebClientFilter::is5xxException)) | ||
.onErrorResume(error -> Mono.just(SearchResponse.builder() | ||
.error(WebClientFilter.getMessage(error)) | ||
.build())); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
apps/dolly-backend/src/main/java/no/nav/dolly/opensearch/dto/SearchRequest.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,52 @@ | ||
package no.nav.dolly.opensearch.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.PersonRequest; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SearchRequest { | ||
|
||
@Schema(description = "Paginering for bestillinger") | ||
private PagineringBestillingRequest pagineringBestillingRequest; | ||
|
||
@Schema(description = "Paginering for personersøk") | ||
private PagineringPersonRequest pagineringPersonRequest; | ||
|
||
@Schema(description = "Persondetaljer") | ||
private PersonRequest personRequest; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class PagineringBestillingRequest { | ||
|
||
@Schema(description = "Seed for paginering") | ||
private Integer seed; | ||
@Schema(description = "Sidenummer") | ||
private Integer side; | ||
@Schema(description = "Antall resultater per side") | ||
private Integer antall; | ||
} | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class PagineringPersonRequest { | ||
|
||
@Schema(description = "Sidenummer") | ||
private Integer side; | ||
@Schema(description = "Antall resultater per side") | ||
private Integer antall; | ||
@Schema(description = "Seed for paginering") | ||
private Integer seed; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
apps/dolly-backend/src/main/java/no/nav/dolly/opensearch/dto/SearchResponse.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,39 @@ | ||
package no.nav.dolly.opensearch.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import net.minidev.json.annotate.JsonIgnore; | ||
import no.nav.dolly.elastic.ElasticTyper; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SearchResponse { | ||
|
||
private RegistreResponseStatus registreSearchResponse; | ||
private no.nav.testnav.libs.data.dollysearchservice.v1.SearchResponse dollySearchResponse; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class RegistreResponseStatus { | ||
|
||
private Long totalHitsBestillinger; | ||
private Float score; | ||
private String took; | ||
private Integer antall; | ||
private Integer side; | ||
private Integer antallIdenter; | ||
private Integer seed; | ||
private List<ElasticTyper> registre; | ||
private String error; | ||
@JsonIgnore | ||
private List<String> identer; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ackend/src/main/java/no/nav/dolly/opensearch/mapper/OpenSearchRequestMappingStrategy.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,29 @@ | ||
package no.nav.dolly.opensearch.mapper; | ||
|
||
import ma.glasnost.orika.CustomMapper; | ||
import ma.glasnost.orika.MapperFactory; | ||
import ma.glasnost.orika.MappingContext; | ||
import no.nav.dolly.mapper.MappingStrategy; | ||
import no.nav.dolly.opensearch.dto.SearchRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OpenSearchRequestMappingStrategy implements MappingStrategy { | ||
|
||
@Override | ||
public void register(MapperFactory factory) { | ||
|
||
factory.classMap(SearchRequest.class, no.nav.testnav.libs.data.dollysearchservice.v1.SearchRequest.class) | ||
.customize(new CustomMapper<>() { | ||
@Override | ||
public void mapAtoB(SearchRequest kilde, no.nav.testnav.libs.data.dollysearchservice.v1.SearchRequest destinasjon, MappingContext context) { | ||
|
||
destinasjon.setAntall(kilde.getPagineringPersonRequest().getAntall()); | ||
destinasjon.setSide(kilde.getPagineringPersonRequest().getSide()); | ||
destinasjon.setSeed(kilde.getPagineringPersonRequest().getSeed()); | ||
} | ||
}) | ||
.byDefault() | ||
.register(); | ||
} | ||
} |
Oops, something went wrong.