Skip to content

Commit

Permalink
fixed Importcandidates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Nov 24, 2023
1 parent 19f41b2 commit 65d6286
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImportCandidatesAwsClient implements OpenSearchClient<OpenSearchSwsResponse, ImportCandidatesAwsQuery> {
private static final Logger logger = LoggerFactory.getLogger(ImportCandidatesAwsClient.class);
public class ImportCandidateClient implements OpenSearchClient<OpenSearchSwsResponse, ImportCandidateQuery> {

private static final Logger logger = LoggerFactory.getLogger(ImportCandidateClient.class);

private final CachedJwtProvider jwtProvider;
private final HttpClient httpClient;
private final BodyHandler<String> bodyHandler;
public ImportCandidatesAwsClient(CachedJwtProvider cachedJwtProvider, HttpClient client) {

public ImportCandidateClient(CachedJwtProvider cachedJwtProvider, HttpClient client) {
super();
this.jwtProvider = cachedJwtProvider;
this.httpClient = client;
this.bodyHandler = HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8);
}

@JacocoGenerated
public static ImportCandidatesAwsClient defaultClient() {
public static ImportCandidateClient defaultClient() {
var cachedJwtProvider =
OpenSearchClient.getCachedJwtProvider(new SecretsReader());
return new ImportCandidatesAwsClient(cachedJwtProvider, HttpClient.newHttpClient());

return new ImportCandidateClient(cachedJwtProvider, HttpClient.newHttpClient());
}

@Override
public OpenSearchSwsResponse doSearch(ImportCandidatesAwsQuery query) {
public OpenSearchSwsResponse doSearch(ImportCandidateQuery query) {
return
query.createQueryBuilderStream()
.map(this::createRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import no.unit.nva.search2.model.OpenSearchQuery;
import no.unit.nva.search2.model.OpenSearchQueryBuilder;
import no.unit.nva.search2.model.OpenSearchSwsResponse;
import no.unit.nva.search2.model.PagedSearchResourceDto;
import no.unit.nva.search2.model.PagedSearchDto;
import no.unit.nva.search2.model.ParameterKey;
import no.unit.nva.search2.model.ParameterKeyImportCandidate;
import no.unit.nva.search2.model.QueryBuilderSourceWrapper;
Expand All @@ -55,9 +55,9 @@
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.search.sort.SortOrder;

public final class ImportCandidatesAwsQuery extends OpenSearchQuery<ParameterKeyImportCandidate> {
private ImportCandidatesAwsQuery() {
public final class ImportCandidateQuery extends OpenSearchQuery<ParameterKeyImportCandidate> {

ImportCandidateQuery() {
super();
}

Expand All @@ -73,7 +73,7 @@ public URI getOpenSearchUri() {
.getUri();
}

public String doSearch(ImportCandidatesAwsClient queryClient) {
public String doSearch(ImportCandidateClient queryClient) {
final var response = queryClient.doSearch(this);
return MediaType.CSV_UTF_8.is(this.getMediaType())
? toCsvText(response)
Expand All @@ -83,13 +83,13 @@ public String doSearch(ImportCandidatesAwsClient queryClient) {
private String toCsvText(OpenSearchSwsResponse response) {
return CsvTransformer.transform(response.getSearchHits());
}
PagedSearchResourceDto toPagedResponse(OpenSearchSwsResponse response) {

PagedSearchDto toPagedResponse(OpenSearchSwsResponse response) {
final var requestParameter = toNvaSearchApiRequestParameter();
final var source = URI.create(getNvaSearchApiUri().toString().split("\\?")[0]);

return
PagedSearchResourceDto.Builder.builder()
PagedSearchDto.Builder.builder()
.withTotalHits(response.getTotalSize())
.withHits(response.getSearchHits())
.withAggregations(response.getAggregationsStructured())
Expand Down Expand Up @@ -178,13 +178,13 @@ boolean isFirstPage() {

@SuppressWarnings("PMD.GodClass")
protected static class Builder
extends OpenSearchQueryBuilder<ParameterKeyImportCandidate, ImportCandidatesAwsQuery> {
extends OpenSearchQueryBuilder<ParameterKeyImportCandidate, ImportCandidateQuery> {

private static final String ALL = "all";
public static final Integer EXPECTED_TWO_PARTS = 2;

Builder() {
super(new ImportCandidatesAwsQuery());
super(new ImportCandidateQuery());
}

@Override
Expand All @@ -208,8 +208,8 @@ protected void setValue(String key, String value) {
case FIELDS -> query.setQueryValue(qpKey, expandFields(value));
case SORT -> addSortQuery(value);
case SORT_ORDER -> addSortOrderQuery(value);
case PUBLISHED_BEFORE, PUBLISHED_SINCE -> query.setSearchFieldValue(qpKey, expandDate(value));
case CATEGORY, CATEGORY_NOT, CATEGORY_SHOULD,
case PUBLISHED_BEFORE, PUBLISHED_SINCE,
CATEGORY, CATEGORY_NOT, CATEGORY_SHOULD,
COLLABORATION_TYPE,
DOI, DOI_NOT, DOI_SHOULD,
ID, ID_NOT, ID_SHOULD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResourceAwsClient implements OpenSearchClient<OpenSearchSwsResponse, ResourceAwsQuery> {
public class ResourceClient implements OpenSearchClient<OpenSearchSwsResponse, ResourceQuery> {

private static final Logger logger = LoggerFactory.getLogger(ResourceAwsClient.class);
private static final Logger logger = LoggerFactory.getLogger(ResourceClient.class);

private final CachedJwtProvider jwtProvider;
private final HttpClient httpClient;
private final BodyHandler<String> bodyHandler;
private final UserSettingsClient userSettingsClient;

public ResourceAwsClient(CachedJwtProvider cachedJwtProvider, HttpClient client) {
public ResourceClient(CachedJwtProvider cachedJwtProvider, HttpClient client) {
super();
this.jwtProvider = cachedJwtProvider;
this.httpClient = client;
Expand All @@ -39,15 +39,15 @@ public ResourceAwsClient(CachedJwtProvider cachedJwtProvider, HttpClient client)
}

@JacocoGenerated
public static ResourceAwsClient defaultClient() {
public static ResourceClient defaultClient() {
var cachedJwtProvider =
OpenSearchClient.getCachedJwtProvider(new SecretsReader());

return new ResourceAwsClient(cachedJwtProvider, HttpClient.newHttpClient());
return new ResourceClient(cachedJwtProvider, HttpClient.newHttpClient());
}

@Override
public OpenSearchSwsResponse doSearch(ResourceAwsQuery query) {
public OpenSearchSwsResponse doSearch(ResourceQuery query) {
return
query.createQueryBuilderStream(userSettingsClient)
.map(this::createRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import no.unit.nva.search2.model.OpenSearchQuery;
import no.unit.nva.search2.model.OpenSearchQueryBuilder;
import no.unit.nva.search2.model.OpenSearchSwsResponse;
import no.unit.nva.search2.model.PagedSearchResourceDto;
import no.unit.nva.search2.model.PagedSearchDto;
import no.unit.nva.search2.model.ParameterKey;
import no.unit.nva.search2.model.ParameterKeyResource;
import no.unit.nva.search2.model.QueryBuilderSourceWrapper;
Expand All @@ -55,17 +55,17 @@
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.search.sort.SortOrder;

public final class ResourceAwsQuery extends OpenSearchQuery<ParameterKeyResource> {
private ResourceAwsQuery() {
public final class ResourceQuery extends OpenSearchQuery<ParameterKeyResource> {

private ResourceQuery() {
super();
}

static Builder builder() {
return new Builder();
}
public String doSearch(ResourceAwsClient queryClient) {

public String doSearch(ResourceClient queryClient) {
final var response = queryClient.doSearch(this);
return MediaType.CSV_UTF_8.is(this.getMediaType())
? toCsvText(response)
Expand All @@ -75,13 +75,13 @@ public String doSearch(ResourceAwsClient queryClient) {
private String toCsvText(OpenSearchSwsResponse response) {
return CsvTransformer.transform(response.getSearchHits());
}
PagedSearchResourceDto toPagedResponse(OpenSearchSwsResponse response) {

PagedSearchDto toPagedResponse(OpenSearchSwsResponse response) {
final var requestParameter = toNvaSearchApiRequestParameter();
final var source = URI.create(getNvaSearchApiUri().toString().split("\\?")[0]);

return
PagedSearchResourceDto.Builder.builder()
PagedSearchDto.Builder.builder()
.withTotalHits(response.getTotalSize())
.withHits(response.getSearchHits())
.withAggregations(response.getAggregationsStructured())
Expand Down Expand Up @@ -187,13 +187,13 @@ boolean isFirstPage() {
}

@SuppressWarnings("PMD.GodClass")
protected static class Builder extends OpenSearchQueryBuilder<ParameterKeyResource, ResourceAwsQuery> {
protected static class Builder extends OpenSearchQueryBuilder<ParameterKeyResource, ResourceQuery> {

private static final String ALL = "all";
public static final Integer EXPECTED_TWO_PARTS = 2;

Builder() {
super(new ResourceAwsQuery());
super(new ResourceQuery());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UserSettingsClient implements OpenSearchClient<UserSettings, ResourceAwsQuery> {
public class UserSettingsClient implements OpenSearchClient<UserSettings, ResourceQuery> {

private static final Logger logger = LoggerFactory.getLogger(UserSettingsClient.class);
private final CachedJwtProvider jwtProvider;
Expand All @@ -38,7 +38,7 @@ public UserSettingsClient(CachedJwtProvider cachedJwtProvider, HttpClient client
}

@Override
public UserSettings doSearch(ResourceAwsQuery query) {
public UserSettings doSearch(ResourceQuery query) {
return
createQueryBuilderStream(query)
.map(this::populateSearchRequest)
Expand All @@ -49,7 +49,7 @@ public UserSettings doSearch(ResourceAwsQuery query) {
.orElse(new UserSettings(Collections.emptyList()));
}

private Stream<String> createQueryBuilderStream(ResourceAwsQuery query) {
private Stream<String> createQueryBuilderStream(ResourceQuery query) {
return query.getOptional(CONTRIBUTOR_ID).stream();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import nva.commons.core.paths.UriWrapper;
import org.jetbrains.annotations.Nullable;

public record PagedSearchResourceDto(
public record PagedSearchDto(
URI id,
int totalHits,
List<JsonNode> hits,
Expand All @@ -22,7 +22,7 @@ public record PagedSearchResourceDto(
URI previousResults,
JsonNode aggregations) {

private PagedSearchResourceDto(Builder builder) {
private PagedSearchDto(Builder builder) {
this(builder.id,
builder.totalHits,
builder.hits,
Expand Down Expand Up @@ -112,12 +112,12 @@ private URI createUriOffsetRef(Map<String, String> params, Integer offset, URI g
}

@SuppressWarnings("PMD.NullAssignment")
public PagedSearchResourceDto build() {
public PagedSearchDto build() {
if (isNull(this.nextResults)) {
this.nextResultsBySortKey = null; // null values are not serialized
}

return new PagedSearchResourceDto(this);
return new PagedSearchDto(this);
}
}
}
Loading

0 comments on commit 65d6286

Please sign in to comment.