use of org.folio.inventory.dataimport.ItemWriterFactory 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.ItemWriterFactory in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldReturnFailedFutureWhenMappedItemWithUnrecognizedStatusName.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedFutureWhenMappedItemWithUnrecognizedStatusName() throws InterruptedException, ExecutionException, TimeoutException {
// given
Mockito.when(fakeReader.read(any(MappingRule.class))).thenReturn(StringValue.of("Invalid status"));
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
CreateItemEventHandler createItemHandler = new CreateItemEventHandler(mockedStorage, mappingMetadataCache, itemIdStorageService);
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_HOLDING_ID));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = createItemHandler.handle(dataImportEventPayload);
// then
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.inventory.dataimport.ItemWriterFactory in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldReturnFailedFutureWhenCouldNotFindHoldingsRecordIdInEventPayload.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedFutureWhenCouldNotFindHoldingsRecordIdInEventPayload() throws InterruptedException, ExecutionException, TimeoutException {
// given
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITHOUT_HOLDING_ID));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
payloadContext.put(EntityType.HOLDINGS.value(), new JsonObject().encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = createItemHandler.handle(dataImportEventPayload);
// then
future.get(5, TimeUnit.SECONDS);
}
use of org.folio.inventory.dataimport.ItemWriterFactory in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldCreateItemAndFillInHoldingsRecordIdFromParsedRecordContent.
@Test
public void shouldCreateItemAndFillInHoldingsRecordIdFromParsedRecordContent() throws UnsupportedEncodingException, InterruptedException, ExecutionException, TimeoutException {
// given
RecordToEntity recordToItem = RecordToEntity.builder().recordId(RECORD_ID).entityId(ITEM_ID).build();
when(itemIdStorageService.store(any(), any(), any())).thenReturn(Future.succeededFuture(recordToItem));
Mockito.doAnswer(invocationOnMock -> {
MultipleRecords<Item> result = new MultipleRecords<>(new ArrayList<>(), 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));
Mockito.doAnswer(invocationOnMock -> {
Item item = invocationOnMock.getArgument(0);
Consumer<Success<Item>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(item));
return null;
}).when(mockedItemCollection).add(any(), any(Consumer.class), any(Consumer.class));
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
Record record = new Record().withParsedRecord(new ParsedRecord().withContent(PARSED_CONTENT_WITH_HOLDING_ID));
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(record));
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = createItemHandler.handle(dataImportEventPayload);
// then
DataImportEventPayload eventPayload = future.get(5, TimeUnit.SECONDS);
Assert.assertEquals(DI_INVENTORY_ITEM_CREATED.value(), eventPayload.getEventType());
Assert.assertNotNull(eventPayload.getContext().get(ITEM.value()));
JsonObject createdItem = new JsonObject(eventPayload.getContext().get(ITEM.value()));
Assert.assertNotNull(createdItem.getJsonObject("status").getString("name"));
Assert.assertNotNull(createdItem.getString("permanentLoanTypeId"));
Assert.assertNotNull(createdItem.getString("materialTypeId"));
Assert.assertNotNull(createdItem.getString("holdingId"));
}
use of org.folio.inventory.dataimport.ItemWriterFactory in project mod-inventory by folio-org.
the class CreateItemEventHandlerTest method shouldReturnFailedFutureIfInventoryStorageErrorExists.
@Test(expected = ExecutionException.class)
public void shouldReturnFailedFutureIfInventoryStorageErrorExists() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
// given
RecordToEntity recordToItem = RecordToEntity.builder().recordId(RECORD_ID).entityId(ITEM_ID).build();
when(itemIdStorageService.store(any(), any(), any())).thenReturn(Future.succeededFuture(recordToItem));
Mockito.doAnswer(invocationOnMock -> {
MultipleRecords<Item> result = new MultipleRecords<>(new ArrayList<>(), 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));
doAnswer(invocationOnMock -> {
Consumer<Failure> failureHandler = invocationOnMock.getArgument(2);
failureHandler.accept(new Failure("Smth error", 400));
return null;
}).when(mockedItemCollection).add(any(), any(), any());
MappingManager.registerReaderFactory(fakeReaderFactory);
MappingManager.registerWriterFactory(new ItemWriterFactory());
String expectedHoldingId = UUID.randomUUID().toString();
JsonObject holdingAsJson = new JsonObject().put("id", expectedHoldingId);
HashMap<String, String> payloadContext = new HashMap<>();
payloadContext.put(EntityType.MARC_BIBLIOGRAPHIC.value(), Json.encode(new Record()));
payloadContext.put(EntityType.HOLDINGS.value(), holdingAsJson.encode());
DataImportEventPayload dataImportEventPayload = new DataImportEventPayload().withEventType(DI_SRS_MARC_BIB_RECORD_CREATED.value()).withJobExecutionId(UUID.randomUUID().toString()).withContext(payloadContext).withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0));
// when
CompletableFuture<DataImportEventPayload> future = createItemHandler.handle(dataImportEventPayload);
future.get(5, TimeUnit.SECONDS);
}
Aggregations