From 8faa91be6b6831cef23d13b9af316e8b60903a18 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Fri, 15 Nov 2024 15:36:29 +0500 Subject: [PATCH] [MODINVOICE-569] - Fix voucher number by setting sequence owner --- .../folio/rest/impl/VoucherNumberImpl.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/folio/rest/impl/VoucherNumberImpl.java b/src/main/java/org/folio/rest/impl/VoucherNumberImpl.java index 5771a781..1eb3ebea 100644 --- a/src/main/java/org/folio/rest/impl/VoucherNumberImpl.java +++ b/src/main/java/org/folio/rest/impl/VoucherNumberImpl.java @@ -28,7 +28,8 @@ public class VoucherNumberImpl implements VoucherStorageVoucherNumber { private static final Logger log = LogManager.getLogger(VoucherNumberImpl.class); private static final String VOUCHER_NUMBER_QUERY = "SELECT nextval('voucher_number')"; private static final String SET_START_SEQUENCE_VALUE_QUERY = "ALTER SEQUENCE voucher_number START WITH %s RESTART;"; - public static final String CURRENT_VOUCHER_NUMBER_QUERY = "SELECT pg_sequences.start_value FROM pg_sequences WHERE sequencename = 'voucher_number'"; + public static final String CURRENT_VOUCHER_NUMBER_QUERY = "SELECT pg_sequences.start_value FROM pg_sequences " + + "WHERE sequencename = 'voucher_number' AND sequenceowner = %_mod_invoice_storage"; @Override public void getVoucherStorageVoucherNumber(Map okapiHeaders, @@ -72,22 +73,24 @@ private void getVoucherNumber(Map okapiHeaders, Handler { String tenantId = TenantTool.calculateTenantId(okapiHeaders.get(RestVerticle.OKAPI_HEADER_TENANT)); - PostgresClient.getInstance(vertxContext.owner(), tenantId).selectSingle(voucherNumberQuery, reply -> { - try { - if (reply.succeeded()) { - String voucherNumber = reply.result().getLong(0).toString(); - log.info("getVoucherNumber:: Retrieved voucher number: {}", voucherNumber); - SequenceNumber sequenceNumber = new SequenceNumber().withSequenceNumber(voucherNumber); - asyncResultHandler.handle(buildOkResponse(sequenceNumber)); - } else { - log.error("getVoucherNumber:: Failed to retrieve voucher number", reply.cause()); - asyncResultHandler.handle(buildErrorResponse(reply.cause())); - } - } catch (Exception e) { - log.error("Error while handling response for voucher number request", e); - asyncResultHandler.handle(buildErrorResponse(e)); - } - }); + PostgresClient.getInstance(vertxContext.owner(), tenantId) + .selectSingle(String.format(voucherNumberQuery, tenantId), + reply -> { + try { + if (reply.succeeded()) { + String voucherNumber = reply.result().getLong(0).toString(); + log.info("getVoucherNumber:: Retrieved voucher number: {}", voucherNumber); + SequenceNumber sequenceNumber = new SequenceNumber().withSequenceNumber(voucherNumber); + asyncResultHandler.handle(buildOkResponse(sequenceNumber)); + } else { + log.error("getVoucherNumber:: Failed to retrieve voucher number", reply.cause()); + asyncResultHandler.handle(buildErrorResponse(reply.cause())); + } + } catch (Exception e) { + log.error("Error while handling response for voucher number request", e); + asyncResultHandler.handle(buildErrorResponse(e)); + } + }); }); log.info("getVoucherNumber:: Finished getting voucher number by query: {}", voucherNumberQuery); }