Skip to content

Commit

Permalink
added ADDITIONAL_IDENTIFIERS
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Nov 27, 2023
1 parent 739d982 commit 046c9f7
Show file tree
Hide file tree
Showing 35 changed files with 433 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 30 additions & 30 deletions search-commons/src/main/java/no/unit/nva/search2/ResourceQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, String> AGGREGATION_FIELDS_TO_CHANGE = Map.of(
"docCount", "count",
"doc_count", "count");

public static JsonNode formatAggregations(JsonNode aggregations) {
var outputAggregationNode = objectMapperWithEmpty.createObjectNode();

Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
Expand All @@ -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<String, String> AGGREGATION_FIELDS_TO_CHANGE = Map.of(
"docCount", "count",
"doc_count", "count");
}
}
Loading

0 comments on commit 046c9f7

Please sign in to comment.