Author: jonesde
Date: Wed Aug 15 23:51:22 2007 New Revision: 566504 URL: http://svn.apache.org/viewvc?view=rev&rev=566504 Log: More testing and review, changes mostly to add validation where it was missing based on new test cases Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java?view=diff&rev=566504&r1=566503&r2=566504 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Wed Aug 15 23:51:22 2007 @@ -149,11 +149,27 @@ * In this message will it serve any purpose, since it is not handled. */ String sign = UtilXml.childElementValue(quantityElement, "of:SIGN"); - // TODO: Not used now, Later we may need it + // TODOLATER: Not used now, Later we may need it //String uom = UtilXml.childElementValue(quantityElement, "of:UOM"); String productId = UtilXml.childElementValue(inventoryElement, "of:ITEM"); String itemStatus = UtilXml.childElementValue(inventoryElement, "of:ITEMSTATUS"); + // make sure productId is valid + try { + GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); + if (product == null) { + String errMsg = "Product with ID [" + productId + "] not found (invalid Product ID)."; + errorMapList.add(UtilMisc.toMap("reasonCode", "ProductIdNotValid", "description", errMsg)); + Debug.logError(errMsg, module); + continue; + } + } catch (GenericEntityException e) { + String errMsg = "Error checking for valid Product ID: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + continue; + } + // if anything but "NOTAVAILABLE" set to available boolean isAvailable = !"NOTAVAILABLE".equals(itemStatus); String statusId = "INV_AVAILABLE"; @@ -437,7 +453,6 @@ Element acknowledgeDeliveryElement = UtilXml.firstChildElement(dataAreaElement, "ns:ACKNOWLEDGE_DELIVERY"); String facilityId = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Warehouse.PoReceiptFacilityId"); - String productId = null; String orderId = null; // get RECEIPTLN elements from message List acknowledgeElementList = UtilXml.childElementList(acknowledgeDeliveryElement, "ns:RECEIPTLN"); @@ -452,7 +467,23 @@ double itemQty = Double.parseDouble(itemQtyStr); String sign = UtilXml.childElementValue(qtyElement, "of:SIGN"); - productId = UtilXml.childElementValue(receiptLnElement, "of:ITEM"); + String productId = UtilXml.childElementValue(receiptLnElement, "of:ITEM"); + + // make sure productId is valid + try { + GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); + if (product == null) { + String errMsg = "Product with ID [" + productId + "] not found (invalid Product ID)."; + errorMapList.add(UtilMisc.toMap("reasonCode", "ProductIdNotValid", "description", errMsg)); + Debug.logError(errMsg, module); + continue; + } + } catch (GenericEntityException e) { + String errMsg = "Error checking for valid Product ID: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + continue; + } Element documentRefElement = UtilXml.firstChildElement(receiptLnElement, "os:DOCUMNTREF"); orderId = UtilXml.childElementValue(documentRefElement, "of:DOCUMENTID"); @@ -698,11 +729,27 @@ String sign = UtilXml.childElementValue(qtyElement, "of:SIGN"); String productId = UtilXml.childElementValue(receiptLnElement, "of:ITEM"); - if (productId == null) { - String errMsg = "productId not available in Message" ; - errorMapList.add(UtilMisc.toMap("reasonCode", "ParseException", "description", errMsg)); + if (UtilValidate.isEmpty(productId)) { + String errMsg = "Product ID Missing"; + errorMapList.add(UtilMisc.toMap("reasonCode", "ProductIdMissing", "description", errMsg)); Debug.logError(errMsg, module); } + // make sure productId is valid + try { + GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); + if (product == null) { + String errMsg = "Product with ID [" + productId + "] not found (invalid Product ID)."; + errorMapList.add(UtilMisc.toMap("reasonCode", "ProductIdNotValid", "description", errMsg)); + Debug.logError(errMsg, module); + continue; + } + } catch (GenericEntityException e) { + String errMsg = "Error checking for valid Product ID: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + continue; + } + Element documentRefElement = UtilXml.firstChildElement(receiptLnElement, "os:DOCUMNTREF"); String returnId = UtilXml.childElementValue(documentRefElement, "of:DOCUMENTID"); lastReturnId = returnId; @@ -712,7 +759,26 @@ if(returnHeaderTypeId.equals("RMA")) { returnHeaderTypeId = "CUSTOMER_RETURN"; } + String returnItemSeqId = UtilXml.childElementValue(documentRefElement, "of:LINENUM"); + if (UtilValidate.isNotEmpty(returnItemSeqId)) { + // if there is a LINENUM/returnItemSeqId make sure it is valid + try { + GenericValue product = delegator.findByPrimaryKeyCache("ReturnItem", UtilMisc.toMap("returnId", returnId, "returnItemSeqId", returnItemSeqId)); + if (product == null) { + String errMsg = "Return Item with ID [" + returnId + ":" + returnItemSeqId + "] not found (invalid Return/Item ID Combination)."; + errorMapList.add(UtilMisc.toMap("reasonCode", "ReturnAndItemIdNotValid", "description", errMsg)); + Debug.logError(errMsg, module); + continue; + } + } catch (GenericEntityException e) { + String errMsg = "Error checking for valid Return/Item ID: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + continue; + } + } + String datetimeReceived = UtilXml.childElementValue(receiptLnElement, "os:DATETIMEISO"); Timestamp timestampItemReceived = OagisServices.parseIsoDateString(datetimeReceived, errorMapList); ripCtx.put("datetimeReceived", timestampItemReceived); @@ -730,7 +796,9 @@ // TODO: for the DISPOSITN of NotAvailableTOAvailable elements, we need to ignore all return stuff and //not try to do anything with the return; note this may be a different DOCTYPE value or no DOCTYPE, so - //may need to be a new/different service called from the message handler service + //may need to be a new/different service called from the message handler service; note that when this + //is implemented need to verify that if configured for it that serial number is valid when present + //otherwise return error if (returnHeader != null) { //getting ReturnHeader status @@ -851,6 +919,35 @@ } invItemIds.add(UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"))); } else { + if (OagisServices.requireSerialNumberExist != null) { + // according to requireSerialNumberExist make sure serialNumber does or does not exist in database, add an error message as needed + try { + Set productIdSet = ProductWorker.getRefurbishedProductIdSet(productId, delegator); + productIdSet.add(productId); + + EntityCondition bySerialNumberCondition = new EntityExpr(new EntityExpr("serialNumber", EntityOperator.EQUALS, serialNumber), + EntityOperator.AND, new EntityExpr("productId", EntityOperator.IN, productIdSet)); + List inventoryItemsBySerialNumber = delegator.findByCondition("InventoryItem", bySerialNumberCondition, null, null); + if (OagisServices.requireSerialNumberExist.booleanValue()) { + if (inventoryItemsBySerialNumber.size() > 0) { + String errMsg = "Referenced serial numbers must already exist, but serial number [" + serialNumber + "] was not found."; + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SerialNumberRequiredButNotFound")); + continue; + } + } else { + if (inventoryItemsBySerialNumber.size() == 0) { + String errMsg = "Referenced serial numbers must NOT already exist, but serial number [" + serialNumber + "] already exists."; + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SerialNumberRequiredNotExistButFound")); + continue; + } + } + } catch (GenericEntityException e) { + String errMsg = "Error checking valid serial number: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + } + } + //clone the context as it may be changed in the call Map localRipCtx = FastMap.newInstance(); localRipCtx.putAll(ripCtx); Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java?view=diff&rev=566504&r1=566503&r2=566504 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java Wed Aug 15 23:51:22 2007 @@ -87,6 +87,19 @@ public static final boolean debugSaveXmlOut = "true".equals(UtilProperties.getPropertyValue("oagis.properties", "Oagis.Debug.Save.Xml.Out")); public static final boolean debugSaveXmlIn = "true".equals(UtilProperties.getPropertyValue("oagis.properties", "Oagis.Debug.Save.Xml.In")); + /** if TRUE then must exist, if FALSE must not exist, if null don't care */ + public static final Boolean requireSerialNumberExist; + static { + String requireSerialNumberExistStr = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Warehouse.RequireSerialNumberExist"); + if ("true".equals(requireSerialNumberExistStr)) { + requireSerialNumberExist = Boolean.TRUE; + } else if ("false".equals(requireSerialNumberExistStr)) { + requireSerialNumberExist = Boolean.FALSE; + } else { + requireSerialNumberExist = null; + } + } + public static Map oagisSendConfirmBod(DispatchContext ctx, Map context) { GenericDelegator delegator = ctx.getDelegator(); Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java?view=diff&rev=566504&r1=566503&r2=566504 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Wed Aug 15 23:51:22 2007 @@ -80,19 +80,6 @@ public static final String oagisSegmentsNamespacePrefix = "os"; public static final String oagisFieldsNamespacePrefix = "of"; - /** if TRUE then must exist, if FALSE must not exist, if null don't care */ - public static final Boolean requireSerialNumberExist; - static { - String requireSerialNumberExistStr = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Warehouse.RequireSerialNumberExist"); - if ("true".equals(requireSerialNumberExistStr)) { - requireSerialNumberExist = Boolean.TRUE; - } else if ("false".equals(requireSerialNumberExistStr)) { - requireSerialNumberExist = Boolean.FALSE; - } else { - requireSerialNumberExist = null; - } - } - public static Map showShipment(DispatchContext ctx, Map context) { Document doc = (Document) context.get("document"); boolean isErrorRetry = Boolean.TRUE.equals(context.get("isErrorRetry")); @@ -187,7 +174,7 @@ } if (shipment == null) { - String errMsg = "Could not find Shipment id ID [" + shipmentId + "]"; + String errMsg = "Could not find Shipment ID [" + shipmentId + "]"; errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "ShipmentIdNotValid")); } @@ -229,14 +216,38 @@ // sort the INVITEM elements by ITEM so that all shipments are processed in the same order, avoids deadlocking problems we've seen with concurrently processed orders List invitemMapList = FastList.newInstance(); Iterator invItemElementIter = invItemElementList.iterator(); - while (invItemElementIter.hasNext()) { + boolean foundBadProductId = false; + while (invItemElementIter.hasNext()) { Element invItemElement = (Element) invItemElementIter.next(); String productId = UtilXml.childElementValue(invItemElement, "of:ITEM"); // of + + // make sure productId is valid + try { + GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); + if (product == null) { + String errMsg = "Product with ID [" + productId + "] not found (invalid Product ID)."; + errorMapList.add(UtilMisc.toMap("reasonCode", "ProductIdNotValid", "description", errMsg)); + Debug.logError(errMsg, module); + foundBadProductId = true; + continue; + } + } catch (GenericEntityException e) { + String errMsg = "Error checking for valid Product ID: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + continue; + } + Map invitemMap = FastMap.newInstance(); invitemMap.put("productId", productId); invitemMap.put("invItemElement", invItemElement); invitemMapList.add(invitemMap); } + + if (foundBadProductId) { + continue; + } + UtilMisc.sortMaps(invitemMapList, UtilMisc.toList("productId")); Iterator invitemMapIter = invitemMapList.iterator(); @@ -331,15 +342,15 @@ for (int i = 0; i < currentResQuantity; i++) { String serialNumber = (String) serialNumberIter.next(); - // according to requireSerialNumberExist make sure serialNumber does or does not exist in database, add an error message as needed - if (requireSerialNumberExist != null) { + if (OagisServices.requireSerialNumberExist != null) { + // according to requireSerialNumberExist make sure serialNumber does or does not exist in database, add an error message as needed Set productIdSet = ProductWorker.getRefurbishedProductIdSet(productId, delegator); productIdSet.add(productId); EntityCondition bySerialNumberCondition = new EntityExpr(new EntityExpr("serialNumber", EntityOperator.EQUALS, serialNumber), EntityOperator.AND, new EntityExpr("productId", EntityOperator.IN, productIdSet)); List inventoryItemsBySerialNumber = delegator.findByCondition("InventoryItem", bySerialNumberCondition, null, null); - if (requireSerialNumberExist.booleanValue()) { + if (OagisServices.requireSerialNumberExist.booleanValue()) { if (inventoryItemsBySerialNumber.size() > 0) { String errMsg = "Referenced serial numbers must already exist, but serial number [" + serialNumber + "] was not found."; errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SerialNumberRequiredButNotFound")); @@ -373,8 +384,8 @@ } } else { try { - //TODO: I think this else part is for NON Serialized Inv item. So it will be different service that we need to call here. isitspastCtx.put("quantity", new Double(currentResQuantity)); + // NOTE: this same service is called for non-serialized inventory in spite of the name it is made to handle it Map resultMap = dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx); if (ServiceUtil.isError(resultMap)){ String errMsg = ServiceUtil.getErrorMessage(resultMap); @@ -393,7 +404,7 @@ errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "NumberFormatException")); Debug.logInfo(e, errMsg, module); } catch (GenericEntityException e) { - String errMsg = "Error executing issueSerializedInvToShipmentPackageAndSetTracking Service: " + e.toString(); + String errMsg = "Data Error processing Show Shipment: " + e.toString(); errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "GenericEntityException")); Debug.logInfo(e, errMsg, module); } |
Free forum by Nabble | Edit this page |