Search in sources :

Example 1 with MarcFieldProtectionSetting

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();
        });
    });
}
Also used : MarcFieldProtectionSetting(org.folio.rest.jaxrs.model.MarcFieldProtectionSetting) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) DataImportEventPayload(org.folio.DataImportEventPayload) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with MarcFieldProtectionSetting

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;
}
Also used : MarcFieldProtectionSetting(org.folio.rest.jaxrs.model.MarcFieldProtectionSetting) ControlField(org.marc4j.marc.ControlField) ByteArrayInputStream(java.io.ByteArrayInputStream) MarcReader(org.marc4j.MarcReader) MarcJsonReader(org.marc4j.MarcJsonReader) VariableField(org.marc4j.marc.VariableField)

Example 3 with MarcFieldProtectionSetting

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();
}
Also used : MarcFieldProtectionSettingsCollection(org.folio.MarcFieldProtectionSettingsCollection) MarcFieldProtectionSetting(org.folio.rest.jaxrs.model.MarcFieldProtectionSetting) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List)

Example 4 with MarcFieldProtectionSetting

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();
        });
    });
}
Also used : MarcFieldProtectionSetting(org.folio.rest.jaxrs.model.MarcFieldProtectionSetting) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) DataImportEventPayload(org.folio.DataImportEventPayload) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with MarcFieldProtectionSetting

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();
        });
    });
}
Also used : MarcFieldProtectionSetting(org.folio.rest.jaxrs.model.MarcFieldProtectionSetting) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.rest.jaxrs.model.MappingMetadataDto) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) DataImportEventPayload(org.folio.DataImportEventPayload) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Async(io.vertx.ext.unit.Async) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

MarcFieldProtectionSetting (org.folio.rest.jaxrs.model.MarcFieldProtectionSetting)5 JsonObject (io.vertx.core.json.JsonObject)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)3 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)3 Async (io.vertx.ext.unit.Async)3 HashMap (java.util.HashMap)3 DataImportEventPayload (org.folio.DataImportEventPayload)3 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)3 MappingMetadataDto (org.folio.rest.jaxrs.model.MappingMetadataDto)3 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)3 RawRecord (org.folio.rest.jaxrs.model.RawRecord)3 Record (org.folio.rest.jaxrs.model.Record)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1 MarcFieldProtectionSettingsCollection (org.folio.MarcFieldProtectionSettingsCollection)1 MarcJsonReader (org.marc4j.MarcJsonReader)1 MarcReader (org.marc4j.MarcReader)1 ControlField (org.marc4j.marc.ControlField)1