Skip to content

Commit

Permalink
Feature/dolly sok inkluder opprettede personer (#3724)
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum authored Feb 25, 2025
1 parent 25fec35 commit 9858317
Show file tree
Hide file tree
Showing 58 changed files with 2,370 additions and 12 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/app.dolly-search-service.yml
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
1 change: 1 addition & 0 deletions apps/dolly-backend/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ spec:
- application: testnav-arbeidsforhold-service
- application: testnav-arbeidsplassencv-proxy
- application: testnav-arbeidssoekerregisteret-proxy
- application: testnav-dolly-search-service
- application: testnav-inntektsmelding-service
- application: testnav-kodeverk-service
- application: testnav-miljoer-service
Expand Down
6 changes: 4 additions & 2 deletions apps/dolly-backend/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ spec:
accessPolicy:
inbound:
rules:

- application: dolly-frontend
- application: dolly-idporten
- application: etterlatte-testdata
namespace: etterlatte
- application: testnav-batch-bestilling-service
- application: testnav-dollystatus
- application: testnav-helsepersonell-service
- application: testnav-oversikt-frontend
- application: testnav-tenor-search-service
- application: etterlatte-testdata
namespace: etterlatte
outbound:
rules:
- application: generer-navn-service
- application: testnav-amelding-service
- application: testnav-arbeidsforhold-service
- application: testnav-arbeidsplassencv-proxy
- application: testnav-arbeidssoekerregisteret-proxy
- application: testnav-dolly-search-service
- application: testnav-inntektsmelding-service
- application: testnav-kodeverk-service
- application: testnav-miljoer-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public static void main(String[] args) {
.initializers(new NaisEnvironmentApplicationContextInitializer())
.run(args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public class Consumers {
private ServerProperties testnavSkattekortService;
private ServerProperties yrkesskadeProxy;
private ServerProperties arbeidssoekerregisteretProxy;
private ServerProperties dollySearchService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import lombok.NoArgsConstructor;
import no.nav.dolly.elastic.ElasticBestilling;

import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.isNull;

@Data
@Builder
@NoArgsConstructor
Expand All @@ -20,6 +23,22 @@ public class SearchResponse {
private Float score;
private String took;
private List<String> identer;
private List<ElasticBestilling> bestillinger;
private List<ElasticBestilling> registre;
private String error;

public List<String> getIdenter() {

if (isNull(identer)) {
identer = new ArrayList<>();
}
return identer;
}

public List<ElasticBestilling> getRegistre() {

if (isNull(registre)) {
registre = new ArrayList<>();
}
return registre;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static BoolQueryBuilder buildTyperQuery(ElasticTyper[] typer) {
return queryBuilder;
}

private void setPersonQuery(BoolQueryBuilder queryBuilder, SearchRequest request) {
private static void setPersonQuery(BoolQueryBuilder queryBuilder, SearchRequest request) {

Optional.ofNullable(request.getPersonRequest())
.ifPresent(value -> {
Expand Down Expand Up @@ -107,7 +107,7 @@ private void setPersonQuery(BoolQueryBuilder queryBuilder, SearchRequest request
});
}

private QueryBuilder getFagsystemQuery(ElasticTyper type) {
public static QueryBuilder getFagsystemQuery(ElasticTyper type) {

return switch (type) {
case AAREG -> QueryBuilders.existsQuery("aareg");
Expand Down
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());
}
}
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()));
}
}
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;
}
}
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;
}
}
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();
}
}
Loading

0 comments on commit 9858317

Please sign in to comment.