Search in sources :

Example 1 with MappingDetail

use of org.folio.rest.jaxrs.model.MappingDetail in project mod-inventory by folio-org.

the class CreateItemEventHandlerTest method shouldNotRequestWhenCreatedItemHasEmptyBarcode.

@Test
public void shouldNotRequestWhenCreatedItemHasEmptyBarcode() throws UnsupportedEncodingException {
    // given
    Mockito.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));
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new ItemWriterFactory());
    JsonObject holdingAsJson = new JsonObject().put("id", UUID.randomUUID().toString());
    HashMap<String, String> payloadContext = new HashMap<>();
    payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
    payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.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
    createItemHandler.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) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ItemWriterFactory(org.folio.inventory.dataimport.ItemWriterFactory) 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) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) Test(org.junit.Test)

Example 2 with MappingDetail

use of org.folio.rest.jaxrs.model.MappingDetail in project mod-inventory by folio-org.

the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfHoldingRecordIsInvalid.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfHoldingRecordIsInvalid() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    MappingProfile mappingProfile = new MappingProfile().withId(UUID.randomUUID().toString()).withName("Prelim item from MARC").withIncomingRecordType(EntityType.MARC_BIBLIOGRAPHIC).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(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(UUID.randomUUID().toString()), StringValue.of(UUID.randomUUID().toString()));
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new HoldingWriterFactory());
    String instanceId = String.valueOf(UUID.randomUUID());
    Instance instance = new Instance(instanceId, "7", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
    HashMap<String, String> context = new HashMap<>();
    context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : Instance(org.folio.inventory.domain.instances.Instance) HashMap(java.util.HashMap) Reader(org.folio.processing.mapping.mapper.reader.Reader) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.DataImportEventPayload) MappingProfile(org.folio.MappingProfile) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with MappingDetail

use of org.folio.rest.jaxrs.model.MappingDetail 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 4 with MappingDetail

use of org.folio.rest.jaxrs.model.MappingDetail 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 5 with MappingDetail

use of org.folio.rest.jaxrs.model.MappingDetail in project mod-source-record-storage by folio-org.

the class DataImportConsumersVerticleTest method shouldModifyRecordWhenPayloadContainsModifyMarcBibActionInCurrentNode.

@Test
public void shouldModifyRecordWhenPayloadContainsModifyMarcBibActionInCurrentNode() throws InterruptedException {
    ProfileSnapshotWrapper profileSnapshotWrapper = new ProfileSnapshotWrapper().withId(UUID.randomUUID().toString()).withContentType(JOB_PROFILE).withContent(JsonObject.mapFrom(new JobProfile().withId(UUID.randomUUID().toString()).withDataType(JobProfile.DataType.MARC)).getMap()).withChildSnapshotWrappers(singletonList(new ProfileSnapshotWrapper().withContentType(ACTION_PROFILE).withContent(JsonObject.mapFrom(new ActionProfile().withId(UUID.randomUUID().toString()).withAction(MODIFY).withFolioRecord(ActionProfile.FolioRecord.MARC_BIBLIOGRAPHIC)).getMap()).withChildSnapshotWrappers(singletonList(new ProfileSnapshotWrapper().withContentType(MAPPING_PROFILE).withContent(JsonObject.mapFrom(new MappingProfile().withId(UUID.randomUUID().toString()).withIncomingRecordType(MARC_BIBLIOGRAPHIC).withExistingRecordType(MARC_BIBLIOGRAPHIC).withMappingDetails(new MappingDetail().withMarcMappingOption(MappingDetail.MarcMappingOption.MODIFY).withMarcMappingDetails(List.of(marcMappingDetail)))).getMap())))));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(profileSnapshotWrapper))));
    String expectedParsedContent = "{\"leader\":\"00107nam  22000491a 4500\",\"fields\":[{\"001\":\"ybp7406411\"},{\"856\":{\"subfields\":[{\"u\":\"http://libproxy.smith.edu?url=example.com\"}],\"ind1\":\" \",\"ind2\":\" \"}}]}";
    DataImportEventPayload eventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(snapshotId).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withOkapiUrl(mockServer.baseUrl()).withTenant(TENANT_ID).withToken(TOKEN).withContext(new HashMap<>() {

        {
            put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
            put(PROFILE_SNAPSHOT_ID_KEY, profileSnapshotWrapper.getId());
        }
    });
    String topic = getTopicName(DI_SRS_MARC_BIB_RECORD_CREATED.value());
    KeyValue<String, String> kafkaRecord = buildKafkaRecord(eventPayload);
    kafkaRecord.addHeader(RECORD_ID_HEADER, record.getId(), UTF_8);
    kafkaRecord.addHeader(CHUNK_ID_HEADER, UUID.randomUUID().toString(), UTF_8);
    SendKeyValues<String, String> request = SendKeyValues.to(topic, singletonList(kafkaRecord)).useDefaults();
    // when
    cluster.send(request);
    // then
    var value = DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value();
    String observeTopic = getTopicName(value);
    List<KeyValue<String, String>> observedRecords = cluster.observe(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
    Event obtainedEvent = Json.decodeValue(observedRecords.get(0).getValue(), Event.class);
    DataImportEventPayload dataImportEventPayload = Json.decodeValue(obtainedEvent.getEventPayload(), DataImportEventPayload.class);
    assertEquals(DI_SRS_MARC_BIB_RECORD_MODIFIED_READY_FOR_POST_PROCESSING.value(), dataImportEventPayload.getEventType());
    Record actualRecord = Json.decodeValue(dataImportEventPayload.getContext().get(MARC_BIBLIOGRAPHIC.value()), Record.class);
    assertEquals(expectedParsedContent, actualRecord.getParsedRecord().getContent().toString());
    assertEquals(Record.State.ACTUAL, actualRecord.getState());
    assertEquals(dataImportEventPayload.getJobExecutionId(), actualRecord.getSnapshotId());
    assertNotNull(observedRecords.get(0).getHeaders().lastHeader(RECORD_ID_HEADER));
}
Also used : KeyValue(net.mguenther.kafka.junit.KeyValue) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) JobProfile(org.folio.JobProfile) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) DataImportEventPayload(org.folio.rest.jaxrs.model.DataImportEventPayload) MappingProfile(org.folio.MappingProfile) MarcMappingDetail(org.folio.rest.jaxrs.model.MarcMappingDetail) MappingDetail(org.folio.rest.jaxrs.model.MappingDetail) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Event(org.folio.rest.jaxrs.model.Event) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Record(org.folio.rest.jaxrs.model.Record) ActionProfile(org.folio.ActionProfile) Test(org.junit.Test) AbstractLBServiceTest(org.folio.services.AbstractLBServiceTest)

Aggregations

MappingProfile (org.folio.MappingProfile)5 MappingDetail (org.folio.rest.jaxrs.model.MappingDetail)5 ProfileSnapshotWrapper (org.folio.rest.jaxrs.model.ProfileSnapshotWrapper)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 DataImportEventPayload (org.folio.DataImportEventPayload)4 MappingRule (org.folio.rest.jaxrs.model.MappingRule)4 Record (org.folio.rest.jaxrs.model.Record)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 JsonObject (io.vertx.core.json.JsonObject)3 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Consumer (java.util.function.Consumer)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 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1