Search in sources :

Example 1 with HoldingWriterFactory

use of org.folio.inventory.dataimport.HoldingWriterFactory in project mod-inventory by folio-org.

the class DataImportKafkaHandler method registerDataImportProcessingHandlers.

private void registerDataImportProcessingHandlers(Storage storage, HttpClient client) {
    MatchValueLoaderFactory.register(new InstanceLoader(storage, vertx));
    MatchValueLoaderFactory.register(new ItemLoader(storage, vertx));
    MatchValueLoaderFactory.register(new HoldingLoader(storage, vertx));
    MatchValueLoaderFactory.register(new AuthorityLoader(storage, vertx));
    MatchValueReaderFactory.register(new MarcValueReaderImpl());
    MatchValueReaderFactory.register(new StaticValueReaderImpl());
    MappingManager.registerReaderFactory(new MarcBibReaderFactory());
    MappingManager.registerReaderFactory(new MarcHoldingsReaderFactory());
    MappingManager.registerWriterFactory(new ItemWriterFactory());
    MappingManager.registerWriterFactory(new HoldingWriterFactory());
    MappingManager.registerWriterFactory(new InstanceWriterFactory());
    PrecedingSucceedingTitlesHelper precedingSucceedingTitlesHelper = new PrecedingSucceedingTitlesHelper(WebClient.wrap(client));
    EventManager.registerEventHandler(new MatchInstanceEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new MatchItemEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new MatchHoldingEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new MatchAuthorityEventHandler(mappingMetadataCache));
    EventManager.registerEventHandler(new CreateItemEventHandler(storage, mappingMetadataCache, new ItemIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateHoldingEventHandler(storage, mappingMetadataCache, new HoldingsIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateInstanceEventHandler(storage, precedingSucceedingTitlesHelper, mappingMetadataCache, new InstanceIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateMarcHoldingsEventHandler(storage, mappingMetadataCache, new HoldingsIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new CreateAuthorityEventHandler(storage, mappingMetadataCache, new AuthorityIdStorageService(new EntityIdStorageDaoImpl(new PostgresClientFactory(vertx)))));
    EventManager.registerEventHandler(new UpdateAuthorityEventHandler(storage, mappingMetadataCache, new KafkaEventPublisher(kafkaConfig, vertx, 100)));
    EventManager.registerEventHandler(new DeleteAuthorityEventHandler(storage));
    EventManager.registerEventHandler(new UpdateItemEventHandler(storage, mappingMetadataCache));
    EventManager.registerEventHandler(new UpdateHoldingEventHandler(storage, mappingMetadataCache));
    EventManager.registerEventHandler(new ReplaceInstanceEventHandler(storage, precedingSucceedingTitlesHelper, mappingMetadataCache));
    EventManager.registerEventHandler(new MarcBibModifiedPostProcessingEventHandler(new InstanceUpdateDelegate(storage), precedingSucceedingTitlesHelper, mappingMetadataCache));
    EventManager.registerEventHandler(new MarcBibMatchedPostProcessingEventHandler(storage));
}
Also used : MatchHoldingEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchHoldingEventHandler) StaticValueReaderImpl(org.folio.processing.matching.reader.StaticValueReaderImpl) MatchInstanceEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchInstanceEventHandler) EntityIdStorageDaoImpl(org.folio.inventory.common.dao.EntityIdStorageDaoImpl) CreateMarcHoldingsEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateMarcHoldingsEventHandler) UpdateItemEventHandler(org.folio.inventory.dataimport.handlers.actions.UpdateItemEventHandler) ItemWriterFactory(org.folio.inventory.dataimport.ItemWriterFactory) ReplaceInstanceEventHandler(org.folio.inventory.dataimport.handlers.actions.ReplaceInstanceEventHandler) CreateAuthorityEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateAuthorityEventHandler) CreateItemEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateItemEventHandler) HoldingsIdStorageService(org.folio.inventory.services.HoldingsIdStorageService) PostgresClientFactory(org.folio.inventory.common.dao.PostgresClientFactory) CreateInstanceEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateInstanceEventHandler) PrecedingSucceedingTitlesHelper(org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper) ItemIdStorageService(org.folio.inventory.services.ItemIdStorageService) MarcBibMatchedPostProcessingEventHandler(org.folio.inventory.dataimport.handlers.actions.MarcBibMatchedPostProcessingEventHandler) MarcValueReaderImpl(org.folio.processing.matching.reader.MarcValueReaderImpl) MarcBibReaderFactory(org.folio.processing.mapping.mapper.reader.record.marc.MarcBibReaderFactory) MatchAuthorityEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchAuthorityEventHandler) KafkaEventPublisher(org.folio.processing.events.services.publisher.KafkaEventPublisher) HoldingLoader(org.folio.inventory.dataimport.handlers.matching.loaders.HoldingLoader) AuthorityIdStorageService(org.folio.inventory.services.AuthorityIdStorageService) ItemLoader(org.folio.inventory.dataimport.handlers.matching.loaders.ItemLoader) DeleteAuthorityEventHandler(org.folio.inventory.dataimport.handlers.actions.DeleteAuthorityEventHandler) InstanceLoader(org.folio.inventory.dataimport.handlers.matching.loaders.InstanceLoader) InstanceWriterFactory(org.folio.inventory.dataimport.InstanceWriterFactory) MarcBibModifiedPostProcessingEventHandler(org.folio.inventory.dataimport.handlers.actions.MarcBibModifiedPostProcessingEventHandler) UpdateHoldingEventHandler(org.folio.inventory.dataimport.handlers.actions.UpdateHoldingEventHandler) MatchItemEventHandler(org.folio.inventory.dataimport.handlers.matching.MatchItemEventHandler) AuthorityLoader(org.folio.inventory.dataimport.handlers.matching.loaders.AuthorityLoader) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) InstanceIdStorageService(org.folio.inventory.services.InstanceIdStorageService) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) UpdateAuthorityEventHandler(org.folio.inventory.dataimport.handlers.actions.UpdateAuthorityEventHandler) MarcHoldingsReaderFactory(org.folio.processing.mapping.mapper.reader.record.marc.MarcHoldingsReaderFactory) CreateHoldingEventHandler(org.folio.inventory.dataimport.handlers.actions.CreateHoldingEventHandler)

Example 2 with HoldingWriterFactory

use of org.folio.inventory.dataimport.HoldingWriterFactory in project mod-inventory by folio-org.

the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfContextIsNull.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfContextIsNull() throws InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    String permanentLocationId = UUID.randomUUID().toString();
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(permanentLocationId));
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new HoldingWriterFactory());
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withContext(null).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) Reader(org.folio.processing.mapping.mapper.reader.Reader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 3 with HoldingWriterFactory

use of org.folio.inventory.dataimport.HoldingWriterFactory in project mod-inventory by folio-org.

the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfInstanceIdIsNotExistsInInstanceInContextAndNotExistsInParsedRecords.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfInstanceIdIsNotExistsInInstanceInContextAndNotExistsInParsedRecords() throws InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    String permanentLocationId = UUID.randomUUID().toString();
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(permanentLocationId));
    when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordsCollection);
    MappingManager.registerReaderFactory(fakeReaderFactory);
    MappingManager.registerWriterFactory(new HoldingWriterFactory());
    Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITHOUT_INSTANCE_ID));
    HashMap<String, String> context = new HashMap<>();
    context.put("INSTANCE", new JsonObject().encode());
    context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
    future.get(5, TimeUnit.MILLISECONDS);
}
Also used : HashMap(java.util.HashMap) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) Reader(org.folio.processing.mapping.mapper.reader.Reader) JsonObject(io.vertx.core.json.JsonObject) HoldingsRecord(org.folio.HoldingsRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Record(org.folio.rest.jaxrs.model.Record) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) Test(org.junit.Test)

Example 4 with HoldingWriterFactory

use of org.folio.inventory.dataimport.HoldingWriterFactory in project mod-inventory by folio-org.

the class CreateHoldingEventHandlerTest method shouldProcessEvent.

@Test
public void shouldProcessEvent() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    String permanentLocationId = UUID.randomUUID().toString();
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(permanentLocationId));
    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, "5", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
    Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
    HashMap<String, String> context = new HashMap<>();
    context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
    context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(context).withProfileSnapshot(profileSnapshotWrapper).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
    CompletableFuture<DataImportEventPayload> future = createHoldingEventHandler.handle(dataImportEventPayload);
    DataImportEventPayload actualDataImportEventPayload = future.get(5, TimeUnit.MILLISECONDS);
    Assert.assertEquals(DI_INVENTORY_HOLDING_CREATED.value(), actualDataImportEventPayload.getEventType());
    Assert.assertNotNull(actualDataImportEventPayload.getContext().get(HOLDINGS.value()));
    Assert.assertNotNull(new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("id"));
    Assert.assertEquals(instanceId, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("instanceId"));
    Assert.assertEquals(permanentLocationId, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("permanentLocationId"));
    Assert.assertEquals(FOLIO_SOURCE_ID, new JsonObject(actualDataImportEventPayload.getContext().get(HOLDINGS.value())).getString("sourceId"));
}
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) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) 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 5 with HoldingWriterFactory

use of org.folio.inventory.dataimport.HoldingWriterFactory in project mod-inventory by folio-org.

the class CreateHoldingEventHandlerTest method shouldNotProcessEventIfPermanentLocationIdIsNotExistsInContext.

@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfPermanentLocationIdIsNotExistsInContext() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    Reader fakeReader = Mockito.mock(Reader.class);
    when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(""));
    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, "8", String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
    Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_INSTANCE_ID));
    HashMap<String, String> context = new HashMap<>();
    context.put("INSTANCE", new JsonObject(new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(instance)).encode());
    context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
    DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_HOLDING_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).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) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) MappingRule(org.folio.rest.jaxrs.model.MappingRule) DataImportEventPayload(org.folio.DataImportEventPayload) HoldingWriterFactory(org.folio.inventory.dataimport.HoldingWriterFactory) 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)

Aggregations

HoldingWriterFactory (org.folio.inventory.dataimport.HoldingWriterFactory)20 DataImportEventPayload (org.folio.DataImportEventPayload)19 Reader (org.folio.processing.mapping.mapper.reader.Reader)19 MappingRule (org.folio.rest.jaxrs.model.MappingRule)19 Test (org.junit.Test)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 HashMap (java.util.HashMap)15 HoldingsRecord (org.folio.HoldingsRecord)13 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)13 Record (org.folio.rest.jaxrs.model.Record)13 JsonObject (io.vertx.core.json.JsonObject)10 Instance (org.folio.inventory.domain.instances.Instance)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Failure (org.folio.inventory.common.domain.Failure)2 MappingProfile (org.folio.MappingProfile)1 EntityIdStorageDaoImpl (org.folio.inventory.common.dao.EntityIdStorageDaoImpl)1 PostgresClientFactory (org.folio.inventory.common.dao.PostgresClientFactory)1 InstanceWriterFactory (org.folio.inventory.dataimport.InstanceWriterFactory)1 ItemWriterFactory (org.folio.inventory.dataimport.ItemWriterFactory)1 CreateAuthorityEventHandler (org.folio.inventory.dataimport.handlers.actions.CreateAuthorityEventHandler)1