Skip to content

Commit b2550de

Browse files
Merge branch 'main' of github.com:BIBSYSDEV/nva-publication-api into NP-3239-SPLIT-HIGHER-LEVEL-EXCEPTIONS-IN-S3
2 parents 7bca30d + 6d1fcc4 commit b2550de

File tree

41 files changed

+231
-335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+231
-335
lines changed

create-publication/build.gradle

Lines changed: 0 additions & 29 deletions
This file was deleted.

cristin-import/src/main/java/no/unit/nva/cristin/lambda/CristinEntryEventConsumer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import static java.util.Objects.isNull;
44
import static no.unit.nva.cristin.lambda.constants.HardcodedValues.HARDCODED_PUBLICATIONS_OWNER;
55
import static no.unit.nva.publication.s3imports.ApplicationConstants.MAX_SLEEP_TIME;
6+
import static no.unit.nva.publication.s3imports.FileImportUtils.timestampToString;
67
import static nva.commons.core.JsonUtils.objectMapperWithEmpty;
78
import static nva.commons.core.attempt.Try.attempt;
89
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
910
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
1011
import com.amazonaws.services.lambda.runtime.Context;
1112
import com.fasterxml.jackson.databind.JsonNode;
1213
import java.time.Clock;
14+
import java.time.Instant;
1315
import java.util.Objects;
1416
import java.util.Optional;
1517
import java.util.Random;
@@ -186,9 +188,11 @@ private void saveReportToS3(Failure<Publication> fail,
186188
private UriWrapper constructErrorFileUri(AwsEventBridgeEvent<FileContentsEvent<JsonNode>> event,
187189
Exception exception) {
188190
UriWrapper fileUri = new UriWrapper(event.getDetail().getFileUri());
191+
Instant timestamp = event.getDetail().getTimestamp();
189192
UriWrapper bucket = fileUri.getHost();
190193
return bucket
191194
.addChild(ERRORS_FOLDER)
195+
.addChild(timestampToString(timestamp))
192196
.addChild(exception.getClass().getSimpleName())
193197
.addChild(fileUri.getPath())
194198
.addChild(createErrorReportFilename(event));

cristin-import/src/main/java/no/unit/nva/cristin/lambda/dtos/CristinObjectEvent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import com.fasterxml.jackson.databind.JsonNode;
66
import java.net.URI;
7+
import java.time.Instant;
8+
79
import no.unit.nva.publication.s3imports.FileContentsEvent;
810

911
/**
@@ -14,8 +16,9 @@ public class CristinObjectEvent extends FileContentsEvent<JsonNode> {
1416

1517
@JsonCreator
1618
public CristinObjectEvent(@JsonProperty(FILE_URI) URI fileUri,
19+
@JsonProperty(TIMESTAMP) Instant timestamp,
1720
@JsonProperty(CONTENTS_FIELD) JsonNode contents) {
1821

19-
super(fileUri, contents);
22+
super(fileUri, timestamp, contents);
2023
}
2124
}

cristin-import/src/test/java/no/unit/nva/cristin/CristinDataGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.databind.node.ObjectNode;
2020
import com.github.javafaker.Faker;
2121
import java.net.URI;
22+
import java.time.Instant;
2223
import java.time.LocalDate;
2324
import java.util.Calendar;
2425
import java.util.Date;
@@ -199,7 +200,7 @@ public static CristinObject randomObject(String secondaryCategory) {
199200
public static <T> AwsEventBridgeEvent<FileContentsEvent<JsonNode>> toAwsEvent(T inputData) {
200201
AwsEventBridgeEvent<FileContentsEvent<JsonNode>> event = new AwsEventBridgeEvent<>();
201202
JsonNode cristinData = convertToJsonNode(inputData);
202-
FileContentsEvent<JsonNode> eventDetail = new FileContentsEvent<>(randomUri(), cristinData);
203+
FileContentsEvent<JsonNode> eventDetail = new FileContentsEvent<>(randomUri(), Instant.now(), cristinData);
203204
event.setDetailType(CristinEntryEventConsumer.EVENT_DETAIL_TYPE);
204205
event.setDetail(eventDetail);
205206
return event;

cristin-import/src/test/java/no/unit/nva/cristin/lambda/CristinEntryEventConsumerTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static no.unit.nva.cristin.lambda.constants.HardcodedValues.UNIT_CUSTOMER_ID;
1111
import static no.unit.nva.cristin.lambda.constants.MappingConstants.NVA_API_DOMAIN;
1212
import static no.unit.nva.cristin.lambda.constants.MappingConstants.PATH_CUSTOMER;
13+
import static no.unit.nva.publication.s3imports.FileImportUtils.timestampToString;
1314
import static nva.commons.core.JsonUtils.objectMapperNoEmpty;
1415
import static nva.commons.core.attempt.Try.attempt;
1516
import static nva.commons.core.ioutils.IoUtils.stringToStream;
@@ -32,6 +33,7 @@
3233
import java.io.InputStream;
3334
import java.nio.file.Path;
3435
import java.time.Clock;
36+
import java.time.Instant;
3537
import java.util.List;
3638
import java.util.Optional;
3739
import java.util.concurrent.ConcurrentHashMap;
@@ -326,7 +328,7 @@ public void handlerCreatesFileWithCustomNameWhenCristinIdIsNotFound() throws Jso
326328
}
327329

328330
@Test
329-
public void savesFileInInputFolderErrorExceptionNameInputFileLocationInputFileWhenFailingToSaveInDynamo()
331+
public void savesFileInInputFolderErrorTimestampExceptionNameInputFileLocationInputFileWhenFailingToSaveInDynamo()
330332
throws Throwable {
331333
CristinObject cristinObject = CristinDataGenerator.randomObject();
332334
JsonNode cristinObjectWithCustomSecondaryCategory =
@@ -341,9 +343,11 @@ public void savesFileInInputFolderErrorExceptionNameInputFileLocationInputFileWh
341343

342344
S3Driver s3Driver = new S3Driver(s3Client, "bucket");
343345
String expectedFilePath = awsEvent.getDetail().getFileUri().getPath();
346+
Instant expectedTimestamp = awsEvent.getDetail().getTimestamp();
344347
String exceptionName = exception.getCause().getClass().getSimpleName();
345348
String fileIdWithEnding = cristinObject.getId().toString() + JSON;
346349
UnixPath expectedErrorFileLocation = UnixPath.of(ERRORS_FOLDER,
350+
timestampToString(expectedTimestamp),
347351
exceptionName,
348352
expectedFilePath,
349353
fileIdWithEnding);
@@ -439,6 +443,7 @@ private UnixPath constructExpectedFilePathForEntryWithUnkownFields(
439443
AwsEventBridgeEvent<FileContentsEvent<Identifiable>> event,
440444
RuntimeException exception) {
441445
return UnixPath.of(ERRORS_FOLDER)
446+
.addChild(timestampToString(event.getDetail().getTimestamp()))
442447
.addChild(exception.getCause().getClass().getSimpleName())
443448
.addChild(event.getDetail().getFileUri().getPath())
444449
.addChild(event.getDetail().getContents().getId() + JSON);
@@ -480,8 +485,10 @@ private UriWrapper constructErrorFileUri(AwsEventBridgeEvent<FileContentsEvent<J
480485
String cristinObjectId = awsEvent.getDetail().getContents().get(ID_FIELD_NAME).asText();
481486
String errorReportFilename = cristinObjectId + JSON;
482487
UriWrapper inputFile = new UriWrapper(awsEvent.getDetail().getFileUri());
488+
Instant timestamp = awsEvent.getDetail().getTimestamp();
483489
UriWrapper bucket = inputFile.getHost();
484490
return bucket.addChild(ERRORS_FOLDER)
491+
.addChild(timestampToString(timestamp))
485492
.addChild(exception.getClass().getSimpleName())
486493
.addChild(inputFile.getPath())
487494
.addChild(errorReportFilename);

cristin-import/src/test/resources/cristin_entry_with_unknown_property.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"detail": {
1313
"publicationsowner": "someRandomUser",
1414
"fileUri": "s3://bucket/parent/child/filename.json",
15+
"timestamp": "2017-02-03T11:25:30.00Z",
1516
"contents": {
1617
"unknownProperty": "helloworld",
1718
"id": 417536,

delete-draft-publication-handler/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,25 @@ dependencies {
1616

1717
testImplementation project(":publication-testing")
1818
}
19+
20+
dependencies {
21+
implementation project(":publication-events")
22+
23+
implementation(libs.nva.datamodel) {
24+
exclude group: 'com.github.bibsysdev', module: 'nva-commons'
25+
}
26+
27+
implementation libs.nva.core
28+
implementation libs.nva.identifiers
29+
implementation libs.nva.eventhandlers
30+
implementation libs.aws.lambda.java.core
31+
32+
runtimeOnly libs.jackson.databind
33+
testImplementation libs.jackson.databind
34+
runtimeOnly libs.jackson.core
35+
testImplementation libs.jackson.core
36+
37+
compileOnly(libs.aws.sdk.apigateway) {
38+
because "PMD complains for the com/amazonaws/regions/Regions class"
39+
}
40+
}

delete-publication/build.gradle

Lines changed: 0 additions & 20 deletions
This file was deleted.

delete-publication/src/main/java/resources/log4j2.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

fetch-publication/build.gradle

Lines changed: 0 additions & 32 deletions
This file was deleted.

fetch-publication/src/main/resources/log4j2.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)