Search in sources :

Example 1 with HoldingsUpdateDelegate

use of org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate in project mod-inventory by folio-org.

the class UpdateHoldingsQuickMarcEventHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(INSTANCE_PATH)).mapTo(HoldingsRecord.class);
    holdingsUpdateDelegate = Mockito.spy(new HoldingsUpdateDelegate(storage));
    updateHoldingsQuickMarcEventHandler = new UpdateHoldingsQuickMarcEventHandler(holdingsUpdateDelegate, context);
    when(storage.getHoldingsRecordCollection(any())).thenReturn(holdingsRecordCollection);
    doAnswer(invocationOnMock -> {
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(existingHoldingsRecord));
        return null;
    }).when(holdingsRecordCollection).findById(anyString(), any(), any());
    doAnswer(invocationOnMock -> {
        HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(holdingsRecord));
        return null;
    }).when(holdingsRecordCollection).update(any(), any(), any());
    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 : HoldingsRecord(org.folio.HoldingsRecord) UpdateHoldingsQuickMarcEventHandler(org.folio.inventory.dataimport.handlers.quickmarc.UpdateHoldingsQuickMarcEventHandler) JsonObject(io.vertx.core.json.JsonObject) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) Success(org.folio.inventory.common.domain.Success) Before(org.junit.Before)

Example 2 with HoldingsUpdateDelegate

use of org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate 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 3 with HoldingsUpdateDelegate

use of org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate in project mod-inventory by folio-org.

the class MarcHoldingsRecordHridSetKafkaHandlerTest method setUp.

@Before
public void setUp() throws IOException {
    mappingRules = new JsonObject(TestUtil.readFileFromPath(MAPPING_RULES_PATH));
    existingHoldingsRecord = new JsonObject(TestUtil.readFileFromPath(HOLDINGS_PATH)).mapTo(HoldingsRecord.class);
    record = Json.decodeValue(TestUtil.readFileFromPath(RECORD_PATH), Record.class);
    record.getParsedRecord().withContent(JsonObject.mapFrom(record.getParsedRecord().getContent()).encode());
    mocks = MockitoAnnotations.openMocks(this);
    when(mockedStorage.getHoldingsRecordCollection(any(Context.class))).thenReturn(mockedHoldingsCollection);
    doAnswer(invocationOnMock -> {
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(existingHoldingsRecord));
        return null;
    }).when(mockedHoldingsCollection).findById(anyString(), any(), any());
    doAnswer(invocationOnMock -> {
        HoldingsRecord holdingsRecord = invocationOnMock.getArgument(0);
        Consumer<Success<HoldingsRecord>> successHandler = invocationOnMock.getArgument(1);
        successHandler.accept(new Success<>(holdingsRecord));
        return null;
    }).when(mockedHoldingsCollection).update(any(HoldingsRecord.class), any(), any());
    List<HoldingsType> holdings = new ArrayList<>();
    holdings.add(new HoldingsType().withName("testingnote$a").withId("5f694a63-1bd4-4002-9f38-09170eb7aa62"));
    MappingParameters mappingParameters = new MappingParameters();
    mappingParameters.withHoldingsTypes(holdings);
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto().withMappingParams(Json.encode(mappingParameters)).withMappingRules(mappingRules.encode())))));
    MappingMetadataCache mappingMetadataCache = new MappingMetadataCache(vertx, vertx.createHttpClient(), 3600);
    marcHoldingsRecordHridSetKafkaHandler = new MarcHoldingsRecordHridSetKafkaHandler(new HoldingsUpdateDelegate(mockedStorage), mappingMetadataCache);
    this.okapiHeaders = List.of(KafkaHeader.header(OKAPI_TENANT_HEADER, "diku"), KafkaHeader.header(OKAPI_URL_HEADER, mockServer.baseUrl()));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Context(org.folio.inventory.common.Context) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) MappingMetadataDto(org.folio.MappingMetadataDto) HoldingsUpdateDelegate(org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate) Success(org.folio.inventory.common.domain.Success) HoldingsRecord(org.folio.HoldingsRecord) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) HoldingsType(org.folio.HoldingsType) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HoldingsRecord(org.folio.HoldingsRecord) KafkaConsumerRecord(io.vertx.kafka.client.consumer.KafkaConsumerRecord) Record(org.folio.rest.jaxrs.model.Record) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Before(org.junit.Before)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)3 HoldingsUpdateDelegate (org.folio.inventory.dataimport.handlers.actions.HoldingsUpdateDelegate)3 HoldingsRecord (org.folio.HoldingsRecord)2 Success (org.folio.inventory.common.domain.Success)2 MappingMetadataCache (org.folio.inventory.dataimport.cache.MappingMetadataCache)2 Before (org.junit.Before)2 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)1 HttpClient (io.vertx.core.http.HttpClient)1 TestContext (io.vertx.ext.unit.TestContext)1 KafkaConsumerRecord (io.vertx.kafka.client.consumer.KafkaConsumerRecord)1 ArrayList (java.util.ArrayList)1 HoldingsType (org.folio.HoldingsType)1 MappingMetadataDto (org.folio.MappingMetadataDto)1 Context (org.folio.inventory.common.Context)1 MarcBibInstanceHridSetKafkaHandler (org.folio.inventory.dataimport.consumers.MarcBibInstanceHridSetKafkaHandler)1 MarcHoldingsRecordHridSetKafkaHandler (org.folio.inventory.dataimport.consumers.MarcHoldingsRecordHridSetKafkaHandler)1 InstanceUpdateDelegate (org.folio.inventory.dataimport.handlers.actions.InstanceUpdateDelegate)1 UpdateHoldingsQuickMarcEventHandler (org.folio.inventory.dataimport.handlers.quickmarc.UpdateHoldingsQuickMarcEventHandler)1 Storage (org.folio.inventory.storage.Storage)1