use of org.folio.circulation.support.results.Result.succeeded 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.succeeded 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