Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Dec 5, 2023
1 parent 32dd3c3 commit 9941693
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 72 deletions.
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
awsApacheInterceptor = { strictly = 'deb7941e85' }
awsIon = { strictly = '1.5.1' }
awsLambdaEvents = { strictly = '3.11.2' }
awsLambdaEvents = { strictly = '3.11.4' }
awsLambdaJavaCore = { strictly = '1.2.2' }
awsSdk2 = { strictly = '2.20.141' }
com-auth0-jwt = { strictly = '3.18.3' }
Expand All @@ -11,11 +11,11 @@ hamcrestJackson = { strictly = '1.2.0' }
jackson = { strictly = '2.15.2' }
javers = { strictly = '6.5.1' }
junit = { strictly = '5.10.0' }
log4j = { strictly = '2.18.0' }
log4j = { strictly = '2.22.0' }
mockito = { strictly = '4.2.0' }
nvaCommons = { prefer = '1.36.1' }
nvaCommons = { prefer = '1.36.2' }
nvaDatamodel = { strictly = '0.20.38' }
open-csv = { strictly = '5.7.1'}
open-csv = { strictly = '5.8' }
openSearchRestClient = { strictly = '2.9.0' }
opensearch = { strictly = '2.6.0' }
opensearch-testcontainer = { strictly = '2.0.0' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ private SwsResponse handleResponse(HttpResponse<String> response) {
throw new RuntimeException(response.body());
}
return attempt(() -> singleLineObjectMapper.readValue(response.body(), SwsResponse.class))
.orElseThrow();
.map(result -> {
logger.info("Opensearch Response Time: {} ms, TotalSize: {}", result.took(), result.getTotalSize());
return result;
}).orElseThrow();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected void setValue(String key, String value) {
PUBLISHED_BEFORE, PUBLISHED_SINCE -> query.setSearchingValue(qpKey, expandYearToDate(value));
case HAS_FILE -> query.setSearchingValue(qpKey, toBool(value).toString());
case CONTEXT_TYPE, CONTEXT_TYPE_NOT, CONTEXT_TYPE_SHOULD,
CONTRIBUTOR_ID, CONTRIBUTOR, CONTRIBUTOR_NOT,
CONTRIBUTOR_ID, CONTRIBUTOR, CONTRIBUTOR_NOT, CONTRIBUTOR_SHOULD,
DOI, DOI_NOT, DOI_SHOULD,
FUNDING, FUNDING_SOURCE, FUNDING_SOURCE_NOT, FUNDING_SOURCE_SHOULD,
ID, ID_NOT, ID_SHOULD,
Expand All @@ -205,9 +205,6 @@ protected void setValue(String key, String value) {
}
}

private Boolean inverseBool(String value) {
return !toBool(value);
}

private Boolean toBool(String value) {
return value.equals("1") ? Boolean.TRUE : Boolean.valueOf(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Streams;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import no.unit.nva.commons.json.JsonUtils;

Expand All @@ -29,13 +30,13 @@ public static JsonNode apply(JsonNode aggregations) {
.filter(AggregationFormat::ignoreSumOtherDoc)
.map(AggregationFormat::getJsonNodeEntry)
.forEach(entry -> {
if (LABELS.equals(entry.getKey())) {
if (keyIsLabel(entry)) {
outputAggregationNode.set(entry.getKey(), formatLabels(entry.getValue()));
} else if (NAME.equals(entry.getKey())) {
} else if (keyIsName(entry)) {
outputAggregationNode.set(LABELS, formatName(entry.getValue()));
} else if (entry.getValue().isValueNode()) {
} else if (isValueNode(entry)) {
outputAggregationNode.set(entry.getKey(), entry.getValue());
} else if (entry.getValue().isArray()) {
} else if (isArrayNode(entry)) {
var arrayNode = JsonUtils.dtoObjectMapper.createArrayNode();
entry.getValue().forEach(element -> arrayNode.add(apply(element)));
outputAggregationNode.set(entry.getKey(), arrayNode);
Expand All @@ -46,6 +47,22 @@ public static JsonNode apply(JsonNode aggregations) {
return outputAggregationNode;
}

private static boolean isArrayNode(Entry<String, JsonNode> entry) {
return entry.getValue().isArray();
}

private static boolean isValueNode(Entry<String, JsonNode> entry) {
return entry.getValue().isValueNode();
}

private static boolean keyIsName(Entry<String, JsonNode> entry) {
return NAME.equals(entry.getKey());
}

private static boolean keyIsLabel(Entry<String, JsonNode> entry) {
return LABELS.equals(entry.getKey());
}

private static Map.Entry<String, JsonNode> getJsonNodeEntry(Map.Entry<String, JsonNode> entry) {
return Map.entry(getNormalizedFieldName(entry.getKey()), getBucketOrValue(entry.getValue()));
}
Expand Down Expand Up @@ -74,7 +91,10 @@ private static JsonNode getBucketOrValue(JsonNode node) {

private static JsonNode formatName(JsonNode nodeEntry) {
var outputAggregationNode = JsonUtils.dtoObjectMapper.createObjectNode();
var keyValue = nodeEntry.at(Constants.BUCKETS_0_KEY_PTR);
var keyValue = nodeEntry.at(Constants.BUCKETS_KEY_PTR);
if (keyValue.isEmpty()) {
keyValue = nodeEntry.at(Constants.KEY_PTR);
}
outputAggregationNode.set(ENGLISH_CODE, keyValue);
return outputAggregationNode;
}
Expand All @@ -88,7 +108,7 @@ private static JsonNode formatLabels(JsonNode value) {
.map(AggregationFormat::getNormalizedJsonNodeEntry)
.filter(entry -> !COUNT.equals(entry.getKey()))
.forEach(node -> {
var keyValue = node.getValue().at(Constants.BUCKETS_0_KEY_PTR);
var keyValue = node.getValue().at(Constants.BUCKETS_KEY_PTR);
outputAggregationNode.set(node.getKey(), keyValue);
});
return outputAggregationNode;
Expand All @@ -102,7 +122,8 @@ private static String getNormalizedFieldName(String fieldName) {
static final class Constants {

public static final String BUCKETS_PTR = SLASH + BUCKETS;
public static final String BUCKETS_0_KEY_PTR = SLASH + BUCKETS + SLASH + ZERO + SLASH + KEY;
public static final String KEY_PTR = SLASH + ZERO + SLASH + KEY;
public static final String BUCKETS_KEY_PTR = SLASH + BUCKETS + KEY_PTR;
public static final String ID_BUCKETS = SLASH + ID + SLASH + BUCKETS;

private static final Map<String, String> AGGREGATION_FIELDS_TO_CHANGE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import static no.unit.nva.search2.constant.Functions.generateSimpleAggregation;
import static no.unit.nva.search2.constant.Functions.jsonPath;
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.CONTRIBUTOR_ID;
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;
Expand Down Expand Up @@ -36,8 +37,6 @@
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 java.util.List;
import org.opensearch.search.aggregations.AbstractAggregationBuilder;
Expand All @@ -59,6 +58,7 @@ public class Resource {
jsonPath(ENTITY_DESCRIPTION, PUBLICATION_DATE, YEAR);
public static final String REFERENCE_DOI_KEYWORD =
jsonPath(ENTITY_DESCRIPTION, REFERENCE, DOI, KEYWORD) + PIPE + jsonPath(DOI, KEYWORD);
public static final String VISIBLE_FOR_NON_OWNER = jsonPath(ASSOCIATED_ARTIFACTS, "visibleForNonOwner");
public static final String PUBLICATION_CONTEXT_ISBN_LIST =
jsonPath(ENTITY_DESCRIPTION, REFERENCE, PUBLICATION_CONTEXT, "isbnList");
public static final String PUBLICATION_CONTEXT_ONLINE_ISSN_KEYWORD =
Expand All @@ -76,7 +76,6 @@ public class Resource {
jsonPath(RESOURCE_OWNER, OWNER_AFFILIATION, KEYWORD);
public static final String RESOURCE_OWNER_OWNER_KEYWORD = jsonPath(RESOURCE_OWNER, OWNER, KEYWORD);


public static final String ENTITY_DESCRIPTION_CONTRIBUTORS_AFFILIATION_LABELS_KEYWORD =
jsonPath(CONTRIBUTORS_AFFILIATION_LABELS, ENGLISH_CODE, KEYWORD) + PIPE
+ jsonPath(CONTRIBUTORS_AFFILIATION_LABELS, NYNORSK_CODE, KEYWORD) + PIPE
Expand Down Expand Up @@ -110,10 +109,9 @@ public class Resource {

public static final List<AbstractAggregationBuilder<? extends AbstractAggregationBuilder<?>>>
RESOURCES_AGGREGATIONS = List.of(
generateSimpleAggregation(USER, CONTRIBUTORS_IDENTITY_NAME_KEYWORD),
generateSimpleAggregation(USER_AFFILIATION, RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD),
generateSimpleAggregation(CONTRIBUTOR_ID, CONTRIBUTORS_IDENTITY_ID)
.subAggregation(generateSimpleAggregation(NAME, CONTRIBUTORS_IDENTITY_NAME_KEYWORD)),
generateSimpleAggregation(TYPE, PUBLICATION_INSTANCE_TYPE),
generateSimpleAggregation(CONTEXT_TYPE, PUBLICATION_CONTEXT_TYPE_KEYWORD),
generateSimpleAggregation(FUNDING_SOURCE, jsonPath(FUNDINGS, SOURCE, IDENTIFIER))
.subAggregation(generateLabelsAggregation(jsonPath(FUNDINGS, SOURCE))),
generateObjectLabelsAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class Words {
public static final String COLON = ":";
public static final String COMMA = ",";
public static final String CONTEXT_TYPE = "contextType";
public static final String CONTRIBUTOR_ID = "contributorId";
public static final String CONTRIBUTORS = "contributors";
public static final String COUNT = "count";
public static final String CREATED_DATE = "createdDate";
Expand Down Expand Up @@ -64,7 +65,6 @@ public final class Words {
public static final String SEARCH_ALL = "SEARCH_ALL";
public static final String SEARCH_INFRASTRUCTURE_CREDENTIALS = "SearchInfrastructureCredentials";
public static final String SLASH = "/";
public static final String SORT = "SORT";
public static final String SOURCE = "source";
public static final String SPACE = " ";
public static final String SUFFIX = ")";
Expand All @@ -73,7 +73,6 @@ public final class Words {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static no.unit.nva.search2.constant.Resource.REFERENCE_DOI_KEYWORD;
import static no.unit.nva.search2.constant.Resource.RESOURCE_OWNER_OWNER_AFFILIATION_KEYWORD;
import static no.unit.nva.search2.constant.Resource.RESOURCE_OWNER_OWNER_KEYWORD;
import static no.unit.nva.search2.constant.Words.ASSOCIATED_ARTIFACTS;
import static no.unit.nva.search2.constant.Resource.VISIBLE_FOR_NON_OWNER;
import static no.unit.nva.search2.constant.Words.ASTERISK;
import static no.unit.nva.search2.constant.Words.COLON;
import static no.unit.nva.search2.constant.Words.CREATED_DATE;
Expand All @@ -58,7 +58,6 @@
import java.util.Set;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import no.unit.nva.search2.constant.Functions;
import no.unit.nva.search2.constant.Words;
import nva.commons.core.JacocoGenerated;

Expand All @@ -78,7 +77,7 @@ public enum ResourceParameter implements ParameterKey {
CONTRIBUTOR_ID(KEYWORD, MUST, CONTRIBUTORS_IDENTITY_ID, null, PATTERN_IS_URI, null),
CONTRIBUTOR(KEYWORD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY),
CONTRIBUTOR_NOT(KEYWORD, MUST_NOT, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY),
CONTRIBUTOR_SHOULD(KEYWORD, SHOULD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY),
CONTRIBUTOR_SHOULD(TEXT, SHOULD, ENTITY_DESCRIPTION_CONTRIBUTORS_IDENTITY),
// TODO fix definition -> CONTRIBUTOR_SHOULD needs text AND keyword.
CREATED_BEFORE(ParamKind.DATE, FieldOperator.LESS_THAN, CREATED_DATE),
CREATED_SINCE(ParamKind.DATE, FieldOperator.GREATER_THAN_OR_EQUAL_TO, CREATED_DATE),
Expand All @@ -90,7 +89,8 @@ public enum ResourceParameter implements ParameterKey {
FUNDING_SOURCE(KEYWORD, FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS),
FUNDING_SOURCE_NOT(KEYWORD, MUST_NOT, FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS),
FUNDING_SOURCE_SHOULD(TEXT, SHOULD, FUNDINGS_SOURCE_IDENTIFIER_FUNDINGS_SOURCE_LABELS),
HAS_FILE(ParamKind.BOOLEAN, MUST, Functions.jsonPath(ASSOCIATED_ARTIFACTS, "visibleForNonOwner")),
HAS_FILE(ParamKind.BOOLEAN, MUST, VISIBLE_FOR_NON_OWNER),
HAS_FILE_SHOULD(ParamKind.BOOLEAN, SHOULD, VISIBLE_FOR_NON_OWNER),
ID(KEYWORD, IDENTIFIER_KEYWORD),
ID_NOT(TEXT, MUST_NOT, IDENTIFIER_KEYWORD),
ID_SHOULD(TEXT, SHOULD, IDENTIFIER_KEYWORD),
Expand Down
Loading

0 comments on commit 9941693

Please sign in to comment.