Search in sources :

Example 1 with LoanLogContext

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));
}
Also used : LoanLogContext(org.folio.circulation.domain.representations.logs.LoanLogContext) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 LoanLogContext (org.folio.circulation.domain.representations.logs.LoanLogContext)1