Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java?rev=932681&r1=932680&r2=932681&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Sat Apr 10 08:59:56 2010 @@ -24,7 +24,6 @@ import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; import java.sql.Timestamp; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -36,20 +35,19 @@ import javolution.util.FastSet; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.collections.MapStack; -import org.ofbiz.base.util.StringUtil; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.condition.EntityConditionList; -import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; @@ -60,9 +58,7 @@ import org.ofbiz.product.product.Product import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.service.ServiceAuthException; import org.ofbiz.service.ServiceUtil; -import org.ofbiz.service.ServiceValidationException; import org.ofbiz.widget.fo.FoFormRenderer; import org.ofbiz.widget.html.HtmlScreenRenderer; import org.ofbiz.widget.screen.ScreenRenderer; @@ -77,7 +73,8 @@ public class OagisShipmentServices { protected static final HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer(); protected static final FoFormRenderer foFormRenderer = new FoFormRenderer(); - public static final Set invalidShipmentStatusSet = UtilMisc.toSet("SHIPMENT_CANCELLED", "SHIPMENT_PICKED", "SHIPMENT_PACKED", "SHIPMENT_SHIPPED", "SHIPMENT_DELIVERED"); + public static final Set<String> invalidShipmentStatusSet = UtilMisc.toSet("SHIPMENT_CANCELLED", "SHIPMENT_PICKED", "SHIPMENT_PACKED", + "SHIPMENT_SHIPPED", "SHIPMENT_DELIVERED"); public static final String resource = "OagisUiLabels"; @@ -89,14 +86,14 @@ public class OagisShipmentServices { public static final String oagisSegmentsNamespacePrefix = "os"; public static final String oagisFieldsNamespacePrefix = "of"; - public static Map oagisReceiveShowShipment(DispatchContext ctx, Map context) { + public static Map<String, Object> oagisReceiveShowShipment(DispatchContext ctx, Map<String, Object> context) { Document doc = (Document) context.get("document"); boolean isErrorRetry = Boolean.TRUE.equals(context.get("isErrorRetry")); LocalDispatcher dispatcher = ctx.getDispatcher(); Delegator delegator = ctx.getDelegator(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); - List errorMapList = FastList.newInstance(); + List<Map<String, String>> errorMapList = FastList.newInstance(); GenericValue userLogin = null; try { @@ -114,7 +111,7 @@ public class OagisShipmentServices { String bsrVerb = UtilXml.childElementValue(bsrElement, "of:VERB"); // of String bsrNoun = UtilXml.childElementValue(bsrElement, "of:NOUN"); // of String bsrRevision = UtilXml.childElementValue(bsrElement, "of:REVISION"); // of - Map oagisMsgInfoCtx = UtilMisc.toMap("bsrVerb", bsrVerb, "bsrNoun", bsrNoun, "bsrRevision", bsrRevision); + Map<String, Object> oagisMsgInfoCtx = UtilMisc.toMap("bsrVerb", (Object) bsrVerb, "bsrNoun", bsrNoun, "bsrRevision", bsrRevision); Element senderElement = UtilXml.firstChildElement(controlAreaElement, "os:SENDER"); // os String logicalId = UtilXml.childElementValue(senderElement, "of:LOGICALID"); // of @@ -132,7 +129,7 @@ public class OagisShipmentServices { Element shipmentElement = UtilXml.firstChildElement(daShowShipmentElement, "ns:SHIPMENT"); // n String shipmentId = UtilXml.childElementValue(shipmentElement, "of:DOCUMENTID"); // of - Map omiPkMap = UtilMisc.toMap("logicalId", logicalId, "component", component, "task", task, "referenceId", referenceId); + Map<String, String> omiPkMap = UtilMisc.toMap("logicalId", logicalId, "component", component, "task", task, "referenceId", referenceId); // always log this to make messages easier to find Debug.log("Processing oagisReceiveShowShipment for shipmentId [" + shipmentId + "] message ID [" + omiPkMap + "]", module); @@ -215,15 +212,15 @@ public class OagisShipmentServices { } } - List shipUnitElementList = UtilXml.childElementList(daShowShipmentElement, "ns:SHIPUNIT"); // n + List<? extends Element> shipUnitElementList = UtilXml.childElementList(daShowShipmentElement, "ns:SHIPUNIT"); // n if (errorMapList.size() == 0 && UtilValidate.isNotEmpty(shipUnitElementList)) { try { String shipGroupSeqId = shipment.getString("primaryShipGroupSeqId"); String originFacilityId = shipment.getString("originFacilityId"); - Element shipUnitElement = (Element)shipUnitElementList.get(0); - String trackingNum = UtilXml.childElementValue(shipUnitElement, "of:TRACKINGID"); // of - String carrierCode = UtilXml.childElementValue(shipUnitElement, "of:CARRIER"); // of + Element shipUnitFirstElement = (Element)shipUnitElementList.get(0); + String trackingNum = UtilXml.childElementValue(shipUnitFirstElement, "of:TRACKINGID"); // of + String carrierCode = UtilXml.childElementValue(shipUnitFirstElement, "of:CARRIER"); // of if (UtilValidate.isNotEmpty(carrierCode)) { String carrierPartyId = null; if (carrierCode.startsWith("F") || carrierCode.startsWith("f")) { @@ -231,7 +228,8 @@ public class OagisShipmentServices { } else if (carrierCode.startsWith("U")|| carrierCode.startsWith("u")) { carrierPartyId = "UPS"; } - Map resultMap = dispatcher.runSync("updateShipmentRouteSegment", UtilMisc.<String, Object>toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", "00001", "carrierPartyId", carrierPartyId, "trackingIdNumber", trackingNum, "userLogin", userLogin)); + Map<String, Object> resultMap = dispatcher.runSync("updateShipmentRouteSegment", UtilMisc.<String, Object>toMap("shipmentId", shipmentId, + "shipmentRouteSegmentId", "00001", "carrierPartyId", carrierPartyId, "trackingIdNumber", trackingNum, "userLogin", userLogin)); if (ServiceUtil.isError(resultMap)) { String errMsg = ServiceUtil.getErrorMessage(resultMap); errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "updateShipmentRouteSegmentError")); @@ -243,19 +241,15 @@ public class OagisShipmentServices { //multiple package we may need to sort by the packages by productId to avoid deadlocks, just like we //do with INVITEMs... note sure exactly how that will work - Iterator shipUnitElementItr = shipUnitElementList.iterator(); - while (shipUnitElementItr.hasNext()) { - shipUnitElement = (Element) shipUnitElementItr.next(); + for (Element shipUnitElement : shipUnitElementList) { String shipmentPackageSeqId = UtilXml.childElementValue(shipUnitElement, "of:SHPUNITSEQ"); // of - List invItemElementList = UtilXml.childElementList(shipUnitElement, "ns:INVITEM"); //n + List<? extends Element> invItemElementList = UtilXml.childElementList(shipUnitElement, "ns:INVITEM"); //n if (UtilValidate.isNotEmpty(invItemElementList)) { // sort the INVITEM elements by ITEM so that all shipments are processed in the same order, avoids deadlocking problems we've seen with concurrently processed orders - List invitemMapList = FastList.newInstance(); - Iterator invItemElementIter = invItemElementList.iterator(); + List<Map<String, Object>> invitemMapList = FastList.newInstance(); boolean foundBadProductId = false; - while (invItemElementIter.hasNext()) { - Element invItemElement = (Element) invItemElementIter.next(); + for (Element invItemElement : invItemElementList) { String productId = UtilXml.childElementValue(invItemElement, "of:ITEM"); // of // make sure productId is valid @@ -268,7 +262,7 @@ public class OagisShipmentServices { continue; } - Map invitemMap = FastMap.newInstance(); + Map<String, Object> invitemMap = FastMap.newInstance(); invitemMap.put("productId", productId); // support multiple INVITEM elements for a given productId UtilMisc.addToListInMap(invItemElement, invitemMap, "invItemElementList"); @@ -279,16 +273,13 @@ public class OagisShipmentServices { continue; } - UtilMisc.sortMaps(invitemMapList, UtilMisc.toList("productId")); + invitemMapList = UtilGenerics.cast( + UtilMisc.sortMaps(UtilGenerics.<List<Map<Object, Object>>>cast(invitemMapList), UtilMisc.toList("productId"))); - Iterator invitemMapIter = invitemMapList.iterator(); - while (invitemMapIter.hasNext()) { - Map invitemMap = (Map) invitemMapIter.next(); - List localInvItemElementList = (List) invitemMap.get("invItemElementList"); - - Iterator localInvItemElementIter = localInvItemElementList.iterator(); - while (localInvItemElementIter.hasNext()) { - Element invItemElement = (Element) localInvItemElementIter.next(); + for (Map<String, Object> invitemMap : invitemMapList) { + List<Element> localInvItemElementList = UtilGenerics.checkList(invitemMap.get("invItemElementList"), Element.class); + + for (Element invItemElement : localInvItemElementList) { String productId = UtilXml.childElementValue(invItemElement, "of:ITEM"); // of // this is based on the SHPUNIT which is basically a box/package, but we'll try to find the item with it if applicable @@ -303,7 +294,7 @@ public class OagisShipmentServices { Integer messageQuantity = Integer.valueOf(quantityValueStr); // do a few things to try to find the ShipmentItem corresponding to the INVITEM - List shipmentItemList = null; + List<GenericValue> shipmentItemList = null; // try getting it by the unit number, which is bogus but can be what some try IFF there is only one INVITEM in the SHPUNIT if (invitemMapList.size() == 1 && localInvItemElementList.size() == 1 && UtilValidate.isNotEmpty(possibleShipmentItemSeqId)) { @@ -329,13 +320,12 @@ public class OagisShipmentServices { // try to isolate it to one item, ie find the first in the list that matches the quantity //AND that has not already been used/issued - Iterator shipmentItemIter = shipmentItemList.iterator(); - while (shipmentItemIter.hasNext()) { - GenericValue shipmentItem = (GenericValue) shipmentItemIter.next(); + for (GenericValue shipmentItem : shipmentItemList) { if (messageQuantity.intValue() == shipmentItem.getDouble("quantity").intValue()) { // see if there is an ItemIssuance for this ShipmentItem, ie has already had inventory issued to it //if so then move on, this isn't the ShipmentItem you want - List itemIssuanceList = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItem.get("shipmentItemSeqId"))); + List<GenericValue> itemIssuanceList = delegator.findByAnd("ItemIssuance", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItem.get("shipmentItemSeqId"))); if (itemIssuanceList.size() == 0) { // found a match, set the list to be a new list with just this item and then break shipmentItemList = UtilMisc.toList(shipmentItem); @@ -373,23 +363,20 @@ public class OagisShipmentServices { } // NOTE: there could be more than one reservation record for a given shipment item? for example if there wasn't enough quantity in one inventory item and reservations on two were needed - List orderItemShipGrpInvReservationList = delegator.findByAnd("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId,"shipGroupSeqId",shipGroupSeqId)); + List<GenericValue> orderItemShipGrpInvReservationList = delegator.findByAnd("OrderItemShipGrpInvRes", + UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId,"shipGroupSeqId",shipGroupSeqId)); // find the total quantity for all reservations int totalReserved = 0; - Iterator orderItemShipGrpInvReservationCountIter = orderItemShipGrpInvReservationList.iterator(); - while (orderItemShipGrpInvReservationCountIter.hasNext()) { - GenericValue orderItemShipGrpInvReservation = (GenericValue) orderItemShipGrpInvReservationCountIter.next(); + for (GenericValue orderItemShipGrpInvReservation : orderItemShipGrpInvReservationList) { if (orderItemShipGrpInvReservation.getDouble("quantity") != null) { totalReserved += orderItemShipGrpInvReservation.getDouble("quantity").doubleValue(); } } - List serialNumberList = FastList.newInstance(); - List invDetailElementList = UtilXml.childElementList(invItemElement, "ns:INVDETAIL"); //n - Iterator invDetailElementItr = invDetailElementList.iterator(); - while (invDetailElementItr.hasNext()) { - Element invDetailElement = (Element) invDetailElementItr.next(); + List<String> serialNumberList = FastList.newInstance(); + List<? extends Element> invDetailElementList = UtilXml.childElementList(invItemElement, "ns:INVDETAIL"); //n + for (Element invDetailElement : invDetailElementList) { String serialNumber = UtilXml.childElementValue(invDetailElement, "of:SERIALNUM"); // os if (UtilValidate.isNotEmpty(serialNumber)) { serialNumberList.add(serialNumber); @@ -425,10 +412,10 @@ public class OagisShipmentServices { } - Iterator serialNumberIter = serialNumberList.iterator(); - Iterator orderItemShipGrpInvReservationIter = orderItemShipGrpInvReservationList.iterator(); - while (orderItemShipGrpInvReservationIter.hasNext() && quantityLeft > 0) { - GenericValue orderItemShipGrpInvReservation = (GenericValue) orderItemShipGrpInvReservationIter.next(); + for (GenericValue orderItemShipGrpInvReservation : orderItemShipGrpInvReservationList) { + if (quantityLeft <= 0) { + break; + } int currentInvResQuantity = orderItemShipGrpInvReservation.getDouble("quantity").intValue(); int quantityToUse; @@ -440,7 +427,8 @@ public class OagisShipmentServices { quantityLeft = 0; } - Map isitspastCtx = UtilMisc.toMap("orderId", orderId, "shipGroupSeqId", shipGroupSeqId, "orderItemSeqId", orderItemSeqId); + Map<String, Object> isitspastCtx = UtilMisc.toMap("orderId", (Object) orderId, "shipGroupSeqId", shipGroupSeqId, + "orderItemSeqId", orderItemSeqId); isitspastCtx.put("productId", productId); isitspastCtx.put("reservedDatetime", orderItemShipGrpInvReservation.get("reservedDatetime")); isitspastCtx.put("requireInventory", requireInventory); @@ -456,16 +444,16 @@ public class OagisShipmentServices { if (UtilValidate.isNotEmpty(serialNumberList)) { for (int i = 0; i < quantityToUse; i++) { - String serialNumber = (String) serialNumberIter.next(); + String serialNumber = serialNumberList.get(0); if (OagisServices.requireSerialNumberExist != null) { // according to requireSerialNumberExist make sure serialNumber does or does not exist in database, add an error message as needed - Set productIdSet = ProductWorker.getRefurbishedProductIdSet(productId, delegator); + Set<String> productIdSet = ProductWorker.getRefurbishedProductIdSet(productId, delegator); productIdSet.add(productId); EntityCondition bySerialNumberCondition = EntityCondition.makeCondition(EntityCondition.makeCondition("serialNumber", EntityOperator.EQUALS, serialNumber), EntityOperator.AND, EntityCondition.makeCondition("productId", EntityOperator.IN, productIdSet)); - List inventoryItemsBySerialNumber = delegator.findList("InventoryItem", bySerialNumberCondition, null, null, null, false); + List<GenericValue> inventoryItemsBySerialNumber = delegator.findList("InventoryItem", bySerialNumberCondition, null, null, null, false); if (OagisServices.requireSerialNumberExist.booleanValue()) { if (inventoryItemsBySerialNumber.size() == 0) { String errMsg = "Referenced serial numbers must already exist, but serial number [" + serialNumber + "] was not found. Product ID(s) considered are: " + productIdSet; @@ -485,7 +473,7 @@ public class OagisShipmentServices { isitspastCtx.put("quantity", new Double (1)); isitspastCtx.put("inventoryItemId", orderItemShipGrpInvReservation.get("inventoryItemId")); isitspastCtx.remove("itemIssuanceId"); - Map resultMap = dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx); + Map<String, Object> resultMap = dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx); if (ServiceUtil.isError(resultMap)) { String errMsg = ServiceUtil.getErrorMessage(resultMap); errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "IssueSerializedInvServiceError")); @@ -495,7 +483,7 @@ public class OagisShipmentServices { } else { isitspastCtx.put("quantity", new Double(quantityToUse)); // NOTE: this same service is called for non-serialized inventory in spite of the name it is made to handle it - Map resultMap = dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx); + Map<String, Object> resultMap = dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx); if (ServiceUtil.isError(resultMap)) { String errMsg = ServiceUtil.getErrorMessage(resultMap); errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "IssueSerializedInvServiceError")); @@ -515,17 +503,14 @@ public class OagisShipmentServices { // NOTE ON THIS DEJ20070906: this is actually really bad because it implies the shipment //has been split and that isn't really allowed; maybe better to return an error! - List shipmentItemList = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId)); - Iterator shipmentItemIter = shipmentItemList.iterator(); - while (shipmentItemIter.hasNext()) { - GenericValue shipmentItem = (GenericValue) shipmentItemIter.next(); + List<GenericValue> shipmentItemList = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId)); + for (GenericValue shipmentItem : shipmentItemList) { int shipmentItemQuantity = shipmentItem.getDouble("quantity").intValue(); int totalItemIssuanceQuantity = 0; - List itemIssuanceList = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItem.get("shipmentItemSeqId"))); - Iterator itemIssuanceIter = itemIssuanceList.iterator(); - while (itemIssuanceIter.hasNext()) { - GenericValue itemIssuance = (GenericValue) itemIssuanceIter.next(); + List<GenericValue> itemIssuanceList = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", + shipmentItem.get("shipmentItemSeqId"))); + for (GenericValue itemIssuance : itemIssuanceList) { totalItemIssuanceQuantity += itemIssuance.getDouble("quantity").intValue(); } @@ -538,7 +523,8 @@ public class OagisShipmentServices { } if (errorMapList.size() == 0) { - Map resultMap = dispatcher.runSync("setShipmentStatusPackedAndShipped", UtilMisc.<String, Object>toMap("shipmentId", shipmentId, "userLogin", userLogin)); + Map<String, Object> resultMap = dispatcher.runSync("setShipmentStatusPackedAndShipped", + UtilMisc.toMap("shipmentId", shipmentId, "userLogin", userLogin)); if (ServiceUtil.isError(resultMap)) { String errMsg = ServiceUtil.getErrorMessage(resultMap); errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SetShipmentStatusPackedAndShippedError")); @@ -553,7 +539,7 @@ public class OagisShipmentServices { oagisMsgInfoCtx.put("processingStatusId", "OAGMP_SYS_ERROR"); dispatcher.runSync("updateOagisMessageInfo", oagisMsgInfoCtx, 60, true); - Map saveErrorMapListCtx = FastMap.newInstance(); + Map<String, Object> saveErrorMapListCtx = FastMap.newInstance(); saveErrorMapListCtx.putAll(omiPkMap); saveErrorMapListCtx.put("errorMapList", errorMapList); saveErrorMapListCtx.put("userLogin", userLogin); @@ -569,7 +555,7 @@ public class OagisShipmentServices { } } - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); result.putAll(omiPkMap); result.put("userLogin", userLogin); @@ -584,7 +570,7 @@ public class OagisShipmentServices { try { // call services createOagisMsgErrInfosFromErrMapList and for incoming messages oagisSendConfirmBod - Map saveErrorMapListCtx = FastMap.newInstance(); + Map<String, Object> saveErrorMapListCtx = FastMap.newInstance(); saveErrorMapListCtx.putAll(omiPkMap); saveErrorMapListCtx.put("errorMapList", errorMapList); saveErrorMapListCtx.put("userLogin", userLogin); @@ -595,7 +581,7 @@ public class OagisShipmentServices { } try { - Map sendConfirmBodCtx = FastMap.newInstance(); + Map<String, Object> sendConfirmBodCtx = FastMap.newInstance(); sendConfirmBodCtx.putAll(omiPkMap); sendConfirmBodCtx.put("errorMapList", errorMapList); sendConfirmBodCtx.put("userLogin", userLogin); @@ -636,19 +622,17 @@ public class OagisShipmentServices { return result; } - public static Map oagisSendProcessShipmentsFromBackOrderSet(DispatchContext ctx, Map context) { + public static Map<String, Object> oagisSendProcessShipmentsFromBackOrderSet(DispatchContext ctx, Map<String, Object> context) { LocalDispatcher dispatcher = ctx.getDispatcher(); - Set noLongerOnBackOrderIdSet = (Set) context.get("noLongerOnBackOrderIdSet"); + Set<String> noLongerOnBackOrderIdSet = UtilGenerics.checkSet(context.get("noLongerOnBackOrderIdSet"), String.class); Debug.logInfo("Running oagisSendProcessShipmentsFromBackOrderSet with noLongerOnBackOrderIdSet=" + noLongerOnBackOrderIdSet, module); if (UtilValidate.isEmpty(noLongerOnBackOrderIdSet)) { return ServiceUtil.returnSuccess(); } try { - Iterator noLongerOnBackOrderIdIter = noLongerOnBackOrderIdSet.iterator(); - while (noLongerOnBackOrderIdIter.hasNext()) { - String orderId = (String) noLongerOnBackOrderIdIter.next(); + for (String orderId : noLongerOnBackOrderIdSet) { dispatcher.runAsync("oagisSendProcessShipment", UtilMisc.toMap("orderId", orderId), true); } } catch (GenericServiceException e) { @@ -659,14 +643,14 @@ public class OagisShipmentServices { return ServiceUtil.returnSuccess(); } - public static Map oagisSendProcessShipment(DispatchContext ctx, Map context) { + public static Map<String, Object> oagisSendProcessShipment(DispatchContext ctx, Map<String, Object> context) { LocalDispatcher dispatcher = ctx.getDispatcher(); Delegator delegator = ctx.getDelegator(); String orderId = (String) context.get("orderId"); // Check if order is not on back order before processing shipment try { - Map checkOrderResp = dispatcher.runSync("checkOrderIsOnBackOrder", UtilMisc.toMap("orderId", orderId)); + Map<String, Object> checkOrderResp = dispatcher.runSync("checkOrderIsOnBackOrder", UtilMisc.toMap("orderId", orderId)); if (((Boolean) checkOrderResp.get("isBackOrder")).booleanValue()) { Debug.logWarning("Order [" + orderId + "] is on back order, cannot Process Shipment", module); return ServiceUtil.returnSuccess(); @@ -697,8 +681,8 @@ public class OagisShipmentServices { if (Debug.infoOn()) Debug.logInfo("Call to oagisSendProcessShipment for orderId [" + orderId + "], sendToUrl=[" + sendToUrl + "], saveToDirectory=[" + saveToDirectory + "], saveToFilename=[" + saveToFilename + "]", module); - Map result = ServiceUtil.returnSuccess(); - MapStack bodyParameters = MapStack.create(); + Map<String, Object> result = ServiceUtil.returnSuccess(); + MapStack<String> bodyParameters = MapStack.create(); bodyParameters.put("orderId", orderId); // the userLogin passed in will usually be the customer, so don't use it; use the system user instead @@ -716,13 +700,14 @@ public class OagisShipmentServices { String referenceId = null; String task = "SHIPREQUEST"; // Actual value of task is "SHIPREQUEST" which is more than 10 char, need this in the db so it will match Confirm BODs, etc String component = "INVENTORY"; - Map omiPkMap = null; + Map<String, String> omiPkMap = null; String shipmentId = null; try { // see if there are any OagisMessageInfo for this order that are in the OAGMP_OGEN_SUCCESS or OAGMP_SENT statuses, if so don't send again; these need to be manually reviewed before resending to avoid accidental duplicate messages - List previousOagisMessageInfoList = delegator.findByAnd("OagisMessageInfo", UtilMisc.toMap("orderId", orderId, "task", task, "component", component)); + List<GenericValue> previousOagisMessageInfoList = delegator.findByAnd("OagisMessageInfo", + UtilMisc.toMap("orderId", orderId, "task", task, "component", component)); if (EntityUtil.filterByAnd(previousOagisMessageInfoList, UtilMisc.toMap("processingStatusId", "OAGMP_OGEN_SUCCESS")).size() > 0) { // this isn't really an error, just a failed constraint so return success String successMsg = "Found existing message info(s) in OAGMP_OGEN_SUCCESS, so not sending Process Shipment message for order [" + orderId + "] existing message(s) are: " + EntityUtil.filterByAnd(previousOagisMessageInfoList, UtilMisc.toMap("processingStatusId", "OAGMP_OGEN_SUCCESS")); @@ -739,7 +724,7 @@ public class OagisShipmentServices { return ServiceUtil.returnError("Could not find OrderHeader with ID [" + orderId + "]"); } - List validStores = StringUtil.split(UtilProperties.getPropertyValue("oagis.properties", "Oagis.Order.ValidProductStores"), ","); + List<String> validStores = StringUtil.split(UtilProperties.getPropertyValue("oagis.properties", "Oagis.Order.ValidProductStores"), ","); if (UtilValidate.isNotEmpty(validStores)) { if (!validStores.contains(orderHeader.getString("productStoreId"))) { return ServiceUtil.returnSuccess("Order [" + orderId + "] placed is not for valid Store(s)"); @@ -765,11 +750,11 @@ public class OagisShipmentServices { } // check payment authorization - Map authServiceContext = FastMap.newInstance(); + Map<String, Object> authServiceContext = FastMap.newInstance(); authServiceContext.put("orderId", orderId); authServiceContext.put("userLogin", userLogin); authServiceContext.put("reAuth", new Boolean("true")); - Map authResult = dispatcher.runSync("authOrderPayments", authServiceContext); + Map<String, Object> authResult = dispatcher.runSync("authOrderPayments", authServiceContext); if (!authResult.get("processResult").equals("APPROVED")) { return ServiceUtil.returnError("No authorized payment available, not sending Process Shipment"); } @@ -787,7 +772,7 @@ public class OagisShipmentServices { // prepare map to Create Oagis Message Info try { - Map comiCtx = FastMap.newInstance(); + Map<String, Object> comiCtx = FastMap.newInstance(); comiCtx.putAll(omiPkMap); comiCtx.put("processingStatusId", "OAGMP_TRIGGERED"); comiCtx.put("outgoingMessage", "Y"); @@ -811,7 +796,7 @@ public class OagisShipmentServices { EntityCondition.makeCondition("primaryOrderId", EntityOperator.EQUALS, orderId), EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "SHIPMENT_CANCELLED") ), EntityOperator.AND); - List shipmentList = delegator.findList("Shipment", findShipmentCondition, null, null, null, false); + List<GenericValue> shipmentList = delegator.findList("Shipment", findShipmentCondition, null, null, null, false); GenericValue shipment = EntityUtil.getFirst(shipmentList); if (shipment != null) { @@ -822,13 +807,13 @@ public class OagisShipmentServices { } shipmentId = shipment.getString("shipmentId"); } else { - Map cospResult= dispatcher.runSync("createOrderShipmentPlan", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin)); + Map<String, Object> cospResult= dispatcher.runSync("createOrderShipmentPlan", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin)); shipmentId = (String) cospResult.get("shipmentId"); shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId)); } bodyParameters.put("shipment", shipment); - List shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId)); + List<GenericValue> shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId)); bodyParameters.put("shipmentItems", shipmentItems); GenericValue address = EntityUtil.getFirst(orderReadHelper.getShippingLocations()); @@ -845,12 +830,10 @@ public class OagisShipmentServices { orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId))); bodyParameters.put("orderItemShipGroup", orderItemShipGroup); - Set correspondingPoIdSet = FastSet.newInstance(); + Set<String> correspondingPoIdSet = FastSet.newInstance(); - List orderItems = orderReadHelper.getOrderItems(); - Iterator oiIter = orderItems.iterator(); - while (oiIter.hasNext()) { - GenericValue orderItem = (GenericValue) oiIter.next(); + List<GenericValue> orderItems = orderReadHelper.getOrderItems(); + for (GenericValue orderItem : orderItems) { String correspondingPoId = orderItem.getString("correspondingPoId"); if (correspondingPoId != null) { correspondingPoIdSet.add(correspondingPoId); @@ -858,7 +841,7 @@ public class OagisShipmentServices { } bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet); if (orderHeader.get("externalId") != null) { - Set externalIdSet = FastSet.newInstance(); + Set<String> externalIdSet = FastSet.newInstance(); externalIdSet.add(orderHeader.getString("externalId")); bodyParameters.put("externalIdSet", externalIdSet); } @@ -869,7 +852,7 @@ public class OagisShipmentServices { // Get the associated return Id (replaceReturnId) String returnItemResponseId = returnItemResponse.getString("returnItemResponseId"); - List returnItemList = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnItemResponseId", returnItemResponseId)); + List<GenericValue> returnItemList = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnItemResponseId", returnItemResponseId)); GenericValue firstReturnItem = EntityUtil.getFirst(returnItemList); if (firstReturnItem != null) { bodyParameters.put("replacementReturnId", firstReturnItem.getString("returnId")); @@ -880,9 +863,7 @@ public class OagisShipmentServices { // return label should only be sent when we want a return label to be included; this would be for a cross-ship replacement type ReturnItem // go through the returnItemList and if any are cross-ship replacement, then include a label (not for wait replacement in other words) - Iterator returnItemIter = returnItemList.iterator(); - while (returnItemIter.hasNext()) { - GenericValue returnItem = (GenericValue) returnItemIter.next(); + for (GenericValue returnItem : returnItemList) { if ("RTN_CSREPLACE".equals(returnItem.getString("returnTypeId"))) { includeReturnLabel = true; } @@ -896,12 +877,10 @@ public class OagisShipmentServices { // tracking shipper account, other Party info String partyId = shipment.getString("partyIdTo"); bodyParameters.put("partyNameView", delegator.findByPrimaryKey("PartyNameView", UtilMisc.toMap("partyId", partyId))); - List partyCarrierAccounts = delegator.findByAnd("PartyCarrierAccount", UtilMisc.toMap("partyId", partyId)); + List<GenericValue> partyCarrierAccounts = delegator.findByAnd("PartyCarrierAccount", UtilMisc.toMap("partyId", partyId)); partyCarrierAccounts = EntityUtil.filterByDate(partyCarrierAccounts); if (partyCarrierAccounts != null) { - Iterator pcaIter = partyCarrierAccounts.iterator(); - while (pcaIter.hasNext()) { - GenericValue partyCarrierAccount = (GenericValue) pcaIter.next(); + for (GenericValue partyCarrierAccount : partyCarrierAccounts) { String carrierPartyId = partyCarrierAccount.getString("carrierPartyId"); if (carrierPartyId.equals(orderItemShipGroup.getString("carrierPartyId"))) { String accountNumber = partyCarrierAccount.getString("accountNumber"); @@ -924,7 +903,7 @@ public class OagisShipmentServices { if (Debug.infoOn()) Debug.logInfo("Finished rendering oagisSendProcessShipment message for orderId [" + orderId + "]", module); try { - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_OGEN_SUCCESS"); uomiCtx.put("shipmentId", shipmentId); @@ -938,10 +917,10 @@ public class OagisShipmentServices { Debug.logError(e, errMsg, module); } - Map sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); + Map<String, Object> sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); if (sendMessageReturn != null && ServiceUtil.isError(sendMessageReturn)) { try { - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_SEND_ERROR"); uomiCtx.put("userLogin", userLogin); @@ -955,7 +934,7 @@ public class OagisShipmentServices { if (Debug.infoOn()) Debug.logInfo("Message send done for oagisSendProcessShipment for orderId [" + orderId + "], sendToUrl=[" + sendToUrl + "], saveToDirectory=[" + saveToDirectory + "], saveToFilename=[" + saveToFilename + "]", module); try { - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_SENT"); uomiCtx.put("userLogin", userLogin); @@ -976,7 +955,7 @@ public class OagisShipmentServices { return ServiceUtil.returnError(errMsg); } - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_SYS_ERROR"); uomiCtx.put("bsrVerb", "PROCESS"); @@ -986,8 +965,8 @@ public class OagisShipmentServices { uomiCtx.put("userLogin", userLogin); dispatcher.runSync("updateOagisMessageInfo", uomiCtx, 60, true); - List errorMapList = UtilMisc.toList(UtilMisc.toMap("description", errMsg, "reasonCode", "SystemError")); - Map saveErrorMapListCtx = FastMap.newInstance(); + List<Map<String, String>> errorMapList = UtilMisc.toList(UtilMisc.toMap("description", errMsg, "reasonCode", "SystemError")); + Map<String, Object> saveErrorMapListCtx = FastMap.newInstance(); saveErrorMapListCtx.putAll(omiPkMap); saveErrorMapListCtx.put("errorMapList", errorMapList); saveErrorMapListCtx.put("userLogin", userLogin); @@ -1003,7 +982,7 @@ public class OagisShipmentServices { return result; } - public static Map oagisSendReceiveDelivery(DispatchContext dctx, Map context) { + public static Map<String, Object> oagisSendReceiveDelivery(DispatchContext dctx, Map<String, Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); Delegator delegator = dctx.getDelegator(); String returnId = (String) context.get("returnId"); @@ -1034,19 +1013,20 @@ public class OagisShipmentServices { OutputStream out = (OutputStream) context.get("outputStream"); - Map result = ServiceUtil.returnSuccess(); - MapStack bodyParameters = MapStack.create(); + Map<String, Object> result = ServiceUtil.returnSuccess(); + MapStack<String> bodyParameters = MapStack.create(); String orderId = null; String referenceId = null; String task = "RMA"; // Actual value of task is "SHIPREQUEST" which is more than 10 char, need this in the db so it will match Confirm BODs, etc String component = "INVENTORY"; - Map omiPkMap = null; + Map<String, String> omiPkMap = null; try { // see if there are any OagisMessageInfo for this order that are in the OAGMP_OGEN_SUCCESS or OAGMP_SENT statuses, if so don't send again; these need to be manually reviewed before resending to avoid accidental duplicate messages - List previousOagisMessageInfoList = delegator.findByAnd("OagisMessageInfo", UtilMisc.toMap("returnId", returnId, "task", task, "component", component)); + List<GenericValue> previousOagisMessageInfoList = delegator.findByAnd("OagisMessageInfo", + UtilMisc.toMap("returnId", returnId, "task", task, "component", component)); if (EntityUtil.filterByAnd(previousOagisMessageInfoList, UtilMisc.toMap("processingStatusId", "OAGMP_OGEN_SUCCESS")).size() > 0) { // this isn't really an error, just a failed constraint so return success String successMsg = "Found existing message info(s) in OAGMP_OGEN_SUCCESS, so not sending Receive Delivery message for return [" + returnId + "] existing message(s) are: " + EntityUtil.filterByAnd(previousOagisMessageInfoList, UtilMisc.toMap("processingStatusId", "OAGMP_OGEN_SUCCESS")); @@ -1067,7 +1047,7 @@ public class OagisShipmentServices { return ServiceUtil.returnError("Return with ID [" + returnId + "] no in accepted status (RETURN_ACCEPTED)"); } - List returnItems = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnId", returnId)); + List<GenericValue> returnItems = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnId", returnId)); bodyParameters.put("returnItems", returnItems); orderId = EntityUtil.getFirst(returnItems).getString("orderId"); @@ -1087,7 +1067,7 @@ public class OagisShipmentServices { // prepare map to Create Oagis Message Info try { - Map comiCtx = FastMap.newInstance(); + Map<String, Object> comiCtx = FastMap.newInstance(); comiCtx.putAll(omiPkMap); comiCtx.put("outgoingMessage", "Y"); comiCtx.put("confirmation", "1"); @@ -1118,11 +1098,9 @@ public class OagisShipmentServices { // calculate total qty of return items in a shipping unit received, order associated with return double totalQty = 0.0; - Map serialNumberListByReturnItemSeqIdMap = FastMap.newInstance(); + Map<String, List<String>> serialNumberListByReturnItemSeqIdMap = FastMap.newInstance(); bodyParameters.put("serialNumberListByReturnItemSeqIdMap", serialNumberListByReturnItemSeqIdMap); - Iterator riIter = returnItems.iterator(); - while (riIter.hasNext()) { - GenericValue returnItem = (GenericValue) riIter.next(); + for (GenericValue returnItem : returnItems) { double itemQty = returnItem.getDouble("returnQuantity").doubleValue(); totalQty += itemQty; @@ -1131,16 +1109,14 @@ public class OagisShipmentServices { GenericValue orderItem = returnItem.getRelatedOne("OrderItem"); if (orderItem != null) { if (orderItem.getDouble("quantity").doubleValue() == itemQty) { - List itemIssuanceAndInventoryItemList = delegator.findByAnd("ItemIssuanceAndInventoryItem", + List<GenericValue> itemIssuanceAndInventoryItemList = delegator.findByAnd("ItemIssuanceAndInventoryItem", UtilMisc.toMap("orderId", orderItem.get("orderId"), "orderItemSeqId", orderItem.get("orderItemSeqId"), "inventoryItemTypeId", "SERIALIZED_INV_ITEM")); if (itemIssuanceAndInventoryItemList.size() == itemQty) { - List serialNumberList = FastList.newInstance(); - serialNumberListByReturnItemSeqIdMap.put(returnItem.get("returnItemSeqId"), serialNumberList); - Iterator itemIssuanceAndInventoryItemIter = itemIssuanceAndInventoryItemList.iterator(); - while (itemIssuanceAndInventoryItemIter.hasNext()) { - GenericValue itemIssuanceAndInventoryItem = (GenericValue) itemIssuanceAndInventoryItemIter.next(); - serialNumberList.add(itemIssuanceAndInventoryItem.get("serialNumber")); + List<String> serialNumberList = FastList.newInstance(); + serialNumberListByReturnItemSeqIdMap.put(returnItem.getString("returnItemSeqId"), serialNumberList); + for (GenericValue itemIssuanceAndInventoryItem : itemIssuanceAndInventoryItemList) { + serialNumberList.add(itemIssuanceAndInventoryItem.getString("serialNumber")); } } else { // TODO: again a quantity mismatch, whatever to do? @@ -1174,7 +1150,7 @@ public class OagisShipmentServices { String outText = writer.toString(); try { - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_OGEN_SUCCESS"); uomiCtx.put("userLogin", userLogin); @@ -1187,10 +1163,10 @@ public class OagisShipmentServices { Debug.logError(e, errMsg, module); } - Map sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); + Map<String, Object> sendMessageReturn = OagisServices.sendMessageText(outText, out, sendToUrl, saveToDirectory, saveToFilename); if (sendMessageReturn != null && ServiceUtil.isError(sendMessageReturn)) { try { - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_SEND_ERROR"); uomiCtx.put("userLogin", userLogin); @@ -1203,7 +1179,7 @@ public class OagisShipmentServices { } try { - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_SENT"); uomiCtx.put("userLogin", userLogin); @@ -1224,7 +1200,7 @@ public class OagisShipmentServices { return ServiceUtil.returnError(errMsg); } - Map uomiCtx = FastMap.newInstance(); + Map<String, Object> uomiCtx = FastMap.newInstance(); uomiCtx.putAll(omiPkMap); uomiCtx.put("processingStatusId", "OAGMP_SYS_ERROR"); uomiCtx.put("bsrVerb", "RECEIVE"); @@ -1234,8 +1210,8 @@ public class OagisShipmentServices { uomiCtx.put("userLogin", userLogin); dispatcher.runSync("updateOagisMessageInfo", uomiCtx, 60, true); - List errorMapList = UtilMisc.toList(UtilMisc.toMap("description", errMsg, "reasonCode", "SystemError")); - Map saveErrorMapListCtx = FastMap.newInstance(); + List<Map<String, String>> errorMapList = UtilMisc.toList(UtilMisc.toMap("description", errMsg, "reasonCode", "SystemError")); + Map<String, Object> saveErrorMapListCtx = FastMap.newInstance(); saveErrorMapListCtx.putAll(omiPkMap); saveErrorMapListCtx.put("errorMapList", errorMapList); saveErrorMapListCtx.put("userLogin", userLogin); |
Free forum by Nabble | Edit this page |