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