Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java?rev=712918&r1=712917&r2=712918&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java Mon Nov 10 18:19:19 2008 @@ -37,6 +37,7 @@ import org.ofbiz.base.util.HttpClientException; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -145,7 +146,7 @@ * Service to obtain a rate estimate from DHL for a shipment. Notes: Only one package per shipment currently supported by DHL ShipIT. * If this service returns a null shippingEstimateAmount, then the shipment has not been processed */ - public static Map dhlRateEstimate(DispatchContext dctx, Map context) { + public static Map<String, Object> dhlRateEstimate(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); @@ -156,13 +157,13 @@ String carrierPartyId = (String) context.get("carrierPartyId"); String shipmentMethodTypeId = (String) context.get("shipmentMethodTypeId"); String shippingContactMechId = (String) context.get("shippingContactMechId"); - List shippableItemInfo = (List) context.get("shippableItemInfo"); + List shippableItemInfo = UtilGenerics.checkList(context.get("shippableItemInfo")); Double shippableTotal = (Double) context.get("shippableTotal"); Double shippableQuantity = (Double) context.get("shippableQuantity"); Double shippableWeight = (Double) context.get("shippableWeight"); if (shipmentMethodTypeId.equals("NO_SHIPPING")) { - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("shippingEstimateAmount", null); return result; } @@ -230,7 +231,7 @@ return ServiceUtil.returnError("Cannot get DHL Estimate: DHL Rate template not configured (shipment.template.dhl.rate.estimate"); } StringWriter outWriter = new StringWriter(); - Map inContext = FastMap.newInstance(); + Map<String, Object> inContext = FastMap.newInstance(); inContext.put("action", "RateEstimate"); inContext.put("userid", userid); inContext.put("password", password); @@ -296,9 +297,9 @@ /* * Parses an XML document from DHL to get the rate estimate */ - public static Map handleDhlRateResponse(Document rateResponseDocument) { - List errorList = FastList.newInstance(); - Map dhlRateCodeMap = FastMap.newInstance(); + public static Map<String, Object> handleDhlRateResponse(Document rateResponseDocument) { + List<Object> errorList = FastList.newInstance(); + Map<String, Object> dhlRateCodeMap = FastMap.newInstance(); // process RateResponse Element rateResponseElement = rateResponseDocument.getDocumentElement(); DhlServices.handleErrors(rateResponseElement, errorList); @@ -338,15 +339,15 @@ responseRateEstimateElement, "TotalChargeEstimate"); Element responseChargesElement = UtilXml.firstChildElement( responseRateEstimateElement, "Charges"); - List chargeNodeList = UtilXml.childElementList(responseChargesElement, + List<? extends Element> chargeNodeList = UtilXml.childElementList(responseChargesElement, "Charge"); - List chargeList = FastList.newInstance(); + List<Map<String, String>> chargeList = FastList.newInstance(); if (UtilValidate.isNotEmpty(chargeNodeList)) { for (int i = 0; chargeNodeList.size() > i; i++) { - Map charge = FastMap.newInstance(); + Map<String, String> charge = FastMap.newInstance(); - Element responseChargeElement = (Element) chargeNodeList.get(i); + Element responseChargeElement = chargeNodeList.get(i); Element responseChargeTypeElement = UtilXml.firstChildElement( responseChargeElement, "Type"); @@ -370,7 +371,7 @@ dhlRateCodeMap.put("totalChargeEstimate", responseTotalChargeEstimate); dhlRateCodeMap.put("chargeList", chargeList); - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("shippingEstimateAmount", shippingEstimateAmount); result.put("dhlRateCodeMap", dhlRateCodeMap); return result; @@ -379,9 +380,9 @@ /* * Register a DHL account for shipping by obtaining the DHL shipping key */ - public static Map dhlRegisterInquire(DispatchContext dctx, Map context) { + public static Map<String, Object> dhlRegisterInquire(DispatchContext dctx, Map<String, ? extends Object> context) { - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); String postalCode = (String) context.get("postalCode"); String accountNbr = UtilProperties.getPropertyValue("shipment", "shipment.dhl.access.accountNbr"); @@ -455,9 +456,9 @@ /* * Parse response from DHL registration request to get shipping key */ - public static Map handleDhlRegisterResponse( + public static Map<String, Object> handleDhlRegisterResponse( Document registerResponseDocument) { - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); // process RegisterResponse Element registerResponseElement = registerResponseDocument .getDocumentElement(); @@ -485,7 +486,7 @@ String responsePostalCode = UtilXml.childElementValue(responseElement, "PostalCode"); - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("shippingKey", responseShippingKey); return result; } @@ -494,7 +495,7 @@ * Pass a shipment request to DHL via ShipIT and get a tracking number and a label back, among other things */ - public static Map dhlShipmentConfirm(DispatchContext dctx, Map context) { + public static Map<String, Object> dhlShipmentConfirm(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Locale locale = (Locale) context.get("locale"); @@ -502,7 +503,7 @@ GenericValue userLogin = (GenericValue) context.get("userLogin"); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); String shipmentConfirmResponseString = null; try { GenericValue shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId)); @@ -566,7 +567,7 @@ } String recipientEmail = null; - Map results = dispatcher.runSync("getPartyEmail", UtilMisc.toMap("partyId", shipment.get("partyIdTo"), "userLogin", userLogin)); + Map<String, Object> results = dispatcher.runSync("getPartyEmail", UtilMisc.toMap("partyId", shipment.get("partyIdTo"), "userLogin", userLogin)); if (results.get("emailAddress") != null) { recipientEmail = (String) results.get("emailAddress"); } @@ -577,7 +578,7 @@ return ServiceUtil.returnError("DestCountryGeo not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } - List shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); + List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (shipmentPackageRouteSegs == null || shipmentPackageRouteSegs.size() == 0) { return ServiceUtil.returnError("No ShipmentPackageRouteSegs (ie No Packages) found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } @@ -611,15 +612,15 @@ String width = null; String height = null; Double packageWeight = null; - Iterator shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator(); + Iterator<GenericValue> shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator(); while (shipmentPackageRouteSegIter.hasNext()) { - GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegIter.next(); + GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegIter.next(); GenericValue shipmentPackage = shipmentPackageRouteSeg.getRelatedOne("ShipmentPackage"); GenericValue shipmentBoxType = shipmentPackage.getRelatedOne("ShipmentBoxType"); - List carrierShipmentBoxTypes = shipmentPackage.getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "DHL"), null); + List<GenericValue> carrierShipmentBoxTypes = shipmentPackage.getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "DHL"), null); GenericValue carrierShipmentBoxType = null; if (carrierShipmentBoxTypes.size() > 0) { - carrierShipmentBoxType = (GenericValue) carrierShipmentBoxTypes.get(0); + carrierShipmentBoxType = carrierShipmentBoxTypes.get(0); } // TODO: determine what default UoM is (assuming inches) - there should be a defaultDimensionUomId in Facility @@ -705,7 +706,7 @@ return ServiceUtil.returnError("Cannot get DHL Estimate: DHL Rate template not configured (shipment.template.dhl.rate.estimate"); } StringWriter outWriter = new StringWriter(); - Map inContext = FastMap.newInstance(); + Map<String, Object> inContext = FastMap.newInstance(); inContext.put("action", "GenerateLabel"); inContext.put("userid", userid); inContext.put("password", password); @@ -774,10 +775,10 @@ } // NOTE: Must VOID shipments on errors - public static Map handleDhlShipmentConfirmResponse(String rateResponseString, GenericValue shipmentRouteSegment, - List shipmentPackageRouteSegs) throws GenericEntityException { - Map result = FastMap.newInstance(); - GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegs.get(0); + public static Map<String, Object> handleDhlShipmentConfirmResponse(String rateResponseString, GenericValue shipmentRouteSegment, + List<GenericValue> shipmentPackageRouteSegs) throws GenericEntityException { + Map<String, Object> result = FastMap.newInstance(); + GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegs.get(0); // TODO: figure out how to handle validation on return XML, which can be mangled // Ideas: try again right away, let user try again, etc. @@ -841,12 +842,12 @@ return ServiceUtil.returnSuccess("DHL Shipment Confirmed."); } - private static double getWeight(List shippableItemInfo) { + private static double getWeight(List<Map<String, Object>> shippableItemInfo) { double totalWeight = 0; if (shippableItemInfo != null) { - Iterator sii = shippableItemInfo.iterator(); + Iterator<Map<String, Object>> sii = shippableItemInfo.iterator(); while (sii.hasNext()) { - Map itemInfo = (Map) sii.next(); + Map<String, Object> itemInfo = sii.next(); double weight = ((Double) itemInfo.get("weight")).doubleValue(); totalWeight = totalWeight + weight; } @@ -882,15 +883,15 @@ return eCommerceRequestDocument; } - public static void handleErrors(Element responseElement, List errorList) { + public static void handleErrors(Element responseElement, List<Object> errorList) { Element faultsElement = UtilXml.firstChildElement(responseElement, "Faults"); - List faultElements = UtilXml.childElementList(faultsElement, "Fault"); + List<? extends Element> faultElements = UtilXml.childElementList(faultsElement, "Fault"); if (UtilValidate.isNotEmpty(faultElements)) { - Iterator errorElementIter = faultElements.iterator(); + Iterator<? extends Element> errorElementIter = faultElements.iterator(); while (errorElementIter.hasNext()) { StringBuilder errorMessageBuf = new StringBuilder(); - Element errorElement = (Element) errorElementIter.next(); + Element errorElement = errorElementIter.next(); String errorCode = UtilXml.childElementValue(errorElement, "Code"); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java?rev=712918&r1=712917&r2=712918&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java Mon Nov 10 18:19:19 2008 @@ -135,9 +135,9 @@ /* * Register a Fedex account for shipping by obtaining the meter number */ - public static Map fedexSubscriptionRequest( DispatchContext dctx, Map context) { + public static Map<String, Object> fedexSubscriptionRequest( DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); Boolean replaceMeterNumber = (Boolean) context.get("replaceMeterNumber"); @@ -151,7 +151,7 @@ String companyPartyId = (String) context.get("companyPartyId"); String contactPartyName = (String) context.get("contactPartyName"); - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); String accountNumber = UtilProperties.getPropertyValue(shipmentPropertiesFile, "shipment.fedex.access.accountNbr"); if (UtilValidate.isEmpty(accountNumber)) { @@ -186,12 +186,12 @@ } // Get the contact information for the company - List partyContactDetails = delegator.findByAnd("PartyContactDetailByPurpose", UtilMisc.toMap("partyId", companyPartyId)); + List<GenericValue> partyContactDetails = delegator.findByAnd("PartyContactDetailByPurpose", UtilMisc.toMap("partyId", companyPartyId)); partyContactDetails = EntityUtil.filterByDate(partyContactDetails); partyContactDetails = EntityUtil.filterByDate(partyContactDetails, UtilDateTime.nowTimestamp(), "purposeFromDate", "purposeThruDate", true); // Get the first valid postal address (address1, city, postalCode and countryGeoId are required by Fedex) - List postalAddressConditions = FastList.newInstance(); + List<EntityCondition> postalAddressConditions = FastList.newInstance(); postalAddressConditions.add(EntityCondition.makeCondition("contactMechTypeId", EntityOperator.EQUALS, "POSTAL_ADDRESS")); postalAddressConditions.add(EntityCondition.makeCondition("address1", EntityOperator.NOT_EQUAL, null)); postalAddressConditions.add(EntityCondition.makeCondition("address1", EntityOperator.NOT_EQUAL, "")); @@ -201,7 +201,7 @@ postalAddressConditions.add(EntityCondition.makeCondition("postalCode", EntityOperator.NOT_EQUAL, "")); postalAddressConditions.add(EntityCondition.makeCondition("countryGeoId", EntityOperator.NOT_EQUAL, null)); postalAddressConditions.add(EntityCondition.makeCondition("countryGeoId", EntityOperator.NOT_EQUAL, "")); - List postalAddresses = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(postalAddressConditions, EntityOperator.AND)); + List<GenericValue> postalAddresses = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(postalAddressConditions, EntityOperator.AND)); // Fedex requires USA or Canada addresses to have a state/province ID, so filter out the ones without postalAddressConditions.clear(); @@ -229,14 +229,14 @@ } // Get the first valid primary phone number (required by Fedex) - List phoneNumberConditions = FastList.newInstance(); + List<EntityCondition> phoneNumberConditions = FastList.newInstance(); phoneNumberConditions.add(EntityCondition.makeCondition("contactMechTypeId", EntityOperator.EQUALS, "TELECOM_NUMBER")); phoneNumberConditions.add(EntityCondition.makeCondition("contactMechPurposeTypeId", EntityOperator.EQUALS, "PRIMARY_PHONE")); phoneNumberConditions.add(EntityCondition.makeCondition("areaCode", EntityOperator.NOT_EQUAL, null)); phoneNumberConditions.add(EntityCondition.makeCondition("areaCode", EntityOperator.NOT_EQUAL, "")); phoneNumberConditions.add(EntityCondition.makeCondition("contactNumber", EntityOperator.NOT_EQUAL, null)); phoneNumberConditions.add(EntityCondition.makeCondition("contactNumber", EntityOperator.NOT_EQUAL, "")); - List phoneNumbers = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(phoneNumberConditions, EntityOperator.AND)); + List<GenericValue> phoneNumbers = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(phoneNumberConditions, EntityOperator.AND)); GenericValue phoneNumberValue = EntityUtil.getFirst(phoneNumbers); if (UtilValidate.isEmpty(phoneNumberValue)) { String errorMessage = "Party with partyId " + companyPartyId + " does not have a current, fully populated primary phone number"; @@ -251,14 +251,14 @@ phoneNumber = phoneNumber.replaceAll("[^+\\d]", ""); // Get the first valid fax number - List faxNumberConditions = FastList.newInstance(); + List<EntityCondition> faxNumberConditions = FastList.newInstance(); faxNumberConditions.add(EntityCondition.makeCondition("contactMechTypeId", EntityOperator.EQUALS, "TELECOM_NUMBER")); faxNumberConditions.add(EntityCondition.makeCondition("contactMechPurposeTypeId", EntityOperator.EQUALS, "FAX_NUMBER")); faxNumberConditions.add(EntityCondition.makeCondition("areaCode", EntityOperator.NOT_EQUAL, null)); faxNumberConditions.add(EntityCondition.makeCondition("areaCode", EntityOperator.NOT_EQUAL, "")); faxNumberConditions.add(EntityCondition.makeCondition("contactNumber", EntityOperator.NOT_EQUAL, null)); faxNumberConditions.add(EntityCondition.makeCondition("contactNumber", EntityOperator.NOT_EQUAL, "")); - List faxNumbers = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(faxNumberConditions, EntityOperator.AND)); + List<GenericValue> faxNumbers = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(faxNumberConditions, EntityOperator.AND)); GenericValue faxNumberValue = EntityUtil.getFirst(faxNumbers); if(! UtilValidate.isEmpty(faxNumberValue)) { faxNumber = faxNumberValue.getString("areaCode") + faxNumberValue.getString("contactNumber"); @@ -270,11 +270,11 @@ } // Get the first valid email address - List emailConditions = FastList.newInstance(); + List<EntityCondition> emailConditions = FastList.newInstance(); emailConditions.add(EntityCondition.makeCondition("contactMechTypeId", EntityOperator.EQUALS, "EMAIL_ADDRESS")); emailConditions.add(EntityCondition.makeCondition("infoString", EntityOperator.NOT_EQUAL, null)); emailConditions.add(EntityCondition.makeCondition("infoString", EntityOperator.NOT_EQUAL, "")); - List emailAddresses = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(emailConditions, EntityOperator.AND)); + List<GenericValue> emailAddresses = EntityUtil.filterByCondition(partyContactDetails, EntityCondition.makeCondition(emailConditions, EntityOperator.AND)); GenericValue emailAddressValue = EntityUtil.getFirst(emailAddresses); if(! UtilValidate.isEmpty(emailAddressValue)) { emailAddress = emailAddressValue.getString("infoString"); @@ -287,7 +287,7 @@ } // Populate the Freemarker context - Map subscriptionRequestContext = FastMap.newInstance(); + Map<String, Object> subscriptionRequestContext = FastMap.newInstance(); subscriptionRequestContext.put("AccountNumber", accountNumber); subscriptionRequestContext.put("PersonName", contactPartyName); subscriptionRequestContext.put("CompanyName", companyName); @@ -371,12 +371,12 @@ * * Send a FDXShipRequest via the Ship Manager Direct API */ - public static Map fedexShipRequest( DispatchContext dctx, Map context) { + public static Map<String, Object> fedexShipRequest( DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); @@ -431,7 +431,7 @@ try { - Map shipRequestContext = FastMap.newInstance(); + Map<String, Object> shipRequestContext = FastMap.newInstance(); // Get the shipment and the shipmentRouteSegment GenericValue shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId)); @@ -606,7 +606,7 @@ } } - List shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", UtilMisc.toList("+shipmentPackageSeqId")); + List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", UtilMisc.toList("+shipmentPackageSeqId")); if (UtilValidate.isEmpty(shipmentPackageRouteSegs)) { return ServiceUtil.returnError("No ShipmentPackageRouteSegs (ie No Packages) found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } @@ -673,7 +673,7 @@ // Convert the weight if necessary if (! billingWeightUomId.equals(weightUomId)) { - Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", billingWeightUomId, "uomIdTo", weightUomId, "originalValue", billingWeight)); + Map<String, Object> results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", billingWeightUomId, "uomIdTo", weightUomId, "originalValue", billingWeight)); if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) { Debug.logWarning("Unable to convert billing weights for shipmentId " + shipmentId , module); @@ -686,10 +686,10 @@ } // Loop through Shipment segments (NOTE: only one supported, loop is here for future refactoring reference) - Iterator shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator(); + Iterator<GenericValue> shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator(); while (shipmentPackageRouteSegIter.hasNext()) { - GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegIter.next(); + GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegIter.next(); GenericValue shipmentPackage = shipmentPackageRouteSeg.getRelatedOne("ShipmentPackage"); GenericValue shipmentBoxType = shipmentPackage.getRelatedOne("ShipmentBoxType"); @@ -735,7 +735,7 @@ } if (dimensionsLength != null && dimensionsLength.doubleValue() > 0) { if (! boxDimensionsUomId.equals(dimensionsUomId)) { - Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsLength)); + Map<String, Object> results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsLength)); if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) { Debug.logWarning("Unable to convert length for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId , module); dimensionsLength = null; @@ -747,7 +747,7 @@ } if (dimensionsWidth != null && dimensionsWidth.doubleValue() > 0) { if (! boxDimensionsUomId.equals(dimensionsUomId)) { - Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsWidth)); + Map<String, Object> results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsWidth)); if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) { Debug.logWarning("Unable to convert width for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId , module); dimensionsWidth = null; @@ -759,7 +759,7 @@ } if (dimensionsHeight != null && dimensionsHeight.doubleValue() > 0) { if (! boxDimensionsUomId.equals(dimensionsUomId)) { - Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsHeight)); + Map<String, Object> results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsHeight)); if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) { Debug.logWarning("Unable to convert height for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId , module); dimensionsHeight = null; @@ -794,7 +794,7 @@ packageWeightUomId = weightUomId; } if (! packageWeightUomId.equals(weightUomId)) { - Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", packageWeightUomId, "uomIdTo", weightUomId, "originalValue", packageWeight)); + Map<String, Object> results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", packageWeightUomId, "uomIdTo", weightUomId, "originalValue", packageWeight)); if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) { ServiceUtil.returnError("Unable to convert weight for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId); } else { @@ -865,9 +865,9 @@ * @param shipmentPackageRouteSegs * @throws GenericEntityException */ - public static Map handleFedexShipReply(String fDXShipReplyString, GenericValue shipmentRouteSegment, List shipmentPackageRouteSegs) throws GenericEntityException { - List errorList = FastList.newInstance(); - GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegs.get(0); + public static Map<String, Object> handleFedexShipReply(String fDXShipReplyString, GenericValue shipmentRouteSegment, List<GenericValue> shipmentPackageRouteSegs) throws GenericEntityException { + List<Object> errorList = FastList.newInstance(); + GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegs.get(0); Document fdxShipReplyDocument = null; try { @@ -933,7 +933,7 @@ } - public static void handleErrors(Element rootElement, List errorList) { + public static void handleErrors(Element rootElement, List<Object> errorList) { Element errorElement = null; if ("Error".equalsIgnoreCase(rootElement.getNodeName())) { errorElement = rootElement; Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java?rev=712918&r1=712917&r2=712918&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java Mon Nov 10 18:19:19 2008 @@ -41,6 +41,7 @@ import org.ofbiz.base.util.HttpClient; import org.ofbiz.base.util.HttpClientException; import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilNumber; import org.ofbiz.base.util.UtilProperties; @@ -69,23 +70,23 @@ public final static String module = UpsServices.class.getName(); - public static Map unitsUpsToOfbiz = FastMap.newInstance(); - public static Map unitsOfbizToUps = FastMap.newInstance(); + public static Map<String, String> unitsUpsToOfbiz = FastMap.newInstance(); + public static Map<String, String> unitsOfbizToUps = FastMap.newInstance(); static { unitsUpsToOfbiz.put("LBS", "WT_lb"); unitsUpsToOfbiz.put("KGS", "WT_kg"); - Iterator unitsUpsToOfbizIter = unitsUpsToOfbiz.entrySet().iterator(); + Iterator<Map.Entry<String, String>> unitsUpsToOfbizIter = unitsUpsToOfbiz.entrySet().iterator(); while (unitsUpsToOfbizIter.hasNext()) { - Map.Entry entry = (Map.Entry) unitsUpsToOfbizIter.next(); + Map.Entry<String, String> entry = unitsUpsToOfbizIter.next(); unitsOfbizToUps.put(entry.getValue(), entry.getKey()); } } public static final int decimals = UtilNumber.getBigDecimalScale("order.decimals"); public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding"); - public static Map upsShipmentConfirm(DispatchContext dctx, Map context) { - Map result = FastMap.newInstance(); + public static Map<String, Object> upsShipmentConfirm(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); @@ -176,30 +177,30 @@ return ServiceUtil.returnError("DestCountryGeo not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } - Map findCarrierShipmentMethodMap = UtilMisc.toMap("partyId", shipmentRouteSegment.get("carrierPartyId"), "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")); + Map<String, Object> findCarrierShipmentMethodMap = UtilMisc.toMap("partyId", shipmentRouteSegment.get("carrierPartyId"), "roleTypeId", "CARRIER", "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")); GenericValue carrierShipmentMethod = delegator.findByPrimaryKey("CarrierShipmentMethod", findCarrierShipmentMethodMap); if (carrierShipmentMethod == null) { return ServiceUtil.returnError("CarrierShipmentMethod not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId + "; partyId is " + shipmentRouteSegment.get("carrierPartyId") + " and shipmentMethodTypeId is " + shipmentRouteSegment.get("shipmentMethodTypeId")); } - List shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); + List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (shipmentPackageRouteSegs == null || shipmentPackageRouteSegs.size() == 0) { return ServiceUtil.returnError("No ShipmentPackageRouteSegs (ie No Packages) found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } - List itemIssuances = shipment.getRelated("ItemIssuance"); - Set orderIdSet = new TreeSet(); - Iterator itemIssuanceIter = itemIssuances.iterator(); + List<GenericValue> itemIssuances = shipment.getRelated("ItemIssuance"); + Set<String> orderIdSet = new TreeSet<String>(); + Iterator<GenericValue> itemIssuanceIter = itemIssuances.iterator(); while (itemIssuanceIter.hasNext()) { - GenericValue itemIssuance = (GenericValue) itemIssuanceIter.next(); - orderIdSet.add(itemIssuance.get("orderId")); + GenericValue itemIssuance = itemIssuanceIter.next(); + orderIdSet.add(itemIssuance.getString("orderId")); } String ordersDescription = ""; if (orderIdSet.size() > 1) { StringBuilder odBuf = new StringBuilder("Orders "); - Iterator orderIdIter = orderIdSet.iterator(); + Iterator<String> orderIdIter = orderIdSet.iterator(); while (orderIdIter.hasNext()) { - String orderId = (String) orderIdIter.next(); + String orderId = orderIdIter.next(); odBuf.append(orderId); if (orderIdIter.hasNext()) { odBuf.append(", "); @@ -207,7 +208,7 @@ } ordersDescription = odBuf.toString(); } else if (orderIdSet.size() > 0) { - ordersDescription = "Order " + (String) orderIdSet.iterator().next(); + ordersDescription = "Order " + orderIdSet.iterator().next(); } // COD Support @@ -217,8 +218,8 @@ if (allowCOD) { // Get the paymentMethodTypeIds of all the orderPaymentPreferences involved with the shipment - List opps = delegator.findList("OrderPaymentPreference", EntityCondition.makeCondition("orderId", EntityOperator.IN, orderIdSet), null, null, null, false); - List paymentMethodTypeIds = EntityUtil.getFieldListFromEntityList(opps, "paymentMethodTypeId", true); + List<GenericValue> opps = delegator.findList("OrderPaymentPreference", EntityCondition.makeCondition("orderId", EntityOperator.IN, orderIdSet), null, null, null, false); + List<String> paymentMethodTypeIds = EntityUtil.getFieldListFromEntityList(opps, "paymentMethodTypeId", true); if (paymentMethodTypeIds.size() > 1 || ! paymentMethodTypeIds.contains("EXT_COD")) { allowCOD = false; @@ -402,15 +403,15 @@ UtilXml.addChildElementValue(serviceElement, "Code", carrierShipmentMethod.getString("carrierServiceCode"), shipmentConfirmRequestDoc); // Child of Shipment: Package - ListIterator shipmentPackageRouteSegIter = shipmentPackageRouteSegs.listIterator(); + ListIterator<GenericValue> shipmentPackageRouteSegIter = shipmentPackageRouteSegs.listIterator(); while (shipmentPackageRouteSegIter.hasNext()) { - GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegIter.next(); + GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegIter.next(); GenericValue shipmentPackage = shipmentPackageRouteSeg.getRelatedOne("ShipmentPackage"); GenericValue shipmentBoxType = shipmentPackage.getRelatedOne("ShipmentBoxType"); - List carrierShipmentBoxTypes = shipmentPackage.getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "UPS"), null); + List<GenericValue> carrierShipmentBoxTypes = shipmentPackage.getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "UPS"), null); GenericValue carrierShipmentBoxType = null; if (carrierShipmentBoxTypes.size() > 0) { - carrierShipmentBoxType = (GenericValue) carrierShipmentBoxTypes.get(0); + carrierShipmentBoxType = carrierShipmentBoxTypes.get(0); } Element packageElement = UtilXml.addChildElement(shipmentElement, "Package", shipmentConfirmRequestDoc); @@ -441,7 +442,7 @@ Element packageWeightElement = UtilXml.addChildElement(packageElement, "PackageWeight", shipmentConfirmRequestDoc); Element packageWeightUnitOfMeasurementElement = UtilXml.addChildElement(packageElement, "UnitOfMeasurement", shipmentConfirmRequestDoc); - String weightUomUps = (String) unitsOfbizToUps.get(shipmentPackage.get("weightUomId")); + String weightUomUps = unitsOfbizToUps.get(shipmentPackage.get("weightUomId")); if (weightUomUps != null) { UtilXml.addChildElementValue(packageWeightUnitOfMeasurementElement, "Code", weightUomUps, shipmentConfirmRequestDoc); } else { @@ -492,12 +493,12 @@ UtilXml.addChildElementValue(codAmountElement, "CurrencyCode", currencyCode, shipmentConfirmRequestDoc); // Get the value of the package by going back to the orderItems - Map getPackageValueResult = dispatcher.runSync("getShipmentPackageValueFromOrders", UtilMisc.toMap("shipmentId", shipmentId, "shipmentPackageSeqId", shipmentPackage.get("shipmentPackageSeqId"), "currencyUomId", currencyCode, "userLogin", userLogin, "locale", locale)); + Map<String, Object> getPackageValueResult = dispatcher.runSync("getShipmentPackageValueFromOrders", UtilMisc.toMap("shipmentId", shipmentId, "shipmentPackageSeqId", shipmentPackage.get("shipmentPackageSeqId"), "currencyUomId", currencyCode, "userLogin", userLogin, "locale", locale)); if (ServiceUtil.isError(getPackageValueResult)) return getPackageValueResult; BigDecimal packageValue = (BigDecimal) getPackageValueResult.get("packageValue"); // Convert the value of the COD surcharge to the shipment currency, if necessary - Map convertUomResult = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", codSurchargeCurrencyUomId, "uomIdTo", currencyCode, "originalValue", Double.valueOf(codSurchargePackageAmount.doubleValue()))); + Map<String, Object> convertUomResult = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", codSurchargeCurrencyUomId, "uomIdTo", currencyCode, "originalValue", Double.valueOf(codSurchargePackageAmount.doubleValue()))); if (ServiceUtil.isError(convertUomResult)) return convertUomResult; if (convertUomResult.containsKey("convertedValue")) { codSurchargePackageAmount = new BigDecimal(((Double) convertUomResult.get("convertedValue")).doubleValue()).setScale(decimals, rounding); @@ -606,7 +607,7 @@ } } - public static Map handleUpsShipmentConfirmResponse(Document shipmentConfirmResponseDocument, GenericValue shipmentRouteSegment) throws GenericEntityException { + public static Map<String, Object> handleUpsShipmentConfirmResponse(Document shipmentConfirmResponseDocument, GenericValue shipmentRouteSegment) throws GenericEntityException { // process ShipmentConfirmResponse, update data as needed Element shipmentConfirmResponseElement = shipmentConfirmResponseDocument.getDocumentElement(); @@ -618,7 +619,7 @@ String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); UpsServices.handleErrors(responseElement, errorList); if ("1".equals(responseStatusCode)) { @@ -700,10 +701,9 @@ if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway successString.append(", but the following occurred: "); - Iterator errorListIter = errorList.iterator(); + Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { - String errorMsg = (String) errorListIter.next(); - successString.append(errorMsg); + successString.append(errorListIter.next()); if (errorListIter.hasNext()) { successString.append(", "); } @@ -716,8 +716,8 @@ } } - public static Map upsShipmentAccept(DispatchContext dctx, Map context) { - Map result = FastMap.newInstance(); + public static Map<String, Object> upsShipmentAccept(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); @@ -747,7 +747,7 @@ return ServiceUtil.returnError("ERROR: The Carrier Service Status for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is [" + shipmentRouteSegment.getString("carrierServiceStatusId") + "], but must be [SHRSCS_CONFIRMED] to perform the UPS Shipment Accept operation."); } - List shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); + List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (shipmentPackageRouteSegs == null || shipmentPackageRouteSegs.size() == 0) { return ServiceUtil.returnError("No ShipmentPackageRouteSegs found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } @@ -857,7 +857,7 @@ } } - public static Map handleUpsShipmentAcceptResponse(Document shipmentAcceptResponseDocument, GenericValue shipmentRouteSegment, List shipmentPackageRouteSegs) throws GenericEntityException { + public static Map<String, Object> handleUpsShipmentAcceptResponse(Document shipmentAcceptResponseDocument, GenericValue shipmentRouteSegment, List<GenericValue> shipmentPackageRouteSegs) throws GenericEntityException { boolean shipmentUpsSaveCertificationInfo = "true".equals(UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.info")); String shipmentUpsSaveCertificationPath = UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.path"); File shipmentUpsSaveCertificationFile = null; @@ -879,7 +879,7 @@ String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); UpsServices.handleErrors(responseElement, errorList); if ("1".equals(responseStatusCode)) { @@ -962,11 +962,11 @@ shipmentRouteSegment.store(); // now process the PackageResults elements - List packageResultsElements = UtilXml.childElementList(shipmentResultsElement, "PackageResults"); - Iterator packageResultsElementIter = packageResultsElements.iterator(); - Iterator shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator(); + List<? extends Element> packageResultsElements = UtilXml.childElementList(shipmentResultsElement, "PackageResults"); + Iterator<GenericValue> shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator(); + Iterator<? extends Element> packageResultsElementIter = packageResultsElements.iterator(); while (packageResultsElementIter.hasNext()) { - Element packageResultsElement = (Element) packageResultsElementIter.next(); + Element packageResultsElement = packageResultsElementIter.next(); String trackingNumber = UtilXml.childElementValue(packageResultsElement, "TrackingNumber"); @@ -990,7 +990,7 @@ } //NOTE: I guess they come back in the same order we sent them, so we'll get the packages in order and off we go... - GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegIter.next(); + GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegIter.next(); shipmentPackageRouteSeg.set("trackingCode", trackingNumber); shipmentPackageRouteSeg.set("boxNumber", ""); shipmentPackageRouteSeg.set("currencyUomId", packageServiceOptionsCurrencyCode); @@ -1067,10 +1067,9 @@ if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway successString.append(", but the following occurred: "); - Iterator errorListIter = errorList.iterator(); + Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { - String errorMsg = (String) errorListIter.next(); - successString.append(errorMsg); + successString.append(errorListIter.next()); if (errorListIter.hasNext()) { successString.append(", "); } @@ -1083,8 +1082,8 @@ } } - public static Map upsVoidShipment(DispatchContext dctx, Map context) { - Map result = FastMap.newInstance(); + public static Map<String, Object> upsVoidShipment(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); @@ -1219,7 +1218,7 @@ } } - public static Map handleUpsVoidShipmentResponse(Document voidShipmentResponseDocument, GenericValue shipmentRouteSegment) throws GenericEntityException { + public static Map<String, Object> handleUpsVoidShipmentResponse(Document voidShipmentResponseDocument, GenericValue shipmentRouteSegment) throws GenericEntityException { // process VoidShipmentResponse, update data as needed Element voidShipmentResponseElement = voidShipmentResponseDocument.getDocumentElement(); @@ -1231,7 +1230,7 @@ String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); UpsServices.handleErrors(responseElement, errorList); // handle other response elements @@ -1255,10 +1254,9 @@ if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway successString.append(", but the following occurred: "); - Iterator errorListIter = errorList.iterator(); + Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { - String errorMsg = (String) errorListIter.next(); - successString.append(errorMsg); + successString.append(errorListIter.next()); if (errorListIter.hasNext()) { successString.append(", "); } @@ -1271,8 +1269,8 @@ } } - public static Map upsTrackShipment(DispatchContext dctx, Map context) { - Map result = FastMap.newInstance(); + public static Map<String, Object> upsTrackShipment(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> result = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); @@ -1302,7 +1300,7 @@ return ServiceUtil.returnError("ERROR: The Carrier Service Status for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is [" + shipmentRouteSegment.getString("carrierServiceStatusId") + "], but must be [SHRSCS_ACCEPTED] to perform the UPS Track Shipment operation."); } - List shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); + List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (shipmentPackageRouteSegs == null || shipmentPackageRouteSegs.size() == 0) { return ServiceUtil.returnError("No ShipmentPackageRouteSegs found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); } @@ -1410,7 +1408,7 @@ } } - public static Map handleUpsTrackShipmentResponse(Document trackResponseDocument, GenericValue shipmentRouteSegment, List shipmentPackageRouteSegs) throws GenericEntityException { + public static Map<String, Object> handleUpsTrackShipmentResponse(Document trackResponseDocument, GenericValue shipmentRouteSegment, List shipmentPackageRouteSegs) throws GenericEntityException { // process TrackResponse, update data as needed Element trackResponseElement = trackResponseDocument.getDocumentElement(); @@ -1422,7 +1420,7 @@ String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); UpsServices.handleErrors(responseElement, errorList); if ("1".equals(responseStatusCode)) { @@ -1438,10 +1436,10 @@ String shipmentIdentificationNumber = UtilXml.childElementValue(shipmentElement, "ShipmentIdentificationNumber"); - List packageElements = UtilXml.childElementList(shipmentElement, "Package"); - Iterator packageElementIter = packageElements.iterator(); + List<? extends Element> packageElements = UtilXml.childElementList(shipmentElement, "Package"); + Iterator<? extends Element> packageElementIter = packageElements.iterator(); while (packageElementIter.hasNext()) { - Element packageElement = (Element) packageElementIter.next(); + Element packageElement = packageElementIter.next(); } /* <Package> @@ -1485,10 +1483,9 @@ if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway successString.append(", but the following occurred: "); - Iterator errorListIter = errorList.iterator(); + Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { - String errorMsg = (String) errorListIter.next(); - successString.append(errorMsg); + successString.append(errorListIter.next()); if (errorListIter.hasNext()) { successString.append(", "); } @@ -1501,7 +1498,7 @@ } } - public static Map upsRateInquire(DispatchContext dctx, Map context) { + public static Map<String, Object> upsRateInquire(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); // prepare the data String shippingContactMechId = (String) context.get("shippingContactMechId"); @@ -1540,7 +1537,7 @@ if (UtilValidate.isEmpty(destCountryGeo)) { return ServiceUtil.returnError("Destination CountryGeo not found for ship-to address"); } - Map cxt = UtilMisc.toMap("serviceConfigProps", context.get("serviceConfigProps"), "upsRateInquireMode", context.get("upsRateInquireMode"), + Map<String, Object> cxt = UtilMisc.toMap("serviceConfigProps", context.get("serviceConfigProps"), "upsRateInquireMode", context.get("upsRateInquireMode"), "productStoreId", context.get("productStoreId"), "carrierRoleTypeId", context.get("carrierRoleTypeId")); cxt.put("carrierPartyId", context.get("carrierPartyId")); cxt.put("shipmentMethodTypeId", context.get("shipmentMethodTypeId")); @@ -1562,12 +1559,12 @@ } } - private static void splitEstimatePackages(Document requestDoc, Element shipmentElement, List shippableItemInfo, double maxWeight, double minWeight) { - List packages = getPackageSplit(shippableItemInfo, maxWeight); + private static void splitEstimatePackages(Document requestDoc, Element shipmentElement, List<Map<String, Object>> shippableItemInfo, double maxWeight, double minWeight) { + List<Map<String, Double>> packages = getPackageSplit(shippableItemInfo, maxWeight); if (UtilValidate.isNotEmpty(packages)) { - Iterator i = packages.iterator(); + Iterator<Map<String, Double>> i = packages.iterator(); while (i.hasNext()) { - Map packageMap = (Map) i.next(); + Map<String, Double> packageMap = i.next(); addPackageElement(requestDoc, shipmentElement, shippableItemInfo, packageMap, minWeight); } } else { @@ -1588,7 +1585,7 @@ } } - private static void addPackageElement(Document requestDoc, Element shipmentElement, List shippableItemInfo, Map packageMap, double minWeight) { + private static void addPackageElement(Document requestDoc, Element shipmentElement, List<Map<String, Object>> shippableItemInfo, Map<String, Double> packageMap, double minWeight) { double packageWeight = checkForDefaultPackageWeight(calcPackageWeight(packageMap, shippableItemInfo, 0),minWeight); Element packageElement = UtilXml.addChildElement(shipmentElement, "Package", requestDoc); Element packagingTypeElement = UtilXml.addChildElement(packageElement, "PackagingType", requestDoc); @@ -1599,9 +1596,9 @@ UtilXml.addChildElementValue(packageWeightElement, "Weight", Double.toString(packageWeight), requestDoc); //If product is in shippable Package then it we should have one product per packagemap if (packageMap.size() ==1) { - Iterator i = packageMap.keySet().iterator(); - String productId = (String) i.next(); - Map productInfo = getProductItemInfo(shippableItemInfo, productId); + Iterator<String> i = packageMap.keySet().iterator(); + String productId = i.next(); + Map<String, Object> productInfo = getProductItemInfo(shippableItemInfo, productId); if(productInfo.get("inShippingBox") != null && ((String) productInfo.get("inShippingBox")).equalsIgnoreCase("Y") && productInfo.get("shippingDepth") !=null && productInfo.get("shippingWidth") !=null && productInfo.get("shippingHeight") !=null ) { Element dimensionsElement = UtilXml.addChildElement(packageElement, "Dimensions", requestDoc); @@ -1628,14 +1625,14 @@ return (weight > 0 && weight > minWeight ? weight : minWeight); } - private static List getPackageSplit(List shippableItemInfo, double maxWeight) { + private static List<Map<String, Double>> getPackageSplit(List<Map<String, Object>> shippableItemInfo, double maxWeight) { // create the package list w/ the first package - List packages = FastList.newInstance(); + List<Map<String, Double>> packages = FastList.newInstance(); if (shippableItemInfo != null) { - Iterator sii = shippableItemInfo.iterator(); + Iterator<Map<String, Object>> sii = shippableItemInfo.iterator(); while (sii.hasNext()) { - Map itemInfo = (Map) sii.next(); + Map<String, Object> itemInfo = sii.next(); long pieces = ((Long) itemInfo.get("piecesIncluded")).longValue(); double totalQuantity = ((Double) itemInfo.get("quantity")).doubleValue(); double totalWeight = ((Double) itemInfo.get("weight")).doubleValue(); @@ -1651,17 +1648,17 @@ double partialQty = pieces > 1 ? 1.000 / pieces : 1; for (long x = 0; x < pieces; x++) { if(itemInfo.get("inShippingBox") != null && ((String) itemInfo.get("inShippingBox")).equalsIgnoreCase("Y")) { - Map newPackage = FastMap.newInstance(); + Map<String, Double> newPackage = FastMap.newInstance(); newPackage.put(productId, Double.valueOf(partialQty)); packages.add(newPackage); } else if (weight >= maxWeight) { - Map newPackage = FastMap.newInstance(); + Map<String, Double> newPackage = FastMap.newInstance(); newPackage.put(productId, Double.valueOf(partialQty)); packages.add(newPackage); } else if (totalWeight > 0) { // create the first package if (packages.size() == 0) { - packages.add(FastMap.newInstance()); + packages.add(FastMap.<String, Double>newInstance()); } // package loop @@ -1669,7 +1666,7 @@ boolean addedToPackage = false; for (int pi = 0; pi < packageSize; pi++) { if (!addedToPackage) { - Map packageMap = (Map) packages.get(pi); + Map<String, Double> packageMap = packages.get(pi); double packageWeight = calcPackageWeight(packageMap, shippableItemInfo, weight); if (packageWeight <= maxWeight) { Double qtyD = (Double) packageMap.get(productId); @@ -1680,7 +1677,7 @@ } } if (!addedToPackage) { - Map packageMap = FastMap.newInstance(); + Map<String, Double> packageMap = FastMap.newInstance(); packageMap.put(productId, Double.valueOf(partialQty)); packages.add(packageMap); } @@ -1692,24 +1689,24 @@ return packages; } - private static double calcPackageWeight(Map packageMap, List shippableItemInfo, double additionalWeight) { + private static double calcPackageWeight(Map<String, Double> packageMap, List<Map<String, Object>> shippableItemInfo, double additionalWeight) { double totalWeight = 0.00; - Iterator i = packageMap.keySet().iterator(); + Iterator<String> i = packageMap.keySet().iterator(); while (i.hasNext()) { - String productId = (String) i.next(); - Map productInfo = getProductItemInfo(shippableItemInfo, productId); + String productId = i.next(); + Map<String, Object> productInfo = getProductItemInfo(shippableItemInfo, productId); double productWeight = ((Double) productInfo.get("weight")).doubleValue(); - double quantity = ((Double) packageMap.get(productId)).doubleValue(); + double quantity = packageMap.get(productId).doubleValue(); totalWeight += (productWeight * quantity); } return totalWeight + additionalWeight; } - private static Map getProductItemInfo(List shippableItemInfo, String productId) { + private static Map<String, Object> getProductItemInfo(List<Map<String, Object>> shippableItemInfo, String productId) { if (shippableItemInfo != null) { - Iterator i = shippableItemInfo.iterator(); + Iterator<Map<String, Object>> i = shippableItemInfo.iterator(); while (i.hasNext()) { - Map testMap = (Map) i.next(); + Map<String, Object> testMap = i.next(); String id = (String) testMap.get("productId"); if (productId.equals(id)) { return testMap; @@ -1719,7 +1716,7 @@ return null; } - public static Map handleUpsRateInquireResponse(Document rateResponseDocument) { + public static Map<String, Object> handleUpsRateInquireResponse(Document rateResponseDocument) { // process TrackResponse, update data as needed Element rateResponseElement = rateResponseDocument.getDocumentElement(); @@ -1731,19 +1728,19 @@ String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); UpsServices.handleErrors(responseElement, errorList); if ("1".equals(responseStatusCode)) { - List rates = UtilXml.childElementList(rateResponseElement, "RatedShipment"); - Map rateMap = FastMap.newInstance(); + List<? extends Element> rates = UtilXml.childElementList(rateResponseElement, "RatedShipment"); + Map<String, Double> rateMap = FastMap.newInstance(); Double firstRate = null; if (rates == null || rates.size() == 0) { return ServiceUtil.returnError("No rates available at this time"); } else { - Iterator i = rates.iterator(); + Iterator<? extends Element> i = rates.iterator(); while (i.hasNext()) { - Element element = (Element) i.next(); + Element element = i.next(); // get service Element service = UtilXml.firstChildElement(element, "Service"); @@ -1755,14 +1752,14 @@ rateMap.put(serviceCode, Double.valueOf(totalString)); if (firstRate == null) { - firstRate = (Double) rateMap.get(serviceCode); + firstRate = rateMap.get(serviceCode); } } } Debug.log("UPS Rate Map : " + rateMap, module); - Map resp = ServiceUtil.returnSuccess(); + Map<String, Object> resp = ServiceUtil.returnSuccess(); resp.put("upsRateCodeMap", rateMap); resp.put("shippingEstimateAmount", firstRate); return resp; @@ -1785,12 +1782,12 @@ return accessRequestDocument; } - public static void handleErrors(Element responseElement, List errorList) { - List errorElements = UtilXml.childElementList(responseElement, "Error"); - Iterator errorElementIter = errorElements.iterator(); + public static void handleErrors(Element responseElement, List<Object> errorList) { + List<? extends Element> errorElements = UtilXml.childElementList(responseElement, "Error"); + Iterator<? extends Element> errorElementIter = errorElements.iterator(); while (errorElementIter.hasNext()) { StringBuilder errorMessageBuf = new StringBuilder(); - Element errorElement = (Element) errorElementIter.next(); + Element errorElement = errorElementIter.next(); String errorSeverity = UtilXml.childElementValue(errorElement, "ErrorSeverity"); String errorCode = UtilXml.childElementValue(errorElement, "ErrorCode"); @@ -1811,10 +1808,10 @@ errorMessageBuf.append(". "); } - List errorLocationElements = UtilXml.childElementList(errorElement, "ErrorLocation"); - Iterator errorLocationElementIter = errorLocationElements.iterator(); + List<? extends Element> errorLocationElements = UtilXml.childElementList(errorElement, "ErrorLocation"); + Iterator<? extends Element> errorLocationElementIter = errorLocationElements.iterator(); while (errorLocationElementIter.hasNext()) { - Element errorLocationElement = (Element) errorLocationElementIter.next(); + Element errorLocationElement = errorLocationElementIter.next(); String errorLocationElementName = UtilXml.childElementValue(errorLocationElement, "ErrorLocationElementName"); String errorLocationAttributeName = UtilXml.childElementValue(errorLocationElement, "ErrorLocationAttributeName"); @@ -1828,10 +1825,10 @@ errorMessageBuf.append("]"); } - List errorDigestElements = UtilXml.childElementList(errorLocationElement, "ErrorDigest"); - Iterator errorDigestElementIter = errorDigestElements.iterator(); + List<? extends Element> errorDigestElements = UtilXml.childElementList(errorLocationElement, "ErrorDigest"); + Iterator<? extends Element> errorDigestElementIter = errorDigestElements.iterator(); while (errorDigestElementIter.hasNext()) { - Element errorDigestElement = (Element) errorDigestElementIter.next(); + Element errorDigestElement = errorDigestElementIter.next(); errorMessageBuf.append(" full text: ["); errorMessageBuf.append(UtilXml.elementValue(errorDigestElement)); errorMessageBuf.append("]"); @@ -1903,7 +1900,7 @@ return response; } - public static Map upsRateInquireByPostalCode(DispatchContext dctx, Map context) { + public static Map<String, Object> upsRateInquireByPostalCode(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); @@ -1917,8 +1914,8 @@ // String shippingContactMechId = (String) context.get("shippingContactMechId"); String shippingPostalCode = (String) context.get("shippingPostalCode"); String shippingCountryCode = (String) context.get("shippingCountryCode"); - List packageWeights = (List) context.get("packageWeights"); - List shippableItemInfo = (List) context.get("shippableItemInfo"); + List<Double> packageWeights = UtilGenerics.checkList(context.get("packageWeights")); + List<Map<String, Object>> shippableItemInfo = UtilGenerics.checkList(context.get("shippableItemInfo")); Double shippableTotal = (Double) context.get("shippableTotal"); Double shippableQuantity = (Double) context.get("shippableQuantity"); Double shippableWeight = (Double) context.get("shippableWeight"); @@ -2056,9 +2053,9 @@ splitEstimatePackages(rateRequestDoc, shipmentElement, shippableItemInfo, maxWeight, minWeight); } else { - Iterator i = packageWeights.iterator(); + Iterator<Double> i = packageWeights.iterator(); while (i.hasNext()) { - Double packageWeight = (Double) i.next(); + Double packageWeight = i.next(); addPackageElement(rateRequestDoc, shipmentElement, packageWeight); } } @@ -2122,7 +2119,7 @@ } - public static Map upsAddressValidation(DispatchContext dctx, Map context) { + public static Map<String, Object> upsAddressValidation(DispatchContext dctx, Map<String, ? extends Object> context) { String city = (String) context.get("city"); String stateProvinceGeoId = (String) context.get("stateProvinceGeoId"); @@ -2216,26 +2213,26 @@ } - public static Map handleUpsAddressValidationResponse(Document rateResponseDocument) { + public static Map<String, Object> handleUpsAddressValidationResponse(Document rateResponseDocument) { Element avResponseElement = rateResponseDocument.getDocumentElement(); Element responseElement = UtilXml.firstChildElement(avResponseElement, "Response"); String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); - List errorList = FastList.newInstance(); + List<Object> errorList = FastList.newInstance(); UpsServices.handleErrors(responseElement, errorList); if ("1".equals(responseStatusCode)) { - List matches = FastList.newInstance(); + List<Map<String, String>> matches = FastList.newInstance(); - List avResultList = UtilXml.childElementList(avResponseElement, "AddressValidationResult"); + List<? extends Element> avResultList = UtilXml.childElementList(avResponseElement, "AddressValidationResult"); // TODO: return error if there are no matches? if (UtilValidate.isNotEmpty(avResultList)) { - Iterator i = avResultList.iterator(); + Iterator<? extends Element> i = avResultList.iterator(); while (i.hasNext()) { - Element avResultElement = (Element) i.next(); + Element avResultElement = i.next(); - Map match = FastMap.newInstance(); + Map<String, String> match = FastMap.newInstance(); match.put("Rank", UtilXml.childElementValue(avResultElement, "Rank")); match.put("Quality", UtilXml.childElementValue(avResultElement, "Quality")); @@ -2251,7 +2248,7 @@ } } - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("matches", matches); return result; } else { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsMockApiServlet.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsMockApiServlet.java?rev=712918&r1=712917&r2=712918&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsMockApiServlet.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsMockApiServlet.java Mon Nov 10 18:19:19 2008 @@ -91,12 +91,12 @@ return; } - List packageElementList = UtilXml.childElementList(requestDocument.getDocumentElement(), "Package"); + List<? extends Element> packageElementList = UtilXml.childElementList(requestDocument.getDocumentElement(), "Package"); if (UtilValidate.isNotEmpty(packageElementList)) { Document responseDocument = UtilXml.makeEmptyXmlDocument("RateResponse"); - for (Iterator i = packageElementList.iterator(); i.hasNext();) { - Element packageElement = (Element) i.next(); + for (Iterator<? extends Element> i = packageElementList.iterator(); i.hasNext();) { + Element packageElement = i.next(); Element responsePackageElement = UtilXml.addChildElement(responseDocument.getDocumentElement(), "Package", responseDocument); |
Free forum by Nabble | Edit this page |