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 6aab5b0 commit 9794d26
Show file tree
Hide file tree
Showing 168 changed files with 7,359 additions and 7,989 deletions.
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
package no.unit.nva.indexingclient;

import com.fasterxml.jackson.databind.JsonNode;

import java.util.ArrayList;
import java.util.List;

public class AggregationsValidator {

private static final String ENTITY_DESCRIPTION_POINTER = "/entityDescription";
private static final String REFERENCE_POINTER = "/entityDescription/reference";
private static final String PUBLICATION_CONTEXT_POINTER =
"/entityDescription/reference/publicationContext";
private static final String PUBLICATION_INSTANCE_POINTER =
"/entityDescription/reference/publicationInstance";
private static final String IDENTIFIER_POINTER = "/identifier";
private static final String DELIMITER = ", ";
private static final String REPORT_TEMPLATE = "Document %s has missing fields %s";
private final List<String> report;
private final JsonNode document;

public AggregationsValidator(JsonNode document) {
this.document = document;
this.report = new ArrayList<>();
}

private static boolean isNotValidNode(JsonNode node) {
return !node.isObject();
}

public String getReport() {
return String.format(
REPORT_TEMPLATE,
document.at(IDENTIFIER_POINTER).textValue(),
String.join(DELIMITER, report));
}

public boolean isValid() {
List.of(
ENTITY_DESCRIPTION_POINTER,
REFERENCE_POINTER,
PUBLICATION_CONTEXT_POINTER,
PUBLICATION_INSTANCE_POINTER)
.forEach(this::validateNode);
return report.isEmpty();
}

private void validateNode(String value) {
if (isNotValidNode(document.at(value))) {
report.add(value);
}
private static final String ENTITY_DESCRIPTION_POINTER = "/entityDescription";
private static final String REFERENCE_POINTER = "/entityDescription/reference";
private static final String PUBLICATION_CONTEXT_POINTER =
"/entityDescription/reference/publicationContext";
private static final String PUBLICATION_INSTANCE_POINTER =
"/entityDescription/reference/publicationInstance";
private static final String IDENTIFIER_POINTER = "/identifier";
private static final String DELIMITER = ", ";
private static final String REPORT_TEMPLATE = "Document %s has missing fields %s";
private final List<String> report;
private final JsonNode document;

public AggregationsValidator(JsonNode document) {
this.document = document;
this.report = new ArrayList<>();
}

private static boolean isNotValidNode(JsonNode node) {
return !node.isObject();
}

public String getReport() {
return String.format(
REPORT_TEMPLATE,
document.at(IDENTIFIER_POINTER).textValue(),
String.join(DELIMITER, report));
}

public boolean isValid() {
List.of(
ENTITY_DESCRIPTION_POINTER,
REFERENCE_POINTER,
PUBLICATION_CONTEXT_POINTER,
PUBLICATION_INSTANCE_POINTER)
.forEach(this::validateNode);
return report.isEmpty();
}

private void validateNode(String value) {
if (isNotValidNode(document.at(value))) {
report.add(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package no.unit.nva.indexingclient;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import no.unit.nva.identifiers.SortableIdentifier;
import no.unit.nva.indexingclient.models.IndexDocument;
import no.unit.nva.s3.ListingResult;
import no.unit.nva.s3.S3Driver;

import nva.commons.core.paths.UnixPath;

import org.opensearch.action.bulk.BulkItemResponse;
import org.opensearch.action.bulk.BulkItemResponse.Failure;
import org.opensearch.action.bulk.BulkResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.amazon.awssdk.services.s3.S3Client;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class BatchIndexer implements IndexingResult<SortableIdentifier> {

private static final Logger logger = LoggerFactory.getLogger(BatchIndexer.class);
Expand Down
82 changes: 41 additions & 41 deletions batch-index/src/main/java/no/unit/nva/indexingclient/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,45 @@

public final class Constants {

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");
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");

public static final int NUMBER_OF_FILES_PER_EVENT_ENVIRONMENT_VARIABLE =
ENVIRONMENT
.readEnvOpt("NUMBER_OF_FILES_PER_EVENT")
.map(Integer::parseInt)
.orElse(NUMBER_OF_FILES_PER_EVENT);

@JacocoGenerated
public Constants() {}

@JacocoGenerated
public static EventBridgeClient defaultEventBridgeClient() {
return EventBridgeClient.builder().httpClient(UrlConnectionHttpClient.create()).build();
}

@JacocoGenerated
public static IndexingClient defaultEsClient() {
return IndexingClient.defaultIndexingClient();
}

@JacocoGenerated
public static S3Client defaultS3Client() {
String awsRegion =
ENVIRONMENT.readEnvOpt(AWS_REGION_ENV_VARIABLE).orElse(Region.EU_WEST_1.toString());
return S3Client.builder()
.region(Region.of(awsRegion))
.httpClient(UrlConnectionHttpClient.builder().build())
.build();
}
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");
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");

public static final int NUMBER_OF_FILES_PER_EVENT_ENVIRONMENT_VARIABLE =
ENVIRONMENT
.readEnvOpt("NUMBER_OF_FILES_PER_EVENT")
.map(Integer::parseInt)
.orElse(NUMBER_OF_FILES_PER_EVENT);

@JacocoGenerated
public Constants() {}

@JacocoGenerated
public static EventBridgeClient defaultEventBridgeClient() {
return EventBridgeClient.builder().httpClient(UrlConnectionHttpClient.create()).build();
}

@JacocoGenerated
public static IndexingClient defaultEsClient() {
return IndexingClient.defaultIndexingClient();
}

@JacocoGenerated
public static S3Client defaultS3Client() {
String awsRegion =
ENVIRONMENT.readEnvOpt(AWS_REGION_ENV_VARIABLE).orElse(Region.EU_WEST_1.toString());
return S3Client.builder()
.region(Region.of(awsRegion))
.httpClient(UrlConnectionHttpClient.builder().build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import static no.unit.nva.indexingclient.Constants.MANDATORY_UNUSED_SUBTOPIC;

import com.amazonaws.services.lambda.runtime.Context;

import java.time.Instant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
import software.amazon.awssdk.services.eventbridge.model.PutEventsRequest;
import software.amazon.awssdk.services.eventbridge.model.PutEventsRequestEntry;

import java.time.Instant;

public final class EmitEventUtils {

private static final Logger logger = LoggerFactory.getLogger(EmitEventUtils.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@
import static no.unit.nva.indexingclient.EmitEventUtils.emitEvent;

import com.amazonaws.services.lambda.runtime.Context;

import java.io.InputStream;
import java.io.OutputStream;
import no.unit.nva.events.handlers.EventHandler;
import no.unit.nva.events.models.AwsEventBridgeEvent;
import no.unit.nva.identifiers.SortableIdentifier;

import nva.commons.core.JacocoGenerated;
import nva.commons.core.ioutils.IoUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
import software.amazon.awssdk.services.s3.S3Client;

import java.io.InputStream;
import java.io.OutputStream;

public class EventBasedBatchIndexer
extends EventHandler<ImportDataRequestEvent, SortableIdentifier[]> {

Expand Down
Loading

0 comments on commit 9794d26

Please sign in to comment.