use of org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate 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.handlers.actions.InstanceUpdateDelegate in project mod-inventory by folio-org.
the class UpdateInstanceQuickMarcEventHandlerTest method shouldProcessEvent.
@Test
public void shouldProcessEvent() {
HashMap<String, String> eventPayload = new HashMap<>();
eventPayload.put("RECORD_TYPE", "MARC_BIB");
eventPayload.put("MARC_BIB", record.encode());
eventPayload.put("MAPPING_RULES", mappingRules.encode());
eventPayload.put("MAPPING_PARAMS", new JsonObject().encode());
eventPayload.put("RELATED_RECORD_VERSION", INSTANCE_VERSION);
Future<Instance> future = updateInstanceEventHandler.handle(eventPayload);
Instance updatedInstance = future.result();
Assert.assertNotNull(updatedInstance);
Assert.assertEquals(INSTANCE_ID, updatedInstance.getId());
Assert.assertEquals(INSTANCE_VERSION, updatedInstance.getVersion());
Assert.assertEquals("Victorian environmental nightmares and something else/", updatedInstance.getIndexTitle());
Assert.assertNotNull(updatedInstance.getIdentifiers().stream().filter(i -> "(OCoLC)1060180367".equals(i.value)).findFirst().orElse(null));
Assert.assertNotNull(updatedInstance.getContributors().stream().filter(c -> "Mazzeno, Laurence W., 1234566".equals(c.name)).findFirst().orElse(null));
Assert.assertNotNull(updatedInstance.getSubjects());
Assert.assertEquals(1, updatedInstance.getSubjects().size());
Assert.assertTrue(updatedInstance.getSubjects().get(0).contains("additional subfield"));
Assert.assertFalse(updatedInstance.getSubjects().get(0).contains("Environmentalism in literature"));
Assert.assertNotNull(updatedInstance.getNotes());
Assert.assertEquals("Adding a note", updatedInstance.getNotes().get(0).note);
ArgumentCaptor<Context> argument = ArgumentCaptor.forClass(Context.class);
verify(instanceUpdateDelegate).handle(any(), any(), argument.capture());
Assert.assertEquals("token", argument.getValue().getToken());
Assert.assertEquals("dummy", argument.getValue().getTenantId());
Assert.assertEquals("http://localhost", argument.getValue().getOkapiLocation());
}
use of org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate in project mod-inventory by folio-org.
the class UpdateInstanceQuickMarcEventHandlerTest method setUp.
@Before
public void setUp() throws IOException {
existingInstance = Instance.fromJson(new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)));
instanceUpdateDelegate = Mockito.spy(new InstanceUpdateDelegate(storage));
precedingSucceedingTitlesHelper = Mockito.spy(new PrecedingSucceedingTitlesHelper(ctxt -> okapiHttpClient));
updateInstanceEventHandler = new UpdateInstanceQuickMarcEventHandler(instanceUpdateDelegate, context, precedingSucceedingTitlesHelper);
when(storage.getInstanceCollection(any())).thenReturn(instanceRecordCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingInstance));
return null;
}).when(instanceRecordCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
Instance instanceRecord = invocationOnMock.getArgument(0);
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instanceRecord));
return null;
}).when(instanceRecordCollection).update(any(), any(), any());
when(okapiHttpClient.put(anyString(), any(JsonObject.class))).thenReturn(CompletableFuture.completedFuture(new Response(204, null, null, null)));
when(context.getTenantId()).thenReturn("dummy");
when(context.getToken()).thenReturn("token");
when(context.getOkapiLocation()).thenReturn("http://localhost");
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
record = new JsonObject(TestUtil.readFileFromPath(RECORD_PATH));
}
use of org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate in project mod-inventory by folio-org.
the class MarcHridSetConsumerVerticle method start.
@Override
public void start(Promise<Void> startPromise) {
JsonObject config = vertx.getOrCreateContext().config();
KafkaConfig kafkaConfig = KafkaConfig.builder().envId(config.getString(KAFKA_ENV)).kafkaHost(config.getString(KAFKA_HOST)).kafkaPort(config.getString(KAFKA_PORT)).okapiUrl(config.getString(OKAPI_URL)).replicationFactor(Integer.parseInt(config.getString(KAFKA_REPLICATION_FACTOR))).maxRequestSize(Integer.parseInt(config.getString(KAFKA_MAX_REQUEST_SIZE))).build();
LOGGER.info("kafkaConfig: {}", kafkaConfig);
marcBibConsumerWrapper = createConsumerByEvent(kafkaConfig, DI_SRS_MARC_BIB_INSTANCE_HRID_SET);
marcHoldingsConsumerWrapper = createConsumerByEvent(kafkaConfig, DI_SRS_MARC_HOLDINGS_HOLDING_HRID_SET);
HttpClient client = vertx.createHttpClient();
Storage storage = Storage.basedUpon(vertx, config, client);
InstanceUpdateDelegate instanceUpdateDelegate = new InstanceUpdateDelegate(storage);
HoldingsUpdateDelegate holdingsRecordUpdateDelegate = new HoldingsUpdateDelegate(storage);
String mappingMetadataExpirationTime = getCacheEnvVariable(config, "inventory.mapping-metadata-cache.expiration.time.seconds");
MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, client, Long.parseLong(mappingMetadataExpirationTime));
MarcBibInstanceHridSetKafkaHandler marcBibInstanceHridSetKafkaHandler = new MarcBibInstanceHridSetKafkaHandler(instanceUpdateDelegate, mappingMetadataCache);
MarcHoldingsRecordHridSetKafkaHandler marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(holdingsRecordUpdateDelegate, mappingMetadataCache);
CompositeFuture.all(marcBibConsumerWrapper.start(marcBibInstanceHridSetKafkaHandler, constructModuleName()), marcHoldingsConsumerWrapper.start(marcHoldingsRecordHridSetKafkaHandler, constructModuleName())).onFailure(startPromise::fail).onSuccess(ar -> startPromise.complete());
}
use of org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate in project mod-inventory by folio-org.
the class MarcBibInstanceHridSetKafkaHandlerTest method setUp.
@Before
public void setUp() throws IOException {
mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
existingInstance = Instance.fromJson(new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)));
record = Json.decodeValue(TestUtil.readFileFromPath(RECORD_PATH), Record.class);
record.getParsedRecord().withContent(JsonObject.mapFrom(record.getParsedRecord().getContent()).encode());
mocks = MockitoAnnotations.openMocks(this);
when(mockedStorage.getInstanceCollection(any(Context.class))).thenReturn(mockedInstanceCollection);
doAnswer(invocationOnMock -> {
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(existingInstance));
return null;
}).when(mockedInstanceCollection).findById(anyString(), any(), any());
doAnswer(invocationOnMock -> {
Instance instance = invocationOnMock.getArgument(0);
Consumer<Success<Instance>> successHandler = invocationOnMock.getArgument(1);
successHandler.accept(new Success<>(instance));
return null;
}).when(mockedInstanceCollection).update(any(Instance.class), any(), any());
Mockito.when(mappingMetadataCache.get(anyString(), any(Context.class))).thenReturn(Future.succeededFuture(Optional.of(new MappingMetadataDto().withMappingRules(mappingRules.encode()).withMappingParams(Json.encode(new MappingParameters())))));
marcBibInstanceHridSetKafkaHandler = new MarcBibInstanceHridSetKafkaHandler(new InstanceUpdateDelegate(mockedStorage), mappingMetadataCache);
}
Aggregations