Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODINV-1066: Update mapping for "sourceRecordIdentifier" property in … #754

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

public interface InstanceIngressEventHandler {
String LINKED_DATA_ID = "linkedDataId";
String INSTANCE_ID = "instanceId";
String FAILURE = "Failed to process InstanceIngressEvent with id {}";

CompletableFuture<Instance> handle(InstanceIngressEvent instanceIngressEvent);
Expand All @@ -57,11 +58,15 @@ default boolean eventContainsNoData(InstanceIngressEvent event) {
}

default Optional<String> getInstanceId(InstanceIngressEvent event) {
return ofNullable(event.getEventPayload().getSourceRecordIdentifier());
return ofNullable(event.getEventPayload())
.map(InstanceIngressPayload::getAdditionalProperties)
.map(ap -> ap.get(INSTANCE_ID))
.map(o -> (String) o);
}

default Record constructMarcBibRecord(InstanceIngressPayload eventPayload) {
var recordId = UUID.randomUUID().toString();
var recordId = ofNullable(eventPayload.getSourceRecordIdentifier())
.orElseGet(() -> UUID.randomUUID().toString());
var marcBibRecord = new org.folio.rest.jaxrs.model.Record()
.withId(recordId)
.withRecordType(MARC_BIB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,16 @@ public void shouldReturnFailedFuture_ifItsFailedToCreateMarcRecordInSrs() throws
@Test
public void shouldReturnSucceededFuture_ifProcessFinishedCorrectly() throws IOException, ExecutionException, InterruptedException {
// given
var linkedDataIdId = "someLinkedDataIdId";
var linkedDataId = "someLinkedDataId";
var instanceId = "someInstanceId";
var event = new InstanceIngressEvent()
.withId(UUID.randomUUID().toString())
.withEventPayload(new InstanceIngressPayload()
.withSourceRecordObject(TestUtil.readFileFromPath(BIB_RECORD_PATH))
.withSourceType(LINKED_DATA)
.withSourceRecordIdentifier(UUID.randomUUID().toString())
.withAdditionalProperty("linkedDataId", linkedDataIdId)
.withAdditionalProperty("linkedDataId", linkedDataId)
.withAdditionalProperty("instanceId", instanceId)
);
doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString());
var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
Expand Down Expand Up @@ -365,18 +367,16 @@ public void shouldReturnSucceededFuture_ifProcessFinishedCorrectly() throws IOEx
assertThat(future.isDone()).isTrue();

var instance = future.get();
assertThat(instance.getId()).isEqualTo(event.getEventPayload().getSourceRecordIdentifier());
assertThat(instance.getId()).isEqualTo(instanceId);
assertThat(instance.getSource()).isEqualTo("LINKED_DATA");
assertThat(instance.getIdentifiers().stream().anyMatch(i -> i.value.equals("(ld) " + linkedDataIdId))).isTrue();
assertThat(instance.getIdentifiers().stream().anyMatch(i -> i.value.equals("(ld) " + linkedDataId))).isTrue();

var recordCaptor = ArgumentCaptor.forClass(Record.class);
verify(sourceStorageClient).postSourceStorageRecords(recordCaptor.capture());
var recordSentToSRS = recordCaptor.getValue();
assertThat(recordSentToSRS.getId()).isNotNull();
assertThat(recordSentToSRS.getId()).isNotEqualTo(event.getEventPayload().getSourceRecordIdentifier());
assertThat(recordSentToSRS.getId()).doesNotContain(linkedDataIdId);
assertThat(recordSentToSRS.getId()).isEqualTo(event.getEventPayload().getSourceRecordIdentifier());
assertThat(recordSentToSRS.getRecordType()).isEqualTo(Record.RecordType.MARC_BIB);
assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_I)).hasValue(instance.getId());
assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_L)).hasValue(linkedDataIdId);
assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_L)).hasValue(linkedDataId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,16 @@ public void shouldReturnFailedFuture_ifCreatePrecedingSucceedingTitlesFailed() t
@Test
public void shouldReturnSucceededFuture_ifProcessFinishedCorrectly() throws IOException, ExecutionException, InterruptedException {
// given
var linkedDataIdId = "someLinkedDataIdId";
var linkedDataId = "someLinkedDataId";
var instanceId = "instanceId";
var event = new InstanceIngressEvent()
.withId(UUID.randomUUID().toString())
.withEventPayload(new InstanceIngressPayload()
.withSourceRecordObject(TestUtil.readFileFromPath(BIB_RECORD_PATH))
.withSourceType(LINKED_DATA)
.withSourceRecordIdentifier(UUID.randomUUID().toString())
.withAdditionalProperty("linkedDataId", linkedDataIdId)
.withAdditionalProperty("linkedDataId", linkedDataId)
.withAdditionalProperty("instanceId", instanceId)
);
var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
doReturn(succeededFuture(Optional.of(new MappingMetadataDto()
Expand Down Expand Up @@ -537,22 +539,21 @@ public void shouldReturnSucceededFuture_ifProcessFinishedCorrectly() throws IOEx
assertThat(future.isDone()).isTrue();

var instance = future.get();
assertThat(instance.getId()).isEqualTo(event.getEventPayload().getSourceRecordIdentifier());
assertThat(instance.getId()).isEqualTo(instanceId);
assertThat(instance.getHrid()).isEqualTo(existedInstance.getHrid());
assertThat(instance.getSource()).isEqualTo("LINKED_DATA");
assertThat(instance.getIdentifiers().stream().anyMatch(i -> i.value.equals("(ld) " + linkedDataIdId))).isTrue();
assertThat(instance.getIdentifiers().stream().anyMatch(i -> i.value.equals("(ld) " + linkedDataId))).isTrue();

var recordCaptor = ArgumentCaptor.forClass(Record.class);
verify(sourceStorageClient).putSourceStorageRecordsGenerationById(eq(previousSrsId), recordCaptor.capture());
var recordSentToSRS = recordCaptor.getValue();
assertThat(recordSentToSRS.getId()).isNotNull();
assertThat(recordSentToSRS.getId()).isNotEqualTo(previousSrsId);
assertThat(recordSentToSRS.getMatchedId()).isEqualTo(previousSrsId);
assertThat(recordSentToSRS.getId()).isNotEqualTo(event.getEventPayload().getSourceRecordIdentifier());
assertThat(recordSentToSRS.getId()).doesNotContain(linkedDataIdId);
assertThat(recordSentToSRS.getId()).isEqualTo(event.getEventPayload().getSourceRecordIdentifier());
assertThat(recordSentToSRS.getRecordType()).isEqualTo(Record.RecordType.MARC_BIB);
assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_I)).hasValue(instance.getId());
assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_L)).hasValue(linkedDataIdId);
assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_L)).hasValue(linkedDataId);
}

}
Loading