use of org.folio.circulation.domain.representations.logs.LoanLogContext in project mod-circulation by folio-org.
the class EventPublisher method publishStatusChangeEvent.
private CompletableFuture<Result<Loan>> publishStatusChangeEvent(EventType eventType, Loan loan) {
final String eventName = eventType.name();
if (loan == null) {
logger.error(FAILED_TO_PUBLISH_LOG_TEMPLATE, eventName);
return completedFuture(succeeded(null));
}
LoanLogContext loanLogContext = LoanLogContext.from(loan).withDescription(String.format("Additional information: %s", loan.getActionComment()));
runAsync(() -> publishLogRecord(loanLogContext.asJson(), LOAN));
JsonObject payloadJson = new JsonObject();
write(payloadJson, USER_ID_FIELD, loan.getUserId());
write(payloadJson, LOAN_ID_FIELD, loan.getId());
return pubSubPublishingService.publishEvent(eventName, payloadJson.encode()).handle((result, error) -> handlePublishEventError(error, loan));
}
Aggregations