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=1053074&r1=1053073&r2=1053074&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 Dec 27 14:19:29 2010 @@ -49,6 +49,7 @@ import org.ofbiz.base.util.UtilNumber; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; @@ -62,6 +63,7 @@ import org.ofbiz.service.GenericServiceE import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; +import org.ofbiz.shipment.shipment.ShipmentServices; import org.ofbiz.shipment.shipment.ShipmentWorker; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -89,6 +91,8 @@ public class UpsServices { public static final MathContext generalRounding = new MathContext(10); public static final int returnServiceCode = 8; public static final String dateFormatString = "yyyyMMdd"; + public static final String resourceError = "ProductUiLabels"; + public static final String resourceOrder = "OrderUiLabels"; public static Map<String, Object> upsShipmentConfirm(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); @@ -98,8 +102,14 @@ public class UpsServices { String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); - boolean shipmentUpsSaveCertificationInfo = "true".equals(UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.info")); - String shipmentUpsSaveCertificationPath = UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.path"); + Map<String, Object> shipmentGatewayConfig = ShipmentServices.getShipmentGatewayConfigFromShipment(delegator, shipmentId); + String shipmentGatewayConfigId = (String) shipmentGatewayConfig.get("shipmentGatewayConfigId"); + String resource = (String) shipmentGatewayConfig.get("configProps"); + if (UtilValidate.isEmpty(shipmentGatewayConfigId) && UtilValidate.isEmpty(resource)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsGatewayNotAvailable", locale)); + } + boolean shipmentUpsSaveCertificationInfo = "true".equals(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertInfo", resource, "shipment.ups.save.certification.info", "true")); + String shipmentUpsSaveCertificationPath = FlexibleStringExpander.expandString(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertPath", resource, "shipment.ups.save.certification.path", ""), context); File shipmentUpsSaveCertificationFile = null; if (shipmentUpsSaveCertificationInfo) { shipmentUpsSaveCertificationFile = new File(shipmentUpsSaveCertificationPath); @@ -113,30 +123,35 @@ public class UpsServices { try { GenericValue shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId)); if (shipment == null) { - return ServiceUtil.returnError("Shipment not found with ID " + shipmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductShipmentNotFoundId", locale) + " " + shipmentId); } GenericValue shipmentRouteSegment = delegator.findByPrimaryKey("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId)); if (shipmentRouteSegment == null) { - return ServiceUtil.returnError("ShipmentRouteSegment not found with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "ProductShipmentRouteSegmentNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (!"UPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) { - return ServiceUtil.returnError("ERROR: The Carrier for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is not UPS."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsNotRouteSegmentCarrier", + UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId), locale)); } - + // add ShipmentRouteSegment carrierServiceStatusId, check before all UPS services if (UtilValidate.isNotEmpty(shipmentRouteSegment.getString("carrierServiceStatusId")) && !"SHRSCS_NOT_STARTED".equals(shipmentRouteSegment.getString("carrierServiceStatusId"))) { - return ServiceUtil.returnError("ERROR: The Carrier Service Status for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is [" + shipmentRouteSegment.getString("carrierServiceStatusId") + "], but must be not-set or [SHRSCS_NOT_STARTED] to perform the UPS Shipment Confirm operation."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentStatusNotStarted", + UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId, "shipmentRouteSegmentStatus", shipmentRouteSegment.getString("carrierServiceStatusId")), locale)); } // Get Origin Info GenericValue originPostalAddress = shipmentRouteSegment.getRelatedOne("OriginPostalAddress"); if (originPostalAddress == null) { - return ServiceUtil.returnError("OriginPostalAddress not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentOriginPostalAddressNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } GenericValue originTelecomNumber = shipmentRouteSegment.getRelatedOne("OriginTelecomNumber"); if (originTelecomNumber == null) { - return ServiceUtil.returnError("OriginTelecomNumber not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentOriginTelecomNumberNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } String originPhoneNumber = originTelecomNumber.getString("areaCode") + originTelecomNumber.getString("contactNumber"); // don't put on country code if not specified or is the US country code (UPS wants it this way) @@ -148,13 +163,15 @@ public class UpsServices { // lookup the two letter country code (in the geoCode field) GenericValue originCountryGeo = originPostalAddress.getRelatedOne("CountryGeo"); if (originCountryGeo == null) { - return ServiceUtil.returnError("OriginCountryGeo not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentOriginCountryGeoNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } // Get Dest Info GenericValue destPostalAddress = shipmentRouteSegment.getRelatedOne("DestPostalAddress"); if (destPostalAddress == null) { - return ServiceUtil.returnError("DestPostalAddress not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentDestPostalAddressNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } GenericValue destTelecomNumber = shipmentRouteSegment.getRelatedOne("DestTelecomNumber"); @@ -178,18 +195,21 @@ public class UpsServices { // lookup the two letter country code (in the geoCode field) GenericValue destCountryGeo = destPostalAddress.getRelatedOne("CountryGeo"); if (destCountryGeo == null) { - return ServiceUtil.returnError("DestCountryGeo not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentDestCountryGeoNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } 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")); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentCarrierShipmentMethodNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "carrierPartyId", shipmentRouteSegment.get("carrierPartyId"), "shipmentMethodTypeId", shipmentRouteSegment.get("shipmentMethodTypeId")), locale)); } List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (UtilValidate.isEmpty(shipmentPackageRouteSegs)) { - return ServiceUtil.returnError("No ShipmentPackageRouteSegs (ie No Packages) found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsPackageRouteSegsNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } List<GenericValue> itemIssuances = shipment.getRelated("ItemIssuance"); @@ -199,7 +219,8 @@ public class UpsServices { } String ordersDescription = ""; if (orderIdSet.size() > 1) { - StringBuilder odBuf = new StringBuilder("Orders "); + + StringBuilder odBuf = new StringBuilder(UtilProperties.getMessage(resourceOrder, "OrderOrders", locale) + " "); for (String orderId: orderIdSet) { if (odBuf.length() > 0) { odBuf.append(", "); @@ -208,11 +229,11 @@ public class UpsServices { } ordersDescription = odBuf.toString(); } else if (orderIdSet.size() > 0) { - ordersDescription = "Order " + orderIdSet.iterator().next(); + ordersDescription = UtilProperties.getMessage(resourceOrder, "OrderOrder", locale) + " " + orderIdSet.iterator().next(); } // COD Support - boolean allowCOD = "true".equalsIgnoreCase(UtilProperties.getPropertyValue("shipment", "shipment.ups.cod.allowCOD")); + boolean allowCOD = "true".equalsIgnoreCase(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "codAllowCod", resource, "shipment.ups.cod.allowCOD", "true")); // COD only applies if all orders involved with the shipment were paid only with EXT_COD - anything else becomes too complicated if (allowCOD) { @@ -238,22 +259,21 @@ public class UpsServices { BigDecimal codSurchargePackageAmount = null; if (allowCOD) { - - codSurchargeAmount = UtilProperties.getPropertyValue("shipment", "shipment.ups.cod.surcharge.amount"); + codSurchargeAmount = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "codSurchargeAmount", resource, "shipment.ups.cod.surcharge.amount", ""); if (UtilValidate.isEmpty(codSurchargeAmount)) { - return ServiceUtil.returnError("shipment.ups.cod.surcharge.amount is not configured in shipment.properties"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsSurchargeAmountIsNotConfigurated", locale)); } - codSurchargeCurrencyUomId = UtilProperties.getPropertyValue("shipment", "shipment.ups.cod.surcharge.currencyUomId"); + codSurchargeCurrencyUomId = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "codSurchargeCurrencyUomId", resource, "shipment.ups.cod.surcharge.currencyUomId", ""); if (UtilValidate.isEmpty(codSurchargeCurrencyUomId)) { - return ServiceUtil.returnError("shipment.ups.cod.surcharge.currencyUomId is not configured in shipment.properties"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsSurchargeCurrencyIsNotConfigurated", locale)); } - String codSurchargeApplyToPackages = UtilProperties.getPropertyValue("shipment", "shipment.ups.cod.surcharge.applyToPackages"); + String codSurchargeApplyToPackages = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "codSurchargeApplyToPackage", resource, "shipment.ups.cod.surcharge.applyToPackages", ""); if (UtilValidate.isEmpty(codSurchargeApplyToPackages)) { - return ServiceUtil.returnError("shipment.ups.cod.surcharge.applyToPackages is not configured in shipment.properties"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsApplyToPackagesIsNotConfigured", locale)); } - codFundsCode = UtilProperties.getPropertyValue("shipment", "shipment.ups.cod.codFundsCode"); + codFundsCode = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "codFundsCode", resource, "shipment.ups.cod.codFundsCode", ""); if (UtilValidate.isEmpty(codFundsCode)) { - return ServiceUtil.returnError("shipment.ups.cod.codFundsCode is not configured in shipment.properties"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsCodFundsCodeIsNotConfigured", locale)); } codSurchargeApplyToFirstPackage = "first".equalsIgnoreCase(codSurchargeApplyToPackages); @@ -261,7 +281,9 @@ public class UpsServices { codSurchargeSplitBetweenPackages = "split".equalsIgnoreCase(codSurchargeApplyToPackages); codSurchargeApplyToNoPackages = "none".equalsIgnoreCase(codSurchargeApplyToPackages); - if (codSurchargeApplyToNoPackages) codSurchargeAmount = "0"; + if (codSurchargeApplyToNoPackages) { + codSurchargeAmount = "0"; + } codSurchargePackageAmount = new BigDecimal(codSurchargeAmount).setScale(decimals, rounding); if (codSurchargeSplitBetweenPackages) { codSurchargePackageAmount = codSurchargePackageAmount.divide(new BigDecimal(shipmentPackageRouteSegs.size()), decimals, rounding); @@ -316,11 +338,12 @@ public class UpsServices { UtilXml.addChildElementValue(shipmentElement, "Description", "Goods for Shipment " + shipment.get("shipmentId") + " from " + ordersDescription, shipmentConfirmRequestDoc); // Child of Shipment: Shipper + String shipperNumber = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "shipperNumber", resource, "shipment.ups.shipper.number", ""); Element shipperElement = UtilXml.addChildElement(shipmentElement, "Shipper", shipmentConfirmRequestDoc); UtilXml.addChildElementValue(shipperElement, "Name", UtilValidate.isNotEmpty(originPostalAddress.getString("toName")) ? originPostalAddress.getString("toName") : "", shipmentConfirmRequestDoc); UtilXml.addChildElementValue(shipperElement, "AttentionName", UtilValidate.isNotEmpty(originPostalAddress.getString("attnName")) ? originPostalAddress.getString("attnName") : "", shipmentConfirmRequestDoc); UtilXml.addChildElementValue(shipperElement, "PhoneNumber", originPhoneNumber, shipmentConfirmRequestDoc); - UtilXml.addChildElementValue(shipperElement, "ShipperNumber", UtilProperties.getPropertyValue("shipment", "shipment.ups.shipper.number"), shipmentConfirmRequestDoc); + UtilXml.addChildElementValue(shipperElement, "ShipperNumber", shipperNumber, shipmentConfirmRequestDoc); Element shipperAddressElement = UtilXml.addChildElement(shipperElement, "Address", shipmentConfirmRequestDoc); UtilXml.addChildElementValue(shipperAddressElement, "AddressLine1", originPostalAddress.getString("address1"), shipmentConfirmRequestDoc); @@ -399,8 +422,9 @@ public class UpsServices { Element prepaidElement = UtilXml.addChildElement(paymentInformationElement, "Prepaid", shipmentConfirmRequestDoc); Element billShipperElement = UtilXml.addChildElement(prepaidElement, "BillShipper", shipmentConfirmRequestDoc); - // fill in BillShipper AccountNumber element from properties file - UtilXml.addChildElementValue(billShipperElement, "AccountNumber", UtilProperties.getPropertyValue("shipment", "shipment.ups.bill.shipper.account.number"), shipmentConfirmRequestDoc); + // fill in BillShipper AccountNumber element + String billShipperAccountNumber = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "billShipperAccountNumber", resource, "shipment.ups.bill.shipper.account.number", ""); + UtilXml.addChildElementValue(billShipperElement, "AccountNumber", billShipperAccountNumber, shipmentConfirmRequestDoc); } else { // Paid by another shipper (may be receiver or not) @@ -408,11 +432,13 @@ public class UpsServices { // UPS requires the postal code and country code of the third party String thirdPartyPostalCode = shipmentRouteSegment.getString("thirdPartyPostalCode"); if (UtilValidate.isEmpty(thirdPartyPostalCode)) { - return ServiceUtil.returnError("Third-party postal code not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentThirdPartyPostalCodeNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } String thirdPartyCountryGeoCode = shipmentRouteSegment.getString("thirdPartyCountryGeoCode"); if (UtilValidate.isEmpty(thirdPartyCountryGeoCode)) { - return ServiceUtil.returnError("Third-party country not found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentThirdPartyCountryNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } Element billThirdPartyElement = UtilXml.addChildElement(paymentInformationElement, "BillThirdParty", shipmentConfirmRequestDoc); @@ -510,7 +536,10 @@ public class UpsServices { Element packageWeightElement = UtilXml.addChildElement(packageElement, "PackageWeight", shipmentConfirmRequestDoc); Element packageWeightUnitOfMeasurementElement = UtilXml.addChildElement(packageElement, "UnitOfMeasurement", shipmentConfirmRequestDoc); - String weightUomUps = unitsOfbizToUps.get(shipmentPackage.get("weightUomId")); + String weightUomUps = null; + if (shipmentPackage.get("weightUomId") != null) { + weightUomUps = unitsOfbizToUps.get(shipmentPackage.get("weightUomId")); + } if (weightUomUps != null) { UtilXml.addChildElementValue(packageWeightUnitOfMeasurementElement, "Code", weightUomUps, shipmentConfirmRequestDoc); } else { @@ -519,7 +548,8 @@ public class UpsServices { } if (shipmentPackage.getString("weight") == null) { - return ServiceUtil.returnError("Weight value not found for ShipmentRouteSegment with shipmentId " + shipmentId + ", shipmentRouteSegmentId " + shipmentRouteSegmentId + ", and shipmentPackageSeqId " + shipmentPackage.getString("shipmentPackageSeqId")); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsWeightValueNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentPackageSeqId", shipmentPackage.getString("shipmentPackageSeqId")), locale)); } BigDecimal boxWeight = shipmentPackage.getBigDecimal("weight"); UtilXml.addChildElementValue(packageWeightElement, "Weight", UtilValidate.isNotEmpty(boxWeight) ? ""+ boxWeight.setScale(0, BigDecimal.ROUND_CEILING) : "", shipmentConfirmRequestDoc); @@ -571,32 +601,33 @@ public class UpsServices { UtilXml.addChildElementValue(codAmountElement, "MonetaryValue", packageValue.setScale(decimals, rounding).toString(), shipmentConfirmRequestDoc); } } - + String shipmentConfirmRequestString = null; try { shipmentConfirmRequestString = UtilXml.writeXmlDocument(shipmentConfirmRequestDoc); } catch (IOException e) { String ioeErrMsg = "Error writing the ShipmentConfirmRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorShipmentConfirmRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // create AccessRequest XML doc - Document accessRequestDocument = createAccessRequestDocument(); + Document accessRequestDocument = createAccessRequestDocument(delegator, shipmentGatewayConfigId, resource); String accessRequestString = null; try { accessRequestString = UtilXml.writeXmlDocument(accessRequestDocument); } catch (IOException e) { String ioeErrMsg = "Error writing the AccessRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorAccessRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // connect to UPS server, send AccessRequest to auth // send ShipmentConfirmRequest String // get ShipmentConfirmResponse String back StringBuilder xmlString = new StringBuilder(); - // TODO: note that we may have to append <?xml version="1.0"?> before each string xmlString.append(accessRequestString); xmlString.append(shipmentConfirmRequestString); @@ -613,11 +644,12 @@ public class UpsServices { } try { - shipmentConfirmResponseString = sendUpsRequest("ShipConfirm", xmlString.toString()); + shipmentConfirmResponseString = sendUpsRequest("ShipConfirm", xmlString.toString(), shipmentGatewayConfigId, resource, delegator, locale); } catch (UpsConnectException e) { String uceErrMsg = "Error sending UPS request for UPS Service ShipConfirm: " + e.toString(); Debug.logError(e, uceErrMsg, module); - return ServiceUtil.returnError(uceErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorSendingShipConfirm", + UtilMisc.toMap("errorString", e.toString()), locale)); } if (shipmentUpsSaveCertificationInfo) { @@ -638,35 +670,42 @@ public class UpsServices { } catch (SAXException e2) { String excErrMsg = "Error parsing the ShipmentConfirmResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingShipmentConfirm", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (ParserConfigurationException e2) { String excErrMsg = "Error parsing the ShipmentConfirmResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingShipmentConfirm", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (IOException e2) { String excErrMsg = "Error parsing the ShipmentConfirmResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingShipmentConfirm", + UtilMisc.toMap("errorString", e2.toString()), locale)); } - return handleUpsShipmentConfirmResponse(shipmentConfirmResponseDocument, shipmentRouteSegment); + return handleUpsShipmentConfirmResponse(shipmentConfirmResponseDocument, shipmentRouteSegment, locale); } catch (GenericServiceException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Error reading or writing Shipment data for UPS Shipment Confirm: " + e.toString()); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorDataShipmentConfirm", + UtilMisc.toMap("errorString", e.toString()), locale)); } catch (GenericEntityException e) { Debug.logError(e, module); if (shipmentConfirmResponseString != null) { Debug.logError("Got XML ShipmentConfirmRespose: " + shipmentConfirmResponseString, module); return ServiceUtil.returnError(UtilMisc.toList( - "Error reading or writing Shipment data for UPS Shipment Confirm: " + e.toString(), - "A ShipmentConfirmRespose was received: " + shipmentConfirmResponseString)); + UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorDataShipmentConfirm", + UtilMisc.toMap("errorString", e.toString()), locale), + UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentConfirmResposeWasReceived", + UtilMisc.toMap("shipmentConfirmResponseString", shipmentConfirmResponseString), locale))); } else { - return ServiceUtil.returnError("Error reading or writing Shipment data for UPS Shipment Confirm: " + e.toString()); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorDataShipmentConfirm", + UtilMisc.toMap("errorString", e.toString()), locale)); } } } - public static Map<String, Object> handleUpsShipmentConfirmResponse(Document shipmentConfirmResponseDocument, GenericValue shipmentRouteSegment) throws GenericEntityException { + public static Map<String, Object> handleUpsShipmentConfirmResponse(Document shipmentConfirmResponseDocument, GenericValue shipmentRouteSegment, Locale locale) throws GenericEntityException { // process ShipmentConfirmResponse, update data as needed Element shipmentConfirmResponseElement = shipmentConfirmResponseDocument.getDocumentElement(); @@ -679,7 +718,7 @@ public class UpsServices { String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); //String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); List<Object> errorList = FastList.newInstance(); - UpsServices.handleErrors(responseElement, errorList); + UpsServices.handleErrors(responseElement, errorList, locale); if ("1".equals(responseStatusCode)) { // handle ShipmentCharges element info @@ -701,8 +740,9 @@ public class UpsServices { if (UtilValidate.isEmpty(shipmentRouteSegment.getString("currencyUomId"))) { shipmentRouteSegment.set("currencyUomId", totalCurrencyCode); } else if (!totalCurrencyCode.equals(shipmentRouteSegment.getString("currencyUomId"))) { - errorList.add("The Currency Unit of Measure returned [" + totalCurrencyCode + "] is not the same as the original [" + shipmentRouteSegment.getString("currencyUomId") + "], setting to the new one."); shipmentRouteSegment.set("currencyUomId", totalCurrencyCode); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsCurrencyDoesNotMatch", + UtilMisc.toMap("currency1", totalCurrencyCode, "currency2", shipmentRouteSegment.getString("currencyUomId")), locale)); } } @@ -711,21 +751,24 @@ public class UpsServices { } catch (NumberFormatException e) { String excErrMsg = "Error parsing the transportationMonetaryValue [" + transportationMonetaryValue + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTransportationMonetaryValue", + UtilMisc.toMap("transportationMonetaryValue", transportationMonetaryValue, "errorString", e.toString()), locale)); } try { shipmentRouteSegment.set("actualServiceCost", new BigDecimal(serviceOptionsMonetaryValue)); } catch (NumberFormatException e) { String excErrMsg = "Error parsing the serviceOptionsMonetaryValue [" + serviceOptionsMonetaryValue + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingServiceOptionsMonetaryValue", + UtilMisc.toMap("serviceOptionsMonetaryValue", serviceOptionsMonetaryValue, "errorString", e.toString()), locale)); } try { shipmentRouteSegment.set("actualCost", new BigDecimal(totalMonetaryValue)); } catch (NumberFormatException e) { String excErrMsg = "Error parsing the totalMonetaryValue [" + totalMonetaryValue + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTotalMonetaryValue", + UtilMisc.toMap("totalMonetaryValue", totalMonetaryValue, "errorString", e.toString()), locale)); } // handle BillingWeight element info @@ -738,7 +781,8 @@ public class UpsServices { } catch (NumberFormatException e) { String excErrMsg = "Error parsing the billingWeight [" + billingWeight + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingBillingWeight", + UtilMisc.toMap("billingWeight", billingWeight, "errorString", e.toString()), locale)); } shipmentRouteSegment.set("billingWeightUomId", unitsUpsToOfbiz.get(billingWeightUnitOfMeasurement)); @@ -755,11 +799,12 @@ public class UpsServices { shipmentRouteSegment.store(); // -=-=-=- Okay, now done with that, just return any extra info... - - StringBuilder successString = new StringBuilder("The UPS ShipmentConfirm succeeded"); + StringBuilder successString = new StringBuilder(UtilProperties.getMessage(resourceError, + "FacilityShipmentUpsShipmentConfirmSucceeded", locale)); + if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway - successString.append(", but the following occurred: "); + successString.append(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentConfirmError", locale)); Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { successString.append(errorListIter.next()); @@ -770,7 +815,7 @@ public class UpsServices { } return ServiceUtil.returnSuccess(successString.toString()); } else { - errorList.add(0, "The UPS ShipmentConfirm failed"); + errorList.add(0, UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentConfirmFailed", locale)); return ServiceUtil.returnError(errorList); } } @@ -779,9 +824,16 @@ public class UpsServices { Delegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); + Locale locale = (Locale) context.get("locale"); - boolean shipmentUpsSaveCertificationInfo = "true".equals(UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.info")); - String shipmentUpsSaveCertificationPath = UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.path"); + Map<String, Object> shipmentGatewayConfig = ShipmentServices.getShipmentGatewayConfigFromShipment(delegator, shipmentId); + String shipmentGatewayConfigId = (String) shipmentGatewayConfig.get("shipmentGatewayConfigId"); + String resource = (String) shipmentGatewayConfig.get("configProps"); + if (UtilValidate.isEmpty(shipmentGatewayConfigId) && UtilValidate.isEmpty(resource)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsGatewayNotAvailable", locale)); + } + boolean shipmentUpsSaveCertificationInfo = "true".equals(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertInfo", resource, "shipment.ups.save.certification.info", "true")); + String shipmentUpsSaveCertificationPath = FlexibleStringExpander.expandString(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertPath", resource, "shipment.ups.save.certification.path", ""), context); File shipmentUpsSaveCertificationFile = null; if (shipmentUpsSaveCertificationInfo) { shipmentUpsSaveCertificationFile = new File(shipmentUpsSaveCertificationPath); @@ -797,21 +849,24 @@ public class UpsServices { GenericValue shipmentRouteSegment = delegator.findByPrimaryKey("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId)); if (!"UPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) { - return ServiceUtil.returnError("ERROR: The Carrier for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is not UPS."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsNotRouteSegmentCarrier", UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId), locale)); } // add ShipmentRouteSegment carrierServiceStatusId, check before all UPS services if (!"SHRSCS_CONFIRMED".equals(shipmentRouteSegment.getString("carrierServiceStatusId"))) { - 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."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentStatusNotConfirmed", + UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId, "shipmentRouteSegmentStatus", shipmentRouteSegment.getString("carrierServiceStatusId")), locale)); } List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (UtilValidate.isEmpty(shipmentPackageRouteSegs)) { - return ServiceUtil.returnError("No ShipmentPackageRouteSegs found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsPackageRouteSegsNotFound", + UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (UtilValidate.isEmpty(shipmentRouteSegment.getString("trackingDigest"))) { - return ServiceUtil.returnError("ERROR: The trackingDigest was not set for this Route Segment, meaning that a UPS shipment confirm has not been done."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "FacilityShipmentUpsTrackingDigestWasNotSet", locale)); } Document shipmentAcceptRequestDoc = UtilXml.makeEmptyXmlDocument("ShipmentAcceptRequest"); @@ -837,25 +892,27 @@ public class UpsServices { } catch (IOException e) { String ioeErrMsg = "Error writing the ShipmentAcceptRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + "FacilityShipmentUpsErrorShipmentAcceptRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // create AccessRequest XML doc - Document accessRequestDocument = createAccessRequestDocument(); + Document accessRequestDocument = createAccessRequestDocument(delegator, shipmentGatewayConfigId, resource); String accessRequestString = null; try { accessRequestString = UtilXml.writeXmlDocument(accessRequestDocument); } catch (IOException e) { String ioeErrMsg = "Error writing the AccessRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorAccessRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // connect to UPS server, send AccessRequest to auth // send ShipmentConfirmRequest String // get ShipmentConfirmResponse String back StringBuilder xmlString = new StringBuilder(); - // TODO: note that we may have to append <?xml version="1.0"?> before each string xmlString.append(accessRequestString); xmlString.append(shipmentAcceptRequestString); @@ -872,11 +929,12 @@ public class UpsServices { } try { - shipmentAcceptResponseString = sendUpsRequest("ShipAccept", xmlString.toString()); + shipmentAcceptResponseString = sendUpsRequest("ShipAccept", xmlString.toString(), shipmentGatewayConfigId, resource, delegator, locale); } catch (UpsConnectException e) { String uceErrMsg = "Error sending UPS request for UPS Service ShipAccept: " + e.toString(); Debug.logError(e, uceErrMsg, module); - return ServiceUtil.returnError(uceErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorSendingShipAccept", + UtilMisc.toMap("errorString", e.toString()), locale)); } if (shipmentUpsSaveCertificationInfo) { @@ -897,27 +955,33 @@ public class UpsServices { } catch (SAXException e2) { String excErrMsg = "Error parsing the ShipmentAcceptResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingShipmentAcceptResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (ParserConfigurationException e2) { String excErrMsg = "Error parsing the ShipmentAcceptResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingShipmentAcceptResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (IOException e2) { String excErrMsg = "Error parsing the ShipmentAcceptResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingShipmentAcceptResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } - return handleUpsShipmentAcceptResponse(shipmentAcceptResponseDocument, shipmentRouteSegment, shipmentPackageRouteSegs); + return handleUpsShipmentAcceptResponse(shipmentAcceptResponseDocument, shipmentRouteSegment, shipmentPackageRouteSegs, delegator, + shipmentGatewayConfigId, resource, context, locale); } catch (GenericEntityException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Error reading or writing Shipment data for UPS Shipment Accept: " + e.toString()); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorDataShipmentAccept", + UtilMisc.toMap("errorString", e.toString()), locale)); } } - 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"); + public static Map<String, Object> handleUpsShipmentAcceptResponse(Document shipmentAcceptResponseDocument, GenericValue shipmentRouteSegment, List<GenericValue> shipmentPackageRouteSegs, + Delegator delegator, String shipmentGatewayConfigId, String resource, Map<String, ? extends Object> context, Locale locale) throws GenericEntityException { + boolean shipmentUpsSaveCertificationInfo = "true".equals(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertInfo", resource, "shipment.ups.save.certification.info", "true")); + String shipmentUpsSaveCertificationPath = FlexibleStringExpander.expandString(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertPath", resource, "shipment.ups.save.certification.path", ""), context); File shipmentUpsSaveCertificationFile = null; if (shipmentUpsSaveCertificationInfo) { shipmentUpsSaveCertificationFile = new File(shipmentUpsSaveCertificationPath); @@ -938,7 +1002,7 @@ public class UpsServices { String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); //String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); List<Object> errorList = FastList.newInstance(); - UpsServices.handleErrors(responseElement, errorList); + UpsServices.handleErrors(responseElement, errorList, locale); if ("1".equals(responseStatusCode)) { Element shipmentResultsElement = UtilXml.firstChildElement(shipmentAcceptResponseElement, "ShipmentResults"); @@ -967,8 +1031,9 @@ public class UpsServices { if (UtilValidate.isEmpty(shipmentRouteSegment.getString("currencyUomId"))) { shipmentRouteSegment.set("currencyUomId", totalCurrencyCode); } else if (!totalCurrencyCode.equals(shipmentRouteSegment.getString("currencyUomId"))) { - errorList.add("The Currency Unit of Measure returned [" + totalCurrencyCode + "] is not the same as the original [" + shipmentRouteSegment.getString("currencyUomId") + "], setting to the new one."); shipmentRouteSegment.set("currencyUomId", totalCurrencyCode); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsCurrencyDoesNotMatch", + UtilMisc.toMap("currency1", totalCurrencyCode, "currency2", shipmentRouteSegment.getString("currencyUomId")), locale)); } } @@ -977,21 +1042,24 @@ public class UpsServices { } catch (NumberFormatException e) { String excErrMsg = "Error parsing the transportationMonetaryValue [" + transportationMonetaryValue + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTransportationMonetaryValue", + UtilMisc.toMap("transportationMonetaryValue", transportationMonetaryValue, "errorString", e.toString()), locale)); } try { shipmentRouteSegment.set("actualServiceCost", new BigDecimal(serviceOptionsMonetaryValue)); } catch (NumberFormatException e) { String excErrMsg = "Error parsing the serviceOptionsMonetaryValue [" + serviceOptionsMonetaryValue + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingServiceOptionsMonetaryValue", + UtilMisc.toMap("serviceOptionsMonetaryValue", serviceOptionsMonetaryValue, "errorString", e.toString()), locale)); } try { shipmentRouteSegment.set("actualCost", new BigDecimal(totalMonetaryValue)); } catch (NumberFormatException e) { String excErrMsg = "Error parsing the totalMonetaryValue [" + totalMonetaryValue + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTotalMonetaryValue", + UtilMisc.toMap("totalMonetaryValue", totalMonetaryValue, "errorString", e.toString()), locale)); } // handle BillingWeight element info @@ -1004,7 +1072,8 @@ public class UpsServices { } catch (NumberFormatException e) { String excErrMsg = "Error parsing the billingWeight [" + billingWeight + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingBillingWeight", + UtilMisc.toMap("billingWeight", billingWeight, "errorString", e.toString()), locale)); } shipmentRouteSegment.set("billingWeightUomId", unitsUpsToOfbiz.get(billingWeightUnitOfMeasurement)); @@ -1039,7 +1108,8 @@ public class UpsServices { String packageLabelHTMLImageString = UtilXml.childElementValue(packageLabelImageElement, "HTMLImage"); if (!shipmentPackageRouteSegIter.hasNext()) { - errorList.add("Error: More PackageResults were returned than there are Packages on this Shipment; the TrackingNumber is [" + trackingNumber + "], the ServiceOptionsCharges were " + packageServiceOptionsMonetaryValue + packageServiceOptionsCurrencyCode); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorMorePackageResultsWereReturned", + UtilMisc.toMap("trackingNumber", trackingNumber, "ServiceOptionsCharges", packageServiceOptionsMonetaryValue + packageServiceOptionsCurrencyCode), locale)); // NOTE: if this happens much we should just create a new package to store all of the info... continue; } @@ -1054,9 +1124,9 @@ public class UpsServices { } catch (NumberFormatException e) { String excErrMsg = "Error parsing the packageServiceOptionsMonetaryValue [" + packageServiceOptionsMonetaryValue + "] for Package [" + shipmentPackageRouteSeg.getString("shipmentPackageSeqId") + "]: " + e.toString(); Debug.logError(e, excErrMsg, module); - errorList.add(excErrMsg); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingServiceOptionsMonetaryValue", + UtilMisc.toMap("serviceOptionsMonetaryValue", serviceOptionsMonetaryValue, "errorString", e.toString()), locale)); } - byte[] labelImageBytes = null; if (packageLabelGraphicImageString != null) { labelImageBytes = Base64.base64Decode(packageLabelGraphicImageString.getBytes()); @@ -1136,10 +1206,12 @@ public class UpsServices { } if (shipmentPackageRouteSegIter.hasNext()) { - errorList.add("Error: There are more Packages on this Shipment than there were PackageResults returned from UPS"); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorMorePackageOnThisShipment", locale)); + while (shipmentPackageRouteSegIter.hasNext()) { GenericValue shipmentPackageRouteSeg = shipmentPackageRouteSegIter.next(); - errorList.add("Error: No PackageResults were returned for the Package [" + shipmentPackageRouteSeg.getString("shipmentPackageSeqId") + "]"); + errorList.add(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorNoPackageResultsWereReturned", + UtilMisc.toMap("shipmentPackageSeqId", shipmentPackageRouteSeg.getString("shipmentPackageSeqId")), locale)); } } @@ -1164,10 +1236,12 @@ public class UpsServices { } // -=-=-=- Okay, now done with that, just return any extra info... - StringBuilder successString = new StringBuilder("The UPS ShipmentAccept succeeded"); + StringBuilder successString = new StringBuilder(UtilProperties.getMessage(resourceError, + "FacilityShipmentUpsShipmentAcceptSucceeded", locale)); if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway - successString.append(", but the following occurred: "); + successString.append(UtilProperties.getMessage(resourceError, + "FacilityShipmentUpsShipmentAcceptError", locale)); Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { successString.append(errorListIter.next()); @@ -1178,7 +1252,7 @@ public class UpsServices { } return ServiceUtil.returnSuccess(successString.toString()); } else { - errorList.add(0, "The UPS ShipmentConfirm failed"); + errorList.add(0, UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentAcceptFailed", locale)); return ServiceUtil.returnError(errorList); } } @@ -1187,9 +1261,16 @@ public class UpsServices { Delegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); + Locale locale = (Locale) context.get("locale"); - boolean shipmentUpsSaveCertificationInfo = "true".equals(UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.info")); - String shipmentUpsSaveCertificationPath = UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.path"); + Map<String, Object> shipmentGatewayConfig = ShipmentServices.getShipmentGatewayConfigFromShipment(delegator, shipmentId); + String shipmentGatewayConfigId = (String) shipmentGatewayConfig.get("shipmentGatewayConfigId"); + String resource = (String) shipmentGatewayConfig.get("configProps"); + if (UtilValidate.isEmpty(shipmentGatewayConfigId) && UtilValidate.isEmpty(resource)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsGatewayNotAvailable", locale)); + } + boolean shipmentUpsSaveCertificationInfo = "true".equals(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertInfo", resource, "shipment.ups.save.certification.info", "true")); + String shipmentUpsSaveCertificationPath = FlexibleStringExpander.expandString(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertPath", resource, "shipment.ups.save.certification.path", ""), context); File shipmentUpsSaveCertificationFile = null; if (shipmentUpsSaveCertificationInfo) { shipmentUpsSaveCertificationFile = new File(shipmentUpsSaveCertificationPath); @@ -1205,17 +1286,19 @@ public class UpsServices { GenericValue shipmentRouteSegment = delegator.findByPrimaryKey("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId)); if (!"UPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) { - return ServiceUtil.returnError("ERROR: The Carrier for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is not UPS."); - } + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsNotRouteSegmentCarrier", UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId), locale)); + } // add ShipmentRouteSegment carrierServiceStatusId, check before all UPS services if (!"SHRSCS_CONFIRMED".equals(shipmentRouteSegment.getString("carrierServiceStatusId")) && !"SHRSCS_ACCEPTED".equals(shipmentRouteSegment.getString("carrierServiceStatusId"))) { - return ServiceUtil.returnError("ERROR: The Carrier Service Status for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is [" + shipmentRouteSegment.getString("carrierServiceStatusId") + "], but must be [SHRSCS_CONFIRMED] or [SHRSCS_ACCEPTED] to perform the UPS Void Shipment operation."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentStatusMustBeConfirmedOrAccepted", + UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId, "shipmentRouteSegmentStatus", + shipmentRouteSegment.getString("carrierServiceStatusId")), locale)); } if (UtilValidate.isEmpty(shipmentRouteSegment.getString("trackingIdNumber"))) { - return ServiceUtil.returnError("ERROR: The trackingIdNumber was not set for this Route Segment, meaning that a UPS shipment confirm has not been done."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsTrackingIdNumberWasNotSet", locale)); } Document voidShipmentRequestDoc = UtilXml.makeEmptyXmlDocument("VoidShipmentRequest"); @@ -1240,25 +1323,26 @@ public class UpsServices { } catch (IOException e) { String ioeErrMsg = "Error writing the VoidShipmentRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorVoidShipmentRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // create AccessRequest XML doc - Document accessRequestDocument = createAccessRequestDocument(); + Document accessRequestDocument = createAccessRequestDocument(delegator, shipmentGatewayConfigId, resource); String accessRequestString = null; try { accessRequestString = UtilXml.writeXmlDocument(accessRequestDocument); } catch (IOException e) { String ioeErrMsg = "Error writing the AccessRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorAccessRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // connect to UPS server, send AccessRequest to auth // send ShipmentConfirmRequest String // get ShipmentConfirmResponse String back StringBuilder xmlString = new StringBuilder(); - // TODO: note that we may have to append <?xml version="1.0"?> before each string xmlString.append(accessRequestString); xmlString.append(voidShipmentRequestString); @@ -1275,11 +1359,12 @@ public class UpsServices { } try { - voidShipmentResponseString = sendUpsRequest("Void", xmlString.toString()); + voidShipmentResponseString = sendUpsRequest("Void", xmlString.toString(), shipmentGatewayConfigId, resource, delegator, locale); } catch (UpsConnectException e) { String uceErrMsg = "Error sending UPS request for UPS Service Void: " + e.toString(); Debug.logError(e, uceErrMsg, module); - return ServiceUtil.returnError(uceErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorSendingVoid", + UtilMisc.toMap("errorString", e.toString()), locale)); } if (shipmentUpsSaveCertificationInfo) { @@ -1300,25 +1385,29 @@ public class UpsServices { } catch (SAXException e2) { String excErrMsg = "Error parsing the VoidShipmentResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingVoidShipmentResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (ParserConfigurationException e2) { String excErrMsg = "Error parsing the VoidShipmentResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingVoidShipmentResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (IOException e2) { String excErrMsg = "Error parsing the VoidShipmentResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingVoidShipmentResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } - return handleUpsVoidShipmentResponse(voidShipmentResponseDocument, shipmentRouteSegment); + return handleUpsVoidShipmentResponse(voidShipmentResponseDocument, shipmentRouteSegment, locale); } catch (GenericEntityException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Error reading or writing Shipment data for UPS Void Shipment: " + e.toString()); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorDataShipmentVoid", + UtilMisc.toMap("errorString", e.toString()), locale)); } } - public static Map<String, Object> handleUpsVoidShipmentResponse(Document voidShipmentResponseDocument, GenericValue shipmentRouteSegment) throws GenericEntityException { + public static Map<String, Object> handleUpsVoidShipmentResponse(Document voidShipmentResponseDocument, GenericValue shipmentRouteSegment, Locale locale) throws GenericEntityException { // process VoidShipmentResponse, update data as needed Element voidShipmentResponseElement = voidShipmentResponseDocument.getDocumentElement(); @@ -1331,7 +1420,7 @@ public class UpsServices { String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); //String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); List<Object> errorList = FastList.newInstance(); - UpsServices.handleErrors(responseElement, errorList); + UpsServices.handleErrors(responseElement, errorList, locale); // handle other response elements Element statusElement = UtilXml.firstChildElement(voidShipmentResponseElement, "Status"); @@ -1350,10 +1439,12 @@ public class UpsServices { shipmentRouteSegment.store(); // -=-=-=- Okay, now done with that, just return any extra info... - StringBuilder successString = new StringBuilder("The UPS VoidShipment succeeded; the StatusType is: [" + statusTypeCode + ":" + statusTypeDescription + "], the StatusCode is: [" + statusCodeCode + ":" + statusCodeDescription + "]"); + StringBuilder successString = new StringBuilder(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentVoidSucceeded", + UtilMisc.toMap("statusTypeCode", statusTypeCode, "statusTypeDescription", statusTypeDescription, + "statusCodeCode", statusCodeCode, "statusCodeDescription", statusCodeDescription), locale)); if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway - successString.append(", but the following occurred: "); + successString.append(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentVoidError", locale)); Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { successString.append(errorListIter.next()); @@ -1364,7 +1455,9 @@ public class UpsServices { } return ServiceUtil.returnSuccess(successString.toString()); } else { - errorList.add(0, "The UPS ShipmentConfirm failed; the StatusType is: [" + statusTypeCode + ":" + statusTypeDescription + "], the StatusCode is: [" + statusCodeCode + ":" + statusCodeDescription + "]"); + errorList.add(0, UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentVoidFailed", + UtilMisc.toMap("statusTypeCode", statusTypeCode, "statusTypeDescription", statusTypeDescription, + "statusCodeCode", statusCodeCode, "statusCodeDescription", statusCodeDescription), locale)); return ServiceUtil.returnError(errorList); } } @@ -1373,9 +1466,16 @@ public class UpsServices { Delegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId"); + Locale locale = (Locale) context.get("locale"); - boolean shipmentUpsSaveCertificationInfo = "true".equals(UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.info")); - String shipmentUpsSaveCertificationPath = UtilProperties.getPropertyValue("shipment", "shipment.ups.save.certification.path"); + Map<String, Object> shipmentGatewayConfig = ShipmentServices.getShipmentGatewayConfigFromShipment(delegator, shipmentId); + String shipmentGatewayConfigId = (String) shipmentGatewayConfig.get("shipmentGatewayConfigId"); + String resource = (String) shipmentGatewayConfig.get("configProps"); + if (UtilValidate.isEmpty(shipmentGatewayConfigId) && UtilValidate.isEmpty(resource)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsGatewayNotAvailable", locale)); + } + boolean shipmentUpsSaveCertificationInfo = "true".equals(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertInfo", resource, "shipment.ups.save.certification.info", "true")); + String shipmentUpsSaveCertificationPath = FlexibleStringExpander.expandString(getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "saveCertPath", resource, "shipment.ups.save.certification.path", ""), context); File shipmentUpsSaveCertificationFile = null; if (shipmentUpsSaveCertificationInfo) { shipmentUpsSaveCertificationFile = new File(shipmentUpsSaveCertificationPath); @@ -1391,21 +1491,21 @@ public class UpsServices { GenericValue shipmentRouteSegment = delegator.findByPrimaryKey("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId)); if (!"UPS".equals(shipmentRouteSegment.getString("carrierPartyId"))) { - return ServiceUtil.returnError("ERROR: The Carrier for ShipmentRouteSegment " + shipmentRouteSegmentId + " of Shipment " + shipmentId + ", is not UPS."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsNotRouteSegmentCarrier", UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId), locale)); } // add ShipmentRouteSegment carrierServiceStatusId, check before all UPS services if (!"SHRSCS_ACCEPTED".equals(shipmentRouteSegment.getString("carrierServiceStatusId"))) { - 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."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRouteSegmentStatusNotAccepted", UtilMisc.toMap("shipmentRouteSegmentId", shipmentRouteSegmentId, "shipmentId", shipmentId, "shipmentRouteSegmentStatus", shipmentRouteSegment.getString("carrierServiceStatusId")), locale)); } List<GenericValue> shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, UtilMisc.toList("+shipmentPackageSeqId")); if (UtilValidate.isEmpty(shipmentPackageRouteSegs)) { - return ServiceUtil.returnError("No ShipmentPackageRouteSegs found for ShipmentRouteSegment with shipmentId " + shipmentId + " and shipmentRouteSegmentId " + shipmentRouteSegmentId); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsPackageRouteSegsNotFound", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId), locale)); } if (UtilValidate.isEmpty(shipmentRouteSegment.getString("trackingIdNumber"))) { - return ServiceUtil.returnError("ERROR: The trackingIdNumber was not set for this Route Segment, meaning that a UPS shipment confirm has not been done."); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsTrackingIdNumberWasNotSet", locale)); } Document trackRequestDoc = UtilXml.makeEmptyXmlDocument("TrackRequest"); @@ -1429,25 +1529,26 @@ public class UpsServices { } catch (IOException e) { String ioeErrMsg = "Error writing the TrackRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorTrackRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // create AccessRequest XML doc - Document accessRequestDocument = createAccessRequestDocument(); + Document accessRequestDocument = createAccessRequestDocument(delegator, shipmentGatewayConfigId, resource); String accessRequestString = null; try { accessRequestString = UtilXml.writeXmlDocument(accessRequestDocument); } catch (IOException e) { String ioeErrMsg = "Error writing the AccessRequest XML Document to a String: " + e.toString(); Debug.logError(e, ioeErrMsg, module); - return ServiceUtil.returnError(ioeErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorAccessRequestXmlToString", + UtilMisc.toMap("errorString", e.toString()), locale)); } // connect to UPS server, send AccessRequest to auth // send ShipmentConfirmRequest String // get ShipmentConfirmResponse String back StringBuilder xmlString = new StringBuilder(); - // TODO: note that we may have to append <?xml version="1.0"?> before each string xmlString.append(accessRequestString); xmlString.append(trackRequestString); @@ -1464,11 +1565,12 @@ public class UpsServices { } try { - trackResponseString = sendUpsRequest("Track", xmlString.toString()); + trackResponseString = sendUpsRequest("Track", xmlString.toString(), shipmentGatewayConfigId, resource, delegator, locale); } catch (UpsConnectException e) { String uceErrMsg = "Error sending UPS request for UPS Service Track: " + e.toString(); Debug.logError(e, uceErrMsg, module); - return ServiceUtil.returnError(uceErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorSendingTrack", + UtilMisc.toMap("errorString", e.toString()), locale)); } if (shipmentUpsSaveCertificationInfo) { @@ -1489,26 +1591,30 @@ public class UpsServices { } catch (SAXException e2) { String excErrMsg = "Error parsing the TrackResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTrackResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (ParserConfigurationException e2) { String excErrMsg = "Error parsing the TrackResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTrackResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } catch (IOException e2) { String excErrMsg = "Error parsing the TrackResponse: " + e2.toString(); Debug.logError(e2, excErrMsg, module); - return ServiceUtil.returnError(excErrMsg); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorParsingTrackResponse", + UtilMisc.toMap("errorString", e2.toString()), locale)); } - return handleUpsTrackShipmentResponse(trackResponseDocument, shipmentRouteSegment, shipmentPackageRouteSegs); + return handleUpsTrackShipmentResponse(trackResponseDocument, shipmentRouteSegment, shipmentPackageRouteSegs, locale); } catch (GenericEntityException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Error reading or writing Shipment data for UPS Track Shipment: " + e.toString()); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorDataShipmentTrack", + UtilMisc.toMap("errorString", e.toString()), locale)); } } public static Map<String, Object> handleUpsTrackShipmentResponse(Document trackResponseDocument, GenericValue shipmentRouteSegment, - List<GenericValue> shipmentPackageRouteSegs) throws GenericEntityException { + List<GenericValue> shipmentPackageRouteSegs, Locale locale) throws GenericEntityException { // process TrackResponse, update data as needed Element trackResponseElement = trackResponseDocument.getDocumentElement(); @@ -1521,7 +1627,7 @@ public class UpsServices { String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); //String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); List<Object> errorList = FastList.newInstance(); - UpsServices.handleErrors(responseElement, errorList); + UpsServices.handleErrors(responseElement, errorList, locale); if ("1".equals(responseStatusCode)) { // TODO: handle other response elements @@ -1579,10 +1685,11 @@ public class UpsServices { // -=-=-=- Okay, now done with that, just return any extra info... - StringBuilder successString = new StringBuilder("The UPS TrackShipment succeeded"); + StringBuilder successString = new StringBuilder(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentTrackSucceeded", locale)); + if (errorList.size() > 0) { // this shouldn't happen much, but handle it anyway - successString.append(", but the following occurred: "); + successString.append(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentTrackError", locale)); Iterator<Object> errorListIter = errorList.iterator(); while (errorListIter.hasNext()) { successString.append(errorListIter.next()); @@ -1593,13 +1700,14 @@ public class UpsServices { } return ServiceUtil.returnSuccess(successString.toString()); } else { - errorList.add(0, "The UPS ShipmentConfirm failed"); + errorList.add(0, UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipmentTrackFailed", locale)); return ServiceUtil.returnError(errorList); } } public static Map<String, Object> upsRateInquire(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); + Locale locale = (Locale) context.get("locale"); // prepare the data String shippingContactMechId = (String) context.get("shippingContactMechId"); String shippingOriginContactMechId = (String) context.get("shippingOriginContactMechId"); @@ -1613,7 +1721,7 @@ public class UpsServices { } } if (shipToAddress == null) { - return ServiceUtil.returnError("Unable to determine ship-to address"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsUnableFoundShipToAddresss", locale)); } // obtain the ship from address if provided @@ -1623,7 +1731,7 @@ public class UpsServices { shipFromAddress = delegator.findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", shippingOriginContactMechId)); } catch (GenericEntityException e) { Debug.logError(e, module); - return ServiceUtil.returnError("Unable to determine ship-from address for drop shipping"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsUnableFoundShipToAddresssForDropShipping", locale)); } } @@ -1635,7 +1743,7 @@ public class UpsServices { return ServiceUtil.returnError(e.getMessage()); } if (UtilValidate.isEmpty(destCountryGeo)) { - return ServiceUtil.returnError("Destination CountryGeo not found for ship-to address"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsShipToAddresssNoDestionationCountry", locale)); } Map<String, Object> cxt = UtilMisc.toMap("serviceConfigProps", context.get("serviceConfigProps"), "upsRateInquireMode", context.get("upsRateInquireMode"), "productStoreId", context.get("productStoreId"), "carrierRoleTypeId", context.get("carrierRoleTypeId")); @@ -1650,25 +1758,26 @@ public class UpsServices { cxt.put("shippableWeight", context.get("shippableWeight")); cxt.put("isResidentialAddress", context.get("isResidentialAddress")); cxt.put("shipFromAddress", shipFromAddress); + cxt.put("shipmentGatewayConfigId", context.get("shipmentGatewayConfigId")); try { return dctx.getDispatcher().runSync("upsRateEstimateByPostalCode", cxt); } catch (GenericServiceException e) { Debug.logError(e, module); - return ServiceUtil.returnError(e.getMessage()); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsRateEstimateError", + UtilMisc.toMap("errorString", e.getMessage()), locale)); } } - private static void splitEstimatePackages(DispatchContext dctx, Document requestDoc, Element shipmentElement, List<Map<String, Object>> shippableItemInfo, BigDecimal maxWeight, BigDecimal minWeight) { + private static void splitEstimatePackages(DispatchContext dctx, Document requestDoc, Element shipmentElement, List<Map<String, Object>> shippableItemInfo, + BigDecimal maxWeight, BigDecimal minWeight, String totalWeightStr) { List<Map<String, BigDecimal>> packages = ShipmentWorker.getPackageSplit(dctx, shippableItemInfo, maxWeight); if (UtilValidate.isNotEmpty(packages)) { for (Map<String, BigDecimal> packageMap: packages) { addPackageElement(dctx, requestDoc, shipmentElement, shippableItemInfo, packageMap, minWeight); } } else { - // Add a dummy package - String totalWeightStr = UtilProperties.getPropertyValue("shipment", "shipment.ups.min.estimate.weight", "1"); BigDecimal packageWeight = BigDecimal.ONE; try { packageWeight = new BigDecimal(totalWeightStr); @@ -1705,7 +1814,6 @@ public class UpsServices { UtilXml.addChildElementValue(dimensionsElement, "Height", productInfo.get("shippingHeight").toString(), requestDoc); } } - } private static void addPackageElement(Document requestDoc, Element shipmentElement, BigDecimal packageWeight) { @@ -1723,7 +1831,7 @@ public class UpsServices { return (weight.compareTo(BigDecimal.ZERO) > 0 && weight.compareTo(minWeight) > 0 ? weight : minWeight); } - public static Map<String, Object> handleUpsRateInquireResponse(Document rateResponseDocument) { + public static Map<String, Object> handleUpsRateInquireResponse(Document rateResponseDocument, Locale locale) { // process TrackResponse, update data as needed Element rateResponseElement = rateResponseDocument.getDocumentElement(); @@ -1736,14 +1844,14 @@ public class UpsServices { String responseStatusCode = UtilXml.childElementValue(responseElement, "ResponseStatusCode"); //String responseStatusDescription = UtilXml.childElementValue(responseElement, "ResponseStatusDescription"); List<Object> errorList = FastList.newInstance(); - UpsServices.handleErrors(responseElement, errorList); + UpsServices.handleErrors(responseElement, errorList, locale); if ("1".equals(responseStatusCode)) { List<? extends Element> rates = UtilXml.childElementList(rateResponseElement, "RatedShipment"); Map<String, BigDecimal> rateMap = FastMap.newInstance(); BigDecimal firstRate = null; if (UtilValidate.isEmpty(rates)) { - return ServiceUtil.returnError("No rates available at this time"); + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsNoRateAvailable", locale)); } else { for (Element element: rates) { // get service @@ -1768,25 +1876,26 @@ public class UpsServices { resp.put("shippingEstimateAmount", firstRate); return resp; } else { - errorList.add("Error status code : " + responseStatusCode); + errorList.add(ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUpsErrorStatusCode", + UtilMisc.toMap("responseStatusCode", responseStatusCode), locale))); return ServiceUtil.returnFailure(errorList); } } - public static Document createAccessRequestDocument() { - return createAccessRequestDocument("shipment.properties"); - } - - public static Document createAccessRequestDocument(String props) { + public static Document createAccessRequestDocument(Delegator delegator, String shipmentGatewayConfigId, + String serviceConfigProps) { Document accessRequestDocument = UtilXml.makeEmptyXmlDocument("AccessRequest"); Element accessRequestElement = accessRequestDocument.getDocumentElement(); - UtilXml.addChildElementValue(accessRequestElement, "AccessLicenseNumber", UtilProperties.getPropertyValue(props, "shipment.ups.access.license.number"), accessRequestDocument); - UtilXml.addChildElementValue(accessRequestElement, "UserId", UtilProperties.getPropertyValue(props, "shipment.ups.access.user.id"), accessRequestDocument); - UtilXml.addChildElementValue(accessRequestElement, "Password", UtilProperties.getPropertyValue(props, "shipment.ups.access.password"), accessRequestDocument); + String accessLicenseNumber = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "accessLicenseNumber", serviceConfigProps, "shipment.ups.access.license.number", ""); + String userId = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "accessUserId", serviceConfigProps, "shipment.ups.access.user.id", ""); + String password = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "accessPassword", serviceConfigProps, "shipment.ups.access.password", ""); + UtilXml.addChildElementValue(accessRequestElement, "AccessLicenseNumber",accessLicenseNumber, accessRequestDocument); + UtilXml.addChildElementValue(accessRequestElement, "UserId", userId, accessRequestDocument); + UtilXml.addChildElementValue(accessRequestElement, "Password", password, accessRequestDocument); return accessRequestDocument; } - public static void handleErrors(Element responseElement, List<Object> errorList) { + public static void handleErrors(Element responseElement, List<Object> errorList, Locale locale) { List<? extends Element> errorElements = UtilXml.childElementList(responseElement, "Error"); for (Element errorElement: errorElements) { StringBuilder errorMessageBuf = new StringBuilder(); @@ -1795,17 +1904,12 @@ public class UpsServices { String errorCode = UtilXml.childElementValue(errorElement, "ErrorCode"); String errorDescription = UtilXml.childElementValue(errorElement, "ErrorDescription"); [... 919 lines stripped ...] |
Free forum by Nabble | Edit this page |