use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class UpdateRequestQueueTest method removalShouldFailWhenBatchUpdateFails.
@Test
void removalShouldFailWhenBatchUpdateFails() throws Exception {
UUID itemId = UUID.randomUUID();
RequestQueue requestQueue = createRequestQueue(itemId, 4);
Request requestToRemove = requestQueue.getRequests().iterator().next();
when(requestQueueRepository.getByItemId(itemId.toString())).thenReturn(completedFuture(succeeded(requestQueue)));
CompletableFuture<Result<Request>> completableFutureResult = updateRequestQueue.onDeletion(requestToRemove);
assertFailedOnFailureResponse(completableFutureResult);
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class FailureMatchers method errorResultFor.
public static <T> TypeSafeDiagnosingMatcher<Result<T>> errorResultFor(String propertyName, String reason) {
return new TypeSafeDiagnosingMatcher<Result<T>>() {
@Override
public void describeTo(Description description) {
description.appendValue(reason).appendText(" for ").appendValue(propertyName);
}
@Override
protected boolean matchesSafely(Result<T> failure, Description description) {
if (failure.succeeded()) {
description.appendText("is not a failed result");
return false;
}
if (failure.cause() instanceof ValidationErrorFailure) {
ValidationErrorFailure error = (ValidationErrorFailure) failure.cause();
if (!error.hasErrorForKey(propertyName)) {
description.appendText("not for ").appendValue(propertyName).appendText(" property");
return false;
}
description.appendValue(error.toString());
return error.hasErrorWithReason(reason);
} else {
description.appendText("is not a validation error failure");
return false;
}
}
};
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class CirculationRulesCache method getDrools.
public CompletableFuture<Result<Drools>> getDrools(String tenantId, CollectionResourceClient circulationRulesClient) {
final CompletableFuture<Result<Drools>> cfDrools = new CompletableFuture<>();
Rules rules = rulesMap.get(tenantId);
if (isCurrent(rules)) {
cfDrools.complete(succeeded(rules.drools));
if (reloadNeeded(rules)) {
rules.reloadInitiated = true;
reloadRules(rules, circulationRulesClient).thenCompose(r -> r.after(updatedRules -> ofAsync(() -> updatedRules.drools)));
}
return cfDrools;
}
if (rules == null) {
rules = new Rules();
rulesMap.put(tenantId, rules);
}
return reloadRules(rules, circulationRulesClient).thenCompose(r -> r.after(updatedRules -> ofAsync(() -> updatedRules.drools)));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class EventPublisher method publishItemCheckedOutEvent.
public CompletableFuture<Result<LoanAndRelatedRecords>> publishItemCheckedOutEvent(LoanAndRelatedRecords loanAndRelatedRecords, UserRepository userRepository) {
if (loanAndRelatedRecords.getLoan() != null) {
Loan loan = loanAndRelatedRecords.getLoan();
JsonObject payloadJsonObject = new JsonObject();
write(payloadJsonObject, USER_ID_FIELD, loan.getUserId());
write(payloadJsonObject, LOAN_ID_FIELD, loan.getId());
write(payloadJsonObject, DUE_DATE_FIELD, loan.getDueDate());
ofNullable(loan.getLoanPolicy()).map(LoanPolicy::getGracePeriod).filter(Period::isValid).map(Period::asJson).ifPresent(json -> write(payloadJsonObject, GRACE_PERIOD_FIELD, json));
runAsync(() -> userRepository.getUser(loanAndRelatedRecords.getLoggedInUserId()).thenApplyAsync(r -> r.after(loggedInUser -> CompletableFuture.completedFuture(Result.succeeded(pubSubPublishingService.publishEvent(LOG_RECORD.name(), mapToCheckOutLogEventContent(loanAndRelatedRecords, loggedInUser)))))));
return pubSubPublishingService.publishEvent(ITEM_CHECKED_OUT.name(), payloadJsonObject.encode()).handle((result, error) -> handlePublishEventError(error, loanAndRelatedRecords));
} else {
logger.error(FAILED_TO_PUBLISH_LOG_TEMPLATE, ITEM_CHECKED_OUT.name());
}
return completedFuture(succeeded(loanAndRelatedRecords));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class EventPublisher method publishItemCheckedInEvents.
public CompletableFuture<Result<CheckInContext>> publishItemCheckedInEvents(CheckInContext checkInContext, UserRepository userRepository) {
runAsync(() -> userRepository.getUser(checkInContext.getLoggedInUserId()).thenApplyAsync(r -> r.after(loggedInUser -> CompletableFuture.completedFuture(Result.succeeded(pubSubPublishingService.publishEvent(LOG_RECORD.name(), mapToCheckInLogEventContent(checkInContext, loggedInUser)))))));
if (checkInContext.getLoan() != null) {
Loan loan = checkInContext.getLoan();
JsonObject payloadJsonObject = new JsonObject();
write(payloadJsonObject, USER_ID_FIELD, loan.getUserId());
write(payloadJsonObject, LOAN_ID_FIELD, loan.getId());
write(payloadJsonObject, RETURN_DATE_FIELD, loan.getReturnDate());
return pubSubPublishingService.publishEvent(ITEM_CHECKED_IN.name(), payloadJsonObject.encode()).handle((result, error) -> handlePublishEventError(error, checkInContext));
} else {
logger.error(FAILED_TO_PUBLISH_LOG_TEMPLATE, ITEM_CHECKED_IN.name());
}
return completedFuture(succeeded(checkInContext));
}
Aggregations