From 177eeac6c7fdd20b39b584703739d85102845b33 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Tue, 3 Dec 2024 12:42:38 +0500 Subject: [PATCH] [MODFIN-381] - Implement endpoint to process FY finance bulk update --- descriptors/ModuleDescriptor-template.json | 24 +++++++++++- ramls/acq-models | 2 +- ramls/finance-data.raml | 35 ++++++++++++++++- .../org/folio/rest/impl/FinanceDataApi.java | 9 +++++ .../financedata/FinanceDataService.java | 38 +++++++++++++++++++ 5 files changed, 105 insertions(+), 3 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 0d5895d2..f272d529 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -804,6 +804,14 @@ "acquisitions-units-storage.units.collection.get", "acquisitions-units-storage.memberships.collection.get" ] + }, + { + "methods": ["PUT"], + "pathPattern": "/finance/finance-data", + "permissionsRequired": ["finance.finance-data.collection.put"], + "modulePermissions": [ + "finance-storage.finance-data.collection.put" + ] } ] }, @@ -1378,6 +1386,20 @@ "displayName": "Finances - get finance data collection", "description": "Get finance data collection" }, + { + "permissionName": "finance.finance-data.collection.put", + "displayName": "Finances - update finance data collection", + "description": "Update finance data collection" + }, + { + "permissionName": "finance.finance-data.all", + "displayName": "Finance data - all permissions", + "description": "All finance data permissions", + "subPermissions": [ + "finance.finance-data.collection.get", + "finance.finance-data.collection.put" + ] + }, { "permissionName": "finance.all", "displayName": "Finance module - all permissions", @@ -1398,7 +1420,7 @@ "finance.expense-classes.all", "finance.acquisitions-units-assignments.all", "finance.fund-update-logs.all", - "finance.finance-data.collection.get" + "finance.finance-data.all" ], "visible": false }, diff --git a/ramls/acq-models b/ramls/acq-models index 0d8f736a..f09326b4 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit 0d8f736a3f2b5401a5cfad20a95bd831843f77a6 +Subproject commit f09326b40c4ce0ea9e27ccd0fd4fcfa792d3c173 diff --git a/ramls/finance-data.raml b/ramls/finance-data.raml index 6d807495..8438f3c7 100644 --- a/ramls/finance-data.raml +++ b/ramls/finance-data.raml @@ -26,7 +26,7 @@ resourceTypes: /finance/finance-data: type: collection-get: - exampleCollection: !include acq-models/mod-finance/examples/fy_finance_data_collection.sample + exampleCollection: !include acq-models/mod-finance/examples/fy_finance_data_collection_get.sample schemaCollection: fy-finance-data-collection get: description: Get finance data @@ -34,4 +34,37 @@ resourceTypes: searchable: { description: "with valid searchable fields: for example fiscalYearId", example: "[\"fiscalYearId\", \"7a4c4d30-3b63-4102-8e2d-3ee5792d7d02\", \"=\"]" }, pageable ] + put: + description: Update finance, budget as a bulk + is: [ validate ] + body: + application/json: + type: fy-finance-data-collection + example: !include acq-models/mod-finance/examples/fy_finance_data_collection_put.sample + responses: + 204: + description: "Items successfully updated" + 404: + description: "One or more items not found" + body: + text/plain: + example: | + "One or more items not found" + 400: + description: "Bad request, e.g. malformed request body or query parameter. Details of the error (e.g. name of the parameter or line/character number with malformed data) provided in the response." + body: + text/plain: + example: | + "unable to update items -- malformed JSON at 13:4" + 409: + description: "Optimistic locking version conflict" + body: + text/plain: + example: "version conflict" + 500: + description: "Internal server error, e.g. due to misconfiguration" + body: + text/plain: + example: "internal server error, contact administrator" + diff --git a/src/main/java/org/folio/rest/impl/FinanceDataApi.java b/src/main/java/org/folio/rest/impl/FinanceDataApi.java index 70b5c4ac..405c6aec 100644 --- a/src/main/java/org/folio/rest/impl/FinanceDataApi.java +++ b/src/main/java/org/folio/rest/impl/FinanceDataApi.java @@ -10,6 +10,7 @@ import javax.ws.rs.core.Response; import org.folio.rest.annotations.Validate; import org.folio.rest.core.models.RequestContext; +import org.folio.rest.jaxrs.model.FyFinanceDataCollection; import org.folio.rest.jaxrs.resource.FinanceFinanceData; import org.folio.services.financedata.FinanceDataService; import org.folio.spring.SpringContextUtil; @@ -34,4 +35,12 @@ public void getFinanceFinanceData(String query, String totalRecords, int offset, .onSuccess(financeData -> asyncResultHandler.handle(succeededFuture(buildOkResponse(financeData)))) .onFailure(fail -> handleErrorResponse(asyncResultHandler, fail)); } + + @Override + @Validate + public void putFinanceFinanceData(FyFinanceDataCollection entity, Map okapiHeaders, Handler> asyncResultHandler, Context vertxContext) { + financeDataService.putFinanceData(entity, new RequestContext(vertxContext, okapiHeaders)) + .onSuccess(v -> asyncResultHandler.handle(succeededFuture(buildNoContentResponse()))) + .onFailure(fail -> handleErrorResponse(asyncResultHandler, fail)); + } } diff --git a/src/main/java/org/folio/services/financedata/FinanceDataService.java b/src/main/java/org/folio/services/financedata/FinanceDataService.java index 8d68415f..0c3fe855 100644 --- a/src/main/java/org/folio/services/financedata/FinanceDataService.java +++ b/src/main/java/org/folio/services/financedata/FinanceDataService.java @@ -35,5 +35,43 @@ private Future getFinanceData(String query, int offset, .withQuery(query); return restClient.get(requestEntry.buildEndpoint(), FyFinanceDataCollection.class, requestContext); } + + public Future putFinanceData(FyFinanceDataCollection entity, RequestContext requestContext) { + // 1. Validate + validateFinanceData(entity); + + // 2. Apply calculation with allocating new value(allocation transaction should be created): + calculateAllocation(); + + // 3. Send request to update finance data + updateFinanceData(entity, requestContext); + + // 4. Invoke Bulk Transactions API to create allocation transactions + processTransaction(entity, requestContext); + + // 5. Invoke storage actions logs endpoint to save request payload + status metadata + recordsCount + processLogs(entity, requestContext); + return null; + } + + private void validateFinanceData(FyFinanceDataCollection entity) { + // validate entity + } + + private void calculateAllocation() { + // calculate allocation + } + + private void updateFinanceData(FyFinanceDataCollection entity, RequestContext requestContext) { + // send request to update finance data + } + + private void processTransaction(FyFinanceDataCollection entity, RequestContext requestContext) { + // invoke Bulk Transactions API to create allocation transactions + } + + private void processLogs(FyFinanceDataCollection entity, RequestContext requestContext) { + // invoke storage actions logs endpoint to save request payload + status metadata + recordsCount + } }