use of org.folio.rest.jaxrs.model.MarcFieldProtectionSetting in project mod-source-record-storage by folio-org.
the class InstancePostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsProtected.
@Test
public void shouldUpdateField005WhenThisFiledIsProtected(TestContext context) throws IOException {
Async async = context.async();
MappingParameters mappingParameters = new MappingParameters().withMarcFieldProtectionSettings(List.of(new MarcFieldProtectionSetting().withField(TAG_005).withData("*")));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters))))));
String recordId = UUID.randomUUID().toString();
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_BIB).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
String expectedInstanceId = UUID.randomUUID().toString();
String expectedHrId = UUID.randomUUID().toString();
JsonObject instance = createExternalEntity(expectedInstanceId, expectedHrId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(INSTANCE.value(), instance.encode());
payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(defaultRecord));
String expectedDate = AdditionalFieldsUtil.getValueFromControlledField(record, TAG_005);
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_INSTANCE_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, throwable) -> {
if (throwable != null) {
context.fail(throwable);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record updatedRecord = getAr.result().get();
String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
Assert.assertEquals(expectedDate, actualDate);
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.MarcFieldProtectionSetting in project mod-source-record-storage by folio-org.
the class AdditionalFieldsUtil method isField005NeedToUpdate.
/**
* Checks whether field 005 needs to be updated or this field is protected.
*
* @param record record to check
* @param mappingParameters
* @return true for case when field 005 have to updated
*/
private static boolean isField005NeedToUpdate(Record record, MappingParameters mappingParameters) {
boolean needToUpdate = true;
List<MarcFieldProtectionSetting> fieldProtectionSettings = mappingParameters.getMarcFieldProtectionSettings();
if ((fieldProtectionSettings != null) && !fieldProtectionSettings.isEmpty()) {
MarcReader reader = new MarcJsonReader(new ByteArrayInputStream(record.getParsedRecord().getContent().toString().getBytes()));
if (reader.hasNext()) {
org.marc4j.marc.Record marcRecord = reader.next();
for (VariableField field : marcRecord.getVariableFields(AdditionalFieldsUtil.TAG_005)) {
needToUpdate = isNotProtected(fieldProtectionSettings, (ControlField) field);
break;
}
}
}
return needToUpdate;
}
use of org.folio.rest.jaxrs.model.MarcFieldProtectionSetting in project mod-source-record-manager by folio-org.
the class MappingParametersProvider method getMarcFieldProtectionSettings.
private Future<List<MarcFieldProtectionSetting>> getMarcFieldProtectionSettings(OkapiConnectionParams params) {
Promise<List<MarcFieldProtectionSetting>> promise = Promise.promise();
String fieldProtectionSettingsUrl = "/field-protection-settings/marc?limit=" + settingsLimit;
RestUtil.doRequest(params, fieldProtectionSettingsUrl, HttpMethod.GET, null).onComplete(ar -> {
if (RestUtil.validateAsyncResult(ar, promise)) {
JsonObject response = ar.result().getJson();
if (response != null && response.containsKey(FIELD_PROTECTION_SETTINGS_RESPONSE_PARAM)) {
List<MarcFieldProtectionSetting> itemNoteTypes = response.mapTo(MarcFieldProtectionSettingsCollection.class).getMarcFieldProtectionSettings();
promise.complete(itemNoteTypes);
} else {
promise.complete(Collections.emptyList());
}
}
});
return promise.future();
}
use of org.folio.rest.jaxrs.model.MarcFieldProtectionSetting in project mod-source-record-storage by folio-org.
the class HoldingsPostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsProtected.
@Test
public void shouldUpdateField005WhenThisFiledIsProtected(TestContext context) throws IOException {
Async async = context.async();
MappingParameters mappingParameters = new MappingParameters().withMarcFieldProtectionSettings(List.of(new MarcFieldProtectionSetting().withField(TAG_005).withData("*")));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters))))));
String recordId = UUID.randomUUID().toString();
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_HOLDING).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
String expectedHoldingsId = UUID.randomUUID().toString();
String expectedHrId = UUID.randomUUID().toString();
JsonObject holdings = createExternalEntity(expectedHoldingsId, expectedHrId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(HOLDINGS.value(), holdings.encode());
payloadContext.put(MARC_HOLDINGS.value(), Json.encode(defaultRecord));
String expectedDate = AdditionalFieldsUtil.getValueFromControlledField(record, TAG_005);
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, throwable) -> {
if (throwable != null) {
context.fail(throwable);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record updatedRecord = getAr.result().get();
String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
Assert.assertEquals(expectedDate, actualDate);
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.MarcFieldProtectionSetting in project mod-source-record-storage by folio-org.
the class AuthorityPostProcessingEventHandlerTest method shouldUpdateField005WhenThisFiledIsProtected.
@Test
public void shouldUpdateField005WhenThisFiledIsProtected(TestContext context) throws IOException {
Async async = context.async();
MappingParameters mappingParameters = new MappingParameters().withMarcFieldProtectionSettings(List.of(new MarcFieldProtectionSetting().withField(TAG_005).withData("*")));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA__URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters))))));
String recordId = UUID.randomUUID().toString();
RawRecord rawRecord = new RawRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(RAW_MARC_RECORD_CONTENT_SAMPLE_PATH), String.class));
ParsedRecord parsedRecord = new ParsedRecord().withId(recordId).withContent(new ObjectMapper().readValue(TestUtil.readFileFromPath(PARSED_MARC_RECORD_CONTENT_SAMPLE_PATH), JsonObject.class).encode());
Record defaultRecord = new Record().withId(recordId).withMatchedId(recordId).withSnapshotId(snapshotId1).withGeneration(0).withRecordType(MARC_AUTHORITY).withRawRecord(rawRecord).withParsedRecord(parsedRecord);
String expectedAuthorityId = UUID.randomUUID().toString();
JsonObject authority = createExternalEntity(expectedAuthorityId, null);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(AUTHORITY.value(), authority.encode());
payloadContext.put(MARC_AUTHORITY.value(), Json.encode(defaultRecord));
String expectedDate = AdditionalFieldsUtil.getValueFromControlledField(record, TAG_005);
DataImportEventPayload dataImportEventPayload = createDataImportEventPayload(payloadContext, DI_INVENTORY_AUTHORITY_CREATED_READY_FOR_POST_PROCESSING);
CompletableFuture<DataImportEventPayload> future = handler.handle(dataImportEventPayload);
future.whenComplete((payload, throwable) -> {
if (throwable != null) {
context.fail(throwable);
}
recordDao.getRecordByMatchedId(defaultRecord.getMatchedId(), TENANT_ID).onComplete(getAr -> {
if (getAr.failed()) {
context.fail(getAr.cause());
}
context.assertTrue(getAr.result().isPresent());
Record updatedRecord = getAr.result().get();
String actualDate = AdditionalFieldsUtil.getValueFromControlledField(updatedRecord, TAG_005);
Assert.assertEquals(expectedDate, actualDate);
async.complete();
});
});
}
Aggregations