Skip to content

Commit

Permalink
[MODFIN-381] - Implement endpoint to process FY finance bulk update
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Dec 3, 2024
1 parent f38fea2 commit 177eeac
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
24 changes: 23 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
},
Expand Down Expand Up @@ -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",
Expand All @@ -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
},
Expand Down
35 changes: 34 additions & 1 deletion ramls/finance-data.raml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,45 @@ 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
is: [
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"


9 changes: 9 additions & 0 deletions src/main/java/org/folio/rest/impl/FinanceDataApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
financeDataService.putFinanceData(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(v -> asyncResultHandler.handle(succeededFuture(buildNoContentResponse())))
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,43 @@ private Future<FyFinanceDataCollection> getFinanceData(String query, int offset,
.withQuery(query);
return restClient.get(requestEntry.buildEndpoint(), FyFinanceDataCollection.class, requestContext);
}

public Future<Void> 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
}
}

0 comments on commit 177eeac

Please sign in to comment.