Skip to content

Commit

Permalink
Merge branch 'master' into MODORDERS-1169-2
Browse files Browse the repository at this point in the history
  • Loading branch information
BKadirkhodjaev authored Aug 22, 2024
2 parents 32d3479 + 92a6845 commit 3ead6ae
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 218 deletions.
2 changes: 1 addition & 1 deletion ramls/acq-models
7 changes: 4 additions & 3 deletions src/main/java/org/folio/helper/BindHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Future<Void> removeBinding(String pieceId, RequestContext requestContext)
return pieceStorageService.getPieceById(pieceId, requestContext)
.compose(piece -> {
var bindItemId = piece.getBindItemId();
piece.withBindItemId(null).withIsBound(false);
piece.withBindItemId(null).withBindItemTenantId(null).withIsBound(false);
return removeForbiddenEntities(piece, requestContext)
.map(v -> Collections.<String, List<Piece>>singletonMap(null, List.of(piece)))
.compose(piecesGroupedByPoLine -> storeUpdatedPieceRecords(piecesGroupedByPoLine, requestContext))
Expand Down Expand Up @@ -220,18 +220,19 @@ private Future<BindPiecesHolder> updateItemStatus(BindPiecesHolder holder, Reque
private Future<BindPiecesHolder> createItemForPieces(BindPiecesHolder holder, RequestContext requestContext) {
var bindPiecesCollection = holder.getBindPiecesCollection();
var poLineId = holder.getPoLineId();
var bindItem = bindPiecesCollection.getBindItem();
logger.debug("createItemForPiece:: Trying to get poLine by id '{}'", poLineId);
return purchaseOrderLineService.getOrderLineById(poLineId, requestContext)
.map(PoLineCommonUtil::convertToCompositePoLine)
.compose(compPOL -> createInventoryObjects(compPOL, bindPiecesCollection.getInstanceId(), bindPiecesCollection.getBindItem(), requestContext))
.compose(compPOL -> createInventoryObjects(compPOL, bindPiecesCollection.getInstanceId(), bindItem, requestContext))
.map(newItemId -> {
// Move requests if requestsAction is TRANSFER, otherwise do nothing
if (TRANSFER.equals(bindPiecesCollection.getRequestsAction())) {
var itemIds = holder.getPieces().map(Piece::getItemId).toList();
inventoryItemRequestService.transferItemRequests(itemIds, newItemId, requestContext);
}
// Set new item ids for pieces and holder
holder.getPieces().forEach(piece -> piece.setBindItemId(newItemId));
holder.getPieces().forEach(piece -> piece.withBindItemTenantId(bindItem.getTenantId()).setBindItemId(newItemId));
return holder.withBindItemId(newItemId);
});
}
Expand Down
61 changes: 44 additions & 17 deletions src/main/java/org/folio/orders/utils/PoLineCommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.ONGOING;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import one.util.streamex.StreamEx;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.folio.rest.core.exceptions.HttpException;
Expand Down Expand Up @@ -182,32 +183,58 @@ public static boolean isHoldingCreationRequiredForLocation(CompositePoLine compP
* @return map of grouped locations where key is location id and value is list of locations with the same id
*/
public static Map<String, List<Location>> groupLocationsByLocationId(CompositePoLine compPOL) {
if (CollectionUtils.isEmpty(compPOL.getLocations())) {
return Collections.emptyMap();
}
return extractLocationsForPoLineByLocationId(compPOL)
.collect(Collectors.groupingBy(Location::getLocationId));
}

return compPOL.getLocations()
.stream()
.filter(location -> Objects.nonNull(location.getLocationId()))
.filter(location -> !isHoldingCreationRequiredForLocation(compPOL, location))
.collect(Collectors.groupingBy(Location::getLocationId));
/**
* Map all PO Line's location to tenantIds for which the holding should be created by location identifier
* @param compPOL PO line with locations
* @return map of locations and tenantIds where key is location id and value is the tenantId of the specified location
*/
public static Map<String, String> mapLocationIdsToTenantIds(CompositePoLine compPOL) {
return extractLocationsForPoLineByLocationId(compPOL)
.filter(location -> Objects.nonNull(location.getTenantId()))
.collect(Collectors.toMap(Location::getLocationId, Location::getTenantId));
}

/**
* Group all PO Line's locations for which the holding should be created by location identifier
* Group all PO Line's locations for which the holding should be created by holding identifier
* @param compPOL PO line with locations to group
* @return map of grouped locations where key is holding id and value is list of locations with the same id
*/
public static Map<String, List<Location>> groupLocationsByHoldingId(CompositePoLine compPOL) {
return extractLocationsForPoLineByHoldingId(compPOL)
.collect(Collectors.groupingBy(Location::getHoldingId));
}

/**
* Map all PO Line's location to tenantIds for which the holding should be created by holding identifier
* @param compPOL PO line with locations
* @return map of locations and tenantIds where key is holding id and value is the tenantId of the specified location
*/
public static Map<String, String> mapHoldingIdsToTenantIds(CompositePoLine compPOL) {
return extractLocationsForPoLineByHoldingId(compPOL)
.filter(location -> Objects.nonNull(location.getTenantId()))
.collect(Collectors.toMap(Location::getHoldingId, Location::getTenantId));
}

private static StreamEx<Location> extractLocationsForPoLineByLocationId(CompositePoLine compPOL) {
return extractLocationsForPoLine(compPOL, Location::getLocationId)
.filter(location -> !isHoldingCreationRequiredForLocation(compPOL, location));
}

private static StreamEx<Location> extractLocationsForPoLineByHoldingId(CompositePoLine compPOL) {
return extractLocationsForPoLine(compPOL, Location::getHoldingId)
.filter(location -> isHoldingCreationRequiredForLocation(compPOL, location));
}

private static StreamEx<Location> extractLocationsForPoLine(CompositePoLine compPOL, Function<Location, String> fieldExtractor) {
if (CollectionUtils.isEmpty(compPOL.getLocations())) {
return Collections.emptyMap();
return StreamEx.empty();
}

return compPOL.getLocations()
.stream()
.filter(location -> Objects.nonNull(location.getHoldingId()))
.filter(location -> isHoldingCreationRequiredForLocation(compPOL, location))
.collect(Collectors.groupingBy(Location::getHoldingId));
return StreamEx.of(compPOL.getLocations())
.filter(location -> Objects.nonNull(fieldExtractor.apply(location)));
}

public static List<String> getTenantsFromLocations(CompositePoLine poLine) {
Expand Down
Loading

0 comments on commit 3ead6ae

Please sign in to comment.