Skip to content

Commit

Permalink
[MODORDERS-1209]. Apply review recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
BKadirkhodjaev committed Dec 9, 2024
1 parent d4d605d commit b015700
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 81 deletions.
22 changes: 15 additions & 7 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1180,22 +1180,26 @@
]
},
{
"id": "orders.send-claims",
"id": "pieces.send-claims",
"version": "1.0",
"handlers": [
{
"methods": ["POST"],
"pathPattern": "/orders/claim",
"permissionsRequired": [
"orders.send-claims.collection.post"
"pieces.send-claims.collection.post"
],
"modulePermissions": [
"configuration.entries.collection.get",
"orders-storage.pieces.collection.get",
"orders-storage.pieces.item.put",
"orders-storage.po-lines.item.get",
"orders-storage.po-lines.item.put",
"orders-storage.purchase-orders.item.get"
"orders-storage.purchase-orders.item.get",
"orders-storage.purchase-orders.item.put",
"organizations-storage.organizations.item.get",
"data-export.job.item.post",
"data-export.job.send.item.execute"
]
}
]
Expand Down Expand Up @@ -1442,6 +1446,10 @@
{
"id": "consortia",
"version": "1.0"
},
{
"id": "data-export-spring",
"version": "2.0"
}
],
"permissionSets": [
Expand Down Expand Up @@ -2015,16 +2023,16 @@
]
},
{
"permissionName": "orders.send-claims.collection.post",
"permissionName": "pieces.send-claims.collection.post",
"displayName" : "send-claims collection post",
"description" : "Send claims collection post"
},
{
"permissionName": "orders.send-claims.all",
"permissionName": "pieces.send-claims.all",
"displayName": "All send claims perms",
"description": "All permissions for the send claims",
"subPermissions": [
"orders.send-claims.collection.post"
"pieces.send-claims.collection.post"
]
},
{
Expand Down Expand Up @@ -2064,7 +2072,7 @@
"orders.export-history.all",
"orders.routing-lists.all",
"orders.bind-pieces.all",
"orders.send-claims.all"
"pieces.send-claims.all"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions ramls/claim.raml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: v1
protocols: [ HTTP, HTTPS ]

documentation:
- title: Orders Business Logic API
- title: Pieces Business Logic API
content: <b>API for claiming pieces</b>

types:
Expand All @@ -22,7 +22,7 @@ traits:
resourceTypes:
post-with-200: !include rtypes/post-json-200.raml

/orders/claim:
/pieces/claim:
displayName: Claim pieces
description: |
Claim pieces. The endpoint is used to:
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/folio/models/claiming/IntegrationDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.folio.models.claiming;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum IntegrationDetail {
EXPORT_TYPE_SPECIFIC_PARAMETERS("exportTypeSpecificParameters"),
VENDOR_EDI_ORDERS_EXPORT_CONFIG("vendorEdiOrdersExportConfig"),
CLAIM_PIECE_IDS("claimPieceIds");

private final String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private ResourcePathResolver() {
public static final String PO_LINES_BATCH_STORAGE = "poLines.batch";
public static final String PO_LINES_BUSINESS = "poLinesBusinessEndpoint";
public static final String ORDERS_BUSINESS = "ordersBusinessEndpoint";
public static final String CLAIMING_BUSINESS = "claimingBusinessEndpoint";
public static final String PIECES_CLAIMING_BUSINESS = "piecesClaimingBusinessEndpoint";
public static final String PO_NUMBER = "poNumber";
public static final String VENDOR_ID = "vendor";
public static final String PO_LINE_NUMBER = "poLineNumber";
Expand Down Expand Up @@ -75,7 +75,7 @@ private ResourcePathResolver() {
apis.put(PO_LINES_BATCH_STORAGE, "/orders-storage/po-lines-batch");
apis.put(PO_LINES_BUSINESS, "/orders/order-lines");
apis.put(ORDERS_BUSINESS, "/orders/composite-orders");
apis.put(CLAIMING_BUSINESS, "/orders/claim");
apis.put(PIECES_CLAIMING_BUSINESS, "/pieces/claim");
apis.put(PO_NUMBER, "/orders-storage/po-number");
apis.put(PURCHASE_ORDER_STORAGE, "/orders-storage/purchase-orders");
apis.put(PIECES_STORAGE, "/orders-storage/pieces");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@
import org.folio.rest.annotations.Validate;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.model.ClaimingCollection;
import org.folio.rest.jaxrs.resource.OrdersClaim;
import org.folio.service.claiming.ClaimingService;
import org.folio.rest.jaxrs.resource.PiecesClaim;
import org.folio.service.pieces.PiecesClaimingService;
import org.folio.spring.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.core.Response;
import java.util.Map;

import static org.folio.orders.utils.ResourcePathResolver.CLAIMING_BUSINESS;
import static org.folio.orders.utils.ResourcePathResolver.PIECES_CLAIMING_BUSINESS;
import static org.folio.orders.utils.ResourcePathResolver.resourceByIdPath;
import static org.folio.rest.RestConstants.OKAPI_URL;

public class ClaimingApi extends BaseApi implements OrdersClaim {
public class PiecesClaimingApi extends BaseApi implements PiecesClaim {

@Autowired
private ClaimingService claimingService;
private PiecesClaimingService pieceClaimingService;

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

@Override
@Validate
public void postOrdersClaim(ClaimingCollection claimingCollection, Map<String, String> okapiHeaders,
public void postPiecesClaim(ClaimingCollection claimingCollection, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
var requestContext = new RequestContext(vertxContext, okapiHeaders);
claimingService.sendClaims(claimingCollection, requestContext)
pieceClaimingService.sendClaims(claimingCollection, requestContext)
.onSuccess(claimingResults -> {
var okapiUrl = okapiHeaders.get(OKAPI_URL);
var url = resourceByIdPath(CLAIMING_BUSINESS);
var url = resourceByIdPath(PIECES_CLAIMING_BUSINESS);
var response = buildResponseWithLocation(okapiUrl, url, claimingResults);
asyncResultHandler.handle(Future.succeededFuture(response));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,19 @@ public Future<List<Piece>> getPiecesByIds(List<String> pieceIds, RequestContext
.flatMap(Collection::stream)
.toList())
.onSuccess(v -> log.info("getPiecesByIds:: pieces by ids successfully retrieve: {}", pieceIds))
.onFailure(t -> log.error("Failed to get pieces by ids"));
.onFailure(t -> log.error("Failed to get pieces by ids", t));
}

public Future<List<Piece>> getPiecesByLineIdsByChunks(List<String> lineIds, RequestContext requestContext) {
log.info("getPiecesByLineIdsByChunks:: start");
log.debug("getPiecesByLineIdsByChunks:: start");
var futures = ofSubLists(new ArrayList<>(lineIds), MAX_IDS_FOR_GET_RQ_15)
.map(ids -> getPieceChunkByLineIds(ids, requestContext))
.toList();
return collectResultsOnSuccess(futures)
.map(lists -> lists.stream()
.flatMap(Collection::stream)
.collect(Collectors.toList()))
.onSuccess(v -> log.info("getPiecesByLineIdsByChunks:: end"));

.onSuccess(v -> log.debug("getPiecesByLineIdsByChunks:: end"));
}

private Future<List<Piece>> getPieceChunkByLineIds(Collection<String> poLineIds, RequestContext requestContext) {
Expand Down
Loading

0 comments on commit b015700

Please sign in to comment.