Search in sources :

Example 1 with InstanceUpdateDelegate

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));
}
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 InstanceUpdateDelegate

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Json(io.vertx.core.json.Json) Context(org.folio.inventory.common.Context) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Failure(org.folio.inventory.common.domain.Failure) Response(org.folio.inventory.support.http.client.Response) InstanceCollection(org.folio.inventory.domain.instances.InstanceCollection) TestUtil(org.folio.inventory.TestUtil) ArgumentCaptor(org.mockito.ArgumentCaptor) TITLE_KEY(org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle.TITLE_KEY) Mockito.doAnswer(org.mockito.Mockito.doAnswer) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) PrecedingSucceedingTitlesHelper(org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper) Record(org.folio.rest.jaxrs.model.Record) UpdateInstanceQuickMarcEventHandler(org.folio.inventory.dataimport.handlers.quickmarc.UpdateInstanceQuickMarcEventHandler) OkapiHttpClient(org.folio.inventory.support.http.client.OkapiHttpClient) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Storage(org.folio.inventory.storage.Storage) Consumer(java.util.function.Consumer) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) Mockito(org.mockito.Mockito) Success(org.folio.inventory.common.domain.Success) Instance(org.folio.inventory.domain.instances.Instance) OptimisticLockingException(org.folio.inventory.dataimport.exceptions.OptimisticLockingException) Assert(org.junit.Assert) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Context(org.folio.inventory.common.Context) HashMap(java.util.HashMap) Instance(org.folio.inventory.domain.instances.Instance) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with InstanceUpdateDelegate

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));
}
Also used : Response(org.folio.inventory.support.http.client.Response) UpdateInstanceQuickMarcEventHandler(org.folio.inventory.dataimport.handlers.quickmarc.UpdateInstanceQuickMarcEventHandler) Instance(org.folio.inventory.domain.instances.Instance) PrecedingSucceedingTitlesHelper(org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) JsonObject(io.vertx.core.json.JsonObject) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Example 4 with InstanceUpdateDelegate

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());
}
Also used : MarcBibInstanceHridSetKafkaHandler(org.folio.inventory.dataimport.consumers.MarcBibInstanceHridSetKafkaHandler) Storage(org.folio.inventory.storage.Storage) MarcHoldingsRecordHridSetKafkaHandler(org.folio.inventory.dataimport.consumers.MarcHoldingsRecordHridSetKafkaHandler) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HttpClient(io.vertx.core.http.HttpClient) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) JsonObject(io.vertx.core.json.JsonObject) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) KafkaConfig(org.folio.kafka.KafkaConfig)

Example 5 with InstanceUpdateDelegate

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);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) Instance(org.folio.inventory.domain.instances.Instance) InstanceUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate) JsonObject(io.vertx.core.json.JsonObject) Record(org.folio.rest.jaxrs.model.Record) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) MappingMetadataDto(org.folio.MappingMetadataDto) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Aggregations

InstanceUpdateDelegate (org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate)5 JsonObject (io.vertx.core.json.JsonObject)4 Success (org.folio.inventory.common.domain.Success)3 PrecedingSucceedingTitlesHelper (org.folio.inventory.dataimport.handlers.actions.PrecedingSucceedingTitlesHelper)3 Instance (org.folio.inventory.domain.instances.Instance)3 Before (org.junit.Before)3 Context (org.folio.inventory.common.Context)2 UpdateInstanceQuickMarcEventHandler (org.folio.inventory.dataimport.handlers.quickmarc.UpdateInstanceQuickMarcEventHandler)2 Response (org.folio.inventory.support.http.client.Response)2 Future (io.vertx.core.Future)1 HttpClient (io.vertx.core.http.HttpClient)1 Json (io.vertx.core.json.Json)1 TestContext (io.vertx.ext.unit.TestContext)1 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (java.util.function.Consumer)1 MappingMetadataDto (org.folio.MappingMetadataDto)1 TestUtil (org.folio.inventory.TestUtil)1