Skip to content

Commit

Permalink
autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNorland committed Jan 8, 2025
1 parent ad04a9f commit 6aab5b0
Show file tree
Hide file tree
Showing 24 changed files with 216 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@

public final class Constants {

static final String BATCH_INDEX_EVENT_TOPIC = "SearchService.Index.Batch";
public static final String MANDATORY_UNUSED_SUBTOPIC = "DETAIL.WITH.TOPIC";
public static final String EVENT_BUS = ENVIRONMENT.readEnv("EVENT_BUS");
public static final String TOPIC = ENVIRONMENT.readEnv("TOPIC");
static final String BATCH_INDEX_EVENT_TOPIC = "SearchService.Index.Batch";
static final String S3_LOCATION_FIELD = "s3Location";

static final Config config = ConfigFactory.load();
static final String PERSISTED_RESOURCES_PATH = config.getString("batch.persistedResourcesPath");
static final String BATCH_INDEX_EVENT_BUS_NAME = config.getString("batch.index.eventbusname");
static final boolean RECURSION_ENABLED = config.getBoolean("batch.index.recursion");

public static final String EVENT_BUS = ENVIRONMENT.readEnv("EVENT_BUS");
public static final String TOPIC = ENVIRONMENT.readEnv("TOPIC");

private static final String AWS_REGION_ENV_VARIABLE = "AWS_REGION";
private static final int NUMBER_OF_FILES_PER_EVENT =
config.getInt("batch.index.number_of_files_per_event");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public class GenerateKeyBatchesHandler extends EventHandler<KeyBatchRequestEvent
public static final String DELIMITER = "/";
public static final String DEFAULT_START_MARKER = null;
public static final String START_MARKER_MESSAGE = "Start marker: {}";
private static final Logger logger = LoggerFactory.getLogger(GenerateKeyBatchesHandler.class);
public static final String INPUT_BUCKET = ENVIRONMENT.readEnv("PERSISTED_RESOURCES_BUCKET");
public static final String OUTPUT_BUCKET = ENVIRONMENT.readEnv("KEY_BATCHES_BUCKET");
public static final int MAX_KEYS =
Integer.parseInt(ENVIRONMENT.readEnvOpt("BATCH_SIZE").orElse(DEFAULT_BATCH_SIZE));
private static final Logger logger = LoggerFactory.getLogger(GenerateKeyBatchesHandler.class);
private final S3Client inputClient;
private final S3Client outputClient;
private final EventBridgeClient eventBridgeClient;
Expand Down Expand Up @@ -109,7 +109,7 @@ private static List<String> getKeys(ListObjectsV2Response response) {
}

private static String getLastEvaluatedKey(List<String> keys) {
return keys.get(keys.size() - 1);
return keys.getLast();
}

@JacocoGenerated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
public class IndexResourceHandler
extends DestinationsEventBridgeEventHandler<EventReference, Void> {

public static final String INDEXING_MESSAGE = "Indexing document with id: {} to {}";
private static final Logger LOGGER = LoggerFactory.getLogger(IndexResourceHandler.class);
private static final String EXPANDED_RESOURCES_BUCKET =
ENVIRONMENT.readEnv("EXPANDED_RESOURCES_BUCKET");
private static final String SENT_TO_RECOVERY_QUEUE_MESSAGE =
"IndexDocument for index {} has been sent to recovery queue: {}";
public static final String INDEXING_MESSAGE = "Indexing document with id: {} to {}";

private final S3Driver resourcesS3Driver;
private final IndexingClient indexingClient;
private final QueueClient queueClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.net.MediaType;

import java.net.URI;
import java.util.List;
import no.unit.nva.commons.json.JsonUtils;

import nva.commons.apigateway.MediaTypes;
import nva.commons.core.Environment;
import nva.commons.core.JacocoGenerated;

import java.net.URI;
import java.util.List;

/**
* Default values for the search service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public static IndexingClient prepareWithSecretReader(SecretsReader secretReader)
return new IndexingClient(defaultRestHighLevelClientWrapper(), cachedJwtProvider);
}

private static DeleteRequest deleteDocumentRequest(String index, String identifier) {
return new DeleteRequest(index, identifier).routing(DEFAULT_SHARD_ID);
}

public Void addDocumentToIndex(IndexDocument indexDocument) throws IOException {
logger.debug(
INITIAL_LOG_MESSAGE,
Expand All @@ -100,10 +104,6 @@ public void removeDocumentFromResourcesIndex(String identifier) throws IOExcepti
loggWarningIfNotFound(identifier, deleteResponse);
}

private static DeleteRequest deleteDocumentRequest(String index, String identifier) {
return new DeleteRequest(index, identifier).routing(DEFAULT_SHARD_ID);
}

public void removeDocumentFromImportCandidateIndex(String identifier) throws IOException {
var deleteRequest = deleteDocumentRequest(IMPORT_CANDIDATES_INDEX, identifier);
var deleteResponse = openSearchClient.delete(deleteRequest, getRequestOptions());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.unit.nva.indexingclient.models;

import java.io.IOException;
import nva.commons.core.JacocoGenerated;

import org.opensearch.action.admin.indices.delete.DeleteIndexRequest;
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.opensearch.action.support.master.AcknowledgedResponse;
Expand All @@ -12,8 +12,6 @@
import org.opensearch.client.indices.GetIndexRequest;
import org.opensearch.client.indices.GetIndexResponse;

import java.io.IOException;

/** Wrapper class for being able to test calls to the final class IndicesClient. */
@JacocoGenerated
public class IndicesClientWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public AsType(String value, K key) {
this.key = key;
}

private static Stream<String> splitParts(String delimiter, String value) {
return Arrays.stream(value.split(delimiter))
.filter(predicate -> !predicate.isBlank())
.sequential();
}

public <T> T as() {
if (isNull(value)) {
return null;
Expand Down Expand Up @@ -112,12 +118,6 @@ public Stream<String> asSplitStream(String delimiter) {
return asStream().flatMap(value -> splitParts(delimiter, value));
}

private static Stream<String> splitParts(String delimiter, String value) {
return Arrays.stream(value.split(delimiter))
.filter(predicate -> !predicate.isBlank())
.sequential();
}

/**
* AsStream.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public HeaderColumnNameAndOrderMappingStrategy() {
super();
}

public static HeaderColumnNameAndOrderMappingStrategy
headerColumnNameAndOrderMappingStrategyWithType(Class type) {
var strategy = new HeaderColumnNameAndOrderMappingStrategy<>();
strategy.setType(type);
return strategy;
}

/**
* This maintains case of header strings.
*
Expand Down Expand Up @@ -103,11 +110,4 @@ private String extractHeaderName(final BeanField<T, String> beanField) {
}
return StringUtils.EMPTY;
}

public static HeaderColumnNameAndOrderMappingStrategy
headerColumnNameAndOrderMappingStrategyWithType(Class type) {
var strategy = new HeaderColumnNameAndOrderMappingStrategy<>();
strategy.setType(type);
return strategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public ResourceAccessFilter(ResourceSearchQuery query) {
this.searchQuery.filters().set();
}

private static URI getCurationInstitutionId(RequestInfo requestInfo)
throws UnauthorizedException {
return requestInfo.getTopLevelOrgCristinId().isPresent()
? requestInfo.getTopLevelOrgCristinId().get()
: requestInfo.getPersonAffiliation();
}

@Override
public ResourceSearchQuery apply() {
return searchQuery;
Expand Down Expand Up @@ -118,13 +125,6 @@ public ResourceAccessFilter customerCurationInstitutions(RequestInfo requestInfo
return this;
}

private static URI getCurationInstitutionId(RequestInfo requestInfo)
throws UnauthorizedException {
return requestInfo.getTopLevelOrgCristinId().isPresent()
? requestInfo.getTopLevelOrgCristinId().get()
: requestInfo.getPersonAffiliation();
}

private QueryBuilder getContributingOrganisationAccessFilter(String institutionId) {
return QueryBuilders.termQuery(CONTRIBUTOR_ORG_KEYWORD, institutionId)
.queryName(EDITOR_FILTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ private ResourceSearchQuery() {
filterBuilder = new ResourceAccessFilter(this);
}

public static ResourceParameterValidator builder() {
return new ResourceParameterValidator();
}

private static boolean missingIdentifier(String sortString) {
return !sortString.contains(IDENTIFIER);
}

/**
* Calculate the boost for a promoted publication. (4.14 down to 3.14 (PI))
*
* @param i index of the current publication
* @param size total number of promoted publications
* @return the boost value
*/
private static float calculateBoostValue(AtomicInteger i, int size) {
return PI + 1F - ((float) i.getAndIncrement() / size);
}

/**
* Add a (default) filter to the query that will never match any document.
*
Expand All @@ -108,10 +127,6 @@ private void assignStatusImpossibleWhiteList() {
.queryName(STATUS));
}

public static ResourceParameterValidator builder() {
return new ResourceParameterValidator();
}

@Override
protected ResourceParameter keyFields() {
return NODES_SEARCHED;
Expand All @@ -130,10 +145,6 @@ public AsType<ResourceParameter> sort() {
return parameters().get(SORT);
}

private static boolean missingIdentifier(String sortString) {
return !sortString.contains(IDENTIFIER);
}

@Override
protected String[] exclude() {
return Stream.concat(
Expand Down Expand Up @@ -242,17 +253,6 @@ private void addPromotedPublications(UserSettingsClient client, BoolQueryBuilder
}
}

/**
* Calculate the boost for a promoted publication. (4.14 down to 3.14 (PI))
*
* @param i index of the current publication
* @param size total number of promoted publications
* @return the boost value
*/
private static float calculateBoostValue(AtomicInteger i, int size) {
return PI + 1F - ((float) i.getAndIncrement() / size);
}

@Override
public URI openSearchUri() {
return fromUri(infrastructureApiUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static no.unit.nva.commons.json.JsonUtils.dtoObjectMapper;

import static no.unit.nva.constants.Words.DOT;
import static nva.commons.core.attempt.Try.attempt;

import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down Expand Up @@ -75,20 +76,20 @@ public class SimplifiedMutator implements JsonNodeMutator {
public static final String ROLE = "role";
public static final String MANIFESTATIONS = "manifestations";
public static final String SCIENTIFIC_VALUE = "scientificValue";
private final ObjectMapper objectMapper = dtoObjectMapper.copy();
public static final String ENTITY_DESCRIPTION = "entityDescription";
public static final String REFERENCE = "reference";
public static final String PUBLICATION_CONTEXT = "publicationContext";
public static final String SERIES = "series";
public static final String PUBLISHER = "publisher";
private final ObjectMapper objectMapper = dtoObjectMapper.copy();

public SimplifiedMutator() {
public SimplifiedMutator() {
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

public static String path(String... path) {
return Arrays.stream(path).collect(Collectors.joining("."));
return String.join(DOT, path);
}

public static List<String> getIncludedFields() {
Expand Down Expand Up @@ -129,12 +130,6 @@ public static List<String> getIncludedFields() {
path(ADDITIONAL_IDENTIFIERS, VALUE));
}

@Override
public JsonNode transform(JsonNode source) {
return (JsonNode)
attempt(() -> objectMapper.valueToTree(transformToDto(source))).orElseThrow();
}

@NotNull
private static PublicationDate mutatePublicationDate(JsonNode source) {
return new PublicationDate(
Expand All @@ -143,6 +138,12 @@ private static PublicationDate mutatePublicationDate(JsonNode source) {
source.path(ENTITY_DESCRIPTION).path(PUBLICATION_DATE).path(DAY).textValue());
}

@Override
public JsonNode transform(JsonNode source) {
return (JsonNode)
attempt(() -> objectMapper.valueToTree(transformToDto(source))).orElseThrow();
}

private ResourceSearchResponse transformToDto(JsonNode source) throws IOException {
return new Builder()
.withId(uriFromText(source.path(ID).textValue()))
Expand Down Expand Up @@ -347,7 +348,7 @@ private Publisher mutatePublisher(JsonNode source) {
}

private List<Contributor> mutateContributorsPreview(JsonNode source) {
var contributors = new ArrayList();
var contributors = new ArrayList<Contributor>();
source.path(ENTITY_DESCRIPTION)
.path(CONTRIBUTORS_PREVIEW)
.iterator()
Expand All @@ -359,12 +360,12 @@ private List<Contributor> mutateContributorsPreview(JsonNode source) {
affiliationNode
.iterator()
.forEachRemaining(
aff -> {
affiliations.add(
new Affiliation(
aff.path(ID).textValue(),
aff.path(TYPE).textValue()));
});
aff ->
affiliations.add(
new Affiliation(
aff.path(ID).textValue(),
aff.path(TYPE)
.textValue())));
}

contributors.add(
Expand Down
Loading

0 comments on commit 6aab5b0

Please sign in to comment.