From 046c9f765f94b580d137b40ed981a12652affe8e Mon Sep 17 00:00:00 2001 From: Stig Norland Date: Mon, 27 Nov 2023 10:27:56 +0100 Subject: [PATCH] added ADDITIONAL_IDENTIFIERS --- .../nva/search2/ImportCandidateClient.java | 6 +- .../nva/search2/ImportCandidateQuery.java | 52 ++--- .../no/unit/nva/search2/ResourceClient.java | 6 +- .../no/unit/nva/search2/ResourceQuery.java | 60 ++--- .../unit/nva/search2/UserSettingsClient.java | 6 +- .../OpenSearchClient.java | 4 +- .../{model/opensearch => common}/Query.java | 21 +- .../opensearch => common}/QueryBuilder.java | 7 +- .../QueryBuilderSourceWrapper.java | 2 +- .../nva/search2/common/QueryBuilderTools.java | 20 +- .../opensearch => common}/SwsResponse.java | 27 ++- .../constant/ApplicationConstants.java | 115 ++++------ .../unit/nva/search2/constant/Defaults.java | 2 +- .../nva/search2/constant/ErrorMessages.java | 9 +- .../no/unit/nva/search2/constant/Words.java | 67 ++++++ .../nva/search2/{model => dto}/Facet.java | 2 +- .../PagedSearch.java} | 4 +- .../{model => dto}/PagedSearchBuilder.java | 10 +- .../search2/{model => dto}/UserSettings.java | 4 +- .../ImportCandidateParameter.java | 91 ++++---- .../ImportCandidateSort.java | 4 +- .../parameterkeys => enums}/ParameterKey.java | 2 +- .../ResourceParameter.java | 206 +++++++++--------- .../sortkeys => enums}/ResourceSort.java | 4 +- .../java/no/unit/nva/search2/FacetsTest.java | 2 +- .../search2/ImportCandidateClientTest.java | 10 +- .../nva/search2/ResourceClientNoHitsTest.java | 10 +- .../unit/nva/search2/ResourceClientTest.java | 24 +- .../unit/nva/search2/ResourceQueryTest.java | 22 +- .../nva/search2/UserSettingsClientTest.java | 8 +- .../ImportCandidatePagedSearchHandlerAws.java | 6 +- .../ResourcePagedSearchHandlerAws.java | 6 +- ...ortCandidatePagedSearchHandlerAwsTest.java | 12 +- .../ResourcePagedSearchHandlerAwsTest.java | 12 +- .../search/common/FakeGatewayResponse.java | 11 +- 35 files changed, 433 insertions(+), 421 deletions(-) rename search-commons/src/main/java/no/unit/nva/search2/{model/opensearch => common}/OpenSearchClient.java (91%) rename search-commons/src/main/java/no/unit/nva/search2/{model/opensearch => common}/Query.java (91%) rename search-commons/src/main/java/no/unit/nva/search2/{model/opensearch => common}/QueryBuilder.java (97%) rename search-commons/src/main/java/no/unit/nva/search2/{model => common}/QueryBuilderSourceWrapper.java (82%) rename search-commons/src/main/java/no/unit/nva/search2/{model/opensearch => common}/SwsResponse.java (86%) create mode 100644 search-commons/src/main/java/no/unit/nva/search2/constant/Words.java rename search-commons/src/main/java/no/unit/nva/search2/{model => dto}/Facet.java (92%) rename search-commons/src/main/java/no/unit/nva/search2/{model/PagedSearchDto.java => dto/PagedSearch.java} (92%) rename search-commons/src/main/java/no/unit/nva/search2/{model => dto}/PagedSearchBuilder.java (91%) rename search-commons/src/main/java/no/unit/nva/search2/{model => dto}/UserSettings.java (81%) rename search-commons/src/main/java/no/unit/nva/search2/{model/parameterkeys => enums}/ImportCandidateParameter.java (63%) rename search-commons/src/main/java/no/unit/nva/search2/{model/sortkeys => enums}/ImportCandidateSort.java (96%) rename search-commons/src/main/java/no/unit/nva/search2/{model/parameterkeys => enums}/ParameterKey.java (98%) rename search-commons/src/main/java/no/unit/nva/search2/{model/parameterkeys => enums}/ResourceParameter.java (54%) rename search-commons/src/main/java/no/unit/nva/search2/{model/sortkeys => enums}/ResourceSort.java (96%) diff --git a/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateClient.java b/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateClient.java index 4e031be05..d26fcfa41 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateClient.java +++ b/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateClient.java @@ -13,9 +13,9 @@ import java.net.http.HttpResponse.BodyHandler; import java.nio.charset.StandardCharsets; import no.unit.nva.search.CachedJwtProvider; -import no.unit.nva.search2.model.QueryBuilderSourceWrapper; -import no.unit.nva.search2.model.opensearch.OpenSearchClient; -import no.unit.nva.search2.model.opensearch.SwsResponse; +import no.unit.nva.search2.common.OpenSearchClient; +import no.unit.nva.search2.common.QueryBuilderSourceWrapper; +import no.unit.nva.search2.common.SwsResponse; import nva.commons.core.JacocoGenerated; import nva.commons.secrets.SecretsReader; import org.slf4j.Logger; diff --git a/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateQuery.java b/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateQuery.java index 093e1209e..98c69c8bf 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateQuery.java +++ b/search-commons/src/main/java/no/unit/nva/search2/ImportCandidateQuery.java @@ -4,28 +4,28 @@ import static java.util.Objects.nonNull; import static no.unit.nva.search.constants.ApplicationConstants.IMPORT_CANDIDATES_AGGREGATIONS; import static no.unit.nva.search.constants.ApplicationConstants.IMPORT_CANDIDATES_INDEX; -import static no.unit.nva.search2.constant.ApplicationConstants.COLON; -import static no.unit.nva.search2.constant.ApplicationConstants.COMMA; -import static no.unit.nva.search2.constant.ApplicationConstants.SEARCH; -import static no.unit.nva.search2.constant.ApplicationConstants.ZERO; import static no.unit.nva.search2.constant.Defaults.DEFAULT_OFFSET; import static no.unit.nva.search2.constant.Defaults.DEFAULT_VALUE_PER_PAGE; import static no.unit.nva.search2.constant.Defaults.DEFAULT_VALUE_SORT; import static no.unit.nva.search2.constant.Defaults.DEFAULT_VALUE_SORT_ORDER; import static no.unit.nva.search2.constant.ErrorMessages.INVALID_VALUE_WITH_SORT; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_IGNORE_CASE; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.FIELDS; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.PAGE; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SEARCH_AFTER; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SEARCH_ALL; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SORT; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SORT_ORDER; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.VALID_LUCENE_PARAMETER_KEYS; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.keyFromString; -import static no.unit.nva.search2.model.sortkeys.ImportCandidateSort.INVALID; -import static no.unit.nva.search2.model.sortkeys.ImportCandidateSort.validSortKeys; +import static no.unit.nva.search2.constant.Words.COLON; +import static no.unit.nva.search2.constant.Words.COMMA; +import static no.unit.nva.search2.constant.Words.SEARCH; +import static no.unit.nva.search2.constant.Words.ZERO; +import static no.unit.nva.search2.enums.ImportCandidateParameter.FIELDS; +import static no.unit.nva.search2.enums.ImportCandidateParameter.FROM; +import static no.unit.nva.search2.enums.ImportCandidateParameter.PAGE; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SEARCH_AFTER; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SEARCH_ALL; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SIZE; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SORT; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SORT_ORDER; +import static no.unit.nva.search2.enums.ImportCandidateParameter.VALID_LUCENE_PARAMETER_KEYS; +import static no.unit.nva.search2.enums.ImportCandidateParameter.keyFromString; +import static no.unit.nva.search2.enums.ImportCandidateSort.INVALID; +import static no.unit.nva.search2.enums.ImportCandidateSort.validSortKeys; import static nva.commons.core.paths.UriWrapper.fromUri; import com.google.common.net.MediaType; import java.net.URI; @@ -36,16 +36,16 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import no.unit.nva.search.CsvTransformer; +import no.unit.nva.search2.common.Query; +import no.unit.nva.search2.common.QueryBuilder; +import no.unit.nva.search2.common.QueryBuilderSourceWrapper; import no.unit.nva.search2.common.QueryBuilderTools; -import no.unit.nva.search2.model.PagedSearchBuilder; -import no.unit.nva.search2.model.PagedSearchDto; -import no.unit.nva.search2.model.QueryBuilderSourceWrapper; -import no.unit.nva.search2.model.opensearch.Query; -import no.unit.nva.search2.model.opensearch.QueryBuilder; -import no.unit.nva.search2.model.opensearch.SwsResponse; -import no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter; -import no.unit.nva.search2.model.parameterkeys.ParameterKey; -import no.unit.nva.search2.model.sortkeys.ImportCandidateSort; +import no.unit.nva.search2.common.SwsResponse; +import no.unit.nva.search2.dto.PagedSearch; +import no.unit.nva.search2.dto.PagedSearchBuilder; +import no.unit.nva.search2.enums.ImportCandidateParameter; +import no.unit.nva.search2.enums.ImportCandidateSort; +import no.unit.nva.search2.enums.ParameterKey; import nva.commons.apigateway.exceptions.BadRequestException; import nva.commons.core.JacocoGenerated; import nva.commons.core.paths.UriWrapper; @@ -88,7 +88,7 @@ private String toCsvText(SwsResponse response) { return CsvTransformer.transform(response.getSearchHits()); } - PagedSearchDto toPagedResponse(SwsResponse response) { + PagedSearch toPagedResponse(SwsResponse response) { final var requestParameter = toNvaSearchApiRequestParameter(); final var source = URI.create(getNvaSearchApiUri().toString().split("\\?")[0]); diff --git a/search-commons/src/main/java/no/unit/nva/search2/ResourceClient.java b/search-commons/src/main/java/no/unit/nva/search2/ResourceClient.java index 2f652ae98..584b6e151 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/ResourceClient.java +++ b/search-commons/src/main/java/no/unit/nva/search2/ResourceClient.java @@ -13,9 +13,9 @@ import java.net.http.HttpResponse.BodyHandler; import java.nio.charset.StandardCharsets; import no.unit.nva.search.CachedJwtProvider; -import no.unit.nva.search2.model.opensearch.OpenSearchClient; -import no.unit.nva.search2.model.opensearch.SwsResponse; -import no.unit.nva.search2.model.QueryBuilderSourceWrapper; +import no.unit.nva.search2.common.OpenSearchClient; +import no.unit.nva.search2.common.QueryBuilderSourceWrapper; +import no.unit.nva.search2.common.SwsResponse; import nva.commons.core.JacocoGenerated; import nva.commons.secrets.SecretsReader; import org.slf4j.Logger; diff --git a/search-commons/src/main/java/no/unit/nva/search2/ResourceQuery.java b/search-commons/src/main/java/no/unit/nva/search2/ResourceQuery.java index 088c15e54..db4e05cff 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/ResourceQuery.java +++ b/search-commons/src/main/java/no/unit/nva/search2/ResourceQuery.java @@ -2,14 +2,7 @@ import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import static no.unit.nva.search2.constant.ApplicationConstants.ALL; -import static no.unit.nva.search2.constant.ApplicationConstants.COLON; -import static no.unit.nva.search2.constant.ApplicationConstants.COMMA; -import static no.unit.nva.search2.constant.ApplicationConstants.EXPECTED_TWO_PARTS; -import static no.unit.nva.search2.constant.ApplicationConstants.ID; -import static no.unit.nva.search2.constant.ApplicationConstants.JANUARY_FIRST; import static no.unit.nva.search2.constant.ApplicationConstants.RESOURCES_AGGREGATIONS; -import static no.unit.nva.search2.constant.ApplicationConstants.ZERO; import static no.unit.nva.search2.constant.Defaults.DEFAULT_OFFSET; import static no.unit.nva.search2.constant.Defaults.DEFAULT_VALUE_PER_PAGE; import static no.unit.nva.search2.constant.Defaults.DEFAULT_VALUE_SORT; @@ -18,19 +11,26 @@ import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_ASC_OR_DESC; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_SELECTED_GROUP; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_URL_PARAM_INDICATOR; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.CONTRIBUTOR_ID; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FIELDS; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FUNDING; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.PAGE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SEARCH_AFTER; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SEARCH_ALL; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT_ORDER; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.keyFromString; -import static no.unit.nva.search2.model.sortkeys.ResourceSort.INVALID; -import static no.unit.nva.search2.model.sortkeys.ResourceSort.validSortKeys; +import static no.unit.nva.search2.constant.Words.ALL; +import static no.unit.nva.search2.constant.Words.COLON; +import static no.unit.nva.search2.constant.Words.COMMA; +import static no.unit.nva.search2.constant.Words.EXPECTED_TWO_PARTS; +import static no.unit.nva.search2.constant.Words.ID; +import static no.unit.nva.search2.constant.Words.JANUARY_FIRST; +import static no.unit.nva.search2.constant.Words.ZERO; +import static no.unit.nva.search2.enums.ResourceParameter.CONTRIBUTOR_ID; +import static no.unit.nva.search2.enums.ResourceParameter.FIELDS; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.FUNDING; +import static no.unit.nva.search2.enums.ResourceParameter.PAGE; +import static no.unit.nva.search2.enums.ResourceParameter.SEARCH_AFTER; +import static no.unit.nva.search2.enums.ResourceParameter.SEARCH_ALL; +import static no.unit.nva.search2.enums.ResourceParameter.SIZE; +import static no.unit.nva.search2.enums.ResourceParameter.SORT; +import static no.unit.nva.search2.enums.ResourceParameter.SORT_ORDER; +import static no.unit.nva.search2.enums.ResourceParameter.keyFromString; +import static no.unit.nva.search2.enums.ResourceSort.INVALID; +import static no.unit.nva.search2.enums.ResourceSort.validSortKeys; import com.google.common.net.MediaType; import java.net.URI; import java.util.Arrays; @@ -40,16 +40,16 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import no.unit.nva.search.CsvTransformer; +import no.unit.nva.search2.common.Query; +import no.unit.nva.search2.common.QueryBuilder; +import no.unit.nva.search2.common.QueryBuilderSourceWrapper; import no.unit.nva.search2.common.QueryBuilderTools; -import no.unit.nva.search2.model.PagedSearchBuilder; -import no.unit.nva.search2.model.PagedSearchDto; -import no.unit.nva.search2.model.QueryBuilderSourceWrapper; -import no.unit.nva.search2.model.opensearch.Query; -import no.unit.nva.search2.model.opensearch.QueryBuilder; -import no.unit.nva.search2.model.opensearch.SwsResponse; -import no.unit.nva.search2.model.parameterkeys.ParameterKey; -import no.unit.nva.search2.model.parameterkeys.ResourceParameter; -import no.unit.nva.search2.model.sortkeys.ResourceSort; +import no.unit.nva.search2.common.SwsResponse; +import no.unit.nva.search2.dto.PagedSearch; +import no.unit.nva.search2.dto.PagedSearchBuilder; +import no.unit.nva.search2.enums.ParameterKey; +import no.unit.nva.search2.enums.ResourceParameter; +import no.unit.nva.search2.enums.ResourceSort; import nva.commons.apigateway.exceptions.BadRequestException; import nva.commons.core.JacocoGenerated; import nva.commons.core.paths.UriWrapper; @@ -86,7 +86,7 @@ private String toCsvText(SwsResponse response) { return CsvTransformer.transform(response.getSearchHits()); } - PagedSearchDto toPagedResponse(SwsResponse response) { + PagedSearch toPagedResponse(SwsResponse response) { final var requestParameter = toNvaSearchApiRequestParameter(); final var source = URI.create(getNvaSearchApiUri().toString().split(PATTERN_IS_URL_PARAM_INDICATOR)[0]); diff --git a/search-commons/src/main/java/no/unit/nva/search2/UserSettingsClient.java b/search-commons/src/main/java/no/unit/nva/search2/UserSettingsClient.java index edc14c6bf..bf13ab9ce 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/UserSettingsClient.java +++ b/search-commons/src/main/java/no/unit/nva/search2/UserSettingsClient.java @@ -6,7 +6,7 @@ import static no.unit.nva.commons.json.JsonUtils.singleLineObjectMapper; import static no.unit.nva.search.utils.UriRetriever.ACCEPT; import static no.unit.nva.search2.constant.ApplicationConstants.readApiHost; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.CONTRIBUTOR_ID; +import static no.unit.nva.search2.enums.ResourceParameter.CONTRIBUTOR_ID; import static nva.commons.core.attempt.Try.attempt; import com.google.common.net.MediaType; import java.net.http.HttpClient; @@ -16,8 +16,8 @@ import java.util.Collections; import java.util.stream.Stream; import no.unit.nva.search.CachedJwtProvider; -import no.unit.nva.search2.model.opensearch.OpenSearchClient; -import no.unit.nva.search2.model.UserSettings; +import no.unit.nva.search2.common.OpenSearchClient; +import no.unit.nva.search2.dto.UserSettings; import nva.commons.core.JacocoGenerated; import nva.commons.core.paths.UriWrapper; import org.slf4j.Logger; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/OpenSearchClient.java b/search-commons/src/main/java/no/unit/nva/search2/common/OpenSearchClient.java similarity index 91% rename from search-commons/src/main/java/no/unit/nva/search2/model/opensearch/OpenSearchClient.java rename to search-commons/src/main/java/no/unit/nva/search2/common/OpenSearchClient.java index 917de1ef0..8c6c9e861 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/OpenSearchClient.java +++ b/search-commons/src/main/java/no/unit/nva/search2/common/OpenSearchClient.java @@ -1,7 +1,7 @@ -package no.unit.nva.search2.model.opensearch; +package no.unit.nva.search2.common; -import static no.unit.nva.search2.constant.ApplicationConstants.SEARCH_INFRASTRUCTURE_CREDENTIALS; import static no.unit.nva.search2.constant.ApplicationConstants.readSearchInfrastructureAuthUri; +import static no.unit.nva.search2.constant.Words.SEARCH_INFRASTRUCTURE_CREDENTIALS; import java.net.URI; import java.util.stream.Stream; import no.unit.nva.auth.CognitoCredentials; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/Query.java b/search-commons/src/main/java/no/unit/nva/search2/common/Query.java similarity index 91% rename from search-commons/src/main/java/no/unit/nva/search2/model/opensearch/Query.java rename to search-commons/src/main/java/no/unit/nva/search2/common/Query.java index d97525646..91abcbbfa 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/Query.java +++ b/search-commons/src/main/java/no/unit/nva/search2/common/Query.java @@ -1,15 +1,15 @@ -package no.unit.nva.search2.model.opensearch; +package no.unit.nva.search2.common; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import static no.unit.nva.search2.constant.ApplicationConstants.AMPERSAND; -import static no.unit.nva.search2.constant.ApplicationConstants.COLON; -import static no.unit.nva.search2.constant.ApplicationConstants.COMMA; -import static no.unit.nva.search2.constant.ApplicationConstants.EQUAL; -import static no.unit.nva.search2.constant.ApplicationConstants.PLUS; -import static no.unit.nva.search2.constant.ApplicationConstants.RESOURCES; -import static no.unit.nva.search2.constant.ApplicationConstants.SEARCH; import static no.unit.nva.search2.constant.ApplicationConstants.readSearchInfrastructureApiUri; +import static no.unit.nva.search2.constant.Words.AMPERSAND; +import static no.unit.nva.search2.constant.Words.COLON; +import static no.unit.nva.search2.constant.Words.COMMA; +import static no.unit.nva.search2.constant.Words.EQUAL; +import static no.unit.nva.search2.constant.Words.PLUS; +import static no.unit.nva.search2.constant.Words.RESOURCES; +import static no.unit.nva.search2.constant.Words.SEARCH; import static nva.commons.core.StringUtils.EMPTY_STRING; import static nva.commons.core.StringUtils.SPACE; import static nva.commons.core.attempt.Try.attempt; @@ -31,9 +31,8 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; - -import no.unit.nva.search2.model.parameterkeys.ParameterKey; -import no.unit.nva.search2.model.parameterkeys.ParameterKey.ValueEncoding; +import no.unit.nva.search2.enums.ParameterKey; +import no.unit.nva.search2.enums.ParameterKey.ValueEncoding; import nva.commons.core.JacocoGenerated; import org.jetbrains.annotations.NotNull; import org.joda.time.DateTime; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/QueryBuilder.java b/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilder.java similarity index 97% rename from search-commons/src/main/java/no/unit/nva/search2/model/opensearch/QueryBuilder.java rename to search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilder.java index 4eb4ff42c..ffa43375b 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/QueryBuilder.java +++ b/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilder.java @@ -1,19 +1,18 @@ -package no.unit.nva.search2.model.opensearch; +package no.unit.nva.search2.common; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import static no.unit.nva.search2.constant.ErrorMessages.invalidQueryParametersMessage; import static no.unit.nva.search2.constant.ErrorMessages.requiredMissingMessage; import static no.unit.nva.search2.constant.ErrorMessages.validQueryParameterNamesMessage; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.VALID_SEARCH_PARAMETER_KEYS; +import static no.unit.nva.search2.enums.ResourceParameter.VALID_SEARCH_PARAMETER_KEYS; import java.net.URI; import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - -import no.unit.nva.search2.model.parameterkeys.ParameterKey; +import no.unit.nva.search2.enums.ParameterKey; import nva.commons.apigateway.RequestInfo; import nva.commons.apigateway.exceptions.BadRequestException; import nva.commons.core.JacocoGenerated; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/QueryBuilderSourceWrapper.java b/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderSourceWrapper.java similarity index 82% rename from search-commons/src/main/java/no/unit/nva/search2/model/QueryBuilderSourceWrapper.java rename to search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderSourceWrapper.java index b4961e277..ba91e481b 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/QueryBuilderSourceWrapper.java +++ b/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderSourceWrapper.java @@ -1,4 +1,4 @@ -package no.unit.nva.search2.model; +package no.unit.nva.search2.common; import java.net.URI; import org.opensearch.search.builder.SearchSourceBuilder; diff --git a/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderTools.java b/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderTools.java index 182988be4..15b4c7ee3 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderTools.java +++ b/search-commons/src/main/java/no/unit/nva/search2/common/QueryBuilderTools.java @@ -1,7 +1,14 @@ package no.unit.nva.search2.common; -import no.unit.nva.search2.model.parameterkeys.ParameterKey; -import no.unit.nva.search2.model.parameterkeys.ResourceParameter; +import static java.util.Objects.isNull; +import static no.unit.nva.search2.constant.ErrorMessages.OPERATOR_NOT_SUPPORTED; +import static no.unit.nva.search2.constant.Words.ALL; +import static no.unit.nva.search2.constant.Words.ASTERISK; +import static no.unit.nva.search2.constant.Words.COMMA; +import java.util.Arrays; +import java.util.Collection; +import no.unit.nva.search2.enums.ParameterKey; +import no.unit.nva.search2.enums.ResourceParameter; import org.jetbrains.annotations.NotNull; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.MultiMatchQueryBuilder.Type; @@ -10,15 +17,6 @@ import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.query.RangeQueryBuilder; -import java.util.Arrays; -import java.util.Collection; - -import static java.util.Objects.isNull; -import static no.unit.nva.search2.constant.ApplicationConstants.ALL; -import static no.unit.nva.search2.constant.ApplicationConstants.ASTERISK; -import static no.unit.nva.search2.constant.ApplicationConstants.COMMA; -import static no.unit.nva.search2.constant.ErrorMessages.OPERATOR_NOT_SUPPORTED; - public final class QueryBuilderTools { private static final Integer SINGLE_FIELD = 1; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java b/search-commons/src/main/java/no/unit/nva/search2/common/SwsResponse.java similarity index 86% rename from search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java rename to search-commons/src/main/java/no/unit/nva/search2/common/SwsResponse.java index 42b215775..3103d8a23 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java +++ b/search-commons/src/main/java/no/unit/nva/search2/common/SwsResponse.java @@ -1,4 +1,4 @@ -package no.unit.nva.search2.model.opensearch; +package no.unit.nva.search2.common; import static java.util.Objects.nonNull; import static no.unit.nva.search.constants.ApplicationConstants.LABELS; @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import no.unit.nva.search2.model.opensearch.SwsResponse.HitsInfo.Hit; +import no.unit.nva.search2.common.SwsResponse.HitsInfo.Hit; import nva.commons.core.JacocoGenerated; import org.jetbrains.annotations.NotNull; @@ -89,12 +89,6 @@ public JsonNode getAggregationsStructured() { : null; } - public static final String WORD_ENDING_WITH_HASHTAG_REGEX = "[A-za-z0-9]*#"; - - private static final Map AGGREGATION_FIELDS_TO_CHANGE = Map.of( - "docCount", "count", - "doc_count", "count"); - public static JsonNode formatAggregations(JsonNode aggregations) { var outputAggregationNode = objectMapperWithEmpty.createObjectNode(); @@ -110,8 +104,8 @@ public static JsonNode formatAggregations(JsonNode aggregations) { continue; } - var newName = Optional.ofNullable(AGGREGATION_FIELDS_TO_CHANGE.get(fieldName)) - .orElse(fieldName.replaceFirst(WORD_ENDING_WITH_HASHTAG_REGEX, "")); + var newName = Optional.ofNullable(Constants.AGGREGATION_FIELDS_TO_CHANGE.get(fieldName)) + .orElse(fieldName.replaceFirst(Constants.WORD_ENDING_WITH_HASHTAG_REGEX, "")); var value = nodeEntry.getValue(); if (value.at("/id/buckets").isArray()) { @@ -158,8 +152,8 @@ private static JsonNode formatLabels(JsonNode value) { if (fieldName.matches(PATTERN_IS_IGNORE_CASE + "sum.?other.?doc.?count")) { continue; } - var newName = Optional.ofNullable(AGGREGATION_FIELDS_TO_CHANGE.get(fieldName)) - .orElse(fieldName.replaceFirst(WORD_ENDING_WITH_HASHTAG_REGEX, "")); + var newName = Optional.ofNullable(Constants.AGGREGATION_FIELDS_TO_CHANGE.get(fieldName)) + .orElse(fieldName.replaceFirst(Constants.WORD_ENDING_WITH_HASHTAG_REGEX, "")); if (newName.equals("count")) { continue; @@ -169,4 +163,13 @@ private static JsonNode formatLabels(JsonNode value) { } return outputAggregationNode; } + + static final class Constants { + + public static final String WORD_ENDING_WITH_HASHTAG_REGEX = "[A-za-z0-9]*#"; + + private static final Map AGGREGATION_FIELDS_TO_CHANGE = Map.of( + "docCount", "count", + "doc_count", "count"); + } } diff --git a/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java b/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java index 3152e9bf1..ed54ca1aa 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java +++ b/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java @@ -1,5 +1,42 @@ package no.unit.nva.search2.constant; +import static no.unit.nva.search2.constant.Words.ADMINSTRATIVE_AGREEMENT; +import static no.unit.nva.search2.constant.Words.AFFILIATIONS; +import static no.unit.nva.search2.constant.Words.ASSOCIATED_ARTIFACTS; +import static no.unit.nva.search2.constant.Words.BOKMAAL_CODE; +import static no.unit.nva.search2.constant.Words.CONTEXT_TYPE; +import static no.unit.nva.search2.constant.Words.CONTRIBUTORS; +import static no.unit.nva.search2.constant.Words.DOI; +import static no.unit.nva.search2.constant.Words.DOT; +import static no.unit.nva.search2.constant.Words.ENGLISH_CODE; +import static no.unit.nva.search2.constant.Words.ENTITY_DESCRIPTION; +import static no.unit.nva.search2.constant.Words.FUNDINGS; +import static no.unit.nva.search2.constant.Words.FUNDING_SOURCE; +import static no.unit.nva.search2.constant.Words.ID; +import static no.unit.nva.search2.constant.Words.IDENTIFIER; +import static no.unit.nva.search2.constant.Words.IDENTITY; +import static no.unit.nva.search2.constant.Words.INSTANCE_TYPE; +import static no.unit.nva.search2.constant.Words.KEYWORD; +import static no.unit.nva.search2.constant.Words.LABELS; +import static no.unit.nva.search2.constant.Words.NAME; +import static no.unit.nva.search2.constant.Words.NYNORSK_CODE; +import static no.unit.nva.search2.constant.Words.ORC_ID; +import static no.unit.nva.search2.constant.Words.OWNER; +import static no.unit.nva.search2.constant.Words.OWNER_AFFILIATION; +import static no.unit.nva.search2.constant.Words.PUBLICATION_CONTEXT; +import static no.unit.nva.search2.constant.Words.PUBLICATION_DATE; +import static no.unit.nva.search2.constant.Words.PUBLICATION_INSTANCE; +import static no.unit.nva.search2.constant.Words.PUBLISHED_FILE; +import static no.unit.nva.search2.constant.Words.REFERENCE; +import static no.unit.nva.search2.constant.Words.RESOURCE_OWNER; +import static no.unit.nva.search2.constant.Words.SAMI_CODE; +import static no.unit.nva.search2.constant.Words.SOURCE; +import static no.unit.nva.search2.constant.Words.TOP_LEVEL_ORGANIZATION; +import static no.unit.nva.search2.constant.Words.TOP_LEVEL_ORGANIZATIONS; +import static no.unit.nva.search2.constant.Words.TYPE; +import static no.unit.nva.search2.constant.Words.USER; +import static no.unit.nva.search2.constant.Words.USER_AFFILIATION; +import static no.unit.nva.search2.constant.Words.YEAR; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.util.stream.Stream; @@ -16,66 +53,6 @@ @JacocoGenerated public final class ApplicationConstants { - public static final Integer EXPECTED_TWO_PARTS = 2; - public static final String AFFILIATIONS = "affiliations"; - public static final String ALL = "all"; - public static final String AMPERSAND = "&"; - public static final String ASTERISK = "*"; - public static final String BOKMAAL_CODE = "nb"; - public static final String COLON = ":"; - public static final String COMMA = ","; - public static final String CONTEXT_TYPE = "contextType"; - public static final String CONTRIBUTORS = "contributors"; - public static final String DOI = "doi"; - public static final String DOT = "."; - public static final String ENGLISH_CODE = "en"; - public static final String ENTITY_DESCRIPTION = "entityDescription"; - public static final String EQUAL = "="; - public static final String FUNDINGS = "fundings"; - public static final String FUNDING_SOURCE = "fundingSource"; - public static final String ID = "id"; - public static final String IDENTIFIER = "identifier"; - public static final String IDENTITY = "identity"; - public static final String INSTANCE_TYPE = "instanceType"; - public static final String JANUARY_FIRST = "-01-01"; - public static final String KEYWORD = "keyword"; - public static final String LABELS = "labels"; - public static final String NAME = "name"; - public static final String NYNORSK_CODE = "nn"; - public static final String ORC_ID = "orcId"; - public static final String OWNER = "owner"; - public static final String OWNER_AFFILIATION = "ownerAffiliation"; - public static final String PIPE = "|"; - public static final String PLUS = "+"; - public static final String PREFIX = "("; - public static final String PUBLICATION_CONTEXT = "publicationContext"; - public static final String PUBLICATION_DATE = "publicationDate"; - public static final String PUBLICATION_INSTANCE = "publicationInstance"; - public static final String QUOTE = "'"; - public static final String REFERENCE = "reference"; - public static final String RESOURCES = "resources"; - public static final String RESOURCE_OWNER = "resourceOwner"; - public static final String SAMI_CODE = "sme"; - public static final String SEARCH = "_search"; - public static final String SEARCH_INFRASTRUCTURE_CREDENTIALS = "SearchInfrastructureCredentials"; - public static final String SOURCE = "source"; - public static final String SPACE = " "; - public static final String SUFFIX = ")"; - public static final String TOP_LEVEL_ORGANIZATION = "topLevelOrganization"; - public static final String TOP_LEVEL_ORGANIZATIONS = "topLevelOrganizations"; - public static final String TYPE = "type"; - public static final String UNDERSCORE = "_"; - public static final String USER = "user"; - public static final String USER_AFFILIATION = "userAffiliation"; - public static final String YEAR = "year"; - public static final String ZERO = "0"; - public static final String MODIFIED_DATE = "modifiedDate"; - public static final String PROJECTS_ID = "projects.id"; - public static final String PUBLISHED_DATE = "publishedDate"; - public static final String ASSOCIATED_ARTIFACTS = "associatedArtifacts"; - public static final String PUBLISHED_FILE = "PublishedFile"; - public static final String ADMINSTRATIVE_AGREEMENT = "administrativeAgreement"; - public static final ObjectMapper objectMapperWithEmpty = JsonUtils.dtoObjectMapper; public static final Environment ENVIRONMENT = new Environment(); @@ -172,7 +149,6 @@ private static TermsAggregationBuilder generateFundingSourceAggregation() { generateLabelsAggregation(jsonPath(FUNDINGS, SOURCE))); } - private static TermsAggregationBuilder generateIdAggregation(String object) { return new TermsAggregationBuilder(ID) .field(jsonPath(object, ID, KEYWORD)) @@ -180,7 +156,6 @@ private static TermsAggregationBuilder generateIdAggregation(String object) { .subAggregation(generateLabelsAggregation(object)); } - private static NestedAggregationBuilder generateLabelsAggregation(String jsonPath) { var nestedAggregation = new NestedAggregationBuilder(LABELS, jsonPath(jsonPath, LABELS)); Stream.of(BOKMAAL_CODE, ENGLISH_CODE, NYNORSK_CODE, SAMI_CODE) @@ -190,17 +165,7 @@ private static NestedAggregationBuilder generateLabelsAggregation(String jsonPat } private static TermsAggregationBuilder generateHasFileAggregation() { - // var publishedFileQuery = new TermQueryBuilder(jsonPath(ASSOCIATED_ARTIFACTS, TYPE, KEYWORD), - // PUBLISHED_FILE); - // var notAdministrativeAgreementQuery = - // new TermQueryBuilder(jsonPath(ASSOCIATED_ARTIFACTS, ADMINSTRATIVE_AGREEMENT), false); - // - // var queryToMatch = QueryBuilders.boolQuery() - // .must(publishedFileQuery) - // .must(notAdministrativeAgreementQuery); - var include = new IncludeExclude(PUBLISHED_FILE, ""); - return AggregationBuilders .terms(ASSOCIATED_ARTIFACTS) .field(jsonPath(ASSOCIATED_ARTIFACTS, TYPE, KEYWORD)) @@ -210,11 +175,5 @@ private static TermsAggregationBuilder generateHasFileAggregation() { generateSimpleAggregation("public", jsonPath(ASSOCIATED_ARTIFACTS, ADMINSTRATIVE_AGREEMENT)) ); - - // return new FilterAggregationBuilder(ASSOCIATED_ARTIFACTS, queryToMatch) - // .subAggregation( - // new NestedAggregationBuilder("associatedArtifact", jsonPath(ASSOCIATED_ARTIFACTS, - // "visibleForNonOwner", KEYWORD)) - // ); } } diff --git a/search-commons/src/main/java/no/unit/nva/search2/constant/Defaults.java b/search-commons/src/main/java/no/unit/nva/search2/constant/Defaults.java index 388d06b12..c4be033be 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/constant/Defaults.java +++ b/search-commons/src/main/java/no/unit/nva/search2/constant/Defaults.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Locale; import no.unit.nva.commons.json.JsonUtils; -import no.unit.nva.search2.model.sortkeys.ResourceSort; +import no.unit.nva.search2.enums.ResourceSort; import nva.commons.apigateway.MediaTypes; import nva.commons.core.JacocoGenerated; diff --git a/search-commons/src/main/java/no/unit/nva/search2/constant/ErrorMessages.java b/search-commons/src/main/java/no/unit/nva/search2/constant/ErrorMessages.java index 88209715c..02b9399c7 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/constant/ErrorMessages.java +++ b/search-commons/src/main/java/no/unit/nva/search2/constant/ErrorMessages.java @@ -1,15 +1,14 @@ package no.unit.nva.search2.constant; +import static no.unit.nva.search2.constant.Words.PREFIX; +import static no.unit.nva.search2.constant.Words.QUOTE; +import static no.unit.nva.search2.constant.Words.SUFFIX; +import static nva.commons.core.StringUtils.EMPTY_STRING; import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; import nva.commons.core.JacocoGenerated; -import static no.unit.nva.search2.constant.ApplicationConstants.QUOTE; -import static no.unit.nva.search2.constant.ApplicationConstants.SUFFIX; -import static no.unit.nva.search2.constant.ApplicationConstants.PREFIX; -import static nva.commons.core.StringUtils.EMPTY_STRING; - @JacocoGenerated public class ErrorMessages { public static final String INVALID_VALUE = "Parameter [%s] has invalid value [%s]"; diff --git a/search-commons/src/main/java/no/unit/nva/search2/constant/Words.java b/search-commons/src/main/java/no/unit/nva/search2/constant/Words.java new file mode 100644 index 000000000..517c568d5 --- /dev/null +++ b/search-commons/src/main/java/no/unit/nva/search2/constant/Words.java @@ -0,0 +1,67 @@ +package no.unit.nva.search2.constant; + +import nva.commons.core.JacocoGenerated; + +@JacocoGenerated +public final class Words { + + public static final Integer EXPECTED_TWO_PARTS = 2; + public static final String AFFILIATIONS = "affiliations"; + public static final String ALL = "all"; + public static final String AMPERSAND = "&"; + public static final String ASTERISK = "*"; + public static final String BOKMAAL_CODE = "nb"; + public static final String COLON = ":"; + public static final String COMMA = ","; + public static final String CONTEXT_TYPE = "contextType"; + public static final String CONTRIBUTORS = "contributors"; + public static final String DOI = "doi"; + public static final String DOT = "."; + public static final String ENGLISH_CODE = "en"; + public static final String ENTITY_DESCRIPTION = "entityDescription"; + public static final String EQUAL = "="; + public static final String FUNDINGS = "fundings"; + public static final String FUNDING_SOURCE = "fundingSource"; + public static final String ID = "id"; + public static final String IDENTIFIER = "identifier"; + public static final String IDENTITY = "identity"; + public static final String INSTANCE_TYPE = "instanceType"; + public static final String JANUARY_FIRST = "-01-01"; + public static final String KEYWORD = "keyword"; + public static final String LABELS = "labels"; + public static final String NAME = "name"; + public static final String NYNORSK_CODE = "nn"; + public static final String ORC_ID = "orcId"; + public static final String OWNER = "owner"; + public static final String OWNER_AFFILIATION = "ownerAffiliation"; + public static final String PIPE = "|"; + public static final String PLUS = "+"; + public static final String PREFIX = "("; + public static final String PUBLICATION_CONTEXT = "publicationContext"; + public static final String PUBLICATION_DATE = "publicationDate"; + public static final String PUBLICATION_INSTANCE = "publicationInstance"; + public static final String QUOTE = "'"; + public static final String REFERENCE = "reference"; + public static final String RESOURCES = "resources"; + public static final String RESOURCE_OWNER = "resourceOwner"; + public static final String SAMI_CODE = "sme"; + public static final String SEARCH = "_search"; + public static final String SEARCH_INFRASTRUCTURE_CREDENTIALS = "SearchInfrastructureCredentials"; + public static final String SOURCE = "source"; + public static final String SPACE = " "; + public static final String SUFFIX = ")"; + public static final String TOP_LEVEL_ORGANIZATION = "topLevelOrganization"; + public static final String TOP_LEVEL_ORGANIZATIONS = "topLevelOrganizations"; + public static final String TYPE = "type"; + public static final String UNDERSCORE = "_"; + public static final String USER = "user"; + public static final String USER_AFFILIATION = "userAffiliation"; + public static final String YEAR = "year"; + public static final String ZERO = "0"; + public static final String MODIFIED_DATE = "modifiedDate"; + public static final String PROJECTS_ID = "projects.id"; + public static final String PUBLISHED_DATE = "publishedDate"; + public static final String ASSOCIATED_ARTIFACTS = "associatedArtifacts"; + public static final String PUBLISHED_FILE = "PublishedFile"; + public static final String ADMINSTRATIVE_AGREEMENT = "administrativeAgreement"; +} diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/Facet.java b/search-commons/src/main/java/no/unit/nva/search2/dto/Facet.java similarity index 92% rename from search-commons/src/main/java/no/unit/nva/search2/model/Facet.java rename to search-commons/src/main/java/no/unit/nva/search2/dto/Facet.java index 60a45b4a3..1cb954789 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/Facet.java +++ b/search-commons/src/main/java/no/unit/nva/search2/dto/Facet.java @@ -1,4 +1,4 @@ -package no.unit.nva.search2.model; +package no.unit.nva.search2.dto; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.net.URI; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/PagedSearchDto.java b/search-commons/src/main/java/no/unit/nva/search2/dto/PagedSearch.java similarity index 92% rename from search-commons/src/main/java/no/unit/nva/search2/model/PagedSearchDto.java rename to search-commons/src/main/java/no/unit/nva/search2/dto/PagedSearch.java index edbf82b87..436796a46 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/PagedSearchDto.java +++ b/search-commons/src/main/java/no/unit/nva/search2/dto/PagedSearch.java @@ -1,4 +1,4 @@ -package no.unit.nva.search2.model; +package no.unit.nva.search2.dto; import static java.util.Objects.nonNull; import static no.unit.nva.search2.constant.Defaults.PAGINATED_SEARCH_RESULT_CONTEXT; @@ -9,7 +9,7 @@ import java.util.Map; import no.unit.nva.commons.json.JsonSerializable; -public record PagedSearchDto( +public record PagedSearch( URI id, int totalHits, List hits, diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/PagedSearchBuilder.java b/search-commons/src/main/java/no/unit/nva/search2/dto/PagedSearchBuilder.java similarity index 91% rename from search-commons/src/main/java/no/unit/nva/search2/model/PagedSearchBuilder.java rename to search-commons/src/main/java/no/unit/nva/search2/dto/PagedSearchBuilder.java index fa1dcba57..2a5f679ff 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/PagedSearchBuilder.java +++ b/search-commons/src/main/java/no/unit/nva/search2/dto/PagedSearchBuilder.java @@ -1,7 +1,7 @@ -package no.unit.nva.search2.model; +package no.unit.nva.search2.dto; import static java.util.Objects.isNull; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; import static nva.commons.core.attempt.Try.attempt; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; @@ -24,12 +24,12 @@ public class PagedSearchBuilder { private Map> aggregations; @SuppressWarnings("PMD.NullAssignment") - public PagedSearchDto build() { + public PagedSearch build() { if (isNull(this.nextResults)) { this.nextSearchAfterResults = null; // null values are not serialized } - return new PagedSearchDto(id, totalHits, hits, nextResults, nextSearchAfterResults, previousResults, - aggregations); + return new PagedSearch(id, totalHits, hits, nextResults, nextSearchAfterResults, previousResults, + aggregations); } public PagedSearchBuilder withIds(URI gatewayUri, Map requestParameter, Integer offset, diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/UserSettings.java b/search-commons/src/main/java/no/unit/nva/search2/dto/UserSettings.java similarity index 81% rename from search-commons/src/main/java/no/unit/nva/search2/model/UserSettings.java rename to search-commons/src/main/java/no/unit/nva/search2/dto/UserSettings.java index 924936238..ea5cd0823 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/UserSettings.java +++ b/search-commons/src/main/java/no/unit/nva/search2/dto/UserSettings.java @@ -1,8 +1,6 @@ -package no.unit.nva.search2.model; - +package no.unit.nva.search2.dto; import com.fasterxml.jackson.annotation.JsonInclude; - import java.util.List; diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/parameterkeys/ImportCandidateParameter.java b/search-commons/src/main/java/no/unit/nva/search2/enums/ImportCandidateParameter.java similarity index 63% rename from search-commons/src/main/java/no/unit/nva/search2/model/parameterkeys/ImportCandidateParameter.java rename to search-commons/src/main/java/no/unit/nva/search2/enums/ImportCandidateParameter.java index 47edc1fc9..db7c73a7e 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/parameterkeys/ImportCandidateParameter.java +++ b/search-commons/src/main/java/no/unit/nva/search2/enums/ImportCandidateParameter.java @@ -1,20 +1,10 @@ -package no.unit.nva.search2.model.parameterkeys; +package no.unit.nva.search2.enums; import static java.util.Objects.nonNull; -import static no.unit.nva.search2.constant.ApplicationConstants.COLON; -import static no.unit.nva.search2.constant.ApplicationConstants.UNDERSCORE; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_IGNORE_CASE; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_NONE_OR_ONE; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.FieldOperator.GREATER_THAN_OR_EQUAL_TO; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.FieldOperator.LESS_THAN; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.FieldOperator.MUST; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.FieldOperator.MUST_NOT; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.FieldOperator.SHOULD; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.ParamKind.CUSTOM; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.ParamKind.KEYWORD; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.ParamKind.NUMBER; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.ParamKind.SORT_KEY; -import static no.unit.nva.search2.model.parameterkeys.ParameterKey.ParamKind.TEXT; +import static no.unit.nva.search2.constant.Words.COLON; +import static no.unit.nva.search2.constant.Words.UNDERSCORE; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; @@ -31,42 +21,45 @@ */ public enum ImportCandidateParameter implements ParameterKey { - INVALID(TEXT), + INVALID(ParamKind.TEXT), // Parameters converted to Lucene query - ADDITIONAL_IDENTIFIERS(KEYWORD, MUST, Constants.ADDITIONAL_IDENTIFIERS_VALUE_KEYWORD), - ADDITIONAL_IDENTIFIERS_NOT(KEYWORD, MUST_NOT, Constants.ADDITIONAL_IDENTIFIERS_VALUE_KEYWORD), - ADDITIONAL_IDENTIFIERS_SHOULD(TEXT, SHOULD, Constants.ADDITIONAL_IDENTIFIERS_VALUE_KEYWORD), - CATEGORY(KEYWORD, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE), - CATEGORY_NOT(KEYWORD, MUST_NOT, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE), - CATEGORY_SHOULD(TEXT, SHOULD, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE), - COLLABORATION_TYPE(KEYWORD, MUST, ""), - DOI(KEYWORD, Constants.DOI), - DOI_NOT(TEXT, MUST_NOT, Constants.DOI), - DOI_SHOULD(TEXT, SHOULD, Constants.DOI), - ID(KEYWORD, Constants.IDENTIFIER), - ID_NOT(KEYWORD, MUST_NOT, Constants.IDENTIFIER), - ID_SHOULD(TEXT, SHOULD, Constants.IDENTIFIER), - OWNER(KEYWORD, MUST, Constants.RESOURCE_OWNER), - OWNER_NOT(KEYWORD, MUST_NOT, Constants.RESOURCE_OWNER), - OWNER_SHOULD(TEXT, SHOULD, Constants.RESOURCE_OWNER), - PUBLISHED_BEFORE(NUMBER, LESS_THAN, Constants.PUBLISHED_DATE), - PUBLISHED_SINCE(NUMBER, GREATER_THAN_OR_EQUAL_TO, Constants.PUBLISHED_DATE), - PUBLISHER(KEYWORD, MUST, Constants.PUBLISHER), - PUBLISHER_NOT(KEYWORD, MUST_NOT, Constants.PUBLISHER), - PUBLISHER_SHOULD(TEXT, SHOULD, Constants.PUBLISHER), - TITLE(TEXT, Constants.MAIN_TITLE, 2F), - TITLE_NOT(TEXT, MUST_NOT, Constants.MAIN_TITLE), - TITLE_SHOULD(TEXT, SHOULD, Constants.MAIN_TITLE), + ADDITIONAL_IDENTIFIERS(ParamKind.KEYWORD, FieldOperator.MUST, Constants.ADDITIONAL_IDENTIFIERS_VALUE_KEYWORD), + ADDITIONAL_IDENTIFIERS_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, + Constants.ADDITIONAL_IDENTIFIERS_VALUE_KEYWORD), + ADDITIONAL_IDENTIFIERS_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.ADDITIONAL_IDENTIFIERS_VALUE_KEYWORD), + CATEGORY(ParamKind.KEYWORD, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE), + CATEGORY_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, + Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE), + CATEGORY_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, + Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE), + COLLABORATION_TYPE(ParamKind.KEYWORD, FieldOperator.MUST, ""), + DOI(ParamKind.KEYWORD, Constants.DOI), + DOI_NOT(ParamKind.TEXT, FieldOperator.MUST_NOT, Constants.DOI), + DOI_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.DOI), + ID(ParamKind.KEYWORD, Constants.IDENTIFIER), + ID_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, Constants.IDENTIFIER), + ID_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.IDENTIFIER), + OWNER(ParamKind.KEYWORD, FieldOperator.MUST, Constants.RESOURCE_OWNER), + OWNER_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, Constants.RESOURCE_OWNER), + OWNER_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.RESOURCE_OWNER), + PUBLISHED_BEFORE(ParamKind.NUMBER, FieldOperator.LESS_THAN, Constants.PUBLISHED_DATE), + PUBLISHED_SINCE(ParamKind.NUMBER, FieldOperator.GREATER_THAN_OR_EQUAL_TO, Constants.PUBLISHED_DATE), + PUBLISHER(ParamKind.KEYWORD, FieldOperator.MUST, Constants.PUBLISHER), + PUBLISHER_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, Constants.PUBLISHER), + PUBLISHER_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.PUBLISHER), + TITLE(ParamKind.TEXT, Constants.MAIN_TITLE, 2F), + TITLE_NOT(ParamKind.TEXT, FieldOperator.MUST_NOT, Constants.MAIN_TITLE), + TITLE_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.MAIN_TITLE), // Query parameters passed to SWS/Opensearch - SEARCH_ALL(TEXT, MUST, "q", "(?i)search.?all|query", null, null), - FIELDS(CUSTOM), + SEARCH_ALL(ParamKind.TEXT, FieldOperator.MUST, "q", "(?i)search.?all|query", null, null), + FIELDS(ParamKind.CUSTOM), // Pagination parameters - PAGE(NUMBER), - FROM(NUMBER, null, null, "(?i)offset|from", null, null), - SIZE(NUMBER, null, null, "(?i)per.?page|results|limit|size", null, null), - SORT(SORT_KEY, null, null, "(?i)order.?by|sort", null, null), - SORT_ORDER(CUSTOM, MUST, null, "(?i)sort.?order|order", "(?i)asc|desc", null), - SEARCH_AFTER(CUSTOM); + PAGE(ParamKind.NUMBER), + FROM(ParamKind.NUMBER, null, null, "(?i)offset|from", null, null), + SIZE(ParamKind.NUMBER, null, null, "(?i)per.?page|results|limit|size", null, null), + SORT(ParamKind.SORT_KEY, null, null, "(?i)order.?by|sort", null, null), + SORT_ORDER(ParamKind.CUSTOM, FieldOperator.MUST, null, "(?i)sort.?order|order", "(?i)asc|desc", null), + SEARCH_AFTER(ParamKind.CUSTOM); public static final int IGNORE_PARAMETER_INDEX = 0; @@ -87,15 +80,15 @@ public enum ImportCandidateParameter implements ParameterKey { INVALID(ParamKind.INVALID), // Parameters converted to Lucene query - CONTEXT_TYPE(KEYWORD, MUST, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), - CONTEXT_TYPE_NOT(KEYWORD, MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), - CONTEXT_TYPE_SHOULD(KEYWORD, SHOULD, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), - CONTRIBUTOR_ID(KEYWORD, MUST, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ID, null, PATTERN_IS_URI, null), - CONTRIBUTOR(KEYWORD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY), - CONTRIBUTOR_NOT(KEYWORD, MUST_NOT, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY), - CONTRIBUTOR_SHOULD(TEXT, SHOULD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY), - CREATED_BEFORE(DATE, LESS_THAN, Constants.CREATED_DATE), - CREATED_SINCE(DATE, GREATER_THAN_OR_EQUAL_TO, Constants.CREATED_DATE), - DOI(KEYWORD, ENTITY_DESCRIPTION_REFERENCE_DOI), - DOI_NOT(TEXT, MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_DOI), - DOI_SHOULD(TEXT, SHOULD, ENTITY_DESCRIPTION_REFERENCE_DOI), - FUNDING(KEYWORD, MUST, Constants.FUNDINGS_IDENTIFIER_FUNDINGS_SOURCE_IDENTIFIER, null, PATTERN_IS_FUNDING, null), - FUNDING_SOURCE(KEYWORD, Constants.FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS), - FUNDING_SOURCE_NOT(KEYWORD, MUST_NOT, Constants.FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS), - FUNDING_SOURCE_SHOULD(TEXT, SHOULD, Constants.FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS), - ID(KEYWORD, IDENTIFIER_KEYWORD), - ID_NOT(KEYWORD, MUST_NOT, IDENTIFIER_KEYWORD), - ID_SHOULD(TEXT, SHOULD, IDENTIFIER_KEYWORD), - INSTANCE_TYPE(KEYWORD, MUST, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE, + CONTEXT_TYPE(ParamKind.KEYWORD, FieldOperator.MUST, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), + CONTEXT_TYPE_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, + ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), + CONTEXT_TYPE_SHOULD(ParamKind.KEYWORD, FieldOperator.SHOULD, + ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), + CONTRIBUTOR_ID(ParamKind.KEYWORD, FieldOperator.MUST, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ID, null, + PATTERN_IS_URI, null), + CONTRIBUTOR(ParamKind.KEYWORD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY), + CONTRIBUTOR_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY), + CONTRIBUTOR_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY), + CREATED_BEFORE(ParamKind.DATE, FieldOperator.LESS_THAN, Constants.CREATED_DATE), + CREATED_SINCE(ParamKind.DATE, FieldOperator.GREATER_THAN_OR_EQUAL_TO, Constants.CREATED_DATE), + DOI(ParamKind.KEYWORD, ENTITY_DESCRIPTION_REFERENCE_DOI), + DOI_NOT(ParamKind.TEXT, FieldOperator.MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_DOI), + DOI_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, ENTITY_DESCRIPTION_REFERENCE_DOI), + FUNDING(ParamKind.KEYWORD, FieldOperator.MUST, Constants.FUNDINGS_IDENTIFIER_FUNDINGS_SOURCE_IDENTIFIER, null, + PATTERN_IS_FUNDING, null), + FUNDING_SOURCE(ParamKind.KEYWORD, Constants.FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS), + FUNDING_SOURCE_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, + Constants.FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS), + FUNDING_SOURCE_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, + Constants.FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS), + ID(ParamKind.KEYWORD, IDENTIFIER_KEYWORD), + ID_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, IDENTIFIER_KEYWORD), + ID_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, IDENTIFIER_KEYWORD), + INSTANCE_TYPE(ParamKind.KEYWORD, FieldOperator.MUST, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE, "(?i)instance.?type|category", null, null), - INSTANCE_TYPE_NOT(KEYWORD, MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE, + INSTANCE_TYPE_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE, "(?i)instance.?type.?not|category.?not", null, null), - INSTANCE_TYPE_SHOULD(KEYWORD, SHOULD, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE, + INSTANCE_TYPE_SHOULD(ParamKind.KEYWORD, FieldOperator.SHOULD, + ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE, "(?i)instance.?type.?should|category.?should", null, null), - INSTITUTION(KEYWORD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION), - INSTITUTION_NOT(KEYWORD, MUST_NOT, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION), - INSTITUTION_SHOULD(TEXT, SHOULD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION), - ISBN(KEYWORD, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISBN_LIST), - ISBN_NOT(KEYWORD, MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISBN_LIST), - ISBN_SHOULD(KEYWORD, SHOULD, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISBN_LIST), - ISSN(KEYWORD, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISSN), - ISSN_NOT(KEYWORD, MUST_NOT, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISSN), - ISSN_SHOULD(KEYWORD, SHOULD, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISSN), - ORCID(KEYWORD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ORC_ID), - ORCID_NOT(KEYWORD, MUST_NOT, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ORC_ID), - ORCID_SHOULD(KEYWORD, SHOULD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ORC_ID), - MODIFIED_BEFORE(DATE, LESS_THAN, MODIFIED_DATE), - MODIFIED_SINCE(DATE, GREATER_THAN_OR_EQUAL_TO, MODIFIED_DATE), - PARENT_PUBLICATION(KEYWORD, MUST, Constants.PARENT_PUBLICATION_ID), - PARENT_PUBLICATION_SHOULD(TEXT, SHOULD, Constants.PARENT_PUBLICATION_ID), - PROJECT(KEYWORD, PROJECTS_ID), - PROJECT_NOT(KEYWORD, MUST_NOT, PROJECTS_ID), - PROJECT_SHOULD(TEXT, SHOULD, PROJECTS_ID), - PUBLISHED_BEFORE(DATE, LESS_THAN, PUBLISHED_DATE), - PUBLISHED_SINCE(DATE, GREATER_THAN_OR_EQUAL_TO, PUBLISHED_DATE), - TITLE(TEXT, MAIN_TITLE, 2F), - TITLE_NOT(TEXT, MUST_NOT, MAIN_TITLE), - TITLE_SHOULD(TEXT, SHOULD, MAIN_TITLE), - TOP_LEVEL_ORGANIZATION(KEYWORD, MUST, TOP_LEVEL_ORGANIZATIONS + ".id.keyword"), - UNIT(KEYWORD, ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_ID), - UNIT_NOT(KEYWORD, MUST_NOT, ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_ID), - UNIT_SHOULD(TEXT, SHOULD, ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_ID), - USER(KEYWORD, RESOURCE_OWNER_OWNER_KEYWORD), - USER_NOT(KEYWORD, MUST_NOT, RESOURCE_OWNER_OWNER_KEYWORD), - USER_SHOULD(TEXT, SHOULD, RESOURCE_OWNER_OWNER_KEYWORD), - USER_AFFILIATION(KEYWORD, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD), - USER_AFFILIATION_NOT(KEYWORD, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD), - USER_AFFILIATION_SHOULD(TEXT, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD), - PUBLICATION_YEAR(NUMBER, MUST, ENTITY_DESCRIPTION_PUBLICATION_DATE_YEAR, + INSTITUTION(ParamKind.KEYWORD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION), + INSTITUTION_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION), + INSTITUTION_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION), + ISBN(ParamKind.KEYWORD, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISBN_LIST), + ISBN_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISBN_LIST), + ISBN_SHOULD(ParamKind.KEYWORD, FieldOperator.SHOULD, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISBN_LIST), + ISSN(ParamKind.KEYWORD, Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISSN), + ISSN_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, + Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISSN), + ISSN_SHOULD(ParamKind.KEYWORD, FieldOperator.SHOULD, + Constants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_ISSN), + ORCID(ParamKind.KEYWORD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ORC_ID), + ORCID_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ORC_ID), + ORCID_SHOULD(ParamKind.KEYWORD, FieldOperator.SHOULD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY_ORC_ID), + MODIFIED_BEFORE(ParamKind.DATE, FieldOperator.LESS_THAN, MODIFIED_DATE), + MODIFIED_SINCE(ParamKind.DATE, FieldOperator.GREATER_THAN_OR_EQUAL_TO, MODIFIED_DATE), + PARENT_PUBLICATION(ParamKind.KEYWORD, FieldOperator.MUST, Constants.PARENT_PUBLICATION_ID), + PARENT_PUBLICATION_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, Constants.PARENT_PUBLICATION_ID), + PROJECT(ParamKind.KEYWORD, PROJECTS_ID), + PROJECT_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, PROJECTS_ID), + PROJECT_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, PROJECTS_ID), + PUBLISHED_BEFORE(ParamKind.DATE, FieldOperator.LESS_THAN, PUBLISHED_DATE), + PUBLISHED_SINCE(ParamKind.DATE, FieldOperator.GREATER_THAN_OR_EQUAL_TO, PUBLISHED_DATE), + TITLE(ParamKind.TEXT, MAIN_TITLE, 2F), + TITLE_NOT(ParamKind.TEXT, FieldOperator.MUST_NOT, MAIN_TITLE), + TITLE_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, MAIN_TITLE), + TOP_LEVEL_ORGANIZATION(ParamKind.KEYWORD, FieldOperator.MUST, TOP_LEVEL_ORGANIZATIONS + ".id.keyword"), + UNIT(ParamKind.KEYWORD, ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_ID), + UNIT_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_ID), + UNIT_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_ID), + USER(ParamKind.KEYWORD, RESOURCE_OWNER_OWNER_KEYWORD), + USER_NOT(ParamKind.KEYWORD, FieldOperator.MUST_NOT, RESOURCE_OWNER_OWNER_KEYWORD), + USER_SHOULD(ParamKind.TEXT, FieldOperator.SHOULD, RESOURCE_OWNER_OWNER_KEYWORD), + USER_AFFILIATION(ParamKind.KEYWORD, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD), + USER_AFFILIATION_NOT(ParamKind.KEYWORD, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD), + USER_AFFILIATION_SHOULD(ParamKind.TEXT, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD), + PUBLICATION_YEAR(ParamKind.NUMBER, FieldOperator.MUST, ENTITY_DESCRIPTION_PUBLICATION_DATE_YEAR, "(?i)year.?reported|publication.?year", null, null), - PUBLICATION_YEAR_SHOULD(NUMBER, SHOULD, ENTITY_DESCRIPTION_PUBLICATION_DATE_YEAR, + PUBLICATION_YEAR_SHOULD(ParamKind.NUMBER, FieldOperator.SHOULD, ENTITY_DESCRIPTION_PUBLICATION_DATE_YEAR, "(?i)year.?reported.?should|publication.?year.?should", null, null), // Query parameters passed to SWS/Opensearch - SEARCH_ALL(TEXT, MUST, "q", "(?i)search.?all|query", null, null), - FIELDS(CUSTOM), + SEARCH_ALL(ParamKind.TEXT, FieldOperator.MUST, "q", "(?i)search.?all|query", null, null), + FIELDS(ParamKind.CUSTOM), // Pagination parameters - PAGE(NUMBER), - FROM(NUMBER, null, null, "(?i)offset|from", null, null), - SIZE(NUMBER, null, null, "(?i)per.?page|results|limit|size", null, null), - SORT(SORT_KEY, null, null, "(?i)order.?by|sort", null, null), - SORT_ORDER(CUSTOM, MUST, null, "(?i)sort.?order|order", "(?i)asc|desc", null), - SEARCH_AFTER(CUSTOM), + PAGE(ParamKind.NUMBER), + FROM(ParamKind.NUMBER, null, null, "(?i)offset|from", null, null), + SIZE(ParamKind.NUMBER, null, null, "(?i)per.?page|results|limit|size", null, null), + SORT(ParamKind.SORT_KEY, null, null, "(?i)order.?by|sort", null, null), + SORT_ORDER(ParamKind.CUSTOM, FieldOperator.MUST, null, "(?i)sort.?order|order", "(?i)asc|desc", null), + SEARCH_AFTER(ParamKind.CUSTOM), // ignored parameter - LANG(CUSTOM); + LANG(ParamKind.CUSTOM); public static final int IGNORE_PARAMETER_INDEX = 0; @@ -168,15 +166,15 @@ public enum ResourceParameter implements ParameterKey { private final Float boost; ResourceParameter(ParamKind kind) { - this(kind, MUST, null, null, null, null); + this(kind, FieldOperator.MUST, null, null, null, null); } ResourceParameter(ParamKind kind, String fieldsToSearch) { - this(kind, MUST, fieldsToSearch, null, null, null); + this(kind, FieldOperator.MUST, fieldsToSearch, null, null, null); } ResourceParameter(ParamKind kind, String fieldsToSearch, Float boost) { - this(kind, MUST, fieldsToSearch, null, null, boost); + this(kind, FieldOperator.MUST, fieldsToSearch, null, null, boost); } ResourceParameter(ParamKind kind, FieldOperator operator, String fieldsToSearch) { @@ -278,8 +276,8 @@ private static boolean isSearchField(ResourceParameter f) { private static class Constants { public static final String CREATED_DATE = "createdDate"; - private static final String AC_KEYWORD = ApplicationConstants.KEYWORD; - public static final String AC_ID = ApplicationConstants.ID; + private static final String AC_KEYWORD = Words.KEYWORD; + public static final String AC_ID = Words.ID; public static final String ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_LABELS_KEYWORD = jsonPath(ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_LABELS, ENGLISH_CODE, AC_KEYWORD) diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/sortkeys/ResourceSort.java b/search-commons/src/main/java/no/unit/nva/search2/enums/ResourceSort.java similarity index 96% rename from search-commons/src/main/java/no/unit/nva/search2/model/sortkeys/ResourceSort.java rename to search-commons/src/main/java/no/unit/nva/search2/enums/ResourceSort.java index 71b0fe5fa..20037094d 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/sortkeys/ResourceSort.java +++ b/search-commons/src/main/java/no/unit/nva/search2/enums/ResourceSort.java @@ -1,9 +1,9 @@ -package no.unit.nva.search2.model.sortkeys; +package no.unit.nva.search2.enums; import static no.unit.nva.search2.constant.ApplicationConstants.ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE; -import static no.unit.nva.search2.constant.ApplicationConstants.UNDERSCORE; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_IGNORE_CASE; import static no.unit.nva.search2.constant.Patterns.PATTERN_IS_NONE_OR_ONE; +import static no.unit.nva.search2.constant.Words.UNDERSCORE; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; diff --git a/search-commons/src/test/java/no/unit/nva/search2/FacetsTest.java b/search-commons/src/test/java/no/unit/nva/search2/FacetsTest.java index ffa81006b..f065da729 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/FacetsTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/FacetsTest.java @@ -1,7 +1,7 @@ package no.unit.nva.search2; import static no.unit.nva.search.constants.ApplicationConstants.objectMapperWithEmpty; -import static no.unit.nva.search2.model.opensearch.SwsResponse.formatAggregations; +import static no.unit.nva.search2.common.SwsResponse.formatAggregations; import static nva.commons.core.attempt.Try.attempt; import static nva.commons.core.ioutils.IoUtils.inputStreamFromResources; import static nva.commons.core.ioutils.IoUtils.streamToString; diff --git a/search-commons/src/test/java/no/unit/nva/search2/ImportCandidateClientTest.java b/search-commons/src/test/java/no/unit/nva/search2/ImportCandidateClientTest.java index 45e67d758..847663d20 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/ImportCandidateClientTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/ImportCandidateClientTest.java @@ -1,11 +1,11 @@ package no.unit.nva.search2; import static no.unit.nva.indexing.testutils.MockedJwtProvider.setupMockedCachedJwtProvider; -import static no.unit.nva.search2.model.opensearch.Query.queryToMapEntries; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.CATEGORY; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SORT; +import static no.unit.nva.search2.common.Query.queryToMapEntries; +import static no.unit.nva.search2.enums.ImportCandidateParameter.CATEGORY; +import static no.unit.nva.search2.enums.ImportCandidateParameter.FROM; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SIZE; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SORT; import static nva.commons.core.ioutils.IoUtils.stringFromResources; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/search-commons/src/test/java/no/unit/nva/search2/ResourceClientNoHitsTest.java b/search-commons/src/test/java/no/unit/nva/search2/ResourceClientNoHitsTest.java index 84b5a50bf..0611c7ea0 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/ResourceClientNoHitsTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/ResourceClientNoHitsTest.java @@ -2,10 +2,10 @@ import static no.unit.nva.indexing.testutils.MockedJwtProvider.setupMockedCachedJwtProvider; import static no.unit.nva.search2.common.MockedHttpResponse.mockedHttpResponse; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.INSTANCE_TYPE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.INSTANCE_TYPE; +import static no.unit.nva.search2.enums.ResourceParameter.SIZE; +import static no.unit.nva.search2.enums.ResourceParameter.SORT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -16,7 +16,7 @@ import java.net.URI; import java.net.http.HttpClient; import java.util.stream.Stream; -import no.unit.nva.search2.model.opensearch.Query; +import no.unit.nva.search2.common.Query; import nva.commons.apigateway.exceptions.ApiGatewayException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; diff --git a/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java b/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java index 2f17a62bb..76b40781c 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java @@ -1,12 +1,12 @@ package no.unit.nva.search2; import static no.unit.nva.indexing.testutils.MockedJwtProvider.setupMockedCachedJwtProvider; -import static no.unit.nva.search2.constant.ApplicationConstants.SPACE; -import static no.unit.nva.search2.model.opensearch.Query.queryToMapEntries; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.INSTANCE_TYPE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT; +import static no.unit.nva.search2.common.Query.queryToMapEntries; +import static no.unit.nva.search2.constant.Words.SPACE; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.INSTANCE_TYPE; +import static no.unit.nva.search2.enums.ResourceParameter.SIZE; +import static no.unit.nva.search2.enums.ResourceParameter.SORT; import static nva.commons.core.attempt.Try.attempt; import static nva.commons.core.ioutils.IoUtils.stringFromResources; import static org.hamcrest.MatcherAssert.assertThat; @@ -278,12 +278,12 @@ static Stream uriProvider() { URI.create("https://x.org/?INSTANCE_TYPE=AcademicArticle&size=9"), URI.create("https://x.org/?fields=category,title,CONTRIBUTOR&query=Kjetil+Møkkelgjerd&size=2"), URI.create("https://x.org/?funding=AFR:296896&size=1"), - URI.create("https://x.org/?funding=NFR:1296896&size=1"), - URI.create("https://x.org/?funding=NFR:296896&size=1"), - URI.create("https://x.org/?funding_source=Norges+forskningsråd&size=1"), - URI.create("https://x.org/?funding_source_not=Norges+forskningsråd&size=19"), - URI.create("https://x.org/?funding_source_SHOULD=Norges&size=1"), - URI.create("https://x.org/?funding_source=Research+Council+of+Norway+(RCN)&size=1"), + URI.create("https://x.org/?funding=NFR:1296896&size=2"), + URI.create("https://x.org/?funding=NFR:296896&size=2"), + URI.create("https://x.org/?funding_source=Norges+forskningsråd&size=2"), + URI.create("https://x.org/?funding_source_not=Norges+forskningsråd&size=18"), + URI.create("https://x.org/?funding_source_SHOULD=Norges&size=2"), + URI.create("https://x.org/?funding_source=Research+Council+of+Norway+(RCN)&size=2"), URI.create("https://x.org/?published_before=2023-09-29&size=5"), URI.create("https://x.org/?published_since=2023-11-05&size=1"), URI.create("https://x.org/?query=Forsvarets+høgskole&fields=INSTITUTION&size=2"), diff --git a/search-commons/src/test/java/no/unit/nva/search2/ResourceQueryTest.java b/search-commons/src/test/java/no/unit/nva/search2/ResourceQueryTest.java index 1008a9a84..c45bb442a 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/ResourceQueryTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/ResourceQueryTest.java @@ -1,16 +1,16 @@ package no.unit.nva.search2; import static java.util.Objects.nonNull; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.CREATED_BEFORE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.DOI; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.INSTANCE_TYPE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.MODIFIED_BEFORE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.PAGE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.PUBLISHED_BEFORE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.PUBLISHED_SINCE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT; +import static no.unit.nva.search2.enums.ResourceParameter.CREATED_BEFORE; +import static no.unit.nva.search2.enums.ResourceParameter.DOI; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.INSTANCE_TYPE; +import static no.unit.nva.search2.enums.ResourceParameter.MODIFIED_BEFORE; +import static no.unit.nva.search2.enums.ResourceParameter.PAGE; +import static no.unit.nva.search2.enums.ResourceParameter.PUBLISHED_BEFORE; +import static no.unit.nva.search2.enums.ResourceParameter.PUBLISHED_SINCE; +import static no.unit.nva.search2.enums.ResourceParameter.SIZE; +import static no.unit.nva.search2.enums.ResourceParameter.SORT; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -18,7 +18,7 @@ import java.net.URI; import java.util.stream.Collectors; import java.util.stream.Stream; -import no.unit.nva.search2.model.opensearch.Query; +import no.unit.nva.search2.common.Query; import nva.commons.apigateway.exceptions.BadRequestException; import nva.commons.core.paths.UriWrapper; import org.joda.time.DateTime; diff --git a/search-commons/src/test/java/no/unit/nva/search2/UserSettingsClientTest.java b/search-commons/src/test/java/no/unit/nva/search2/UserSettingsClientTest.java index 05b57c126..46c8417e0 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/UserSettingsClientTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/UserSettingsClientTest.java @@ -2,10 +2,10 @@ import static no.unit.nva.indexing.testutils.MockedJwtProvider.setupMockedCachedJwtProvider; import static no.unit.nva.search2.common.MockedHttpResponse.mockedHttpResponse; -import static no.unit.nva.search2.model.opensearch.Query.queryToMapEntries; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT; +import static no.unit.nva.search2.common.Query.queryToMapEntries; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.SIZE; +import static no.unit.nva.search2.enums.ResourceParameter.SORT; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; diff --git a/search-resources-api/src/main/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAws.java b/search-resources-api/src/main/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAws.java index 4f71c9f65..526ff3c84 100644 --- a/search-resources-api/src/main/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAws.java +++ b/search-resources-api/src/main/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAws.java @@ -2,9 +2,9 @@ import static no.unit.nva.search2.ImportCandidateClient.defaultClient; import static no.unit.nva.search2.constant.Defaults.DEFAULT_RESPONSE_MEDIA_TYPES; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SORT; +import static no.unit.nva.search2.enums.ImportCandidateParameter.FROM; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SIZE; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SORT; import com.amazonaws.services.lambda.runtime.Context; import com.google.common.net.MediaType; import java.net.HttpURLConnection; diff --git a/search-resources-api/src/main/java/no/unit/nva/search2/ResourcePagedSearchHandlerAws.java b/search-resources-api/src/main/java/no/unit/nva/search2/ResourcePagedSearchHandlerAws.java index 931a3c316..19071519e 100644 --- a/search-resources-api/src/main/java/no/unit/nva/search2/ResourcePagedSearchHandlerAws.java +++ b/search-resources-api/src/main/java/no/unit/nva/search2/ResourcePagedSearchHandlerAws.java @@ -2,9 +2,9 @@ import static no.unit.nva.search2.ResourceClient.defaultClient; import static no.unit.nva.search2.constant.Defaults.DEFAULT_RESPONSE_MEDIA_TYPES; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.FROM; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SIZE; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SORT; +import static no.unit.nva.search2.enums.ResourceParameter.FROM; +import static no.unit.nva.search2.enums.ResourceParameter.SIZE; +import static no.unit.nva.search2.enums.ResourceParameter.SORT; import com.amazonaws.services.lambda.runtime.Context; import com.google.common.net.MediaType; import java.net.HttpURLConnection; diff --git a/search-resources-api/src/test/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAwsTest.java b/search-resources-api/src/test/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAwsTest.java index 503536206..000ca9630 100644 --- a/search-resources-api/src/test/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAwsTest.java +++ b/search-resources-api/src/test/java/no/unit/nva/search2/ImportCandidatePagedSearchHandlerAwsTest.java @@ -2,9 +2,9 @@ import static java.net.HttpURLConnection.HTTP_OK; import static java.util.Objects.nonNull; -import static no.unit.nva.search2.constant.ApplicationConstants.COMMA; import static no.unit.nva.search2.constant.Defaults.objectMapperWithEmpty; -import static no.unit.nva.search2.model.parameterkeys.ImportCandidateParameter.SEARCH_ALL; +import static no.unit.nva.search2.constant.Words.COMMA; +import static no.unit.nva.search2.enums.ImportCandidateParameter.SEARCH_ALL; import static no.unit.nva.testutils.RandomDataGenerator.randomString; import static no.unit.nva.testutils.RandomDataGenerator.randomUri; import static nva.commons.core.ioutils.IoUtils.stringFromResources; @@ -31,8 +31,8 @@ import no.unit.nva.indexing.testutils.FakeSearchResponse; import no.unit.nva.search.ExportCsv; import no.unit.nva.search.common.FakeGatewayResponse; -import no.unit.nva.search2.model.PagedSearchDto; -import no.unit.nva.search2.model.opensearch.SwsResponse; +import no.unit.nva.search2.common.SwsResponse; +import no.unit.nva.search2.dto.PagedSearch; import no.unit.nva.testutils.HandlerRequestBuilder; import nva.commons.apigateway.GatewayResponse; import nva.commons.core.Environment; @@ -274,9 +274,9 @@ private void prepareRestHighLevelClientEmptyResponseForSortOrder() throws IOExce .thenReturn(body); } - private PagedSearchDto getSearchResourcesResponseFromFile(String filename) + private PagedSearch getSearchResourcesResponseFromFile(String filename) throws JsonProcessingException { - return objectMapperWithEmpty.readValue(stringFromResources(Path.of(filename)), PagedSearchDto.class); + return objectMapperWithEmpty.readValue(stringFromResources(Path.of(filename)), PagedSearch.class); } public static Stream acceptHeaderValuesProducingTextCsvProvider() { diff --git a/search-resources-api/src/test/java/no/unit/nva/search2/ResourcePagedSearchHandlerAwsTest.java b/search-resources-api/src/test/java/no/unit/nva/search2/ResourcePagedSearchHandlerAwsTest.java index 57ff21acb..c7724cee0 100644 --- a/search-resources-api/src/test/java/no/unit/nva/search2/ResourcePagedSearchHandlerAwsTest.java +++ b/search-resources-api/src/test/java/no/unit/nva/search2/ResourcePagedSearchHandlerAwsTest.java @@ -2,9 +2,9 @@ import static java.net.HttpURLConnection.HTTP_OK; import static java.util.Objects.nonNull; -import static no.unit.nva.search2.constant.ApplicationConstants.COMMA; import static no.unit.nva.search2.constant.Defaults.objectMapperWithEmpty; -import static no.unit.nva.search2.model.parameterkeys.ResourceParameter.SEARCH_ALL; +import static no.unit.nva.search2.constant.Words.COMMA; +import static no.unit.nva.search2.enums.ResourceParameter.SEARCH_ALL; import static no.unit.nva.testutils.RandomDataGenerator.randomString; import static no.unit.nva.testutils.RandomDataGenerator.randomUri; import static nva.commons.core.ioutils.IoUtils.stringFromResources; @@ -31,8 +31,8 @@ import no.unit.nva.indexing.testutils.FakeSearchResponse; import no.unit.nva.search.ExportCsv; import no.unit.nva.search.common.FakeGatewayResponse; -import no.unit.nva.search2.model.PagedSearchDto; -import no.unit.nva.search2.model.opensearch.SwsResponse; +import no.unit.nva.search2.common.SwsResponse; +import no.unit.nva.search2.dto.PagedSearch; import no.unit.nva.testutils.HandlerRequestBuilder; import nva.commons.apigateway.GatewayResponse; import nva.commons.core.Environment; @@ -278,9 +278,9 @@ private void prepareRestHighLevelClientEmptyResponseForSortOrder() throws IOExce .thenReturn(body); } - private PagedSearchDto getSearchResourcesResponseFromFile(String filename) + private PagedSearch getSearchResourcesResponseFromFile(String filename) throws JsonProcessingException { - return objectMapperWithEmpty.readValue(stringFromResources(Path.of(filename)), PagedSearchDto.class); + return objectMapperWithEmpty.readValue(stringFromResources(Path.of(filename)), PagedSearch.class); } public static Stream acceptHeaderValuesProducingTextCsvProvider() { diff --git a/search-testing/src/main/java/no/unit/nva/search/common/FakeGatewayResponse.java b/search-testing/src/main/java/no/unit/nva/search/common/FakeGatewayResponse.java index 27cba7558..2337561be 100644 --- a/search-testing/src/main/java/no/unit/nva/search/common/FakeGatewayResponse.java +++ b/search-testing/src/main/java/no/unit/nva/search/common/FakeGatewayResponse.java @@ -1,15 +1,14 @@ package no.unit.nva.search.common; +import static no.unit.nva.commons.json.JsonUtils.dtoObjectMapper; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Map; -import no.unit.nva.search2.model.opensearch.SwsResponse; -import no.unit.nva.search2.model.PagedSearchDto; - -import static no.unit.nva.commons.json.JsonUtils.dtoObjectMapper; +import no.unit.nva.search2.common.SwsResponse; +import no.unit.nva.search2.dto.PagedSearch; @SuppressWarnings("PMD.ShortMethodName") public record FakeGatewayResponse( @@ -24,9 +23,9 @@ public static FakeGatewayResponse ofSwsGatewayResponse(InputStream return dtoObjectMapper.readValue(inputStream, typeReference); } - public static FakeGatewayResponse of(OutputStream outputStream) throws IOException { + public static FakeGatewayResponse of(OutputStream outputStream) throws IOException { var response = ofString(outputStream); - var typeReference2 = new TypeReference() { + var typeReference2 = new TypeReference() { }; var body = dtoObjectMapper.readValue(response.body(), typeReference2); return new FakeGatewayResponse<>(