Skip to content

Commit

Permalink
MODINV-986: rename source type BIBFRAME to LINKED_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
PBobylev committed Jun 10, 2024
1 parent 4683d0e commit 28dfa35
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ramls/instance-ingress-payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"sourceType": {
"type": "string",
"enum": ["BIBFRAME", "MARC", "FOLIO"],
"enum": ["FOLIO", "LINKED_DATA", "MARC"],
"description": "Source type"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, org.marc4j.marc.Record> parsedRecordContentCacheLoader;
private static final LoadingCache<String, org.marc4j.marc.Record> parsedRecordContentCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -125,9 +125,9 @@ private Future<org.folio.Instance> 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());
Expand Down Expand Up @@ -206,8 +206,8 @@ private Future<Instance> saveInstance(Instance instance, InstanceIngressEvent ev

private Future<Instance> executeFieldsManipulation(Instance instance, Record srcRecord,
Map<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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)
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 28dfa35

Please sign in to comment.