-
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 fund updates logs (#261)
- Loading branch information
Showing
10 changed files
with
335 additions
and
2 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
5 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,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] |
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,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)); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/org/folio/services/fund/FundUpdateLogService.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,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); | ||
} | ||
} |
Oops, something went wrong.