Author: apatel
Date: Fri Aug 10 11:25:45 2007 New Revision: 564706 URL: http://svn.apache.org/viewvc?view=rev&rev=564706 Log: improvement to follow pattern of other similar services. Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.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=564706&r1=564705&r2=564706 ============================================================================== --- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original) +++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Fri Aug 10 11:25:45 2007 @@ -572,27 +572,21 @@ comiCtx.put("bsrRevision", bsrRevision); comiCtx.put("processingStatusId", "OAGMP_RECEIVED"); comiCtx.put("userLogin", userLogin); -// if (OagisServices.debugSaveXmlIn) { -// try { -// comiCtx.put("fullMessageXml", UtilXml.writeXmlDocument(doc)); -// } catch (IOException e) { -// // this is just for debug info, so just log and otherwise ignore error -// String errMsg = "Warning: error creating text from XML Document for saving to database: " + e.toString(); -// Debug.logWarning(errMsg, module); -// } -// } -// try { -// dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); -// /* running async for better error handling -// if (ServiceUtil.isError(comiResult)) { -// String errMsg = ServiceUtil.getErrorMessage(comiResult); -// errorMapList.add(UtilMisc.toMap("reasonCode", "CreateOagisMessageServiceError", "description", errMsg)); -// } -// */ -// } catch (GenericServiceException e) { -// String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString(); -// Debug.logError(e, errMsg, module); -// } + if (OagisServices.debugSaveXmlIn) { + try { + comiCtx.put("fullMessageXml", UtilXml.writeXmlDocument(doc)); + } catch (IOException e) { + // this is just for debug info, so just log and otherwise ignore error + String errMsg = "Warning: error creating text from XML Document for saving to database: " + e.toString(); + Debug.logWarning(errMsg, module); + } + } + try { + dispatcher.runSync("createOagisMessageInfo", comiCtx, 60, true); + } catch (GenericServiceException e) { + String errMsg = "Error creating OagisMessageInfo for the Incoming Message: " + e.toString(); + Debug.logError(e, errMsg, module); + } String statusId = null; // get RECEIPTLN elements from message @@ -637,128 +631,143 @@ } if (UtilValidate.isNotEmpty(returnHeader)) { + //getting ReturnHeader status statusId = returnHeader.get("statusId").toString(); - if (statusId.equals("RETURN_ACCEPTED")) { - // getting inventory item status - String invItemStatus = UtilXml.childElementValue(receiptLnElement, "of:DISPOSITN"); - if ( invItemStatus.equals("ReceivedTOAvailable") || invItemStatus.equals("NotAvailableTOAvailable")) { - ripCtx.put("statusId", "INV_AVAILABLE"); - } else if ( invItemStatus.equals("ReceivedTONotAvailable") || invItemStatus.equals("AvailableTONotAvailable") ) { - ripCtx.put("statusId", "INV_ON_HOLD"); - } - // geting the serial number(s) - String serialNumber = null; - List serialNumsList = FastList.newInstance(); - List invDetailList = UtilXml.childElementList(receiptLnElement, "ns:INVDETAIL"); - if (UtilValidate.isNotEmpty(invDetailList)) { - inventoryItemTypeId = "SERIALIZED_INV_ITEM"; - ripCtx.put("inventoryItemTypeId", inventoryItemTypeId); - for (Iterator j = invDetailList.iterator(); j.hasNext();) { - Element invDetailElement = (Element) j.next(); - serialNumber = UtilXml.childElementValue(invDetailElement, "of:SERIALNUM"); - if (UtilValidate.isNotEmpty(serialNumber)) { - serialNumsList.add(serialNumber); - } + + // getting inventory item status + String invItemStatusId = null; + String invItemStatus = UtilXml.childElementValue(receiptLnElement, "of:DISPOSITN"); + if ( invItemStatus.equals("ReceivedTOAvailable") || invItemStatus.equals("NotAvailableTOAvailable")) { + invItemStatusId = "INV_AVAILABLE"; + } else if ( invItemStatus.equals("ReceivedTONotAvailable") || invItemStatus.equals("AvailableTONotAvailable") ) { + invItemStatusId = "INV_ON_HOLD"; + } + ripCtx.put("statusId", invItemStatusId); + // geting the serial number(s) + String serialNumber = null; + List serialNumsList = FastList.newInstance(); + List invDetailList = UtilXml.childElementList(receiptLnElement, "ns:INVDETAIL"); + if (UtilValidate.isNotEmpty(invDetailList)) { + inventoryItemTypeId = "SERIALIZED_INV_ITEM"; + ripCtx.put("inventoryItemTypeId", inventoryItemTypeId); + for (Iterator j = invDetailList.iterator(); j.hasNext();) { + Element invDetailElement = (Element) j.next(); + serialNumber = UtilXml.childElementValue(invDetailElement, "of:SERIALNUM"); + if (UtilValidate.isNotEmpty(serialNumber)) { + serialNumsList.add(serialNumber); } - - /* DEJ20070711 Commenting this out because it shouldn't happen, ie more likely the ITEM element will be filled - * than INVDETAIL->SERIALNUM, and this isn't a reliable way to look it up (may be more than 1 record for a given - * serialNumber for different products - // this is a Serialized Inventory Item. If the productId from the message is not valid then lets read it from InventoryItem in Ofbiz database. - if (productId == null || "".equals(productId)) { - try { - GenericValue inventoryItem = EntityUtil.getFirst(delegator.findByAnd("InventoryItem", UtilMisc.toMap("serialNumber", serialNumber))); - if (inventoryItem !=null) { - productId = inventoryItem.getString("productId"); - } - } catch (GenericEntityException e){ - String errMsg = "Error Getting Entity InventoryItem"; - Debug.logError(e, errMsg, module); - } */ - } else { - inventoryItemTypeId = "NON_SERIAL_INV_ITEM"; - ripCtx.put("inventoryItemTypeId", inventoryItemTypeId); } - ripCtx.put("facilityId",facilityId); - ripCtx.put("locationSeqId", locationSeqId); - ripCtx.put("userLogin", userLogin); - - // sign handling for items - double quantityAccepted = 0.0; - double quantityRejected = 0.0; - if (sign.equals("+")) { - quantityAccepted = itemQty; - quantityRejected= 0.0; - } else { - quantityRejected = itemQty; - quantityAccepted = 0.0; + + /* DEJ20070711 Commenting this out because it shouldn't happen, ie more likely the ITEM element will be filled + * than INVDETAIL->SERIALNUM, and this isn't a reliable way to look it up (may be more than 1 record for a given + * serialNumber for different products + // this is a Serialized Inventory Item. If the productId from the message is not valid then lets read it from InventoryItem in Ofbiz database. + if (productId == null || "".equals(productId)) { + try { + GenericValue inventoryItem = EntityUtil.getFirst(delegator.findByAnd("InventoryItem", UtilMisc.toMap("serialNumber", serialNumber))); + if (inventoryItem !=null) { + productId = inventoryItem.getString("productId"); + } + } catch (GenericEntityException e){ + String errMsg = "Error Getting Entity InventoryItem"; + Debug.logError(e, errMsg, module); + } */ + } else { + inventoryItemTypeId = "NON_SERIAL_INV_ITEM"; + ripCtx.put("inventoryItemTypeId", inventoryItemTypeId); + } + + //do some validations + boolean continueLoop = false; + Integer messageQuantity = Integer.valueOf(itemQtyStr); + if(UtilValidate.isNotEmpty(serialNumsList)) { + if (messageQuantity.intValue() != serialNumsList.size()) { + String errMsg = "Not enough serial numbers [" + serialNumsList.size() + "] for the quantity [" + messageQuantity.intValue() + "]."; + errorMapList.add(UtilMisc.toMap("description", errMsg, "reasonCode", "SerialNumbersMissing")); + Debug.logInfo(errMsg, module); + continueLoop = true; } - if (quantityAccepted > 0) { - if (serialNumsList.size() > 0) { - if (serialNumsList.size() != quantityAccepted) { - String errMsg = "Error: the quantity [" + quantityAccepted + "] did not match the number of serial numbers passed [" + serialNumsList.size() + "]."; - errorMapList.add(UtilMisc.toMap("reasonCode", "QuantitySerialMismatch", "description", errMsg)); + } + + if (continueLoop) { + continue; + } + + ripCtx.put("facilityId",facilityId); + ripCtx.put("locationSeqId", locationSeqId); + ripCtx.put("userLogin", userLogin); + + // sign handling for items + double quantityAccepted = 0.0; + double quantityRejected = 0.0; + if (sign.equals("+")) { + quantityAccepted = itemQty; + quantityRejected= 0.0; + } else { + quantityRejected = itemQty; + quantityAccepted = 0.0; + } + if (quantityAccepted > 0) { + if (serialNumsList.size() > 0) { + if (serialNumsList.size() != quantityAccepted) { + String errMsg = "Error: the quantity [" + quantityAccepted + "] did not match the number of serial numbers passed [" + serialNumsList.size() + "]."; + errorMapList.add(UtilMisc.toMap("reasonCode", "QuantitySerialMismatch", "description", errMsg)); + } + Iterator serialNumIter = serialNumsList.iterator(); + while (serialNumIter.hasNext()) { + String serialNum = (String) serialNumIter.next(); + GenericValue inventoryItem = null; + try { + inventoryItem = EntityUtil.getFirst(delegator.findByAnd("InventoryItem", UtilMisc.toMap("serialNumber", serialNum))); + } catch (GenericEntityException e) { + String errMsg = "Error Getting Entity InventoryItem"; + Debug.logError(e, errMsg, module); } - - Iterator serialNumIter = serialNumsList.iterator(); - while (serialNumIter.hasNext()) { - String serialNum = (String) serialNumIter.next(); + if (inventoryItem != null) { + Map updateInvItmMap = FastMap.newInstance(); + updateInvItmMap.put( "inventoryItemId" , inventoryItem.get("inventoryItemId").toString()); + updateInvItmMap.put( "userLogin" , userLogin); + updateInvItmMap.put( "statusId",invItemStatusId); + String inventoryItemProductId = inventoryItem.getString("productId"); + if(!inventoryItemProductId.equals(productId)) { + updateInvItmMap.put( "productId",productId); + } try { - GenericValue inventoryItem = EntityUtil.getFirst(delegator.findByAnd("InventoryItem", UtilMisc.toMap("serialNumber", serialNum))); - if (inventoryItem != null) { - String inventoryItemProductId = inventoryItem.getString("productId"); - if(inventoryItemProductId.equals(productId)) { - Map updateInvItmMap = FastMap.newInstance(); - updateInvItmMap.put( "inventoryItemId" , inventoryItem.get("inventoryItemId").toString()); - updateInvItmMap.put( "userLogin" , userLogin); - updateInvItmMap.put( "productId",productId); - updateInvItmMap.put( "statusId","INV_ON_HOLD"); - try { - Map test = dispatcher.runSync("updateInventoryItem", updateInvItmMap); - } catch (GenericServiceException e) { - String errMsg = "Error running service updateInventoryItem: " + e.toString(); - errorMapList.add(UtilMisc.toMap("reasonCode", "GenericServiceException", "description", errMsg)); - Debug.logError(e, errMsg, module); - } - } - } - } catch (GenericEntityException e) { - String errMsg = "Error Getting Entity InventoryItem"; + Map test = dispatcher.runSync("updateInventoryItem", updateInvItmMap); + } catch (GenericServiceException e) { + String errMsg = "Error running service updateInventoryItem: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericServiceException", "description", errMsg)); Debug.logError(e, errMsg, module); } - - // clone the context as it may be changed in the call + + } else { + //clone the context as it may be changed in the call Map localRipCtx = FastMap.newInstance(); localRipCtx.putAll(ripCtx); localRipCtx.put("quantityAccepted", new Double(1.0)); // always set this to 0, if needed we'll handle the rejected quantity separately localRipCtx.put("quantityRejected", new Double(0.0)); - localRipCtx.put("serialNumber", serialNum); localRipCtx.put("productId", productId); localRipCtx.put("returnItemSeqId", returnItemSeqId); runReceiveInventoryProduct( localRipCtx , errorMapList , dispatcher); } - } else { - // no serial numbers, just receive the quantity - // clone the context as it may be changted in the call - Map localRipCtx = FastMap.newInstance(); - localRipCtx.putAll(ripCtx); - localRipCtx.put("quantityAccepted", new Double(quantityAccepted)); - // always set this to 0, if needed we'll handle the rejected quantity separately - localRipCtx.put("quantityRejected", new Double(0.0)); - localRipCtx.put("productId", productId); - localRipCtx.put("returnItemSeqId", returnItemSeqId); - runReceiveInventoryProduct( localRipCtx , errorMapList , dispatcher); } } else { - // TODOLATER: need to run service receiveInventoryProduct and updateInventoryItem when quantityRejected > 0 - // NOTE DEJ20070711 this shouldn't happen for current needs, so save for later + // no serial numbers, just receive the quantity + // clone the context as it may be changted in the call + Map localRipCtx = FastMap.newInstance(); + localRipCtx.putAll(ripCtx); + localRipCtx.put("quantityAccepted", new Double(quantityAccepted)); + // always set this to 0, if needed we'll handle the rejected quantity separately + localRipCtx.put("quantityRejected", new Double(0.0)); + localRipCtx.put("productId", productId); + localRipCtx.put("returnItemSeqId", returnItemSeqId); + runReceiveInventoryProduct( localRipCtx , errorMapList , dispatcher); } - } else { - String errMsg = "Return status is not RETURN_ACCEPTED"; - Debug.logError(errMsg, module); - errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + } else { + // TODOLATER: need to run service receiveInventoryProduct and updateInventoryItem when quantityRejected > 0 + // NOTE DEJ20070711 this shouldn't happen for current needs, so save for later } } else { String errMsg = "ReturnId Not Valid: Id not present in Database"; @@ -766,19 +775,20 @@ errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); } } - statusId = "RETURN_COMPLETED"; - try { - dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("statusId", statusId, "returnId", returnId, "userLogin", userLogin)); - } catch (GenericServiceException e) { - String errMsg = "Error Storing the value: " + e.toString(); - errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); - Debug.logError(e, errMsg, module); + + if (statusId.equals("RETURN_ACCEPTED")) { + statusId = "RETURN_COMPLETED"; + try { + dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("statusId", statusId, "returnId", returnId, "userLogin", userLogin)); + } catch (GenericServiceException e) { + String errMsg = "Error Storing the value: " + e.toString(); + errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg)); + Debug.logError(e, errMsg, module); + } } + } - // prepare result Map for createOagisMessageinfo - - Map result = FastMap.newInstance(); result.put("logicalId", logicalId); result.put("component", component); @@ -790,15 +800,15 @@ String errMsg = "Error Processing Received Messages"; result.putAll(ServiceUtil.returnError(errMsg)); return result; - } - - comiCtx.put("returnId", returnId); - comiCtx.put("processingStatusId", "OAGMP_PROC_SUCCESS"); - try { - dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true); - } catch (GenericServiceException e){ - String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString(); - Debug.logError(e, errMsg, module); + } else { + comiCtx.put("returnId", returnId); + comiCtx.put("processingStatusId", "OAGMP_PROC_SUCCESS"); + try { + dispatcher.runSync("updateOagisMessageInfo", comiCtx, 60, true); + } catch (GenericServiceException e){ + String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString(); + Debug.logError(e, errMsg, module); + } } result.putAll(ServiceUtil.returnSuccess("Action Performed Successfully")); @@ -807,8 +817,7 @@ public static void runReceiveInventoryProduct(Map localRipCtx, List errorMapList, LocalDispatcher dispatcher) { try { - Map ripResult = dispatcher.runSync("receiveInventoryProduct", - localRipCtx); + Map ripResult = dispatcher.runSync("receiveInventoryProduct", localRipCtx); if (ServiceUtil.isError(ripResult)) { String errMsg = ServiceUtil.getErrorMessage(ripResult); errorMapList.add(UtilMisc.toMap("reasonCode", "ReceiveInventoryServiceError", "description", errMsg)); |
Free forum by Nabble | Edit this page |