Skip to content

Commit

Permalink
[MODINVOSTO-187] Send event only after successful transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Nov 8, 2024
1 parent 6b43675 commit ca86ad4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public void createInvoiceLine(InvoiceLine invoiceLine, Handler<AsyncResult<Respo
log.info("createInvoiceLine:: Creating a new invoiceLine by id: {}", invoiceLine.getId());
new DBClient(vertxContext, headers).getPgClient()
.withTrans(conn -> invoiceLinesDAO.createInvoiceLine(invoiceLine, conn)
.compose(invoiceLineId -> auditOutboxService.saveInvoiceLineOutboxLog(conn, invoiceLine, InvoiceLineAuditEvent.Action.CREATE, headers))
.compose(v -> auditOutboxService.processOutboxEventLogs(headers, vertxContext)))
.compose(invoiceLineId -> auditOutboxService.saveInvoiceLineOutboxLog(conn, invoiceLine, InvoiceLineAuditEvent.Action.CREATE, headers)))
.onSuccess(s -> {
log.info("createInvoiceLine:: Successfully created a new invoiceLine by id: {}", invoiceLine.getId());
asyncResultHandler.handle(buildResponseWithLocation(headers.get(OKAPI_URL), INVOICE_LINES_PREFIX + invoiceLine.getId(), invoiceLine));
auditOutboxService.processOutboxEventLogs(headers, vertxContext);
})
.onFailure(f -> {
log.error("Error occurred while creating a new invoiceLine with id: {}", invoiceLine.getId(), f);
Expand All @@ -55,11 +55,11 @@ public void updateInvoiceLine(String id, InvoiceLine invoiceLine, Map<String, St
}
new DBClient(vertxContext, headers).getPgClient()
.withTrans(conn -> invoiceLinesDAO.updateInvoiceLine(id, invoiceLine, conn)
.compose(invoiceLineId -> auditOutboxService.saveInvoiceLineOutboxLog(conn, invoiceLine, InvoiceLineAuditEvent.Action.EDIT, headers))
.compose(v -> auditOutboxService.processOutboxEventLogs(headers, vertxContext)))
.compose(invoiceLineId -> auditOutboxService.saveInvoiceLineOutboxLog(conn, invoiceLine, InvoiceLineAuditEvent.Action.EDIT, headers)))
.onSuccess(s -> {
log.info("updateInvoiceLine:: Successfully updated invoice line with id: {}", id);
asyncResultHandler.handle(buildNoContentResponse());
auditOutboxService.processOutboxEventLogs(headers, vertxContext);
})
.onFailure(f -> {
log.error("Error occurred while updating invoice line with id: {}", id, f);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/folio/service/InvoiceStorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public void postInvoiceStorageInvoices(Invoice invoice, Handler<AsyncResult<Resp
log.info("postInvoiceStorageInvoices:: Creating a new invoice by id: {}", invoice.getId());
new DBClient(vertxContext, headers).getPgClient()
.withTrans(conn -> invoiceDAO.createInvoice(invoice, conn)
.compose(invoiceId -> auditOutboxService.saveInvoiceOutboxLog(conn, invoice, InvoiceAuditEvent.Action.CREATE, headers))
.compose(v -> auditOutboxService.processOutboxEventLogs(headers, vertxContext)))
.compose(invoiceId -> auditOutboxService.saveInvoiceOutboxLog(conn, invoice, InvoiceAuditEvent.Action.CREATE, headers)))
.onSuccess(s -> {
log.info("postInvoiceStorageInvoices:: Successfully created a new invoice by id: {}", invoice.getId());
asyncResultHandler.handle(buildResponseWithLocation(headers.get(OKAPI_URL), INVOICE_PREFIX + invoice.getId(), invoice));
auditOutboxService.processOutboxEventLogs(headers, vertxContext);
})
.onFailure(f -> {
log.error("Error occurred while creating a new invoice with id: {}", invoice.getId(), f);
Expand All @@ -69,11 +69,11 @@ public void putInvoiceStorageInvoicesById(String id, Invoice invoice, Map<String
}
new DBClient(vertxContext, headers).getPgClient()
.withTrans(conn -> invoiceDAO.updateInvoice(id, invoice, conn)
.compose(invoiceId -> auditOutboxService.saveInvoiceOutboxLog(conn, invoice, InvoiceAuditEvent.Action.EDIT, headers))
.compose(v -> auditOutboxService.processOutboxEventLogs(headers, vertxContext)))
.compose(invoiceId -> auditOutboxService.saveInvoiceOutboxLog(conn, invoice, InvoiceAuditEvent.Action.EDIT, headers)))
.onSuccess(s -> {
log.info("putInvoiceStorageInvoicesById:: Successfully updated invoice with id: {}", id);
asyncResultHandler.handle(buildNoContentResponse());
auditOutboxService.processOutboxEventLogs(headers, vertxContext);
})
.onFailure(f -> {
log.error("Error occurred while updating invoice with id: {}", id, f);
Expand Down

0 comments on commit ca86ad4

Please sign in to comment.