Search in sources :

Example 6 with MappingProfile

use of org.folio.MappingProfile in project mod-source-record-storage by folio-org.

the class MarcAuthorityMatchEventHandlerTest method shouldReturnFalseWhenNotMatchProfileForProfile.

@Test
public void shouldReturnFalseWhenNotMatchProfileForProfile() {
    MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Create authority").withIncomingRecordType(EntityType.MARC_AUTHORITY).withExistingRecordType(EntityType.AUTHORITY);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(mappingProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withTenant(TENANT_ID).withEventType(DI_SRS_MARC_AUTHORITY_RECORD_CREATED.toString()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
    boolean isEligible = handler.isEligible(dataImportEventPayload);
    Assert.assertFalse(isEligible);
}
Also used : MappingProfile(org.folio.MappingProfile) HashMap(java.util.HashMap) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 7 with MappingProfile

use of org.folio.MappingProfile in project mod-source-record-storage by folio-org.

the class AbstractUpdateModifyEventHandler method handle.

@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload payload) {
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    try {
        var payloadContext = payload.getContext();
        if (isNull(payloadContext) || isBlank(payloadContext.get(modifiedEntityType().value()))) {
            LOG.error(PAYLOAD_HAS_NO_DATA_MSG);
            future.completeExceptionally(new EventProcessingException(PAYLOAD_HAS_NO_DATA_MSG));
            return future;
        }
        MappingProfile mappingProfile = retrieveMappingProfile(payload);
        String hrId = retrieveHrid(payload, getMarcMappingOption(mappingProfile));
        preparePayload(payload);
        mappingParametersCache.get(payload.getJobExecutionId(), RestUtil.retrieveOkapiConnectionParams(payload, vertx)).compose(parametersOptional -> parametersOptional.map(mappingParams -> modifyRecord(payload, mappingProfile, mappingParams)).orElseGet(() -> Future.failedFuture(format(MAPPING_PARAMETERS_NOT_FOUND_MSG, payload.getJobExecutionId())))).onSuccess(v -> prepareModificationResult(payload, getMarcMappingOption(mappingProfile))).map(v -> Json.decodeValue(payloadContext.get(modifiedEntityType().value()), Record.class)).onSuccess(changedRecord -> {
            addControlledFieldToMarcRecord(changedRecord, HR_ID_FROM_FIELD, hrId, true);
            remove003FieldIfNeeded(changedRecord, hrId);
            increaseGeneration(changedRecord);
            payloadContext.put(modifiedEntityType().value(), Json.encode(changedRecord));
        }).compose(changedRecord -> recordService.saveRecord(changedRecord, payload.getTenant())).onSuccess(savedRecord -> {
            payload.setEventType(getNextEventType());
            future.complete(payload);
        }).onFailure(throwable -> {
            LOG.error("Error while MARC record modifying", throwable);
            future.completeExceptionally(throwable);
        });
    } catch (Exception e) {
        LOG.error("Error modifying MARC record", e);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : AdditionalFieldsUtil.getValueFromControlledField(org.folio.services.util.AdditionalFieldsUtil.getValueFromControlledField) Json(io.vertx.core.json.Json) EventHandler(org.folio.processing.events.services.handler.EventHandler) RestUtil(org.folio.services.util.RestUtil) MarcRecordModifier(org.folio.processing.mapping.mapper.writer.marc.MarcRecordModifier) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ACTION_PROFILE(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper.ContentType.ACTION_PROFILE) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Map(java.util.Map) RecordService(org.folio.services.RecordService) EntityType(org.folio.rest.jaxrs.model.EntityType) Objects.isNull(java.util.Objects.isNull) JsonObject(io.vertx.core.json.JsonObject) ActionProfile(org.folio.ActionProfile) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) HR_ID_FROM_FIELD(org.folio.services.util.AdditionalFieldsUtil.HR_ID_FROM_FIELD) MappingProfile(org.folio.MappingProfile) MappingParametersSnapshotCache(org.folio.services.caches.MappingParametersSnapshotCache) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) DataImportEventPayload(org.folio.DataImportEventPayload) IOException(java.io.IOException) UUID(java.util.UUID) AdditionalFieldsUtil.addControlledFieldToMarcRecord(org.folio.services.util.AdditionalFieldsUtil.addControlledFieldToMarcRecord) Future(io.vertx.core.Future) String.format(java.lang.String.format) UPDATE(org.folio.ActionProfile.Action.UPDATE) Logger(org.apache.logging.log4j.Logger) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) AdditionalFieldsUtil.remove003FieldIfNeeded(org.folio.services.util.AdditionalFieldsUtil.remove003FieldIfNeeded) MODIFY(org.folio.ActionProfile.Action.MODIFY) Objects.nonNull(java.util.Objects.nonNull) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) MappingProfile(org.folio.MappingProfile) Record(org.folio.rest.jaxrs.model.Record) AdditionalFieldsUtil.addControlledFieldToMarcRecord(org.folio.services.util.AdditionalFieldsUtil.addControlledFieldToMarcRecord) IOException(java.io.IOException) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) DataImportEventPayload(org.folio.DataImportEventPayload) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 8 with MappingProfile

use of org.folio.MappingProfile in project mod-inventory by folio-org.

the class CreateMarcHoldingsEventHandlerTest method shouldNotProcessEventIfHoldingRecordIsInvalid.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfHoldingRecordIsInvalid() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_HOLDINGS).withExistingRecordType(EntityType.HOLDINGS).withMappingDetails(new MappingDetail().withMappingFields(Lists.newArrayList(new MappingRule().withPath("permanentLocationId").withValue("permanentLocationExpression"), new MappingRule().withPath("invalidField").withValue("invalidFieldValue"))));
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(jobProfile.getId()).withContentType(JOB_PROFILE).withContent(jobProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(actionProfile).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap())))));
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
    HoldingsRecord holdings = new HoldingsRecord().withId(String.valueOf(UUID.randomUUID())).withHrid(String.valueOf(UUID.randomUUID())).withInstanceId(String.valueOf(UUID.randomUUID())).withSourceId(String.valueOf(UUID.randomUUID())).withHoldingsTypeId(String.valueOf(UUID.randomUUID())).withPermanentLocationId(PERMANENT_LOCATION_ID);
    var parsedHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(PARSED_HOLDINGS_RECORD));
    Record record = new Record().withParsedRecord(new ParsedRecord().withContent(parsedHoldingsRecord.encode()));
    HashMap<String, String> context = new HashMap<>();
    context.put("HOLDINGS", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(holdings)).encode());
    context.put(MARC_HOLDINGS.value(), Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    CompletableFuture<DataImportEventPayload> future = createMarcHoldingsEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingRule(org.folio.rest.jaxrs.model.MappingRule) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingsRecord(org.folio.HoldingsRecord) MappingProfile(org.folio.MappingProfile) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) HoldingsRecord(org.folio.HoldingsRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with MappingProfile

use of org.folio.MappingProfile in project mod-inventory by folio-org.

the class UpdateItemEventHandlerTest method shouldNotRequestWhenUpdatedItemHasEmptyBarcode.

@Test
public void shouldNotRequestWhenUpdatedItemHasEmptyBarcode() throws UnsupportedEncodingException {
    // given
    doAnswer(invocationOnMock -> {
        Item itemByCql = new Item(null, null, null, new Status(AVAILABLE), null, null, null);
        MultipleRecords<Item> result = new MultipleRecords<>(Collections.singletonList(itemByCql), 0);
        Consumer<Success<MultipleRecords<Item>>> successHandler = invocationOnMock.getArgument(2);
        successHandler.accept(new Success<>(result));
        return null;
    }).when(mockedItemCollection).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
    payloadContext.put(ITEM.value(), existingItemJson.encode());
    MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).withExistingRecordType(ITEM).withMappingDetails(new MappingDetail().withMappingFields(Arrays.asList(new MappingRule().withPath("item.status.name").withValue("\"statusExpression\"").withEnabled("true"), new MappingRule().withPath("item.permanentLoanType.id").withValue("\"permanentLoanTypeExpression\"").withEnabled("true"), new MappingRule().withPath("item.materialType.id").withValue("\"materialTypeExpression\"").withEnabled("true"))));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(new ProfileSnapshotWrapper().withProfileId(actionProfile.getId()).withContentType(ACTION_PROFILE).withContent(JsonObject.mapFrom(actionProfile).getMap()).withChildSnapshotWrappers(Collections.singletonList(new ProfileSnapshotWrapper().withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(mappingProfile).getMap()))));
    // when
    updateItemHandler.handle(dataImportEventPayload);
    // then
    verify(mockedItemCollection, Mockito.times(0)).findByCql(anyString(), any(PagingParameters.class), any(Consumer.class), any(Consumer.class));
}
Also used : Status(org.folio.inventory.domain.items.Status) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) Success(org.folio.inventory.common.domain.Success) DataImportEventPayload(org.folio.DataImportEventPayload) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) Item(org.folio.inventory.domain.items.Item) MappingProfile(org.folio.MappingProfile) Consumer(java.util.function.Consumer) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) HoldingsRecord(org.folio.HoldingsRecord) Record(org.folio.rest.jaxrs.model.Record) Test(org.junit.Test)

Example 10 with MappingProfile

use of org.folio.MappingProfile in project mod-source-record-storage by folio-org.

the class HoldingsPostProcessingEventHandlerTest method shouldReturnTrueWhenHandlerIsEligibleForProfile.

@Test
public void shouldReturnTrueWhenHandlerIsEligibleForProfile() {
    MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Create holdings").withIncomingRecordType(MARC_HOLDINGS).withExistingRecordType(HOLDINGS);
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withProfileId(mappingProfile.getId()).withContentType(MAPPING_PROFILE).withContent(mappingProfile);
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withTenant(TENANT_ID).withEventType(DI_INVENTORY_HOLDINGS_CREATED_READY_FOR_POST_PROCESSING.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper);
    boolean isEligible = handler.isEligible(dataImportEventPayload);
    Assert.assertTrue(isEligible);
}
Also used : MappingProfile(org.folio.MappingProfile) HashMap(java.util.HashMap) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Aggregations

MappingProfile (org.folio.MappingProfile)13 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)13 HashMap (java.util.HashMap)12 DataImportEventPayload (org.folio.DataImportEventPayload)12 Test (org.junit.Test)12 MappingDetail (org.folio.rest.jaxrs.model.MappingDetail)6 Record (org.folio.rest.jaxrs.model.Record)5 JsonObject (io.vertx.core.json.JsonObject)4 MappingRule (org.folio.rest.jaxrs.model.MappingRule)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Consumer (java.util.function.Consumer)2 ActionProfile (org.folio.ActionProfile)2 HoldingsRecord (org.folio.HoldingsRecord)2 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)2 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)2 Success (org.folio.inventory.common.domain.Success)2 Item (org.folio.inventory.domain.items.Item)2 Status (org.folio.inventory.domain.items.Status)2 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)2