-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODFIN-379] - Create API for retrieve finance data (#262)
* [MODFIN-379] - Create API for fund updates logs * Use without acq Units restrictions * [MODFIN-388] - Implement endpoint to return all finance data for FY through acqUnitRestriciton * Added to api test suite * Fixed acqUnitsRestriction and added tests * remove unused variable * fix unit test * change acq-models to master * Fix acqUnitRestriction cql * Add required module permissions * Add comment
- Loading branch information
Showing
14 changed files
with
531 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule acq-models
updated
21 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#%RAML 1.0 | ||
title: Finance - finance data | ||
version: v1 | ||
protocols: [ HTTP, HTTPS ] | ||
baseUri: https://github.com/folio-org/mod-finance | ||
|
||
documentation: | ||
- title: Finance data APIs | ||
content: This documents the API calls that can be made to manage finance data | ||
|
||
types: | ||
errors: !include raml-util/schemas/errors.schema | ||
fy-finance-data-collection: !include acq-models/mod-finance/schemas/fy_finance_data_collection.json | ||
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-get: !include raml-util/rtypes/collection-get.raml | ||
|
||
/finance/finance-data: | ||
type: | ||
collection-get: | ||
exampleCollection: !include acq-models/mod-finance/examples/fy_finance_data_collection.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 | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.folio.rest.impl; | ||
|
||
import static io.vertx.core.Future.succeededFuture; | ||
|
||
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.jaxrs.resource.FinanceFinanceData; | ||
import org.folio.services.financedata.FinanceDataService; | ||
import org.folio.spring.SpringContextUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class FinanceDataApi extends BaseApi implements FinanceFinanceData { | ||
|
||
@Autowired | ||
private FinanceDataService financeDataService; | ||
|
||
public FinanceDataApi() { | ||
SpringContextUtil.autowireDependencies(this, Vertx.currentContext()); | ||
} | ||
|
||
@Override | ||
@Validate | ||
public void getFinanceFinanceData(String query, String totalRecords, int offset, int limit, | ||
Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, | ||
Context vertxContext) { | ||
financeDataService.getFinanceDataWithAcqUnitsRestriction(query, offset, limit, | ||
new RequestContext(vertxContext, okapiHeaders)) | ||
.onSuccess(financeData -> asyncResultHandler.handle(succeededFuture(buildOkResponse(financeData)))) | ||
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/folio/services/financedata/FinanceDataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.folio.services.financedata; | ||
|
||
import static org.folio.rest.util.HelperUtils.combineCqlExpressions; | ||
import static org.folio.rest.util.ResourcePathResolver.FINANCE_DATA_STORAGE; | ||
import static org.folio.rest.util.ResourcePathResolver.resourcesPath; | ||
|
||
import io.vertx.core.Future; | ||
import org.apache.commons.lang3.StringUtils; | ||
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.FyFinanceDataCollection; | ||
import org.folio.services.protection.AcqUnitsService; | ||
|
||
public class FinanceDataService { | ||
private final RestClient restClient; | ||
private final AcqUnitsService acqUnitsService; | ||
|
||
public FinanceDataService(RestClient restClient, AcqUnitsService acqUnitsService) { | ||
this.restClient = restClient; | ||
this.acqUnitsService = acqUnitsService; | ||
} | ||
|
||
public Future<FyFinanceDataCollection> getFinanceDataWithAcqUnitsRestriction(String query, int offset, int limit, | ||
RequestContext requestContext) { | ||
return acqUnitsService.buildAcqUnitsCqlClauseForFinanceData(requestContext) | ||
.map(clause -> StringUtils.isEmpty(query) ? clause : combineCqlExpressions("and", clause, query)) | ||
.compose(effectiveQuery -> getFinanceData(effectiveQuery, offset, limit, requestContext)); | ||
} | ||
|
||
private Future<FyFinanceDataCollection> getFinanceData(String query, int offset, int limit, RequestContext requestContext) { | ||
var requestEntry = new RequestEntry(resourcesPath(FINANCE_DATA_STORAGE)) | ||
.withOffset(offset) | ||
.withLimit(limit) | ||
.withQuery(query); | ||
return restClient.get(requestEntry.buildEndpoint(), FyFinanceDataCollection.class, requestContext); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.