From 28dfa35c474a9628bb91c42c8869913ffcd8f2f6 Mon Sep 17 00:00:00 2001 From: pbobylev Date: Mon, 10 Jun 2024 16:10:05 +0500 Subject: [PATCH] MODINV-986: rename source type BIBFRAME to LINKED_DATA --- ramls/instance-ingress-payload.json | 2 +- .../dataimport/util/AdditionalFieldsUtil.java | 2 +- .../CreateInstanceIngressEventHandler.java | 16 +++++----- ...teInstanceIngressEventHandlerUnitTest.java | 32 +++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ramls/instance-ingress-payload.json b/ramls/instance-ingress-payload.json index 55ce36217..3533b307a 100644 --- a/ramls/instance-ingress-payload.json +++ b/ramls/instance-ingress-payload.json @@ -13,7 +13,7 @@ }, "sourceType": { "type": "string", - "enum": ["BIBFRAME", "MARC", "FOLIO"], + "enum": ["FOLIO", "LINKED_DATA", "MARC"], "description": "Source type" } }, diff --git a/src/main/java/org/folio/inventory/dataimport/util/AdditionalFieldsUtil.java b/src/main/java/org/folio/inventory/dataimport/util/AdditionalFieldsUtil.java index c56f8ae32..7280e0554 100644 --- a/src/main/java/org/folio/inventory/dataimport/util/AdditionalFieldsUtil.java +++ b/src/main/java/org/folio/inventory/dataimport/util/AdditionalFieldsUtil.java @@ -72,8 +72,8 @@ public final class AdditionalFieldsUtil { private static final char TAG_035_IND = ' '; private static final String ANY_STRING = "*"; private static final char INDICATOR = 'f'; - public static final char SUBFIELD_B = 'b'; public static final char SUBFIELD_I = 'i'; + public static final char SUBFIELD_L = 'l'; private static final String HR_ID_FIELD = "hrid"; private static final CacheLoader parsedRecordContentCacheLoader; private static final LoadingCache parsedRecordContentCache; diff --git a/src/main/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandler.java b/src/main/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandler.java index 7640a0d25..4ee681014 100644 --- a/src/main/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandler.java +++ b/src/main/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandler.java @@ -4,7 +4,7 @@ import static java.util.Objects.isNull; import static java.util.Optional.ofNullable; import static org.apache.logging.log4j.LogManager.getLogger; -import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_B; +import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_L; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.TAG_035; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.TAG_035_SUB; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.TAG_999; @@ -56,9 +56,9 @@ public class CreateInstanceIngressEventHandler extends CreateInstanceEventHandler implements InstanceIngressEventHandler { - public static final String BIBFRAME_ID = "bibframeId"; + private static final String LINKED_DATA_ID = "linkedDataId"; private static final Logger LOGGER = getLogger(CreateInstanceIngressEventHandler.class); - private static final String BIBFRAME = "(bibframe) "; + private static final String LD = "(ld) "; private static final String FAILURE = "Failed to process InstanceIngressEvent with id {}"; private final Context context; private final InstanceCollection instanceCollection; @@ -125,9 +125,9 @@ private Future prepareAndExecuteMapping(MappingMetadataDto m AdditionalFieldsUtil.updateLatestTransactionDate(targetRecord, mappingParameters); AdditionalFieldsUtil.move001To035(targetRecord); AdditionalFieldsUtil.normalize035(targetRecord); - if (event.getEventPayload().getAdditionalProperties().containsKey(BIBFRAME_ID)) { - AdditionalFieldsUtil.addFieldToMarcRecord(targetRecord, TAG_035, TAG_035_SUB, - BIBFRAME + event.getEventPayload().getAdditionalProperties().get(BIBFRAME_ID)); + if (event.getEventPayload().getAdditionalProperties().containsKey( + LINKED_DATA_ID)) {AdditionalFieldsUtil.addFieldToMarcRecord(targetRecord, TAG_035, TAG_035_SUB, + LD + event.getEventPayload().getAdditionalProperties().get(LINKED_DATA_ID)); } LOGGER.info("Mapping a Record from InstanceIngressEvent with id '{}' into an Instance", event.getId()); @@ -206,8 +206,8 @@ private Future saveInstance(Instance instance, InstanceIngressEvent ev private Future executeFieldsManipulation(Instance instance, Record srcRecord, Map eventProperties) { - if (eventProperties.containsKey(BIBFRAME_ID)) { - AdditionalFieldsUtil.addFieldToMarcRecord(srcRecord, TAG_999, SUBFIELD_B, (String) eventProperties.get(BIBFRAME_ID)); + if (eventProperties.containsKey(LINKED_DATA_ID)) { + AdditionalFieldsUtil.addFieldToMarcRecord(srcRecord, TAG_999, SUBFIELD_L, (String) eventProperties.get(LINKED_DATA_ID)); } return super.executeFieldsManipulation(instance, srcRecord); } diff --git a/src/test/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandlerUnitTest.java b/src/test/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandlerUnitTest.java index bbe666968..4dbe5cfe8 100644 --- a/src/test/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandlerUnitTest.java +++ b/src/test/java/org/folio/inventory/instanceingress/handler/CreateInstanceIngressEventHandlerUnitTest.java @@ -6,11 +6,11 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.folio.inventory.TestUtil.buildHttpResponseWithBuffer; -import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_B; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_I; +import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.SUBFIELD_L; import static org.folio.inventory.dataimport.util.AdditionalFieldsUtil.TAG_999; import static org.folio.inventory.dataimport.util.MappingConstants.MARC_BIB_RECORD_TYPE; -import static org.folio.rest.jaxrs.model.InstanceIngressPayload.SourceType.BIBFRAME; +import static org.folio.rest.jaxrs.model.InstanceIngressPayload.SourceType.LINKED_DATA; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -119,7 +119,7 @@ public void shouldReturnFailedFuture_ifIdStorageServiceStoreFails() { .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject("{}") - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); var expectedMessage = "idStorageService failure"; doReturn(failedFuture(expectedMessage)).when(idStorageService).store(anyString(), anyString(), anyString()); @@ -139,7 +139,7 @@ public void shouldReturnFailedFuture_ifMappingMetadataWasNotFound() { .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject("{}") - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); doReturn(succeededFuture(Optional.empty())).when(mappingMetadataCache) @@ -161,7 +161,7 @@ public void shouldReturnFailedFuture_ifSourceStorageSnapshotsClientReturnsError( .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject("{}") - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH)); @@ -190,7 +190,7 @@ public void shouldReturnFailedFuture_ifInstanceValidationFails() throws IOExcept .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject("{}") - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH)); @@ -221,7 +221,7 @@ public void shouldReturnFailedFuture_ifInstanceSavingFailed() throws IOException .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject(TestUtil.readFileFromPath(BIB_RECORD_PATH)) - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH)); @@ -255,7 +255,7 @@ public void shouldReturnFailedFuture_ifCreatePrecedingSucceedingTitlesFailed() t .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject(TestUtil.readFileFromPath(BIB_RECORD_PATH)) - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH)); @@ -289,7 +289,7 @@ public void shouldReturnFailedFuture_ifItsFailedToCreateMarcRecordInSrs() throws .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject(TestUtil.readFileFromPath(BIB_RECORD_PATH)) - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH)); @@ -323,14 +323,14 @@ public void shouldReturnFailedFuture_ifItsFailedToCreateMarcRecordInSrs() throws @Test public void shouldReturnSucceededFuture_ifProcessFinishedCorrectly() throws IOException, ExecutionException, InterruptedException { // given - var bibframeId = "someBibframeId"; + var linkedDataIdId = "someLinkedDataIdId"; var event = new InstanceIngressEvent() .withId(UUID.randomUUID().toString()) .withEventPayload(new InstanceIngressPayload() .withSourceRecordObject(TestUtil.readFileFromPath(BIB_RECORD_PATH)) - .withSourceType(BIBFRAME) + .withSourceType(LINKED_DATA) .withSourceRecordIdentifier(UUID.randomUUID().toString()) - .withAdditionalProperty("bibframeId", bibframeId) + .withAdditionalProperty("linkedDataId", linkedDataIdId) ); doReturn(succeededFuture(null)).when(idStorageService).store(anyString(), anyString(), anyString()); var mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH)); @@ -359,17 +359,17 @@ public void shouldReturnSucceededFuture_ifProcessFinishedCorrectly() throws IOEx var instance = future.get(); assertThat(instance.getId()).isEqualTo(event.getEventPayload().getSourceRecordIdentifier()); - assertThat(instance.getSource()).isEqualTo("BIBFRAME"); - assertThat(instance.getIdentifiers().stream().anyMatch(i -> i.value.equals("(bibframe) " + bibframeId))).isTrue(); + assertThat(instance.getSource()).isEqualTo("LINKED_DATA"); + assertThat(instance.getIdentifiers().stream().anyMatch(i -> i.value.equals("(ld) " + linkedDataIdId))).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(bibframeId); + assertThat(recordSentToSRS.getId()).doesNotContain(linkedDataIdId); assertThat(recordSentToSRS.getRecordType()).isEqualTo(Record.RecordType.MARC_BIB); - assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_B)).hasValue(bibframeId); assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_I)).hasValue(instance.getId()); + assertThat(AdditionalFieldsUtil.getValue(recordSentToSRS, TAG_999, SUBFIELD_L)).hasValue(linkedDataIdId); } }