Skip to content
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Stories
* [MODORDERS-1463](https://folio-org.atlassian.net/browse/MODORDERS-1463) - Bump acquisition-methods interfaces to 1.1 for the deprecated flag
* [MODORDERS-1486](https://folio-org.atlassian.net/browse/MODORDERS-1486) - Order import jobs hanging indefinitely
* [MODORDERS-1491](https://folio-org.atlassian.net/browse/MODORDERS-1491) - Select the Claims integrations through `GET /data-export-spring/effective-configs` and send each integration only its own pieces, requires `data-export-spring` 2.1

### Bug fixes
* [MODORDSTOR-535](https://folio-org.atlassian.net/browse/MODORDSTOR-535) - PO line cannot be opened after EDIFACT export: update acq-models for `lastExport` and `exportTransmissionMethod`, bump `orders` to 13.1 and `orders.export-history` to 1.1
Expand Down
4 changes: 2 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@
"orders-storage.purchase-orders.item.get",
"orders-storage.titles.item.get",
"organizations-storage.organizations.item.get",
"data-export.config.collection.get",
"data-export.effective-configs.collection.get",
"data-export.job.item.post",
"data-export.job.send.item.execute"
]
Expand Down Expand Up @@ -1571,7 +1571,7 @@
},
{
"id": "data-export-spring",
"version": "2.0"
"version": "2.1"
},
{
"id": "source-manager-job-executions",
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/folio/models/claiming/ClaimJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.folio.models.claiming;

import io.vertx.core.json.JsonObject;

import java.util.List;

/**
* An export job to be created for one Claims export config.
*
* @param config the export config
* @param pieceIds ids of the pieces this config takes
*/
public record ClaimJob(JsonObject config, List<String> pieceIds) {
}
13 changes: 13 additions & 0 deletions src/main/java/org/folio/models/claiming/ClaimPiece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.folio.models.claiming;

import org.folio.rest.acq.model.Organization;

/**
* A piece to be claimed, with the PO line and order values that select its Claims export configs.
*
* @param vendor vendor of the piece's order
* @param pieceId id of the piece
* @param acquisitionMethod acquisition method of the piece's PO line, null if the PO line has none
*/
public record ClaimPiece(Organization vendor, String pieceId, String acquisitionMethod) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@AllArgsConstructor
public enum IntegrationDetailField {
JOB_ID("id"),
CONFIG_ID("id"),
TENANT("tenant"),
CONFIGS("configs"),
CONFIG_NAME("configName"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class 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_CONFIGURATIONS = "data-export-spring.configs";
public static final String DATA_EXPORT_SPRING_EFFECTIVE_CONFIGS = "data-export-spring.effective-configs";
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";
public static final String EXCHANGE_RATE = "exchangeRate";
Expand Down Expand Up @@ -118,7 +118,7 @@ public class 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_CONFIGURATIONS, "/data-export-spring/configs");
apis.put(DATA_EXPORT_SPRING_EFFECTIVE_CONFIGS, "/data-export-spring/effective-configs");
apis.put(DATA_EXPORT_SPRING_CREATE_JOB, "/data-export-spring/jobs");
apis.put(DATA_EXPORT_SPRING_EXECUTE_JOB, "/data-export-spring/jobs/send");
apis.put(EXCHANGE_RATE, "/finance/exchange-rate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ public enum ErrorCodes {
LAST_PIECE("lastPiece", "The piece cannot be deleted because it is the last piece for the poLine with Receiving Workflow 'Synchronized order and receipt quantity' and cost quantity '1'"),
CANNOT_SEND_CLAIMS_PIECE_IDS_ARE_EMPTY("cannotSendClaimsPieceIdsAreEmpty", "Cannot send claims, piece ids are empty"),
CANNOT_FIND_PIECES_WITH_LATE_STATUS_TO_PROCESS("cannotFindPiecesWithLatestStatusToProcess", "Cannot find pieces with LATE status to process"),
CANNOT_RETRIEVE_CONFIG_ENTRIES("cannotRetrieveConfigEntries", "Cannot retrieve config entries"),
CANNOT_GROUP_PIECES_BY_VENDOR("cannotGroupPiecesByVendorMessage", "Cannot group pieces by vendor"),
CANNOT_CREATE_JOBS_AND_UPDATE_PIECES("cannotCreateJobsAndUpdatePieces", "Cannot create jobs and update pieces"),
CANNOT_FIND_PIECE_BY_ID("cannotFindPieceById", "Cannot find a piece by '%s' id"),
UNABLE_TO_GENERATE_CLAIMS_FOR_ORG_NO_INTEGRATION_DETAILS("unableToGenerateClaimsForOrgNoIntegrationDetails", "Unable to generate claims for %s because no claim integrations exist"),
UNABLE_TO_GENERATE_CLAIMS_FOR_ORG_NO_INTEGRATION_DETAILS("unableToGenerateClaimsForOrgNoIntegrationDetails", "Unable to generate claims for %s because no claims integration applies to the claimed pieces"),
ALL_PIECES_MUST_HAVE_THE_SAME_POLINE_ID_AND_TITLE_ID("allPiecesMustHaveTheSamePoLineIdAndTitleId", "All pieces in the batch should have the same titleId and poLineId"),
EXISTING_HOLDINGS_FOR_DELETE_CONFIRMATION("existingHoldingsForDeleteConfirmation", "There are existing holdings to delete, Try again with 'deleteHoldings' param"),
EXISTING_RECEIVED_PIECES_TITLE_REMOVAL("existingReceivedPiecesTitleRemoval", "Unable to remove the title as there are pieces with a 'Received' status associated with it"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ protected <T> Future<T> cacheData(String url, String query, AsyncCache<String, T
BiFunction<RequestEntry, RequestContext, Future<T>> configExtractor,
boolean byPassCache, RequestContext requestContext) {
var requestEntry = new RequestEntry(url).withQuery(query).withOffset(0).withLimit(Integer.MAX_VALUE);
return cacheData(requestEntry, cache, configExtractor, byPassCache, requestContext);
}

protected <T> Future<T> cacheData(RequestEntry requestEntry, AsyncCache<String, T> cache,
BiFunction<RequestEntry, RequestContext, Future<T>> configExtractor,
boolean byPassCache, RequestContext requestContext) {
var cacheKey = buildUniqueKey(requestEntry, requestContext);
boolean cacheBypassRequested = isCacheBypassRequested(requestContext.getHeaders());
log.debug("loadSettingsData:: Loading setting data, url: '{}', query: '{}', bypass-cache mode: '{}', cache-bypass header: '{}'",
url, query, byPassCache, cacheBypassRequested);
log.debug("loadSettingsData:: Loading setting data, cacheKey: '{}', bypass-cache mode: '{}', cache-bypass header: '{}'",
cacheKey, byPassCache, cacheBypassRequested);
if (byPassCache || cacheBypassRequested) {
return extractData(configExtractor, requestContext, requestEntry);
}
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/org/folio/service/caches/ExportConfigsCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.core.models.RequestEntry;
import org.folio.service.dataexport.ExportConfigsRetriever;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import static org.folio.orders.utils.CacheUtils.buildAsyncCache;
import static org.folio.orders.utils.ResourcePathResolver.DATA_EXPORT_SPRING_CONFIGURATIONS;
import static org.folio.orders.utils.ResourcePathResolver.DATA_EXPORT_SPRING_EFFECTIVE_CONFIGS;
import static org.folio.orders.utils.ResourcePathResolver.resourcesPath;

@Log4j2
@Component
@RequiredArgsConstructor
public class ExportConfigsCache extends AbstractConfigCache {

private static final String TYPE_QUERY = "type==%s";
private static final String VENDOR_ID_PARAMETER = "vendorId";
private static final String TYPE_PARAMETER = "type";
private static final String ACQUISITION_METHOD_PARAMETER = "acquisitionMethod";
private static final String EXPORT_TYPE_CLAIMS = "CLAIMS";

private final ExportConfigsRetriever exportConfigsRetriever;
private AsyncCache<String, JsonObject> configsCache;
Expand All @@ -38,9 +42,22 @@ void init() {
this.configsCache = buildAsyncCache(context, cacheExpirationTime);
}

public Future<JsonObject> loadExportConfigs(String exportType, RequestContext requestContext) {
return cacheData(resourcesPath(DATA_EXPORT_SPRING_CONFIGURATIONS), TYPE_QUERY.formatted(exportType), configsCache,
exportConfigsRetriever::getExportConfigs, byPassCache, requestContext);
/**
* Loads the Claims export configs that apply to a PO line, as a map of config id to config.
*
* @param vendorId vendor of the PO line's order
* @param acquisitionMethod acquisition method of the PO line, null if the PO line has none
* @param requestContext Headers to make HTTP requests
* @return Future of the matching configs, empty if no config applies
*/
public Future<JsonObject> loadClaimsConfigsForPoLine(String vendorId, String acquisitionMethod, RequestContext requestContext) {
var requestEntry = new RequestEntry(resourcesPath(DATA_EXPORT_SPRING_EFFECTIVE_CONFIGS))
.withQueryParameter(VENDOR_ID_PARAMETER, vendorId)
.withQueryParameter(TYPE_PARAMETER, EXPORT_TYPE_CLAIMS);
if (acquisitionMethod != null) {
requestEntry.withQueryParameter(ACQUISITION_METHOD_PARAMETER, acquisitionMethod);
}
return cacheData(requestEntry, configsCache, exportConfigsRetriever::getExportConfigs, byPassCache, requestContext);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.folio.rest.core.models.RequestEntry;

import static org.folio.models.claiming.IntegrationDetailField.CONFIGS;
import static org.folio.models.claiming.IntegrationDetailField.CONFIG_NAME;
import static org.folio.models.claiming.IntegrationDetailField.CONFIG_ID;

@Log4j2
@RequiredArgsConstructor
Expand All @@ -24,7 +24,7 @@ public Future<JsonObject> getExportConfigs(RequestEntry requestEntry, RequestCon
var configs = exportConfigs.getJsonArray(CONFIGS.getValue());
for (int i = 0; i < configs.size(); i++) {
var exportConfig = configs.getJsonObject(i);
result.put(exportConfig.getString(CONFIG_NAME.getValue()), exportConfig);
result.put(exportConfig.getString(CONFIG_ID.getValue()), exportConfig);
}
return result;
});
Expand Down
Loading
Loading