Skip to content

Commit

Permalink
[MODORDERS-1237]. Create a new API and wrapper model for Claiming wit…
Browse files Browse the repository at this point in the history
…h an Organization Id
  • Loading branch information
BKadirkhodjaev committed Jan 20, 2025
1 parent 21452ec commit 57bc886
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 3 deletions.
40 changes: 40 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions ramls/wrapper-pieces.raml
Original file line number Diff line number Diff line change
@@ -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: <b>Read API to manage Wrapper Pieces.</b>

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
9 changes: 9 additions & 0 deletions src/main/java/org/folio/config/ApplicationConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/org/folio/rest/impl/WrapperPiecesAPI.java
Original file line number Diff line number Diff line change
@@ -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<String, String> okapiHeaders, Handler<AsyncResult<Response>> 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<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
wrapperPieceStorageService.getWrapperPieceById(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(wrapperPiece -> asyncResultHandler.handle(succeededFuture(buildOkResponse(wrapperPiece))))
.onFailure(fail -> handleErrorResponse(asyncResultHandler, fail));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,7 +148,7 @@ public Future<PieceCollection> getAllPieces(int limit, int offset, String query,
return restClient.get(requestEntry, PieceCollection.class, requestContext);
}

private Future<List<String>> getUserTenantsIfNeeded(RequestContext requestContext) {
protected Future<List<String>> getUserTenantsIfNeeded(RequestContext requestContext) {
return consortiumConfigurationService.getConsortiumConfiguration(requestContext)
.compose(consortiumConfiguration -> {
if (consortiumConfiguration.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<WrapperPieceCollection> 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<WrapperPieceCollection> 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<WrapperPiece> 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);
}
}

0 comments on commit 57bc886

Please sign in to comment.