Skip to content

Commit

Permalink
[MODFIN-379] - Create API for fund updates logs (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm authored Nov 12, 2024
1 parent e45cbc1 commit 3b5dde8
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 2 deletions.
75 changes: 74 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,37 @@
}
]
},
{
"id": "finance.fund-update-logs",
"version": "1.0",
"handlers": [
{
"methods": ["GET"],
"pathPattern": "/finance/fund-update-logs",
"permissionsRequired": ["finance.fund-update-logs.collection.get"]
},
{
"methods": ["GET"],
"pathPattern": "/finance/fund-update-logs/{id}",
"permissionsRequired": ["finance.fund-update-logs.item.get"]
},
{
"methods": ["POST"],
"pathPattern": "/finance/fund-update-logs",
"permissionsRequired": ["finance.fund-update-logs.item.post"]
},
{
"methods": ["PUT"],
"pathPattern": "/finance/fund-update-logs/{id}",
"permissionsRequired": ["finance.fund-update-logs.item.put"]
},
{
"methods": ["DELETE"],
"pathPattern": "/finance/fund-update-logs/{id}",
"permissionsRequired": ["finance.fund-update-logs.item.delete"]
}
]
},
{
"id": "_jsonSchemas",
"version": "1.0",
Expand Down Expand Up @@ -818,6 +849,10 @@
{
"id": "finance-storage.ledger-rollovers-errors",
"version":"1.0"
},
{
"id": "finance-storage.fund-update-logs",
"version":"1.0"
}
],
"optional": [
Expand Down Expand Up @@ -1266,6 +1301,43 @@
"displayName" : "Pairs fund code - expense class code",
"description" : "Return collection of the pairs <fund code, expense classes>"
},
{
"permissionName" : "finance.fund-update-logs.collection.get",
"displayName" : "Fund update logs collection get",
"description" : "Return collection of the fund update logs"
},
{
"permissionName": "finance.fund-update-logs.item.get",
"displayName": "Fund update logs item get",
"description": "Return a fund update log"
},
{
"permissionName": "finance.fund-update-logs.item.post",
"displayName": "Fund update logs item post",
"description": "Create a fund update log"
},
{
"permissionName": "finance.fund-update-logs.item.put",
"displayName": "Fund update logs item put",
"description": "Update a fund update log"
},
{
"permissionName": "finance.fund-update-logs.item.delete",
"displayName": "Fund update logs item delete",
"description": "Delete a fund update log"
},
{
"permissionName": "finance.fund-update-logs.all",
"displayName": "Fund update logs - all permissions",
"description": "All fund update logs permissions",
"subPermissions": [
"finance.fund-update-logs.collection.get",
"finance.fund-update-logs.item.get",
"finance.fund-update-logs.item.post",
"finance.fund-update-logs.item.put",
"finance.fund-update-logs.item.delete"
]
},
{
"permissionName": "finance.all",
"displayName": "Finance module - all permissions",
Expand All @@ -1284,7 +1356,8 @@
"finance.exchange-rate.item.get",
"finance.calculate-exchange.item.get",
"finance.expense-classes.all",
"finance.acquisitions-units-assignments.all"
"finance.acquisitions-units-assignments.all",
"finance.fund-update-logs.all"
],
"visible": false
},
Expand Down
57 changes: 57 additions & 0 deletions ramls/fund-update-log.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#%RAML 1.0
title: Finance - fund update logs
version: v1
protocols: [ HTTP, HTTPS ]
baseUri: https://github.com/folio-org/mod-finance

documentation:
- title: Fund update logs APIs
content: This documents the API calls that can be made to manage fund update logs

types:
errors: !include raml-util/schemas/errors.schema
fund-update-log: !include acq-models/mod-finance/schemas/fund_update_log.json
fund-update-log-collection: !include acq-models/mod-finance/schemas/fund_update_log_collection.json
example-fund-update-log: !include acq-models/mod-finance/examples/fund_update_log.sample
example-fund-update-log-collection: !include acq-models/mod-finance/examples/fund_update_log_collection.sample
UUID:
type: string
pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$

traits:
pageable: !include raml-util/traits/pageable.raml
searchable: !include raml-util/traits/searchable.raml
validate: !include raml-util/traits/validation.raml

resourceTypes:
collection: !include raml-util/rtypes/collection.raml
collection-item: !include raml-util/rtypes/item-collection.raml


/finance/fund-update-logs:
displayName: Fund update logs APIs
description: Fund update logs
type:
collection:
schemaItem: fund-update-log
schemaCollection: fund-update-log-collection
exampleItem: example-fund-update-log
exampleCollection: example-fund-update-log-collection
post:
is: [validate]
get:
is: [
searchable: {description: "with valid searchable fields: for example jobName", example: "[\"jobName\", \"fund update\", \"=\"]"},
pageable
]
/{id}:
uriParameters:
id:
description: The UUID of a fund update log
type: UUID
type:
collection-item:
schema: fund-update-log
exampleItem: example-fund-update-log
put:
is: [validate]
6 changes: 6 additions & 0 deletions src/main/java/org/folio/config/ServicesConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.folio.services.fund.FundDetailsService;
import org.folio.services.fund.FundFiscalYearService;
import org.folio.services.fund.FundService;
import org.folio.services.fund.FundUpdateLogService;
import org.folio.services.group.GroupExpenseClassTotalsService;
import org.folio.services.group.GroupFiscalYearTotalsService;
import org.folio.services.group.GroupFundFiscalYearService;
Expand Down Expand Up @@ -210,4 +211,9 @@ FundCodeExpenseClassesService fundCodeExpenseClassesService(BudgetService budget
return new FundCodeExpenseClassesService(budgetService, budgetExpenseClassService,
fundService, ledgerService, fiscalYearService, ledgerDetailsService, expenseClassService);
}

@Bean
FundUpdateLogService fundUpdateLogService(RestClient restClient) {
return new FundUpdateLogService(restClient);
}
}
89 changes: 89 additions & 0 deletions src/main/java/org/folio/rest/impl/FundUpdateLogsApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.folio.rest.impl;

import static io.vertx.core.Future.succeededFuture;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.folio.rest.util.ErrorCodes.MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY;
import static org.folio.rest.util.HelperUtils.OKAPI_URL;
import static org.folio.rest.util.ResourcePathResolver.FUND_UPDATE_LOGS;
import static org.folio.rest.util.ResourcePathResolver.resourceByIdPath;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import java.util.Map;
import javax.ws.rs.core.Response;
import org.folio.rest.annotations.Validate;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.exception.HttpException;
import org.folio.rest.jaxrs.model.FundUpdateLog;
import org.folio.rest.jaxrs.resource.FinanceFundUpdateLogs;
import org.folio.services.fund.FundUpdateLogService;
import org.folio.spring.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;

public class FundUpdateLogsApi extends BaseApi implements FinanceFundUpdateLogs {

@Autowired
private FundUpdateLogService fundUpdateLogService;

public FundUpdateLogsApi() {
SpringContextUtil.autowireDependencies(this, Vertx.currentContext());
}

@Override
@Validate
public void getFinanceFundUpdateLogs(String query, String totalRecords, int offset, int limit,
Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
fundUpdateLogService.getFundUpdateLogs(query, offset, limit, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(logs -> asyncResultHandler.handle(succeededFuture(buildOkResponse(logs))))
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail));
}

@Override
@Validate
public void getFinanceFundUpdateLogsById(String id, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
fundUpdateLogService.getFundUpdateLogById(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(log -> asyncResultHandler.handle(succeededFuture(buildOkResponse(log))))
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail));
}

@Override
@Validate
public void postFinanceFundUpdateLogs(FundUpdateLog entity, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> handler, Context vertxContext) {
fundUpdateLogService.createFundUpdateLog(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(log -> handler.handle(succeededFuture(buildResponseWithLocation(
okapiHeaders.get(OKAPI_URL), resourceByIdPath(FUND_UPDATE_LOGS, log.getId()), log))))
.onFailure(fail -> handleErrorResponse(handler, fail));
}

@Override
@Validate
public void putFinanceFundUpdateLogsById(String id, FundUpdateLog entity, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

if (isEmpty(entity.getId())) {
entity.setId(id);
} else if (!id.equals(entity.getId())) {
asyncResultHandler.handle(succeededFuture(buildErrorResponse(
new HttpException(422, MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY))));
return;
}

fundUpdateLogService.updateFundUpdateLog(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(updatedLog -> asyncResultHandler.handle(succeededFuture(buildNoContentResponse())))
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail));
}

@Override
@Validate
public void deleteFinanceFundUpdateLogsById(String id, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
fundUpdateLogService.deleteFundUpdateLog(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(deletedLog -> asyncResultHandler.handle(succeededFuture(buildNoContentResponse())))
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail));
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/folio/rest/util/ResourcePathResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ private ResourcePathResolver() {
public static final String BUDGETS_STORAGE = "budgets";
public static final String FUNDS_STORAGE = "funds";
public static final String FUND_TYPES = "fundTypes";
public static final String FUND_UPDATE_LOGS = "fundUpdateLogs";
public static final String GROUP_FUND_FISCAL_YEARS = "groupFundFiscalYears";
public static final String FISCAL_YEARS_STORAGE = "fiscalYears";
public static final String LEDGERS_STORAGE = "ledgers";
Expand All @@ -39,6 +40,7 @@ private ResourcePathResolver() {
apis.put(BUDGETS_STORAGE, "/finance-storage/budgets");
apis.put(FUNDS_STORAGE, "/finance-storage/funds");
apis.put(FUND_TYPES, "/finance-storage/fund-types");
apis.put(FUND_UPDATE_LOGS, "/finance-storage/fund-update-logs");
apis.put(GROUP_FUND_FISCAL_YEARS, "/finance-storage/group-fund-fiscal-years");
apis.put(FISCAL_YEARS_STORAGE, "/finance-storage/fiscal-years");
apis.put(LEDGERS_STORAGE, "/finance-storage/ledgers");
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/org/folio/services/fund/FundUpdateLogService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.folio.services.fund;

import static org.folio.rest.util.ResourcePathResolver.FUND_UPDATE_LOGS;
import static org.folio.rest.util.ResourcePathResolver.resourceByIdPath;
import static org.folio.rest.util.ResourcePathResolver.resourcesPath;

import io.vertx.core.Future;
import org.folio.rest.core.RestClient;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.core.models.RequestEntry;
import org.folio.rest.jaxrs.model.FundUpdateLog;
import org.folio.rest.jaxrs.model.FundUpdateLogCollection;

public class FundUpdateLogService {

private final RestClient restClient;

public FundUpdateLogService(RestClient restClient) {
this.restClient = restClient;
}

public Future<FundUpdateLogCollection> getFundUpdateLogs(String query, int offset, int limit,
RequestContext requestContext) {
var requestEntry = new RequestEntry(resourcesPath(FUND_UPDATE_LOGS))
.withOffset(offset).withLimit(limit).withQuery(query);
return restClient.get(requestEntry.buildEndpoint(), FundUpdateLogCollection.class, requestContext);
}

public Future<FundUpdateLog> getFundUpdateLogById(String jobId, RequestContext requestContext) {
return restClient.get(resourceByIdPath(FUND_UPDATE_LOGS, jobId), FundUpdateLog.class, requestContext);
}

public Future<FundUpdateLog> createFundUpdateLog(FundUpdateLog fundUpdateLog, RequestContext requestContext) {
return restClient.post(resourcesPath(FUND_UPDATE_LOGS), fundUpdateLog, FundUpdateLog.class, requestContext);
}

public Future<Void> updateFundUpdateLog(FundUpdateLog fundUpdateLog, RequestContext requestContext) {
return restClient.put(resourceByIdPath(FUND_UPDATE_LOGS, fundUpdateLog.getId()), fundUpdateLog, requestContext);
}

public Future<Void> deleteFundUpdateLog(String jobId, RequestContext requestContext) {
return restClient.delete(resourceByIdPath(FUND_UPDATE_LOGS, jobId), requestContext);
}
}
Loading

0 comments on commit 3b5dde8

Please sign in to comment.