use of org.folio.inventory.dataimport.InstanceWriterFactory 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));
}
use of org.folio.inventory.dataimport.InstanceWriterFactory in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest method shouldNotProcessEventIfContextIsEmpty.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfContextIsEmpty() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String instanceTypeId = UUID.randomUUID().toString();
String title = "titleValue";
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new InstanceWriterFactory());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(new HashMap<>()).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
use of org.folio.inventory.dataimport.InstanceWriterFactory in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest method shouldNotProcessEventIfMArcBibliographicIsNotExistsInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfMArcBibliographicIsNotExistsInContext() throws InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String instanceTypeId = UUID.randomUUID().toString();
String title = "titleValue";
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new InstanceWriterFactory());
HashMap<String, String> context = new HashMap<>();
context.put("InvalidField", Json.encode(new Record()));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
use of org.folio.inventory.dataimport.InstanceWriterFactory in project mod-inventory by folio-org.
the class CreateInstanceEventHandlerTest method shouldNotProcessEventWhenRecordToInstanceFutureFails.
@Test(expected = Exception.class)
public void shouldNotProcessEventWhenRecordToInstanceFutureFails() throws ExecutionException, InterruptedException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String instanceTypeId = "fe19bae4-da28-472b-be90-d442e2428ead";
String recordId = "567859ad-505a-400d-a699-0028a1fdbf84";
String title = "titleValue";
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
when(instanceIdStorageService.store(any(), any(), any())).thenReturn(Future.failedFuture(new Exception()));
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new InstanceWriterFactory());
HashMap<String, String> context = new HashMap<>();
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT));
record.setId(recordId);
context.put(MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString()).withOkapiUrl(mockServer.baseUrl());
CompletableFuture<DataImportEventPayload> future = createInstanceEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.inventory.dataimport.InstanceWriterFactory in project mod-inventory by folio-org.
the class ReplaceInstanceEventHandlerTest method shouldNotProcessEventIfMarcBibliographicIsEmptyInContext.
@Test(expected = ExecutionException.class)
public void shouldNotProcessEventIfMarcBibliographicIsEmptyInContext() throws IOException, InterruptedException, ExecutionException, TimeoutException {
Reader fakeReader = Mockito.mock(Reader.class);
String instanceTypeId = UUID.randomUUID().toString();
String title = "titleValue";
when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of(instanceTypeId), StringValue.of(title));
when(fakeReaderFactory.createReader()).thenReturn(fakeReader);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new InstanceWriterFactory());
HashMap<String, String> context = new HashMap<>();
context.put(MARC_BIBLIOGRAPHIC.value(), "");
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_INVENTORY_INSTANCE_CREATED.value()).withContext(context).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)).withTenant(TENANT_ID).withOkapiUrl(mockServer.baseUrl()).withToken(TOKEN).withJobExecutionId(UUID.randomUUID().toString());
;
CompletableFuture<DataImportEventPayload> future = replaceInstanceEventHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.MILLISECONDS);
}
Aggregations