Skip to content

Commit

Permalink
[MODORDERS-1209]. Implement API to Send claims for multiple pieces (#…
Browse files Browse the repository at this point in the history
…1054)

* [MODORDERS-1209]. Implement API to Send claims for multiple pieces

* [MODORDERS-1209]. Update acq-models & add descriptors

* [MODORDERS-1209]. Update service with latest acq-models changes

* [MODORDERS-1209]. Add API tests, clean MockServer

* [MODORDERS-1209]. Improve claiming result output

* [MODORDERS-1209]. Remove logging

* [MODORDERS-1209]. Temporary change export type, add logging

* [MODORDERS-1209]. Remove temporary change export type, change return results, fix tests

* [MODORDERS-1209]. Add sleep 1000

* [MODORDERS-1209]. Change test log level

* [MODORDERS-1209]. Fix failing handleGetPieces

* [MODORDERS-1209]. Add missing pieceRecord to mockData

* [MODORDERS-1209]. Fix handleGetPieceById method

* [MODORDERS-1209]. Fix handleGetPieces

* [MODORDERS-1209]. Revert handleGetPieces & add try-catch

* [MODORDERS-1209]. Remove try-catch, change piece status validation

* [MODORDERS-1209]. Update piece mockData with Late status

* [MODORDERS-1209]. Update piece status validation

* [MODORDERS-1209]. Add more logs

* [MODORDERS-1209]. Add more logs

* [MODORDERS-1209]. Remove piece from mockData piece collections

* [MODORDERS-1209]. Add more logging

* [MODORDERS-1209]. Add claimPieceIds to job integration details

* [MODORDERS-1209]. Add more logs

* [MODORDERS-1209]. Fix MockServer handleGetPieces from interfering

* [MODORDERS-1209]. Revert getPiecesByIds

* [MODORDERS-1209]. Update tests

* [MODORDERS-1209]. Fix sonar

* [MODORDERS-1209]. Apply review recommendations

* [MODORDERS-1209]. Fix descriptors

* [MODORDERS-1209]. Add claimedPieceIds assertion to job creation

* [MODORDERS-1209]. Add unit tests, add ClaimingError enum

* [MODORDERS-1209]. Fix minor typos

* [MODORDERS-1209]. Update descriptors

* [MODORDERS-1209]. Remove redundant message

* [MODORDERS-1209]. Change log level

* [MODORDERS-1209]. Remove old logs, change arg name

* [MODORDERS-1209]. Fix sonar issue, change log level

* [MODORDERS-1209]. Remove CANNOT_COMPLETE_REQ from onComplete
  • Loading branch information
BKadirkhodjaev authored Dec 9, 2024
1 parent 8092d97 commit 65197ef
Show file tree
Hide file tree
Showing 26 changed files with 1,546 additions and 281 deletions.
46 changes: 44 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,31 @@
}
]
},
{
"id": "pieces.send-claims",
"version": "1.0",
"handlers": [
{
"methods": ["POST"],
"pathPattern": "/pieces/claim",
"permissionsRequired": [
"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.titles.item.get",
"organizations-storage.organizations.item.get",
"data-export.job.item.post",
"data-export.job.send.item.execute"
]
}
]
},
{
"id": "_jsonSchemas",
"version": "1.0",
Expand Down Expand Up @@ -1421,6 +1446,10 @@
{
"id": "consortia",
"version": "1.0"
},
{
"id": "data-export-spring",
"version": "2.0"
}
],
"permissionSets": [
Expand Down Expand Up @@ -1993,7 +2022,19 @@
"orders.bind-pieces.item.delete"
]
},

{
"permissionName": "pieces.send-claims.collection.post",
"displayName" : "send-claims collection post",
"description" : "Send claims collection post"
},
{
"permissionName": "pieces.send-claims.all",
"displayName": "All send claims perms",
"description": "All permissions for the send claims",
"subPermissions": [
"pieces.send-claims.collection.post"
]
},
{
"permissionName": "orders.all",
"displayName": "orders - all permissions",
Expand Down Expand Up @@ -2030,7 +2071,8 @@
"orders.acquisition-methods.all",
"orders.export-history.all",
"orders.routing-lists.all",
"orders.bind-pieces.all"
"orders.bind-pieces.all",
"pieces.send-claims.all"
]
},
{
Expand Down
39 changes: 39 additions & 0 deletions ramls/claim.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#%RAML 1.0
title: Claim
baseUri: https://github.com/folio-org/mod-orders
version: v1
protocols: [ HTTP, HTTPS ]

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

types:
claiming-collection: !include acq-models/mod-orders/schemas/claimingCollection.json
claiming-results: !include acq-models/mod-orders/schemas/claimingResults.json
errors: !include raml-util/schemas/errors.schema
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:
validate: !include raml-util/traits/validation.raml

resourceTypes:
post-with-200: !include rtypes/post-json-200.raml

/pieces/claim:
displayName: Claim pieces
description: |
Claim pieces. The endpoint is used to:
- Claims pieces grouped by organizations
- Triggers jobs in mod-data-export per each organization that contains an integration detail
type:
post-with-200:
requestSchema: claiming-collection
responseSchema: claiming-results
requestExample: !include acq-models/mod-orders/examples/claimingCollection.sample
responseExample: !include acq-models/mod-orders/examples/claimingResults.sample
is: [validate]
post:
description: Claim pieces
17 changes: 17 additions & 0 deletions src/main/java/org/folio/models/claiming/ClaimingError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.folio.models.claiming;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ClaimingError {
CANNOT_SEND_CLAIMS_PIECE_IDS_ARE_EMPTY("Cannot send claims, piece ids are empty"),
CANNOT_FIND_PIECES_WITH_LATE_STATUS_TO_PROCESS("Cannot find pieces with LATE status to process"),
CANNOT_RETRIEVE_CONFIG_ENTRIES("Cannot retrieve config entries"),
CANNOT_GROUP_PIECES_BY_VENDOR_MESSAGE("Cannot group pieces by vendor"),
CANNOT_CREATE_JOBS_AND_UPDATE_PIECES("Cannot create jobs and update pieces"),
CANNOT_FIND_A_PIECE_BY_ID("Cannot find a piece by '%s' id");

private final String value;
}
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 IntegrationDetailField {
EXPORT_TYPE_SPECIFIC_PARAMETERS("exportTypeSpecificParameters"),
VENDOR_EDI_ORDERS_EXPORT_CONFIG("vendorEdiOrdersExportConfig"),
CLAIM_PIECE_IDS("claimPieceIds");

private final String value;
}
1 change: 1 addition & 0 deletions src/main/java/org/folio/orders/utils/HelperUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class HelperUtils {

public static final String SYSTEM_CONFIG_MODULE_NAME = "ORG";
public static final String ORDER_CONFIG_MODULE_NAME = "ORDERS";
public static final String DATA_EXPORT_SPRING_CONFIG_MODULE_NAME = "mod-data-export-spring";

public static final String DEFAULT_POLINE_LIMIT = "1";
public static final String REASON_COMPLETE = "Complete";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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 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 All @@ -25,6 +26,7 @@ private ResourcePathResolver() {
public static final String REPORTING_CODES = "reportingCodes";
public static final String PURCHASE_ORDER_STORAGE = "purchaseOrder";
public static final String PIECES_STORAGE = "pieces";
public static final String ORGANIZATION_STORAGE = "organizations";
public static final String RECEIVING_HISTORY = "receiving-history";
public static final String RECEIPT_STATUS = "receiptStatus";
public static final String PAYMENT_STATUS = "paymentStatus";
Expand Down Expand Up @@ -56,7 +58,8 @@ private ResourcePathResolver() {
public static final String ORDER_SETTINGS = "orderSettings";
public static final String USERS = "users";
public static final String CONSORTIA_USER_TENANTS = "consortia.user-tenants";

public static final String DATA_EXPORT_SPRING_CREATE_JOB = "data-export-spring.job";
public static final String DATA_EXPORT_SPRING_EXECUTE_JOB = "data-export-spring.send-job";

private static final Map<String, String> SUB_OBJECT_ITEM_APIS;
private static final Map<String, String> SUB_OBJECT_COLLECTION_APIS;
Expand All @@ -72,9 +75,11 @@ 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(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");
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");
apis.put(ORDER_TEMPLATES, "/orders-storage/order-templates");
Expand Down Expand Up @@ -105,6 +110,8 @@ private ResourcePathResolver() {
apis.put(CONSORTIA_USER_TENANTS, "/consortia/{id}/user-tenants");
apis.put(ORDER_SETTINGS, "/orders-storage/settings");
apis.put(ROUTING_LISTS, "/orders-storage/routing-lists");
apis.put(DATA_EXPORT_SPRING_CREATE_JOB, "/data-export-spring/jobs");
apis.put(DATA_EXPORT_SPRING_EXECUTE_JOB, "/data-export-spring/jobs/send");

SUB_OBJECT_COLLECTION_APIS = Collections.unmodifiableMap(apis);
SUB_OBJECT_ITEM_APIS = Collections.unmodifiableMap(
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/org/folio/rest/impl/PiecesClaimingApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.folio.rest.impl;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
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.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.PIECES_CLAIMING_BUSINESS;
import static org.folio.orders.utils.ResourcePathResolver.resourceByIdPath;
import static org.folio.rest.RestConstants.OKAPI_URL;

public class PiecesClaimingApi extends BaseApi implements PiecesClaim {

@Autowired
private PiecesClaimingService pieceClaimingService;

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

@Override
@Validate
public void postPiecesClaim(ClaimingCollection claimingCollection, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
var requestContext = new RequestContext(vertxContext, okapiHeaders);
pieceClaimingService.sendClaims(claimingCollection, requestContext)
.onSuccess(claimingResults -> {
var okapiUrl = okapiHeaders.get(OKAPI_URL);
var url = resourceByIdPath(PIECES_CLAIMING_BUSINESS);
var response = buildResponseWithLocation(okapiUrl, url, claimingResults);
asyncResultHandler.handle(Future.succeededFuture(response));
})
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}
}
10 changes: 4 additions & 6 deletions src/main/java/org/folio/service/pieces/PieceStorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -135,6 +134,7 @@ public Future<PieceCollection> getAllPieces(String query, RequestContext request
}

public Future<PieceCollection> getAllPieces(int limit, int offset, String query, RequestContext requestContext) {
log.debug("getAllPieces:: limit: {}, offset: {}, query: {}", limit, offset, query);
var requestEntry = new RequestEntry(PIECE_STORAGE_ENDPOINT).withQuery(query).withOffset(offset).withLimit(limit);
return restClient.get(requestEntry, PieceCollection.class, requestContext);
}
Expand Down Expand Up @@ -165,20 +165,18 @@ public Future<List<Piece>> getPiecesByIds(List<String> pieceIds, RequestContext
.map(PieceCollection::getPieces)
.flatMap(Collection::stream)
.toList())
.onSuccess(v -> log.info("getPiecesByIds:: pieces by ids successfully retrieve: {}", pieceIds));
.onSuccess(v -> log.info("getPiecesByIds:: pieces by ids successfully retrieve: {}", pieceIds))
.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");
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"));

.toList());
}

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

0 comments on commit 65197ef

Please sign in to comment.