Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude contributors for resource search #595

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 IDENTIFIER_KEYWORD = IDENTIFIER + DOT + KEYWORD;
public static final String FILES_STATUS_KEYWORD = FILES_STATUS + DOT + KEYWORD;
public static final String ENTITY_CONTRIBUTORS_DOT =
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 @@ -17,7 +17,7 @@
import static no.unit.nva.search.common.constant.Patterns.COLON_OR_SPACE;
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.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 @@ -80,7 +80,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 @@ -89,7 +89,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
Loading