Skip to content

Commit

Permalink
Lagt til nye parametere for soek II #deploy-tenor-search-service
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Jan 23, 2024
1 parent 667a61c commit cd7fd4c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public TenorClient(Consumers consumers, MaskinportenClient maskinportenClient) {
this.maskinportenClient = maskinportenClient;
}

public Mono<TenorResponse> getTestdata(String query, Kilde kilde, InfoType type, Integer seed) {
public Mono<TenorResponse> getTestdata(String query, Kilde kilde, InfoType type, String fields, Integer seed) {

return maskinportenClient.getAccessToken()
.flatMap(token -> new GetTenorTestdata(webClient, query, kilde, type, seed, token.value()).call());
.flatMap(token -> new GetTenorTestdata(webClient, query, kilde, type, fields, seed, token.value()).call());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,30 @@
public class GetTenorTestdata implements Callable<Mono<TenorResponse>> {

private static final String TENOR_QUERY_URL = "/api/testnorge/v2/soek/{kilde}";
private static final String TENOR_UTVIDET_QUERY_URL = "/api/testnorge/v2/soek/{kilde}/utvidet";

private final WebClient webClient;
private final String query;
private final Kilde kilde;
private final InfoType type;
private final String fields;
private final Integer seed;
private final String token;

@Override
public Mono<TenorResponse> call() {

log.info("Query-parameter: {}", query);
var requestParams = Map.of("tenorQuery", query,
"kilde", getKilde(kilde).getKilde());
var requestParams = Map.of(
"kilde", getKilde(kilde).getKilde(),
"query", query);

return webClient.get()
.uri(uriBuilder -> uriBuilder
.path(getUrl(type))
.queryParam("kql", "{tenorQuery}")
.path(TENOR_QUERY_URL)
.queryParam("kql", "{query}")
.queryParam("nokkelinformasjon", isNoekkelinfo(type))
.queryParamIfPresent("seed", Optional.ofNullable(seed))
.queryParamIfPresent("vis", Optional.ofNullable(getVisning(type)))
.build(requestParams))
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.retrieve()
Expand All @@ -65,14 +67,23 @@ public Mono<TenorResponse> call() {
.build()));
}

private Kilde getKilde(Kilde kilde) {
private String getVisning(InfoType type) {

return isNull(kilde) ? Kilde.FREG : kilde;
if (nonNull(type)) {
return switch (type) {
case Kildedata -> "tenorMetadata.kildedata";
case AlleFelter -> "*";
case Spesifikt -> fields;
default -> null;
};
} else {
return null;
}
}

private String getUrl(InfoType type) {
private Kilde getKilde(Kilde kilde) {

return isNull(type) || type != InfoType.Kildedokument ? TENOR_QUERY_URL : TENOR_UTVIDET_QUERY_URL;
return isNull(kilde) ? Kilde.FREG : kilde;
}

private boolean isNoekkelinfo(InfoType type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package no.nav.testnav.apps.tenorsearchservice.consumers.dto;

public enum InfoType {

IdenterKun,
Noekkelinfo,
Kildedokument
Kildedata,
AlleFelter,
Spesifikt
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ public class TenorSearchController {
public Mono<TenorResponse> getTestdata(@RequestParam(required = false) String searchData,
@RequestParam(required = false) Kilde kilde,
@RequestParam(required = false) InfoType type,
@RequestParam(required = false) String fields,
@RequestParam(required = false) Integer seed) {

return tenorSearchService
.getTestdata(searchData, kilde, type, seed);
.getTestdata(searchData, kilde, type, fields, seed);
}

@PostMapping("/testdata")
public Mono<TenorResponse> getTestdata(@RequestBody TenorRequest searchData,
@RequestParam(required = false) Kilde kilde,
@RequestParam(required = false) InfoType type,
@RequestParam(required = false) String fields,
@RequestParam(required = false) Integer seed) {

return tenorSearchService
.getTestdata(searchData, kilde, type, seed);
.getTestdata(searchData, kilde, type, fields, seed);
}

@GetMapping("/testdata/domain")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
public class TenorSearchService {
private final TenorClient tenorClient;

public Mono<TenorResponse> getTestdata(String testDataQuery, Kilde kilde, InfoType type, Integer seed) {
public Mono<TenorResponse> getTestdata(String testDataQuery, Kilde kilde, InfoType type, String fields, Integer seed) {

return tenorClient.getTestdata(isNotBlank(testDataQuery) ? testDataQuery : "", kilde, type, seed);
return tenorClient.getTestdata(isNotBlank(testDataQuery) ? testDataQuery : "", kilde, type, fields, seed);
}

public Mono<TenorResponse> getTestdata(TenorRequest searchData, Kilde kilde, InfoType type, Integer seed) {
public Mono<TenorResponse> getTestdata(TenorRequest searchData, Kilde kilde, InfoType type, String fields, Integer seed) {

var builder = new StringBuilder()
.append(convertObject("identifikator", searchData.getIdentifikator()))
Expand Down Expand Up @@ -90,7 +90,7 @@ public Mono<TenorResponse> getTestdata(TenorRequest searchData, Kilde kilde, Inf
builder.append(TenorEksterneRelasjonerUtility.getEksterneRelasjoner(searchData));

var query = builder.substring(builder.isEmpty() ? 0 : 5, builder.length());
return tenorClient.getTestdata(query, kilde, type, seed);
return tenorClient.getTestdata(query, kilde, type, fields, seed);
}

private String getRelasjonMedFoedselsdato(TenorRequest.Intervall relasjonMedFoedselsaar) {
Expand Down

0 comments on commit cd7fd4c

Please sign in to comment.