From 760bd530d3c7a3bd3ba5e291a3a482379b7a3b7b Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 8 Jan 2024 11:02:36 +0100 Subject: [PATCH 01/17] [PRDP-311] Added new integration tests' scenario --- .../src/features/receipt_pdf_datastore.feature | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/integration-test/src/features/receipt_pdf_datastore.feature b/integration-test/src/features/receipt_pdf_datastore.feature index 0959bfaa..2e3a1da5 100644 --- a/integration-test/src/features/receipt_pdf_datastore.feature +++ b/integration-test/src/features/receipt_pdf_datastore.feature @@ -5,4 +5,14 @@ Feature: All about payment events consumed by Azure functions receipt-pdf-datast When biz event has been properly stored into receipt datastore after 10000 ms with eventId "receipt-datastore-int-test-id-1" Then the receipts datastore returns the receipt And the receipt has eventId "receipt-datastore-int-test-id-1" - And the receipt has not the status "NOT_QUEUE_SENT" \ No newline at end of file + And the receipt has not the status "NOT_QUEUE_SENT" + And the receipt has not the status "FAILED" + + Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore + Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE + And a cart event with id "receipt-datastore-int-test-transactionId-2" containing the ids the bizEvents + When biz event has been properly stored into receipt datastore after 10000 ms with eventId "receipt-datastore-int-test-transactionId-2" + Then the receipts datastore returns the receipt + And the receipt has eventId "receipt-datastore-int-test-transactionId-2" + And the receipt has not the status "NOT_QUEUE_SENT" + And the receipt has not the status "FAILED" \ No newline at end of file From 3d23c368d780dbd874e6adede7239e1b52a22c0a Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 8 Jan 2024 11:05:03 +0100 Subject: [PATCH 02/17] [PRDP-311] Added integration tests definition --- .../biz_events_datastore_client.js | 4 +- .../src/step_definitions/common.js | 17 ++++++-- .../receipt_pdf_datastore_step.js | 40 ++++++++++++++++++- .../receipts_datastore_client.js | 25 +++++++++++- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/integration-test/src/step_definitions/biz_events_datastore_client.js b/integration-test/src/step_definitions/biz_events_datastore_client.js index b719488a..42a9f483 100644 --- a/integration-test/src/step_definitions/biz_events_datastore_client.js +++ b/integration-test/src/step_definitions/biz_events_datastore_client.js @@ -17,8 +17,8 @@ async function getDocumentByIdFromBizEventsDatastore(id) { .fetchAll(); } -async function createDocumentInBizEventsDatastore(id) { - let event = createEvent(id); +async function createDocumentInBizEventsDatastore(id, transactionId, totalNotice) { + let event = createEvent(id, transactionId, totalNotice); try { return await container.items.create(event); } catch (err) { diff --git a/integration-test/src/step_definitions/common.js b/integration-test/src/step_definitions/common.js index efd6bd85..d5600fca 100644 --- a/integration-test/src/step_definitions/common.js +++ b/integration-test/src/step_definitions/common.js @@ -11,7 +11,7 @@ function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } -function createEvent(id) { +function createEvent(id, transactionId, totalNotice) { let json_event = { "id": id, "version": "2", @@ -76,7 +76,7 @@ function createEvent(id) { "paymentToken": "9851395f09544a04b288202299193ca6", "amount": "10.0", "fee": "2.0", - "totalNotice": "1", + "totalNotice": totalNotice ? totalNotice : "1", "paymentMethod": "creditCard", "touchpoint": "app", "remittanceInformation": "TARI 2021", @@ -110,7 +110,7 @@ function createEvent(id) { }, "transaction": { "idTransaction": "123456", - "transactionId": "123456", + "transactionId": transactionId ? transactionId : "123456", "grandTotal": 0, "amount": 0, "fee": 0 @@ -145,6 +145,15 @@ function createReceipt(id, fiscalCode, pdfName) { return receipt } +function createCartEvent(id, listOfBizEventsIds) { + return { + "id":id, + "cartPaymentId": listOfBizEventsIds, + "totalNotice": listOfBizEventsIds.length, + "status": "INSERTED" + } +} + module.exports = { - createEvent, sleep + createEvent, sleep, createCartEvent } \ No newline at end of file diff --git a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js index 4b9e5e22..9029ba87 100644 --- a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js @@ -2,7 +2,7 @@ const assert = require('assert'); const { After, Given, When, Then, setDefaultTimeout } = require('@cucumber/cucumber'); const { sleep, recoverFailedEvent } = require("./common"); const { createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore } = require("./biz_events_datastore_client"); -const { getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, updateReceiptToFailed } = require("./receipts_datastore_client"); +const { getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, deleteDocumentFromCartDatastore, createDocumentInCartDatastore } = require("./receipts_datastore_client"); // set timeout for Hooks function, it allows to wait for long task setDefaultTimeout(360 * 1000); @@ -13,6 +13,8 @@ this.responseToCheck = null; this.response = null; this.receiptId = null; this.event = null; +this.cartId = null; +this.listOfBizEventsIds = null; // After each Scenario After(async function () { @@ -23,10 +25,20 @@ After(async function () { if (this.receiptId != null) { await deleteDocumentFromReceiptsDatastore(this.receiptId); } + if(this.cartId != null) { + await deleteDocumentFromCartDatastore(this.cartId); + } + if(this.listOfBizEventsIds.length > 0) { + for(bizEvent of this.listOfBizEventsIds){ + await deleteDocumentFromBizEventsDatastore(bizEvent.id); + } + } this.eventId = null; this.responseToCheck = null; this.receiptId = null; this.event = null; + this.listOfBizEventsIds = null; + this.cartId = null; }); Given('a random biz event with id {string} stored on biz-events datastore with status DONE', async function (id) { @@ -39,6 +51,32 @@ Given('a random biz event with id {string} stored on biz-events datastore with s assert.strictEqual(bizEventStoreResponse.statusCode, 201); }); +Given('a list of {int} bizEvents starting with id {string} and transactionId {string} stored on biz-events datastore with status DONE', async function (numberOfEvents, id, transactionId) { + this.eventId = transactionId; + this.listOfBizEventsIds = []; + + for(let i = 0; i < numberOfEvents; i++) { + let finalId = id+i; + + await deleteDocumentFromBizEventsDatastore(finalId); + await deleteDocumentFromReceiptsDatastoreByEventId(finalId); + + let bizEventStoreResponse = await createDocumentInBizEventsDatastore(finalId, transactionId, `${numberOfEvents}`); + assert.strictEqual(bizEventStoreResponse.statusCode, 201); + console.log(this.listOfBizEventsIds); + this.listOfBizEventsIds.push(finalId); + } +}); + +Given('a cart event with id {string} containing the ids the bizEvents', async function (id) { + this.cartId = id; + // prior cancellation to avoid dirty cases + await deleteDocumentFromCartDatastore(id); + + let cartResponse = await createDocumentInCartDatastore(id, this.listOfBizEventsIds); + assert.strictEqual(cartResponse.statusCode, 201); + }); + When('biz event has been properly stored into receipt datastore after {int} ms with eventId {string}', async function (time, eventId) { // boundary time spent by azure function to process event await sleep(time); diff --git a/integration-test/src/step_definitions/receipts_datastore_client.js b/integration-test/src/step_definitions/receipts_datastore_client.js index e6010d5b..25b6ea70 100644 --- a/integration-test/src/step_definitions/receipts_datastore_client.js +++ b/integration-test/src/step_definitions/receipts_datastore_client.js @@ -1,12 +1,14 @@ const { CosmosClient } = require("@azure/cosmos"); -const { createReceipt } = require("./common"); +const { createCartEvent } = require("./common"); const cosmos_db_conn_string = process.env.RECEIPTS_COSMOS_CONN_STRING || ""; const databaseId = process.env.RECEIPT_COSMOS_DB_NAME; const receiptContainerId = process.env.RECEIPT_COSMOS_DB_CONTAINER_NAME; +const cartContainerId = process.env.RECEIPTS_COSMOS_CART_CONTAINER_NAME; const client = new CosmosClient(cosmos_db_conn_string); const receiptContainer = client.database(databaseId).container(receiptContainerId); +const cartContainer = client.database(databaseId).container(cartContainerId); async function getDocumentByIdFromReceiptsDatastore(id) { return await receiptContainer.items @@ -35,6 +37,25 @@ async function deleteDocumentFromReceiptsDatastore(id) { } } +async function createDocumentInCartDatastore(id, listOfBizEventsIds) { + let event = createCartEvent(id, listOfBizEventsIds); + try { + return await cartContainer.items.create(event); + } catch (err) { + console.log(err); + } +} + +async function deleteDocumentFromCartDatastore(id){ + try { + return await cartContainer.item(id, id).delete(); + } catch (error) { + if (error.code !== 404) { + console.log(error) + } + } +} + module.exports = { - getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore + getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, createDocumentInCartDatastore, deleteDocumentFromCartDatastore } \ No newline at end of file From cc4498b0069414b004ca188d7c427c0b493e6a9f Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 8 Jan 2024 11:05:44 +0100 Subject: [PATCH 03/17] [PRDP-311] Added new env for cart collection --- integration-test/src/config/.env.dev | 1 + integration-test/src/config/.env.local | 3 ++- integration-test/src/config/.env.uat | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/integration-test/src/config/.env.dev b/integration-test/src/config/.env.dev index 38ab0dcd..e520243e 100644 --- a/integration-test/src/config/.env.dev +++ b/integration-test/src/config/.env.dev @@ -5,5 +5,6 @@ BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events RECEIPTS_COSMOS_CONN_STRING= RECEIPT_COSMOS_DB_NAME=db RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts +RECEIPTS_COSMOS_CART_CONTAINER_NAME=cart-for-receipts DATASTORE_URL=https://api.dev.platform.pagopa.it/receipts/datastore/v1/recoverFailed \ No newline at end of file diff --git a/integration-test/src/config/.env.local b/integration-test/src/config/.env.local index f725a6fa..9e67ddd7 100644 --- a/integration-test/src/config/.env.local +++ b/integration-test/src/config/.env.local @@ -4,4 +4,5 @@ BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events RECEIPTS_COSMOS_CONN_STRING= RECEIPT_COSMOS_DB_NAME=db -RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts \ No newline at end of file +RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts +RECEIPTS_COSMOS_CART_CONTAINER_NAME=cart-for-receipts \ No newline at end of file diff --git a/integration-test/src/config/.env.uat b/integration-test/src/config/.env.uat index 9e3e1fdf..33b70921 100644 --- a/integration-test/src/config/.env.uat +++ b/integration-test/src/config/.env.uat @@ -5,5 +5,6 @@ BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events RECEIPTS_COSMOS_CONN_STRING= RECEIPT_COSMOS_DB_NAME=db RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts +RECEIPTS_COSMOS_CART_CONTAINER_NAME=cart-for-receipts DATASTORE_URL=https://api.uat.platform.pagopa.it/receipts/datastore/v1/recoverFailed \ No newline at end of file From 1c42330c97bf0a208917408121fe1e1f367f757c Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 10:00:25 +0100 Subject: [PATCH 04/17] [PRDP-311] Introduced cart event integration test --- .../features/receipt_pdf_datastore.feature | 11 ++++--- .../receipt_pdf_datastore_step.js | 33 ++++++++++++++++--- .../receipts_datastore_client.js | 21 ++++++++---- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/integration-test/src/features/receipt_pdf_datastore.feature b/integration-test/src/features/receipt_pdf_datastore.feature index 2e3a1da5..e2caee58 100644 --- a/integration-test/src/features/receipt_pdf_datastore.feature +++ b/integration-test/src/features/receipt_pdf_datastore.feature @@ -10,9 +10,12 @@ Feature: All about payment events consumed by Azure functions receipt-pdf-datast Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE - And a cart event with id "receipt-datastore-int-test-transactionId-2" containing the ids the bizEvents - When biz event has been properly stored into receipt datastore after 10000 ms with eventId "receipt-datastore-int-test-transactionId-2" - Then the receipts datastore returns the receipt + When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" + Then the receipts datastore return the cart event + And the cart event has status SENT + And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" + And the receipts datastore returns the receipt And the receipt has eventId "receipt-datastore-int-test-transactionId-2" And the receipt has not the status "NOT_QUEUE_SENT" - And the receipt has not the status "FAILED" \ No newline at end of file + And the receipt has not a datastore reason error message + \ No newline at end of file diff --git a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js index 9029ba87..62cef491 100644 --- a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js @@ -2,7 +2,7 @@ const assert = require('assert'); const { After, Given, When, Then, setDefaultTimeout } = require('@cucumber/cucumber'); const { sleep, recoverFailedEvent } = require("./common"); const { createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore } = require("./biz_events_datastore_client"); -const { getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, deleteDocumentFromCartDatastore, createDocumentInCartDatastore } = require("./receipts_datastore_client"); +const { getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, deleteDocumentFromCartDatastore, createDocumentInCartDatastore, getCartDocumentByIdFromReceiptsDatastore } = require("./receipts_datastore_client"); // set timeout for Hooks function, it allows to wait for long task setDefaultTimeout(360 * 1000); @@ -63,7 +63,7 @@ Given('a list of {int} bizEvents starting with id {string} and transactionId {st let bizEventStoreResponse = await createDocumentInBizEventsDatastore(finalId, transactionId, `${numberOfEvents}`); assert.strictEqual(bizEventStoreResponse.statusCode, 201); - console.log(this.listOfBizEventsIds); + this.listOfBizEventsIds.push(finalId); } }); @@ -77,10 +77,17 @@ Given('a cart event with id {string} containing the ids the bizEvents', async fu assert.strictEqual(cartResponse.statusCode, 201); }); -When('biz event has been properly stored into receipt datastore after {int} ms with eventId {string}', async function (time, eventId) { +When('receipt has been properly stored into receipt datastore after {int} ms with eventId {string}', async function (time, id) { + // boundary time spent by azure function to process event + await sleep(time); + this.responseToCheck = await getDocumentByIdFromReceiptsDatastore(id); +}); + + +When('cart event has been properly stored into receipt datastore after {int} ms with id {string}', async function (time, id) { // boundary time spent by azure function to process event await sleep(time); - this.responseToCheck = await getDocumentByIdFromReceiptsDatastore(eventId); + this.responseToCheck = await getCartDocumentByIdFromReceiptsDatastore(id); }); Then('the receipts datastore returns the receipt', async function () { @@ -89,6 +96,16 @@ Then('the receipts datastore returns the receipt', async function () { assert.strictEqual(this.responseToCheck.resources.length, 1); }); +Then('the receipts datastore return the cart event', async function () { + assert.notStrictEqual(this.responseToCheck.resources.length, 0); + this.cartId = this.responseToCheck.resources[0].id; + assert.strictEqual(this.responseToCheck.resources.length, 1); +}); + +Then("the cart event has status {string}", function(status) { + assert.strictEqual(this.responseToCheck.resources[0].status, status); +}); + Then('the receipt has eventId {string}', function (targetId) { assert.strictEqual(this.responseToCheck.resources[0].eventId, targetId); }); @@ -97,6 +114,14 @@ Then('the receipt has not the status {string}', function (targetStatus) { assert.notStrictEqual(this.responseToCheck.resources[0].status, targetStatus); }); +Then("the receipt has not a datastore reason error message", function(){ + let receiptResponse = this.responseToCheck.resources[0]; + if(receiptResponse?.reasonErr.message){ + let booleanResponseErr = receiptResponse.reasonErr.message.includes("BizEventToReceiptService"); + + assert.strictEqual(booleanResponseErr, false); + } +}); diff --git a/integration-test/src/step_definitions/receipts_datastore_client.js b/integration-test/src/step_definitions/receipts_datastore_client.js index 25b6ea70..981fc365 100644 --- a/integration-test/src/step_definitions/receipts_datastore_client.js +++ b/integration-test/src/step_definitions/receipts_datastore_client.js @@ -1,9 +1,9 @@ const { CosmosClient } = require("@azure/cosmos"); const { createCartEvent } = require("./common"); -const cosmos_db_conn_string = process.env.RECEIPTS_COSMOS_CONN_STRING || ""; -const databaseId = process.env.RECEIPT_COSMOS_DB_NAME; -const receiptContainerId = process.env.RECEIPT_COSMOS_DB_CONTAINER_NAME; +const cosmos_db_conn_string = process.env.RECEIPTS_COSMOS_CONN_STRING || ""; +const databaseId = process.env.RECEIPT_COSMOS_DB_NAME; +const receiptContainerId = process.env.RECEIPT_COSMOS_DB_CONTAINER_NAME; const cartContainerId = process.env.RECEIPTS_COSMOS_CART_CONTAINER_NAME; const client = new CosmosClient(cosmos_db_conn_string); @@ -19,7 +19,16 @@ async function getDocumentByIdFromReceiptsDatastore(id) { .fetchNext(); } -async function deleteDocumentFromReceiptsDatastoreByEventId(eventId){ +async function getCartDocumentByIdFromReceiptsDatastore(id) { + return await cartContainer.items + .query({ + query: "SELECT * from c WHERE c.id=@id", + parameters: [{ name: "@id", value: id }] + }) + .fetchNext(); +} + +async function deleteDocumentFromReceiptsDatastoreByEventId(eventId) { let documents = await getDocumentByIdFromReceiptsDatastore(eventId); documents?.resources?.forEach(el => { @@ -46,7 +55,7 @@ async function createDocumentInCartDatastore(id, listOfBizEventsIds) { } } -async function deleteDocumentFromCartDatastore(id){ +async function deleteDocumentFromCartDatastore(id) { try { return await cartContainer.item(id, id).delete(); } catch (error) { @@ -57,5 +66,5 @@ async function deleteDocumentFromCartDatastore(id){ } module.exports = { - getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, createDocumentInCartDatastore, deleteDocumentFromCartDatastore + getDocumentByIdFromReceiptsDatastore, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, createDocumentInCartDatastore, deleteDocumentFromCartDatastore, getCartDocumentByIdFromReceiptsDatastore } \ No newline at end of file From e2b90e6fbabf189639a51aebddcf8b02893d2892 Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 10:02:44 +0100 Subject: [PATCH 05/17] [PRDP-311] Fixed CartEventToReceipt function save & logic --- .../pdf/datastore/CartEventToReceipt.java | 113 ++++++++++-------- .../client/CartReceiptsCosmosClient.java | 2 + .../impl/CartReceiptsCosmosClientImpl.java | 13 ++ .../client/impl/ReceiptCosmosClientImpl.java | 2 - .../impl/BizEventToReceiptServiceImpl.java | 13 +- 5 files changed, 85 insertions(+), 58 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java index a8b5111d..ad2ca84e 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java @@ -62,7 +62,7 @@ public void run( leaseCollectionName = "cart-for-receipts-leases", connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING", createLeaseCollectionIfNotExists = true) - CartForReceipt cartForReceipt, + List listCartForReceipt, @CosmosDBOutput( name = "ReceiptDatastore", databaseName = "db", @@ -79,61 +79,68 @@ public void run( ) { logger.info("[{}] function called at {}", context.getFunctionName(), LocalDateTime.now()); - if (!cartForReceipt.getStatus().equals(CartStatusType.INSERTED)) { - logger.info("[{}] Cart with id {} not in status {}, this event will be skipped", - context.getFunctionName(), cartForReceipt.getId(), CartStatusType.INSERTED); - return; - } - - if (cartForReceipt.getTotalNotice() != cartForReceipt.getCartPaymentId().size()) { - logger.info("[{}] Not all items collected for cart with id {}, this event will be skipped", - context.getFunctionName(), cartForReceipt.getId()); - return; - } - - List bizEventList = this.bizEventToReceiptService.getCartBizEvents(cartForReceipt.getId()); - Receipt receipt; - try { - receipt = BizEventToReceiptUtils.createCartReceipt(bizEventList, bizEventToReceiptService, logger); - } catch (Exception e) { - cartForReceipt.setStatus(CartStatusType.FAILED); - cartForReceipt.setReasonError(ReasonError.builder().code(500).message(e.getMessage()).build()); - cartForReceiptDocumentdb.setValue(cartForReceipt); - return; - } - - if (!isReceiptStatusValid(receipt)) { - logger.error("[{}] Failed to process cart with id {}: fail to tokenize fiscal codes", - context.getFunctionName(), cartForReceipt.getId()); - cartForReceipt.setStatus(CartStatusType.FAILED); - cartForReceipt.setReasonError(receipt.getReasonErr()); + for(CartForReceipt cartForReceipt : listCartForReceipt){ + if (cartForReceipt.getTotalNotice() != cartForReceipt.getCartPaymentId().size()) { + logger.info("[{}] Not all items collected for cart with id {}, this event will be skipped", + context.getFunctionName(), cartForReceipt.getId()); + return; + } + + if (!cartForReceipt.getStatus().equals(CartStatusType.INSERTED)) { + logger.info("[{}] Cart with id {} not in status {}, this event will be skipped", + context.getFunctionName(), cartForReceipt.getId(), CartStatusType.INSERTED); + return; + } + + List bizEventList; + Receipt receipt; + + try { + bizEventList = this.bizEventToReceiptService.getCartBizEvents(cartForReceipt.getId()); + receipt = BizEventToReceiptUtils.createCartReceipt(bizEventList, bizEventToReceiptService, logger); + + } catch (Exception e) { + cartForReceipt.setStatus(CartStatusType.FAILED); + cartForReceipt.setReasonError(ReasonError.builder().code(500).message(e.getMessage()).build()); + cartForReceiptDocumentdb.setValue(cartForReceipt); + return; + } + + if (!isReceiptStatusValid(receipt)) { + logger.error("[{}] Failed to process cart with id {}: fail to tokenize fiscal codes", + context.getFunctionName(), cartForReceipt.getId()); + cartForReceipt.setStatus(CartStatusType.FAILED); + cartForReceipt.setReasonError(receipt.getReasonErr()); + cartForReceiptDocumentdb.setValue(cartForReceipt); + return; + } + + // Add receipt to items to be saved on CosmosDB + this.bizEventToReceiptService.handleSaveReceipt(receipt); + + if (!isReceiptStatusValid(receipt)) { + logger.error("[{}] Failed to process cart with id {}: fail to save receipt", + context.getFunctionName(), cartForReceipt.getId()); + cartForReceipt.setStatus(CartStatusType.FAILED); + cartForReceipt.setReasonError(receipt.getReasonErr()); + cartForReceiptDocumentdb.setValue(cartForReceipt); + return; + } + + // Send biz event as message to queue (to be processed from the other function) + this.bizEventToReceiptService.handleSendMessageToQueue(bizEventList, receipt); + + + if (!isReceiptStatusValid(receipt)) { + // save only if receipt save on cosmos or send on queue fail + receiptDocumentdb.setValue(receipt); + } + cartForReceipt.setStatus(CartStatusType.SENT); + logger.info("[{}] Cart with id {} processes successfully. Cart with status: {} and receipt with status: {}", + context.getFunctionName(), cartForReceipt.getId(), cartForReceipt.getStatus(), receipt.getStatus()); cartForReceiptDocumentdb.setValue(cartForReceipt); - return; } - // Add receipt to items to be saved on CosmosDB - this.bizEventToReceiptService.handleSaveReceipt(receipt); - if (!isReceiptStatusValid(receipt)) { - logger.error("[{}] Failed to process cart with id {}: fail to save receipt", - context.getFunctionName(), cartForReceipt.getId()); - cartForReceipt.setStatus(CartStatusType.FAILED); - cartForReceipt.setReasonError(receipt.getReasonErr()); - cartForReceiptDocumentdb.setValue(cartForReceipt); - return; - } - - // Send biz event as message to queue (to be processed from the other function) - this.bizEventToReceiptService.handleSendMessageToQueue(bizEventList, receipt); - - - if (!isReceiptStatusValid(receipt)) { - // save only if receipt save on cosmos or send on queue fail - receiptDocumentdb.setValue(receipt); - } - cartForReceipt.setStatus(CartStatusType.SENT); - logger.info("[{}] Cart with id {} processes successfully. Cart with status: {} and receipt with status: {}", - context.getFunctionName(), cartForReceipt.getId(), cartForReceipt.getStatus(), receipt.getStatus()); - cartForReceiptDocumentdb.setValue(cartForReceipt); } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/CartReceiptsCosmosClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/CartReceiptsCosmosClient.java index 4637beb6..85bdad8a 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/CartReceiptsCosmosClient.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/CartReceiptsCosmosClient.java @@ -10,4 +10,6 @@ public interface CartReceiptsCosmosClient { CartForReceipt getCartItem(String eventId) throws CartNotFoundException; CosmosItemResponse saveCart(CartForReceipt receipt); + + CosmosItemResponse updateCart(CartForReceipt receipt); } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/CartReceiptsCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/CartReceiptsCosmosClientImpl.java index fe182e8a..c899fd68 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/CartReceiptsCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/CartReceiptsCosmosClientImpl.java @@ -81,4 +81,17 @@ public CosmosItemResponse saveCart(CartForReceipt receipt) { return cosmosContainer.createItem(receipt); } + /** + * Update Cart For Receipt on CosmosDB database + * + * @param receipt Cart Data to save + * @return cart-to-receipts documents + */ + @Override + public CosmosItemResponse updateCart(CartForReceipt receipt) { + CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId); + CosmosContainer cosmosContainer = cosmosDatabase.getContainer(cartForReceiptContainerName); + return cosmosContainer.upsertItem(receipt); + } + } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/ReceiptCosmosClientImpl.java index a200a265..c2682ff9 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/ReceiptCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/client/impl/ReceiptCosmosClientImpl.java @@ -103,6 +103,4 @@ public CosmosItemResponse saveReceipts(Receipt receipt) { return cosmosContainer.createItem(receipt); } - - } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java index 5a8d86e7..da0a772a 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java @@ -38,6 +38,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; public class BizEventToReceiptServiceImpl implements BizEventToReceiptService { @@ -216,16 +217,22 @@ public void handleSaveCart(BizEvent bizEvent) { String transactionId = bizEvent.getTransactionDetails().getTransaction().getTransactionId(); CartForReceipt cartForReceipt; try { - cartForReceipt = cartReceiptsCosmosClient.getCartItem(String.valueOf(transactionId)); + cartForReceipt = cartReceiptsCosmosClient.getCartItem(transactionId); if (cartForReceipt == null) { throw new CartNotFoundException("Missing Cart"); } } catch (CartNotFoundException ignore) { cartForReceipt = CartForReceipt.builder().id(transactionId).status(CartStatusType.INSERTED).cartPaymentId(new HashSet<>()) .totalNotice(BizEventToReceiptUtils.getTotalNotice(bizEvent, null, null)).build(); + cartReceiptsCosmosClient.saveCart(cartForReceipt); + + return; } - cartForReceipt.getCartPaymentId().add(bizEvent.getId()); - cartReceiptsCosmosClient.saveCart(cartForReceipt); + + Set cartPaymentId = cartForReceipt.getCartPaymentId(); + cartPaymentId.add(bizEvent.getId()); + cartForReceipt.setCartPaymentId(cartPaymentId); + cartReceiptsCosmosClient.updateCart(cartForReceipt); } /** From 54839706a1f129bf9bdef6c311d6374e6a4f955d Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 10:05:07 +0100 Subject: [PATCH 06/17] [PRDP-311] Updated unit tests --- .../pdf/datastore/CartEventToReceiptTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java index e44cfa06..e1bc1f3a 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java @@ -79,7 +79,7 @@ public void releaseMocks() throws Exception { @Test void cartEventToReceiptSuccess() { - CartForReceipt cartForReceipt = getCartForReceipt(); + List cartForReceipt = Collections.singletonList(getCartForReceipt()); List bizEventList = new ArrayList<>(); bizEventList.add(generateValidBizEventWithAmount()); bizEventList.add(generateValidBizEventWithGrandTotal()); @@ -100,8 +100,8 @@ void cartEventToReceiptSuccess() { @Test void cartEventToReceiptSkipNotInStatusInserted() { - CartForReceipt cartForReceipt = getCartForReceipt(); - cartForReceipt.setStatus(CartStatusType.FAILED); + List cartForReceipt = Collections.singletonList(getCartForReceipt()); + cartForReceipt.get(0).setStatus(CartStatusType.FAILED); assertDoesNotThrow(() -> sut.run(cartForReceipt, receiptDocumentdb, cartForReceiptDocumentdb, contextMock)); verify(bizEventToReceiptServiceMock, never()).getCartBizEvents(anyString()); @@ -116,12 +116,12 @@ void cartEventToReceiptSkipNotInStatusInserted() { void cartEventToReceiptSkipNotAllBizEventsCollected() { Set bizEventIds = new HashSet<>(); bizEventIds.add("id"); - CartForReceipt cartForReceipt = CartForReceipt.builder() + List cartForReceipt = Collections.singletonList( CartForReceipt.builder() .id("123") .totalNotice(2) .status(CartStatusType.INSERTED) .cartPaymentId(bizEventIds) - .build(); + .build()); assertDoesNotThrow(() -> sut.run(cartForReceipt, receiptDocumentdb, cartForReceiptDocumentdb, contextMock)); @@ -135,7 +135,7 @@ void cartEventToReceiptSkipNotAllBizEventsCollected() { @Test void cartEventToReceiptFailToCreateReceiptForGenericException() { - CartForReceipt cartForReceipt = getCartForReceipt(); + List cartForReceipt = Collections.singletonList(getCartForReceipt()); Receipt receipt = new Receipt(); receipt.setStatus(ReceiptStatusType.FAILED); @@ -158,7 +158,7 @@ void cartEventToReceiptFailToCreateReceiptForGenericException() { @Test void cartEventToReceiptFailToCreateReceiptTokenizerThrowsException() throws PDVTokenizerException, JsonProcessingException { - CartForReceipt cartForReceipt = getCartForReceipt(); + List cartForReceipt = Collections.singletonList(getCartForReceipt()); Receipt receipt = new Receipt(); receipt.setStatus(ReceiptStatusType.FAILED); @@ -181,7 +181,7 @@ void cartEventToReceiptFailToCreateReceiptTokenizerThrowsException() throws PDVT @Test void cartEventToReceiptFailToSaveReceipt() { - CartForReceipt cartForReceipt = getCartForReceipt(); + List cartForReceipt = Collections.singletonList(getCartForReceipt()); when(bizEventToReceiptServiceMock.getCartBizEvents(anyString())).thenReturn(Collections.singletonList(generateValidBizEventWithAmount())); @@ -208,7 +208,7 @@ void cartEventToReceiptFailToSaveReceipt() { @Test void cartEventToReceiptFailToSendBizEventsOnQueue() { - CartForReceipt cartForReceipt = getCartForReceipt(); + List cartForReceipt = Collections.singletonList(getCartForReceipt()); when(bizEventToReceiptServiceMock.getCartBizEvents(anyString())).thenReturn(Collections.singletonList(generateValidBizEventWithAmount())); From 2d89d36c2909da4794e47938d2315c16e08f0ddf Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 10:55:28 +0100 Subject: [PATCH 07/17] [PRDP-311] Fixed delete cases --- .../src/features/receipt_pdf_datastore.feature | 4 ++-- .../step_definitions/receipt_pdf_datastore_step.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/integration-test/src/features/receipt_pdf_datastore.feature b/integration-test/src/features/receipt_pdf_datastore.feature index e2caee58..d7c80f51 100644 --- a/integration-test/src/features/receipt_pdf_datastore.feature +++ b/integration-test/src/features/receipt_pdf_datastore.feature @@ -6,13 +6,13 @@ Feature: All about payment events consumed by Azure functions receipt-pdf-datast Then the receipts datastore returns the receipt And the receipt has eventId "receipt-datastore-int-test-id-1" And the receipt has not the status "NOT_QUEUE_SENT" - And the receipt has not the status "FAILED" + And the receipt has not a datastore reason error message Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" Then the receipts datastore return the cart event - And the cart event has status SENT + And the cart event has status "SENT" And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" And the receipts datastore returns the receipt And the receipt has eventId "receipt-datastore-int-test-transactionId-2" diff --git a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js index 62cef491..d62c1029 100644 --- a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js @@ -28,9 +28,9 @@ After(async function () { if(this.cartId != null) { await deleteDocumentFromCartDatastore(this.cartId); } - if(this.listOfBizEventsIds.length > 0) { + if(this.listOfBizEventsIds?.length > 0) { for(bizEvent of this.listOfBizEventsIds){ - await deleteDocumentFromBizEventsDatastore(bizEvent.id); + await deleteDocumentFromBizEventsDatastore(bizEvent); } } this.eventId = null; @@ -75,7 +75,13 @@ Given('a cart event with id {string} containing the ids the bizEvents', async fu let cartResponse = await createDocumentInCartDatastore(id, this.listOfBizEventsIds); assert.strictEqual(cartResponse.statusCode, 201); - }); +}); + +When('biz event has been properly stored into receipt datastore after {int} ms with eventId {string}', async function (time, eventId) { + // boundary time spent by azure function to process event + await sleep(time); + this.responseToCheck = await getDocumentByIdFromReceiptsDatastore(eventId); +}); When('receipt has been properly stored into receipt datastore after {int} ms with eventId {string}', async function (time, id) { // boundary time spent by azure function to process event @@ -83,7 +89,6 @@ When('receipt has been properly stored into receipt datastore after {int} ms wit this.responseToCheck = await getDocumentByIdFromReceiptsDatastore(id); }); - When('cart event has been properly stored into receipt datastore after {int} ms with id {string}', async function (time, id) { // boundary time spent by azure function to process event await sleep(time); From 366ba85317865c1d62c8a402974361b65f511fd2 Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 10:56:01 +0100 Subject: [PATCH 08/17] [PRDP-311] Fixed cart save --- .../service/impl/BizEventToReceiptServiceImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java index da0a772a..c030205b 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java @@ -216,20 +216,26 @@ public void tokenizeFiscalCodes(BizEvent bizEvent, Receipt receipt, EventData ev public void handleSaveCart(BizEvent bizEvent) { String transactionId = bizEvent.getTransactionDetails().getTransaction().getTransactionId(); CartForReceipt cartForReceipt; + Set cartPaymentId = new HashSet<>(); try { cartForReceipt = cartReceiptsCosmosClient.getCartItem(transactionId); if (cartForReceipt == null) { throw new CartNotFoundException("Missing Cart"); } } catch (CartNotFoundException ignore) { - cartForReceipt = CartForReceipt.builder().id(transactionId).status(CartStatusType.INSERTED).cartPaymentId(new HashSet<>()) - .totalNotice(BizEventToReceiptUtils.getTotalNotice(bizEvent, null, null)).build(); + cartPaymentId.add(bizEvent.getId()); + cartForReceipt = CartForReceipt.builder() + .id(transactionId) + .status(CartStatusType.INSERTED) + .cartPaymentId(cartPaymentId) + .totalNotice(BizEventToReceiptUtils.getTotalNotice(bizEvent, null, null)) + .build(); cartReceiptsCosmosClient.saveCart(cartForReceipt); return; } - Set cartPaymentId = cartForReceipt.getCartPaymentId(); + cartPaymentId = cartForReceipt.getCartPaymentId(); cartPaymentId.add(bizEvent.getId()); cartForReceipt.setCartPaymentId(cartPaymentId); cartReceiptsCosmosClient.updateCart(cartForReceipt); From da797b354e59da89f932922322be91a35af7787e Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 12:15:47 +0100 Subject: [PATCH 09/17] [PRDP-311] Commented cart integration test --- .../features/receipt_pdf_datastore.feature | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/integration-test/src/features/receipt_pdf_datastore.feature b/integration-test/src/features/receipt_pdf_datastore.feature index d7c80f51..fa95de82 100644 --- a/integration-test/src/features/receipt_pdf_datastore.feature +++ b/integration-test/src/features/receipt_pdf_datastore.feature @@ -8,14 +8,14 @@ Feature: All about payment events consumed by Azure functions receipt-pdf-datast And the receipt has not the status "NOT_QUEUE_SENT" And the receipt has not a datastore reason error message - Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore - Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE - When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" - Then the receipts datastore return the cart event - And the cart event has status "SENT" - And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" - And the receipts datastore returns the receipt - And the receipt has eventId "receipt-datastore-int-test-transactionId-2" - And the receipt has not the status "NOT_QUEUE_SENT" - And the receipt has not a datastore reason error message + # Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore + # Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE + # When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" + # Then the receipts datastore return the cart event + # And the cart event has status "SENT" + # And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" + # And the receipts datastore returns the receipt + # And the receipt has eventId "receipt-datastore-int-test-transactionId-2" + # And the receipt has not the status "NOT_QUEUE_SENT" + # And the receipt has not a datastore reason error message \ No newline at end of file From 538955ad0ffbd7ab42797c5bc3a6112d65429e70 Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 16:05:07 +0100 Subject: [PATCH 10/17] [PRDP-311] Refactor cart function for input list --- .../pdf/datastore/CartEventToReceipt.java | 106 +++++++++--------- .../pdf/datastore/CartEventToReceiptTest.java | 26 ++--- 2 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java index ad2ca84e..ab2900e4 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceipt.java @@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import static it.gov.pagopa.receipt.pdf.datastore.utils.BizEventToReceiptUtils.isReceiptStatusValid; @@ -68,79 +69,82 @@ public void run( databaseName = "db", collectionName = "receipts", connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING") - OutputBinding receiptDocumentdb, + OutputBinding> receiptDocumentdb, @CosmosDBOutput( name = "CartReceiptDatastoreOutput", databaseName = "db", collectionName = "cart-for-receipts", connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING") - OutputBinding cartForReceiptDocumentdb, + OutputBinding> cartForReceiptDocumentdb, final ExecutionContext context ) { logger.info("[{}] function called at {}", context.getFunctionName(), LocalDateTime.now()); + List listOfCartEvents = new ArrayList<>(); + List listOfReceipt = new ArrayList<>(); for(CartForReceipt cartForReceipt : listCartForReceipt){ + if (cartForReceipt.getTotalNotice() != cartForReceipt.getCartPaymentId().size()) { logger.info("[{}] Not all items collected for cart with id {}, this event will be skipped", context.getFunctionName(), cartForReceipt.getId()); - return; + continue; } if (!cartForReceipt.getStatus().equals(CartStatusType.INSERTED)) { logger.info("[{}] Cart with id {} not in status {}, this event will be skipped", context.getFunctionName(), cartForReceipt.getId(), CartStatusType.INSERTED); - return; - } - - List bizEventList; - Receipt receipt; - - try { - bizEventList = this.bizEventToReceiptService.getCartBizEvents(cartForReceipt.getId()); - receipt = BizEventToReceiptUtils.createCartReceipt(bizEventList, bizEventToReceiptService, logger); - - } catch (Exception e) { - cartForReceipt.setStatus(CartStatusType.FAILED); - cartForReceipt.setReasonError(ReasonError.builder().code(500).message(e.getMessage()).build()); - cartForReceiptDocumentdb.setValue(cartForReceipt); - return; + } else { + List bizEventList; + Receipt receipt; + + try { + bizEventList = this.bizEventToReceiptService.getCartBizEvents(cartForReceipt.getId()); + receipt = BizEventToReceiptUtils.createCartReceipt(bizEventList, bizEventToReceiptService, logger); + + if (!isReceiptStatusValid(receipt)) { + logger.error("[{}] Failed to process cart with id {}: fail to tokenize fiscal codes", + context.getFunctionName(), cartForReceipt.getId()); + cartForReceipt.setStatus(CartStatusType.FAILED); + cartForReceipt.setReasonError(receipt.getReasonErr()); + } else { + // Add receipt to items to be saved on CosmosDB + this.bizEventToReceiptService.handleSaveReceipt(receipt); + + if (!isReceiptStatusValid(receipt)) { + logger.error("[{}] Failed to process cart with id {}: fail to save receipt", + context.getFunctionName(), cartForReceipt.getId()); + cartForReceipt.setStatus(CartStatusType.FAILED); + cartForReceipt.setReasonError(receipt.getReasonErr()); + } else{ + // Send biz event as message to queue (to be processed from the other function) + this.bizEventToReceiptService.handleSendMessageToQueue(bizEventList, receipt); + + if (!isReceiptStatusValid(receipt)) { + // save only if receipt save on cosmos or send on queue fail + listOfReceipt.add(receipt); + } + cartForReceipt.setStatus(CartStatusType.SENT); + logger.info("[{}] Cart with id {} processes successfully. Cart with status: {} and receipt with status: {}", + context.getFunctionName(), cartForReceipt.getId(), cartForReceipt.getStatus(), receipt.getStatus()); + + } + } + } catch (Exception e) { + cartForReceipt.setStatus(CartStatusType.FAILED); + cartForReceipt.setReasonError(ReasonError.builder().code(500).message(e.getMessage()).build()); + } + + listOfCartEvents.add(cartForReceipt); } - if (!isReceiptStatusValid(receipt)) { - logger.error("[{}] Failed to process cart with id {}: fail to tokenize fiscal codes", - context.getFunctionName(), cartForReceipt.getId()); - cartForReceipt.setStatus(CartStatusType.FAILED); - cartForReceipt.setReasonError(receipt.getReasonErr()); - cartForReceiptDocumentdb.setValue(cartForReceipt); - return; - } - - // Add receipt to items to be saved on CosmosDB - this.bizEventToReceiptService.handleSaveReceipt(receipt); - - if (!isReceiptStatusValid(receipt)) { - logger.error("[{}] Failed to process cart with id {}: fail to save receipt", - context.getFunctionName(), cartForReceipt.getId()); - cartForReceipt.setStatus(CartStatusType.FAILED); - cartForReceipt.setReasonError(receipt.getReasonErr()); - cartForReceiptDocumentdb.setValue(cartForReceipt); - return; - } - - // Send biz event as message to queue (to be processed from the other function) - this.bizEventToReceiptService.handleSendMessageToQueue(bizEventList, receipt); - - - if (!isReceiptStatusValid(receipt)) { - // save only if receipt save on cosmos or send on queue fail - receiptDocumentdb.setValue(receipt); - } - cartForReceipt.setStatus(CartStatusType.SENT); - logger.info("[{}] Cart with id {} processes successfully. Cart with status: {} and receipt with status: {}", - context.getFunctionName(), cartForReceipt.getId(), cartForReceipt.getStatus(), receipt.getStatus()); - cartForReceiptDocumentdb.setValue(cartForReceipt); } + if(!listOfCartEvents.isEmpty()){ + cartForReceiptDocumentdb.setValue(listOfCartEvents); + } + if(!listOfReceipt.isEmpty()){ + receiptDocumentdb.setValue(listOfReceipt); + } } } diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java index e1bc1f3a..f23654ab 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/CartEventToReceiptTest.java @@ -48,16 +48,16 @@ class CartEventToReceiptTest { private BizEventToReceiptService bizEventToReceiptServiceMock; @Captor - private ArgumentCaptor receiptCaptor; + private ArgumentCaptor> receiptCaptor; @Captor - private ArgumentCaptor cartCaptor; + private ArgumentCaptor> cartCaptor; @Spy - private OutputBinding receiptDocumentdb; + private OutputBinding> receiptDocumentdb; @Spy - private OutputBinding cartForReceiptDocumentdb; + private OutputBinding> cartForReceiptDocumentdb; @Mock private ExecutionContext contextMock; @@ -95,7 +95,7 @@ void cartEventToReceiptSuccess() { verify(receiptDocumentdb, never()).setValue(receiptCaptor.capture()); verify(cartForReceiptDocumentdb).setValue(cartCaptor.capture()); - assertEquals(CartStatusType.SENT, cartCaptor.getValue().getStatus()); + assertEquals(CartStatusType.SENT, cartCaptor.getValue().get(0).getStatus()); } @Test @@ -152,8 +152,8 @@ void cartEventToReceiptFailToCreateReceiptForGenericException() { verify(receiptDocumentdb, never()).setValue(receiptCaptor.capture()); verify(cartForReceiptDocumentdb).setValue(cartCaptor.capture()); - assertEquals(CartStatusType.FAILED, cartCaptor.getValue().getStatus()); - assertEquals(500, cartCaptor.getValue().getReasonError().getCode()); + assertEquals(CartStatusType.FAILED, cartCaptor.getValue().get(0).getStatus()); + assertEquals(500, cartCaptor.getValue().get(0).getReasonError().getCode()); } @Test @@ -176,7 +176,7 @@ void cartEventToReceiptFailToCreateReceiptTokenizerThrowsException() throws PDVT verify(receiptDocumentdb, never()).setValue(receiptCaptor.capture()); verify(cartForReceiptDocumentdb).setValue(cartCaptor.capture()); - assertEquals(CartStatusType.FAILED, cartCaptor.getValue().getStatus()); + assertEquals(CartStatusType.FAILED, cartCaptor.getValue().get(0).getStatus()); } @Test @@ -202,8 +202,8 @@ void cartEventToReceiptFailToSaveReceipt() { verify(receiptDocumentdb, never()).setValue(receiptCaptor.capture()); verify(cartForReceiptDocumentdb).setValue(cartCaptor.capture()); - assertEquals(CartStatusType.FAILED, cartCaptor.getValue().getStatus()); - assertEquals(REASON_ERROR, cartCaptor.getValue().getReasonError()); + assertEquals(CartStatusType.FAILED, cartCaptor.getValue().get(0).getStatus()); + assertEquals(REASON_ERROR, cartCaptor.getValue().get(0).getReasonError()); } @Test @@ -227,11 +227,11 @@ void cartEventToReceiptFailToSendBizEventsOnQueue() { verify(bizEventToReceiptServiceMock).handleSendMessageToQueue(anyList(), any()); verify(receiptDocumentdb).setValue(receiptCaptor.capture()); - assertEquals(ReceiptStatusType.FAILED, receiptCaptor.getValue().getStatus()); - assertEquals(REASON_ERROR, receiptCaptor.getValue().getReasonErr()); + assertEquals(ReceiptStatusType.FAILED, receiptCaptor.getValue().get(0).getStatus()); + assertEquals(REASON_ERROR, receiptCaptor.getValue().get(0).getReasonErr()); verify(cartForReceiptDocumentdb).setValue(cartCaptor.capture()); - assertEquals(CartStatusType.SENT, cartCaptor.getValue().getStatus()); + assertEquals(CartStatusType.SENT, cartCaptor.getValue().get(0).getStatus()); } private CartForReceipt getCartForReceipt() { From 94d4001080c9ccd6e48284c14aa056dcaeda47e7 Mon Sep 17 00:00:00 2001 From: Alessio Cialini Date: Tue, 9 Jan 2024 16:09:27 +0100 Subject: [PATCH 11/17] [PRDP-311] feat: introduced missing inserted_at field --- .../receipt/pdf/datastore/entity/cart/CartForReceipt.java | 2 ++ .../datastore/service/impl/BizEventToReceiptServiceImpl.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java index 2191abb8..71a2f19c 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java @@ -19,4 +19,6 @@ public class CartForReceipt { private Integer totalNotice; private CartStatusType status; private ReasonError reasonError; + private long inserted_at; + } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java index c030205b..4883a1b9 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java @@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory; import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Base64; import java.util.HashSet; @@ -229,6 +230,7 @@ public void handleSaveCart(BizEvent bizEvent) { .status(CartStatusType.INSERTED) .cartPaymentId(cartPaymentId) .totalNotice(BizEventToReceiptUtils.getTotalNotice(bizEvent, null, null)) + .inserted_at(System.currentTimeMillis()) .build(); cartReceiptsCosmosClient.saveCart(cartForReceipt); From 40563dbf0edd65915fd765d66d632d85239e889a Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 17:37:46 +0100 Subject: [PATCH 12/17] [PRDP-311] Fixed int test --- .../src/step_definitions/receipt_pdf_datastore_step.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js index d62c1029..86027757 100644 --- a/integration-test/src/step_definitions/receipt_pdf_datastore_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_datastore_step.js @@ -122,7 +122,7 @@ Then('the receipt has not the status {string}', function (targetStatus) { Then("the receipt has not a datastore reason error message", function(){ let receiptResponse = this.responseToCheck.resources[0]; if(receiptResponse?.reasonErr.message){ - let booleanResponseErr = receiptResponse.reasonErr.message.includes("BizEventToReceiptService"); + let booleanResponseErr = receiptResponse.reasonErr.message.includes("BizEventToReceiptService") || !receiptResponse?.event?.mount; assert.strictEqual(booleanResponseErr, false); } From 3c4008879410aec137ff6aee1b0c08dcca92bee9 Mon Sep 17 00:00:00 2001 From: svariant Date: Tue, 9 Jan 2024 17:38:08 +0100 Subject: [PATCH 13/17] [PRDP-311] Refactor inserted_at property --- .../receipt/pdf/datastore/entity/cart/CartForReceipt.java | 5 ++++- .../datastore/service/impl/BizEventToReceiptServiceImpl.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java index 71a2f19c..ee138c0b 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java @@ -8,6 +8,8 @@ import java.util.Set; +import com.fasterxml.jackson.annotation.JsonProperty; + @AllArgsConstructor @NoArgsConstructor @Builder @@ -19,6 +21,7 @@ public class CartForReceipt { private Integer totalNotice; private CartStatusType status; private ReasonError reasonError; - private long inserted_at; + @JsonProperty("inserted_at") + private long insertedAt; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java index 4883a1b9..d01e69ac 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java @@ -230,7 +230,7 @@ public void handleSaveCart(BizEvent bizEvent) { .status(CartStatusType.INSERTED) .cartPaymentId(cartPaymentId) .totalNotice(BizEventToReceiptUtils.getTotalNotice(bizEvent, null, null)) - .inserted_at(System.currentTimeMillis()) + .insertedAt(System.currentTimeMillis()) .build(); cartReceiptsCosmosClient.saveCart(cartForReceipt); From 66238535d68857c2a6510b0f9bf948294df113af Mon Sep 17 00:00:00 2001 From: svariant Date: Wed, 10 Jan 2024 11:06:40 +0100 Subject: [PATCH 14/17] [PRDP-311] Enabled Cart function in UAT & DEV --- helm/values-dev.yaml | 2 +- helm/values-uat.yaml | 2 +- .../features/receipt_pdf_datastore.feature | 20 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 70715d5b..4c03bfb5 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -104,7 +104,7 @@ microservice-chart: OTEL_TRACES_SAMPLER: "always_on" AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/opentelemetry-javaagent.jar -Xmx768m -XX:+UseG1GC" ECOMMERCE_FILTER_ENABLED: "true" - ENABLE_CART: "false" + ENABLE_CART: "true" envFieldRef: APP_NAME: "metadata.labels['app.kubernetes.io/instance']" APP_VERSION: "metadata.labels['app.kubernetes.io/version']" diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 3515dadd..32e8e9f6 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -104,7 +104,7 @@ microservice-chart: OTEL_TRACES_SAMPLER: "always_on" AZURE_FUNCTIONS_MESH_JAVA_OPTS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -Xmx768m -XX:+UseG1GC" ECOMMERCE_FILTER_ENABLED: "true" - ENABLE_CART: "false" + ENABLE_CART: "true" envFieldRef: APP_NAME: "metadata.labels['app.kubernetes.io/instance']" APP_VERSION: "metadata.labels['app.kubernetes.io/version']" diff --git a/integration-test/src/features/receipt_pdf_datastore.feature b/integration-test/src/features/receipt_pdf_datastore.feature index fa95de82..d7c80f51 100644 --- a/integration-test/src/features/receipt_pdf_datastore.feature +++ b/integration-test/src/features/receipt_pdf_datastore.feature @@ -8,14 +8,14 @@ Feature: All about payment events consumed by Azure functions receipt-pdf-datast And the receipt has not the status "NOT_QUEUE_SENT" And the receipt has not a datastore reason error message - # Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore - # Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE - # When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" - # Then the receipts datastore return the cart event - # And the cart event has status "SENT" - # And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" - # And the receipts datastore returns the receipt - # And the receipt has eventId "receipt-datastore-int-test-transactionId-2" - # And the receipt has not the status "NOT_QUEUE_SENT" - # And the receipt has not a datastore reason error message + Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore + Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE + When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" + Then the receipts datastore return the cart event + And the cart event has status "SENT" + And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" + And the receipts datastore returns the receipt + And the receipt has eventId "receipt-datastore-int-test-transactionId-2" + And the receipt has not the status "NOT_QUEUE_SENT" + And the receipt has not a datastore reason error message \ No newline at end of file From 1060bc232a2f8c8e0c87c6194b6182bfd1de4d79 Mon Sep 17 00:00:00 2001 From: svariant Date: Wed, 10 Jan 2024 11:14:50 +0100 Subject: [PATCH 15/17] [PRDP-311] Fixed unit tests --- .../pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java | 2 +- .../service/impl/BizEventToReceiptServiceImplTest.java | 4 ++-- .../pdf/datastore/utils/BizEventToReceiptUtilsTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java index 68e1b5b5..e15340f6 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/BizEventToReceiptTest.java @@ -480,7 +480,7 @@ void runOk_CartToCreate_ExistingCart() throws CartNotFoundException { verify(documentdb, never()).setValue(any()); verify(cartReceiptsCosmosClient).getCartItem(any()); - verify(cartReceiptsCosmosClient).saveCart(cartForReceiptArgumentCaptor.capture()); + verify(cartReceiptsCosmosClient).updateCart(cartForReceiptArgumentCaptor.capture()); CartForReceipt cartForReceipt = cartForReceiptArgumentCaptor.getValue(); assertEquals(2, cartForReceipt.getCartPaymentId().size()); } diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImplTest.java index 64b3d48b..dfbaf2ba 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImplTest.java @@ -3,7 +3,7 @@ import com.azure.cosmos.models.FeedResponse; import com.microsoft.azure.functions.ExecutionContext; import it.gov.pagopa.receipt.pdf.datastore.client.BizEventCosmosClient; -import it.gov.pagopa.receipt.pdf.datastore.client.impl.CartReceiptsCosmosClientImpl; +import it.gov.pagopa.receipt.pdf.datastore.client.CartReceiptsCosmosClient; import it.gov.pagopa.receipt.pdf.datastore.client.impl.ReceiptCosmosClientImpl; import it.gov.pagopa.receipt.pdf.datastore.client.impl.ReceiptQueueClientImpl; import it.gov.pagopa.receipt.pdf.datastore.entity.event.BizEvent; @@ -36,7 +36,7 @@ class BizEventToReceiptServiceImplTest { @Mock private ReceiptCosmosClientImpl receiptCosmosClient; @Mock - private CartReceiptsCosmosClientImpl cartReceiptsCosmosClient; + private CartReceiptsCosmosClient cartReceiptsCosmosClient; @Mock private BizEventCosmosClient bizEventCosmosClientMock; @Mock diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/utils/BizEventToReceiptUtilsTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/utils/BizEventToReceiptUtilsTest.java index 03fe8128..ad9f621b 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/datastore/utils/BizEventToReceiptUtilsTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/datastore/utils/BizEventToReceiptUtilsTest.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.microsoft.azure.functions.HttpStatus; import it.gov.pagopa.receipt.pdf.datastore.client.BizEventCosmosClient; -import it.gov.pagopa.receipt.pdf.datastore.client.impl.CartReceiptsCosmosClientImpl; +import it.gov.pagopa.receipt.pdf.datastore.client.CartReceiptsCosmosClient; import it.gov.pagopa.receipt.pdf.datastore.client.impl.ReceiptCosmosClientImpl; import it.gov.pagopa.receipt.pdf.datastore.client.impl.ReceiptQueueClientImpl; import it.gov.pagopa.receipt.pdf.datastore.entity.event.BizEvent; @@ -53,7 +53,7 @@ class BizEventToReceiptUtilsTest { @Mock private ReceiptCosmosClientImpl receiptCosmosClient; @Mock - private CartReceiptsCosmosClientImpl cartReceiptsCosmosClient; + private CartReceiptsCosmosClient cartReceiptsCosmosClient; @Mock private BizEventCosmosClient bizEventCosmosClientMock; @Mock From 512f72f8dd7b7a6f26a9930605a724bb530795a2 Mon Sep 17 00:00:00 2001 From: svariant Date: Wed, 10 Jan 2024 11:23:53 +0100 Subject: [PATCH 16/17] [PRDP-311] Increased int test waiting time --- integration-test/src/features/receipt_pdf_datastore.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test/src/features/receipt_pdf_datastore.feature b/integration-test/src/features/receipt_pdf_datastore.feature index d7c80f51..862d34e1 100644 --- a/integration-test/src/features/receipt_pdf_datastore.feature +++ b/integration-test/src/features/receipt_pdf_datastore.feature @@ -10,7 +10,7 @@ Feature: All about payment events consumed by Azure functions receipt-pdf-datast Scenario: a list of biz event from the same cart stored on biz-events datastore is stored into receipts datastore Given a list of 5 bizEvents starting with id "receipt-datastore-int-test-id-2" and transactionId "receipt-datastore-int-test-transactionId-2" stored on biz-events datastore with status DONE - When cart event has been properly stored into receipt datastore after 10000 ms with id "receipt-datastore-int-test-transactionId-2" + When cart event has been properly stored into receipt datastore after 20000 ms with id "receipt-datastore-int-test-transactionId-2" Then the receipts datastore return the cart event And the cart event has status "SENT" And receipt has been properly stored into receipt datastore after 0 ms with eventId "receipt-datastore-int-test-transactionId-2" From 8758154ed25d04d515d0b882c04f5b1cf2d01074 Mon Sep 17 00:00:00 2001 From: svariant Date: Wed, 10 Jan 2024 11:42:16 +0100 Subject: [PATCH 17/17] [PRDP-311] Removed JSONproperty for Cart entity --- .../receipt/pdf/datastore/entity/cart/CartForReceipt.java | 6 +----- .../service/impl/BizEventToReceiptServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java index ee138c0b..b0356644 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/entity/cart/CartForReceipt.java @@ -7,9 +7,6 @@ import lombok.NoArgsConstructor; import java.util.Set; - -import com.fasterxml.jackson.annotation.JsonProperty; - @AllArgsConstructor @NoArgsConstructor @Builder @@ -21,7 +18,6 @@ public class CartForReceipt { private Integer totalNotice; private CartStatusType status; private ReasonError reasonError; - @JsonProperty("inserted_at") - private long insertedAt; + private long inserted_at; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java index d01e69ac..4883a1b9 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/impl/BizEventToReceiptServiceImpl.java @@ -230,7 +230,7 @@ public void handleSaveCart(BizEvent bizEvent) { .status(CartStatusType.INSERTED) .cartPaymentId(cartPaymentId) .totalNotice(BizEventToReceiptUtils.getTotalNotice(bizEvent, null, null)) - .insertedAt(System.currentTimeMillis()) + .inserted_at(System.currentTimeMillis()) .build(); cartReceiptsCosmosClient.saveCart(cartForReceipt);