Search in sources :

Example 1 with AuthorityRecordCollection

use of org.folio.inventory.domain.AuthorityRecordCollection in project mod-inventory by folio-org.

the class DeleteAuthorityEventHandler method handle.

@Override
public CompletableFuture<DataImportEventPayload> handle(DataImportEventPayload payload) {
    CompletableFuture<DataImportEventPayload> future = new CompletableFuture<>();
    try {
        if (!isExpectedPayload(payload)) {
            throw new EventProcessingException(UNEXPECTED_PAYLOAD_MSG);
        }
        var context = constructContext(payload.getTenant(), payload.getToken(), payload.getOkapiUrl());
        AuthorityRecordCollection authorityRecordCollection = storage.getAuthorityRecordCollection(context);
        String id = payload.getContext().get(AUTHORITY_RECORD_ID);
        deleteAuthorityRecord(id, authorityRecordCollection).onSuccess(successHandler(payload, future)).onFailure(failureHandler(payload, future));
    } catch (Exception e) {
        LOGGER.error(constructMsg(DELETE_FAILED_MSG_PATTERN, payload), e);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) EventProcessingException(org.folio.processing.exceptions.EventProcessingException) DataImportException(org.folio.inventory.dataimport.exceptions.DataImportException) DataImportEventPayload(org.folio.DataImportEventPayload) EventProcessingException(org.folio.processing.exceptions.EventProcessingException)

Example 2 with AuthorityRecordCollection

use of org.folio.inventory.domain.AuthorityRecordCollection in project mod-inventory by folio-org.

the class ExternalAuthorityCollectionFailureExamples method serverErrorWhenUpdatingAnInstanceTriggersFailureCallback.

@Test
public void serverErrorWhenUpdatingAnInstanceTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
    AuthorityRecordCollection collection = createCollection();
    CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
    collection.update(createAuthority(), success -> fail("Completion callback should not be called"), failureCalled::complete);
    Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
    check(failure);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 3 with AuthorityRecordCollection

use of org.folio.inventory.domain.AuthorityRecordCollection in project mod-inventory by folio-org.

the class ExternalAuthorityCollectionFailureExamples method serverErrorWhenDeletingAllInstancesTriggersFailureCallback.

@Test
public void serverErrorWhenDeletingAllInstancesTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
    AuthorityRecordCollection collection = createCollection();
    CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
    collection.empty(success -> fail("Completion callback should not be called"), failureCalled::complete);
    Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
    check(failure);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Example 4 with AuthorityRecordCollection

use of org.folio.inventory.domain.AuthorityRecordCollection in project mod-inventory by folio-org.

the class AuthorityUpdateDelegate method handle.

public Future<Authority> handle(Map<String, String> eventPayload, Record marcRecord, Context context) {
    try {
        JsonObject mappingRules = new JsonObject(eventPayload.get(MAPPING_RULES_KEY));
        MappingParameters mappingParameters = new JsonObject(eventPayload.get(MAPPING_PARAMS_KEY)).mapTo(MappingParameters.class);
        JsonObject parsedRecord = retrieveParsedContent(marcRecord.getParsedRecord());
        String authorityId = marcRecord.getExternalIdsHolder().getAuthorityId();
        RecordMapper<Authority> recordMapper = RecordMapperBuilder.buildMapper(MARC_FORMAT);
        var mappedAuthority = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules);
        AuthorityRecordCollection authorityRecordCollection = storage.getAuthorityRecordCollection(context);
        return getAuthorityRecordById(authorityId, authorityRecordCollection).onSuccess(existingAuthorityRecord -> fillVersion(existingAuthorityRecord, eventPayload)).compose(existingAuthorityRecord -> mergeRecords(existingAuthorityRecord, mappedAuthority)).compose(updatedAuthorityRecord -> updateAuthorityRecord(updatedAuthorityRecord, authorityRecordCollection));
    } catch (Exception e) {
        LOGGER.error("Error updating Authority", e);
        return Future.failedFuture(e);
    }
}
Also used : Context(org.folio.inventory.common.Context) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) Record(org.folio.rest.jaxrs.model.Record) Promise(io.vertx.core.Promise) Future(io.vertx.core.Future) String.format(java.lang.String.format) RecordMapperBuilder(org.folio.processing.mapping.defaultmapper.RecordMapperBuilder) Storage(org.folio.inventory.storage.Storage) Logger(org.apache.logging.log4j.Logger) Authority(org.folio.Authority) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) DataImportException(org.folio.inventory.dataimport.exceptions.DataImportException) LogManager(org.apache.logging.log4j.LogManager) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) RecordMapper(org.folio.processing.mapping.defaultmapper.RecordMapper) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) Authority(org.folio.Authority) JsonObject(io.vertx.core.json.JsonObject) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) DataImportException(org.folio.inventory.dataimport.exceptions.DataImportException)

Example 5 with AuthorityRecordCollection

use of org.folio.inventory.domain.AuthorityRecordCollection in project mod-inventory by folio-org.

the class ExternalAuthorityCollectionFailureExamples method serverErrorWhenCreatingAnInstanceTriggersFailureCallback.

@Test
public void serverErrorWhenCreatingAnInstanceTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException {
    AuthorityRecordCollection collection = createCollection();
    CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
    collection.add(createAuthority(), success -> fail("Completion callback should not be called"), failureCalled::complete);
    Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
    check(failure);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AuthorityRecordCollection(org.folio.inventory.domain.AuthorityRecordCollection) Failure(org.folio.inventory.common.domain.Failure) Test(org.junit.Test)

Aggregations

AuthorityRecordCollection (org.folio.inventory.domain.AuthorityRecordCollection)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Failure (org.folio.inventory.common.domain.Failure)7 Test (org.junit.Test)7 DataImportException (org.folio.inventory.dataimport.exceptions.DataImportException)2 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 JsonObject (io.vertx.core.json.JsonObject)1 String.format (java.lang.String.format)1 Map (java.util.Map)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Authority (org.folio.Authority)1 DataImportEventPayload (org.folio.DataImportEventPayload)1 Context (org.folio.inventory.common.Context)1 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)1 Storage (org.folio.inventory.storage.Storage)1 EventProcessingException (org.folio.processing.exceptions.EventProcessingException)1 RecordMapper (org.folio.processing.mapping.defaultmapper.RecordMapper)1 RecordMapperBuilder (org.folio.processing.mapping.defaultmapper.RecordMapperBuilder)1