Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/NP-47931-parent-scientific
Browse files Browse the repository at this point in the history
# Conflicts:
#	search-commons/src/main/java/no/unit/nva/search/resource/ResourceParameter.java
#	search-commons/src/test/resources/resource_urls.json
  • Loading branch information
StigNorland committed Oct 22, 2024
2 parents 531c3f1 + b54355a commit bea0de2
Show file tree
Hide file tree
Showing 11 changed files with 1,474 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ public final ParameterValidator<K, Q> withDockerHostUri(URI uri) {
return this;
}

public final ParameterValidator<K, Q> withAlwaysExcludedFields(List<String> excludedFields) {
searchQuery.setAlwaysExcludedFields(excludedFields);
return this;
}

public final ParameterValidator<K, Q> withAlwaysExcludedFields(String... excludedFields) {
searchQuery.setAlwaysExcludedFields(List.of(excludedFields));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class Constants {
public static final String UNIQUE_PUBLICATIONS = "unique_publications";
public static final String CRISTIN_ORGANIZATION_PATH = "/cristin/organization/";
public static final String CRISTIN_PERSON_PATH = "/cristin/person/";
public static final String EXCLUDED_FIELDS = "joinField";
public static final List<String> GLOBAL_EXCLUDED_FIELDS = List.of("joinField");
public static final String DEFAULT_RESOURCE_SORT_FIELDS =
RELEVANCE_KEY_NAME + COMMA + IDENTIFIER;
public static final String IDENTIFIER_KEYWORD = jsonPath(IDENTIFIER, KEYWORD);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package no.unit.nva.search.resource;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import no.unit.nva.search.common.records.JsonNodeMutator;

public class ContributorCopyMutator implements JsonNodeMutator {

public static final String CONTRIBUTORS_PREVIEW = "contributorsPreview";
public static final String ENTITY_DESCRIPTION = "entityDescription";
public static final String CONTRIBUTORS = "contributors";

@Override
public JsonNode transform(JsonNode source) {
var contributorsPreview = source.path(ENTITY_DESCRIPTION).path(CONTRIBUTORS_PREVIEW);
if (!contributorsPreview.isMissingNode()) {
var entityDescription = (ObjectNode) source.path(ENTITY_DESCRIPTION);
entityDescription.put(CONTRIBUTORS, contributorsPreview);
}
return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static no.unit.nva.search.resource.Constants.CRISTIN_ORGANIZATION_PATH;
import static no.unit.nva.search.resource.Constants.CRISTIN_PERSON_PATH;
import static no.unit.nva.search.resource.Constants.DEFAULT_RESOURCE_SORT_FIELDS;
import static no.unit.nva.search.resource.Constants.EXCLUDED_FIELDS;
import static no.unit.nva.search.resource.Constants.GLOBAL_EXCLUDED_FIELDS;
import static no.unit.nva.search.resource.Constants.IDENTIFIER_KEYWORD;
import static no.unit.nva.search.resource.Constants.RESOURCES_AGGREGATIONS;
import static no.unit.nva.search.resource.Constants.STATUS_KEYWORD;
Expand Down Expand Up @@ -81,7 +81,7 @@
*/
@SuppressWarnings("PMD.GodClass")
public final class ResourceSearchQuery extends SearchQuery<ResourceParameter> {

private static final String EXCLUDED_RESOURCE_FIELDS = "entityDescription.contributors";
private final ResourceStreamBuilders streamBuilders;
private final ResourceAccessFilter filterBuilder;
private final Map<String, String> additionalQueryParameters = new HashMap<>();
Expand All @@ -90,7 +90,7 @@ public final class ResourceSearchQuery extends SearchQuery<ResourceParameter> {
private ResourceSearchQuery() {
super();
assignStatusImpossibleWhiteList();
setAlwaysExcludedFields(List.of(EXCLUDED_FIELDS));
setAlwaysExcludedFields(GLOBAL_EXCLUDED_FIELDS);
streamBuilders = new ResourceStreamBuilders(parameters());
filterBuilder = new ResourceAccessFilter(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Containers {
public static IndexingClient indexingClient;

public static void setup() throws IOException, InterruptedException {
container.start();
container.withEnv("indices.query.bool.max_clause_count", "2048").start();

var restClientBuilder = RestClient.builder(HttpHost.create(container.getHttpHostAddress()));
var restHighLevelClientWrapper = new RestHighLevelClientWrapper(restClientBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static no.unit.nva.search.common.enums.PublicationStatus.PUBLISHED;
import static no.unit.nva.search.common.enums.PublicationStatus.PUBLISHED_METADATA;
import static no.unit.nva.search.common.enums.PublicationStatus.UNPUBLISHED;
import static no.unit.nva.search.resource.Constants.EXCLUDED_FIELDS;
import static no.unit.nva.search.resource.Constants.GLOBAL_EXCLUDED_FIELDS;
import static no.unit.nva.search.resource.ResourceParameter.AGGREGATION;
import static no.unit.nva.search.resource.ResourceParameter.EXCLUDE_SUBUNITS;
import static no.unit.nva.search.resource.ResourceParameter.FROM;
Expand Down Expand Up @@ -870,7 +870,7 @@ void searchWithUriReturnsCsvResponse(URI uri) throws ApiGatewayException {
ResourceSearchQuery.builder()
.fromTestQueryParameters(queryToMapEntries(uri))
.withRequiredParameters(FROM, SIZE, AGGREGATION)
.withAlwaysExcludedFields(EXCLUDED_FIELDS)
.withAlwaysExcludedFields(GLOBAL_EXCLUDED_FIELDS)
.withDockerHostUri(URI.create(container.getHttpHostAddress()))
.withMediaType(Words.TEXT_CSV)
.build()
Expand Down Expand Up @@ -1046,6 +1046,28 @@ void shouldReturnResourcesWithSubunitsWhenExcludedSubunitsNotProvided()
assertThat(pagedSearchResourceDto.hits(), hasSize(2));
}

@Test
void shouldReturnResourcesWithFieldContributorsPreviewAndNotPreview()
throws BadRequestException {

var response =
ResourceSearchQuery.builder()
.withRequiredParameters(FROM, SIZE, AGGREGATION)
.withDockerHostUri(URI.create(container.getHttpHostAddress()))
.withAlwaysExcludedFields("entityDescription.contributors")
.build()
.withFilter()
.requiredStatus(PUBLISHED, PUBLISHED_METADATA, DELETED)
.apply()
.doSearch(searchClient);

var pagedSearchResourceDto = response.toPagedResponse();

assertThat(
pagedSearchResourceDto.toJsonString(), containsString("\"contributorsPreview\":"));
assertThat(pagedSearchResourceDto.toJsonString(), not(containsString("\"contributors\":")));
}

@ParameterizedTest
@MethodSource("provideValidPageRanges")
void shouldFilterByPageCount(int min, int max, int expectedResultCount)
Expand Down
Loading

0 comments on commit bea0de2

Please sign in to comment.