From 57bc8866212725a8438ffe424631f8621c13bb3f Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Mon, 20 Jan 2025 18:08:18 +0500 Subject: [PATCH 1/2] [MODORDERS-1237]. Create a new API and wrapper model for Claiming with an Organization Id --- descriptors/ModuleDescriptor-template.json | 40 ++++++++++++++++ ramls/wrapper-pieces.raml | 46 +++++++++++++++++++ .../org/folio/config/ApplicationConfig.java | 9 ++++ .../orders/utils/ResourcePathResolver.java | 2 + .../org/folio/rest/impl/WrapperPiecesAPI.java | 44 ++++++++++++++++++ .../service/pieces/PieceStorageService.java | 8 ++-- .../pieces/WrapperPieceStorageService.java | 45 ++++++++++++++++++ 7 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 ramls/wrapper-pieces.raml create mode 100644 src/main/java/org/folio/rest/impl/WrapperPiecesAPI.java create mode 100644 src/main/java/org/folio/service/pieces/WrapperPieceStorageService.java diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index a25b9ba87..22d6f1ac8 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -665,6 +665,22 @@ } ] }, + { + "id": "wrapper-pieces", + "version": "1.0", + "handlers": [ + { + "methods": ["GET"], + "pathPattern": "/orders/wrapper-pieces", + "permissionsRequired": ["orders.wrapper-pieces.collection.get"] + }, + { + "methods": ["GET"], + "pathPattern": "/orders/wrapper-pieces/{id}", + "permissionsRequired": ["orders.wrapper-pieces.item.get"] + } + ] + }, { "id": "acquisition-methods", "version": "1.0", @@ -1263,6 +1279,10 @@ "id": "orders-storage.pieces", "version": "5.0" }, + { + "id": "orders-storage.wrapper-pieces", + "version": "1.0" + }, { "id": "orders-storage.receiving-history", "version": "4.0" @@ -1599,6 +1619,25 @@ "orders.piece-requests.collection.get" ] }, + { + "permissionName" : "orders.wrapper-pieces.collection.get", + "displayName" : "orders.wrapper-pieces-collection get", + "description" : "Get a collection of wrapper pieces" + }, + { + "permissionName" : "orders.wrapper-pieces.item.get", + "displayName" : "orders.wrapper-pieces-item get", + "description" : "Fetch a wrapper piece" + }, + { + "permissionName" : "orders.wrapper-pieces.all", + "displayName" : "All orders wrapper pieces perms", + "description" : "All permissions for the orders-wrapper-pieces", + "subPermissions" : [ + "orders.wrapper-pieces.collection.get", + "orders.wrapper-pieces.item.get" + ] + }, { "permissionName" : "orders.acquisition-methods.collection.get", "displayName" : "acquisition-methods-collection get", @@ -2061,6 +2100,7 @@ "orders.expect.collection.post", "orders.receiving-history.collection.get", "orders.pieces.all", + "orders.wrapper-pieces.all", "orders.acquisitions-units-assignments.all", "orders.order-templates.all", "orders.titles.all", diff --git a/ramls/wrapper-pieces.raml b/ramls/wrapper-pieces.raml new file mode 100644 index 000000000..13d180e25 --- /dev/null +++ b/ramls/wrapper-pieces.raml @@ -0,0 +1,46 @@ +#%RAML 1.0 +title: "Wrapper Pieces" +baseUri: https://github.com/folio-org/mod-orders +version: v4 + +documentation: + - title: "Wrapper Pieces" + content: Read API to manage Wrapper Pieces. + +types: + errors: !include raml-util/schemas/errors.schema + wrapper_piece: !include acq-models/mod-orders-storage/schemas/wrapper_piece.json + wrapper_piece_collection: !include acq-models/mod-orders-storage/schemas/wrapper_piece_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: + orderable: !include raml-util/traits/orderable.raml + pageable: !include raml-util/traits/pageable.raml + searchable: !include raml-util/traits/searchable.raml + +resourceTypes: + collection-get: !include raml-util/rtypes/collection-get.raml + collection-item-get: !include raml-util/rtypes/item-collection-get-with-json-response.raml + +/orders/wrapper-pieces: + type: + collection-get: + exampleCollection: !include acq-models/mod-orders-storage/examples/wrapper_piece_collection.sample + schemaCollection: wrapper_piece_collection + get: + description: Get list of Wrapper Pieces + is: [ + searchable: {description: "with valid searchable fields: for example code", example: "[\"code\", \"MEDGRANT\", \"=\"]"}, + pageable + ] + /{id}: + uriParameters: + id: + description: The UUID of a Wrapper Piece + type: UUID + type: + collection-item-get: + exampleItem: !include acq-models/mod-orders-storage/examples/wrapper_piece_get.sample + schema: wrapper_piece diff --git a/src/main/java/org/folio/config/ApplicationConfig.java b/src/main/java/org/folio/config/ApplicationConfig.java index 7ee11cb1f..a5b70c357 100644 --- a/src/main/java/org/folio/config/ApplicationConfig.java +++ b/src/main/java/org/folio/config/ApplicationConfig.java @@ -95,6 +95,7 @@ import org.folio.service.orders.lines.update.instance.WithHoldingOrderLineUpdateInstanceStrategy; import org.folio.service.orders.lines.update.instance.WithoutHoldingOrderLineUpdateInstanceStrategy; import org.folio.service.organization.OrganizationService; +import org.folio.service.pieces.WrapperPieceStorageService; import org.folio.service.pieces.PieceChangeReceiptStatusPublisher; import org.folio.service.pieces.PieceDeleteInventoryService; import org.folio.service.pieces.ItemRecreateInventoryService; @@ -530,6 +531,14 @@ PieceStorageService pieceStorageService(ConsortiumConfigurationService consortiu return new PieceStorageService(consortiumConfigurationService, consortiumUserTenantsRetriever, settingsRetriever, restClient); } + @Bean + WrapperPieceStorageService wrapperPieceStorageService(ConsortiumConfigurationService consortiumConfigurationService, + ConsortiumUserTenantsRetriever consortiumUserTenantsRetriever, + SettingsRetriever settingsRetriever, + RestClient restClient) { + return new WrapperPieceStorageService(consortiumConfigurationService, consortiumUserTenantsRetriever, settingsRetriever, restClient); + } + @Bean PieceService piecesService(PieceChangeReceiptStatusPublisher receiptStatusPublisher) { return new PieceService(receiptStatusPublisher); diff --git a/src/main/java/org/folio/orders/utils/ResourcePathResolver.java b/src/main/java/org/folio/orders/utils/ResourcePathResolver.java index 64f197063..1e42e2b94 100644 --- a/src/main/java/org/folio/orders/utils/ResourcePathResolver.java +++ b/src/main/java/org/folio/orders/utils/ResourcePathResolver.java @@ -27,6 +27,7 @@ private ResourcePathResolver() { public static final String PURCHASE_ORDER_STORAGE = "purchaseOrder"; public static final String PIECES_STORAGE = "pieces"; public static final String PIECES_STORAGE_BATCH = "pieces-batch"; + public static final String WRAPPER_PIECES_STORAGE = "wrapper-pieces"; public static final String ORGANIZATION_STORAGE = "organizations"; public static final String RECEIVING_HISTORY = "receiving-history"; public static final String RECEIPT_STATUS = "receiptStatus"; @@ -81,6 +82,7 @@ private ResourcePathResolver() { apis.put(PURCHASE_ORDER_STORAGE, "/orders-storage/purchase-orders"); apis.put(PIECES_STORAGE, "/orders-storage/pieces"); apis.put(PIECES_STORAGE_BATCH, "/orders-storage/pieces-batch"); + apis.put(WRAPPER_PIECES_STORAGE, "/orders-storage/wrapper-pieces"); apis.put(ORGANIZATION_STORAGE, "/organizations-storage/organizations"); apis.put(RECEIVING_HISTORY, "/orders-storage/receiving-history"); apis.put(PO_LINE_NUMBER, "/orders-storage/po-line-number"); diff --git a/src/main/java/org/folio/rest/impl/WrapperPiecesAPI.java b/src/main/java/org/folio/rest/impl/WrapperPiecesAPI.java new file mode 100644 index 000000000..e9feb95c8 --- /dev/null +++ b/src/main/java/org/folio/rest/impl/WrapperPiecesAPI.java @@ -0,0 +1,44 @@ +package org.folio.rest.impl; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Context; +import io.vertx.core.Handler; +import io.vertx.core.Vertx; +import lombok.extern.log4j.Log4j2; +import org.folio.rest.core.models.RequestContext; +import org.folio.rest.jaxrs.resource.OrdersWrapperPieces; +import org.folio.service.pieces.WrapperPieceStorageService; +import org.folio.spring.SpringContextUtil; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.ws.rs.core.Response; +import java.util.Map; + +import static io.vertx.core.Future.succeededFuture; + +@Log4j2 +public class WrapperPiecesAPI extends BaseApi implements OrdersWrapperPieces { + + @Autowired + private WrapperPieceStorageService wrapperPieceStorageService; + + public WrapperPiecesAPI() { + SpringContextUtil.autowireDependencies(this, Vertx.currentContext()); + } + + @Override + public void getOrdersWrapperPieces(String query, String totalRecords, int offset, int limit, + Map okapiHeaders, Handler> asyncResultHandler, Context vertxContext) { + wrapperPieceStorageService.getWrapperPieces(limit, offset, query, new RequestContext(vertxContext, okapiHeaders)) + .onSuccess(wrapperPieces -> asyncResultHandler.handle(succeededFuture(buildOkResponse(wrapperPieces)))) + .onFailure(fail -> handleErrorResponse(asyncResultHandler, fail)); + } + + @Override + public void getOrdersWrapperPiecesById(String id, Map okapiHeaders, + Handler> asyncResultHandler, Context vertxContext) { + wrapperPieceStorageService.getWrapperPieceById(id, new RequestContext(vertxContext, okapiHeaders)) + .onSuccess(wrapperPiece -> asyncResultHandler.handle(succeededFuture(buildOkResponse(wrapperPiece)))) + .onFailure(fail -> handleErrorResponse(asyncResultHandler, fail)); + } +} diff --git a/src/main/java/org/folio/service/pieces/PieceStorageService.java b/src/main/java/org/folio/service/pieces/PieceStorageService.java index 979e5414e..3ac8af737 100644 --- a/src/main/java/org/folio/service/pieces/PieceStorageService.java +++ b/src/main/java/org/folio/service/pieces/PieceStorageService.java @@ -46,9 +46,11 @@ public class PieceStorageService { private final ConsortiumConfigurationService consortiumConfigurationService; private final ConsortiumUserTenantsRetriever consortiumUserTenantsRetriever; private final SettingsRetriever settingsRetriever; - private final RestClient restClient; + protected final RestClient restClient; - public PieceStorageService(ConsortiumConfigurationService consortiumConfigurationService, ConsortiumUserTenantsRetriever consortiumUserTenantsRetriever, SettingsRetriever settingsRetriever, RestClient restClient) { + public PieceStorageService(ConsortiumConfigurationService consortiumConfigurationService, + ConsortiumUserTenantsRetriever consortiumUserTenantsRetriever, + SettingsRetriever settingsRetriever, RestClient restClient) { this.consortiumConfigurationService = consortiumConfigurationService; this.consortiumUserTenantsRetriever = consortiumUserTenantsRetriever; this.settingsRetriever = settingsRetriever; @@ -146,7 +148,7 @@ public Future getAllPieces(int limit, int offset, String query, return restClient.get(requestEntry, PieceCollection.class, requestContext); } - private Future> getUserTenantsIfNeeded(RequestContext requestContext) { + protected Future> getUserTenantsIfNeeded(RequestContext requestContext) { return consortiumConfigurationService.getConsortiumConfiguration(requestContext) .compose(consortiumConfiguration -> { if (consortiumConfiguration.isEmpty()) { diff --git a/src/main/java/org/folio/service/pieces/WrapperPieceStorageService.java b/src/main/java/org/folio/service/pieces/WrapperPieceStorageService.java new file mode 100644 index 000000000..eabecea46 --- /dev/null +++ b/src/main/java/org/folio/service/pieces/WrapperPieceStorageService.java @@ -0,0 +1,45 @@ +package org.folio.service.pieces; + +import io.vertx.core.Future; +import lombok.extern.log4j.Log4j2; +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.WrapperPiece; +import org.folio.rest.jaxrs.model.WrapperPieceCollection; +import org.folio.service.consortium.ConsortiumConfigurationService; +import org.folio.service.consortium.ConsortiumUserTenantsRetriever; +import org.folio.service.settings.SettingsRetriever; + +import static org.folio.orders.utils.ResourcePathResolver.WRAPPER_PIECES_STORAGE; +import static org.folio.orders.utils.ResourcePathResolver.resourcesPath; + +@Log4j2 +public class WrapperPieceStorageService extends PieceStorageService { + + private static final String WRAPPER_PIECES_STORAGE_ENDPOINT = resourcesPath(WRAPPER_PIECES_STORAGE); + private static final String WRAPPER_PIECES_STORAGE_BY_ID_ENDPOINT = WRAPPER_PIECES_STORAGE_ENDPOINT + "/{id}"; + + public WrapperPieceStorageService(ConsortiumConfigurationService consortiumConfigurationService, + ConsortiumUserTenantsRetriever consortiumUserTenantsRetriever, + SettingsRetriever settingsRetriever, RestClient restClient) { + super(consortiumConfigurationService, consortiumUserTenantsRetriever, settingsRetriever, restClient); + } + + public Future getWrapperPieces(int limit, int offset, String query, RequestContext requestContext) { + return getUserTenantsIfNeeded(requestContext) + .map(userTenants -> getQueryForUserTenants(userTenants, query)) + .compose(cql -> getAllWrapperPieces(limit, offset, cql, requestContext)); + } + + public Future getAllWrapperPieces(int limit, int offset, String query, RequestContext requestContext) { + log.debug("getAllWrapperPieces:: limit: {}, offset: {}, query: {}", limit, offset, query); + var requestEntry = new RequestEntry(WRAPPER_PIECES_STORAGE_ENDPOINT).withQuery(query).withOffset(offset).withLimit(limit); + return super.restClient.get(requestEntry, WrapperPieceCollection.class, requestContext); + } + + public Future getWrapperPieceById(String pieceId, RequestContext requestContext) { + var requestEntry = new RequestEntry(WRAPPER_PIECES_STORAGE_BY_ID_ENDPOINT).withId(pieceId); + return super.restClient.get(requestEntry, WrapperPiece.class, requestContext); + } +} From 665280095bff50735674443337386e5b967887f4 Mon Sep 17 00:00:00 2001 From: BKadirkhodjaev Date: Mon, 20 Jan 2025 18:14:38 +0500 Subject: [PATCH 2/2] [MODORDERS-1237]. Update acq-models --- ramls/acq-models | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ramls/acq-models b/ramls/acq-models index 494a65e44..9dffcde39 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit 494a65e44f01d3ad01dcc46947587d81ca955083 +Subproject commit 9dffcde398f86686f037ff5cc326f0471b0613c5