-
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.
Add OpenSearchResponse DTO and refactor search handling in OpenSearch…
…Service #deploy-dolly-search-service
- Loading branch information
Showing
14 changed files
with
260 additions
and
62 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
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
46 changes: 46 additions & 0 deletions
46
...ervice/src/main/java/no/nav/testnav/dollysearchservice/consumer/DollyBackendConsumer.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,46 @@ | ||
package no.nav.testnav.dollysearchservice.consumer; | ||
|
||
import no.nav.testnav.dollysearchservice.config.Consumers; | ||
import no.nav.testnav.dollysearchservice.consumer.command.FinnesIDollyGetCommand; | ||
import no.nav.testnav.dollysearchservice.dto.DollyBackendSelector; | ||
import no.nav.testnav.libs.dto.dolly.v1.FinnesDTO; | ||
import no.nav.testnav.libs.securitycore.domain.ServerProperties; | ||
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Set; | ||
|
||
import static no.nav.testnav.dollysearchservice.dto.DollyBackendSelector.REGULAR; | ||
|
||
@Service | ||
public class DollyBackendConsumer { | ||
|
||
private final WebClient webClient; | ||
private final WebClient webClientDev; | ||
private final TokenExchange tokenExchange; | ||
private final ServerProperties dollyBackendProperties; | ||
private final ServerProperties dollyBackendPropertiesDev; | ||
|
||
public DollyBackendConsumer(TokenExchange tokenExchange, Consumers serverProperties, | ||
WebClient.Builder webClientBuilder) { | ||
this.webClient = webClientBuilder | ||
.baseUrl(serverProperties.getDollyBackend().getUrl()) | ||
.build(); | ||
this.webClientDev = webClientBuilder | ||
.baseUrl(serverProperties.getDollyBackendDev().getUrl()) | ||
.build(); | ||
this.tokenExchange = tokenExchange; | ||
this.dollyBackendProperties = serverProperties.getDollyBackend(); | ||
this.dollyBackendPropertiesDev = serverProperties.getDollyBackendDev(); | ||
} | ||
|
||
public Mono<FinnesDTO> getFinnesInfo(Set<String> identer, DollyBackendSelector selector) { | ||
|
||
var properties = selector == REGULAR ? dollyBackendProperties : dollyBackendPropertiesDev; | ||
var client = selector == REGULAR ? webClient : webClientDev; | ||
return tokenExchange.exchange(properties) | ||
.flatMap(token -> new FinnesIDollyGetCommand(client, identer, token.getTokenValue()).call()); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
.../main/java/no/nav/testnav/dollysearchservice/consumer/command/FinnesIDollyGetCommand.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,41 @@ | ||
package no.nav.testnav.dollysearchservice.consumer.command; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.testnav.libs.dto.dolly.v1.FinnesDTO; | ||
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.Set; | ||
import java.util.concurrent.Callable; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class FinnesIDollyGetCommand implements Callable<Mono<FinnesDTO>> { | ||
|
||
private static final String FINNES_URL = "/api/v1/ident/finnes"; | ||
private static final String IDENTER = "identer"; | ||
|
||
private final WebClient webClient; | ||
private final Set<String> identer; | ||
private final String token; | ||
|
||
public Mono<FinnesDTO> call() { | ||
|
||
return webClient | ||
.get() | ||
.uri(uriBuilder -> uriBuilder | ||
.path(FINNES_URL) | ||
.queryParam(IDENTER, identer) | ||
.build()) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token) | ||
.retrieve() | ||
.bodyToMono(FinnesDTO.class) | ||
.retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) | ||
.filter(WebClientFilter::is5xxException)); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
...rch-service/src/main/java/no/nav/testnav/dollysearchservice/dto/DollyBackendSelector.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,6 @@ | ||
package no.nav.testnav.dollysearchservice.dto; | ||
|
||
public enum DollyBackendSelector { | ||
REGULAR, | ||
DEV | ||
} |
58 changes: 58 additions & 0 deletions
58
...earch-service/src/main/java/no/nav/testnav/dollysearchservice/dto/OpenSearchResponse.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,58 @@ | ||
package no.nav.testnav.dollysearchservice.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.SearchRequest; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class OpenSearchResponse { | ||
|
||
private SearchRequest request; | ||
|
||
private Integer took; | ||
private Boolean timedOut; | ||
private SearchHits hits; | ||
|
||
private HttpStatus status; | ||
private String error; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class SearchHits { | ||
|
||
private Total total; | ||
private float maxScore; | ||
private List<SearchHit> hits; | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Total { | ||
|
||
private Long value; | ||
private String relation; | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@SuppressWarnings("java:S116") | ||
public static class SearchHit { | ||
|
||
private String _index; | ||
private String _type; | ||
private String _id; | ||
private Double _score; | ||
private Object _source; | ||
} | ||
} |
52 changes: 9 additions & 43 deletions
52
...ly-search-service/src/main/java/no/nav/testnav/dollysearchservice/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 |
---|---|---|
@@ -1,58 +1,24 @@ | ||
package no.nav.testnav.dollysearchservice.dto; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import no.nav.testnav.libs.data.dollysearchservice.v1.SearchRequest; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SearchResponse { | ||
|
||
private SearchRequest request; | ||
|
||
private Integer took; | ||
private Boolean timedOut; | ||
private SearchHits hits; | ||
|
||
private HttpStatus status; | ||
private Long totalHits; | ||
private String took; | ||
private Integer side; | ||
private Integer antall; | ||
private Integer seed; | ||
private Map<String, JsonNode> personer; | ||
private String error; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class SearchHits { | ||
|
||
private Total total; | ||
private float maxScore; | ||
private List<SearchHit> hits; | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Total { | ||
|
||
private Long value; | ||
private String relation; | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@SuppressWarnings("java:S116") | ||
public static class SearchHit { | ||
|
||
private String _index; | ||
private String _type; | ||
private String _id; | ||
private Double _score; | ||
private Object _source; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.