/** * Check if components required by specified products are available. * * @param products list of ProdOrderProductVO objects * @params compAltComps collection of <component item code,HashSet of alternative component item * codes>; filled by this method (and given back by reference) * @return VOListResponse of ProdOrderComponentVO objects */ public final Response checkComponentsAvailability( Connection conn, Hashtable compAltComps, ArrayList products, UserSessionParameters userSessionPars, HttpServletRequest request, HttpServletResponse response, HttpSession userSession, ServletContext context) { String serverLanguageId = ((JAIOUserSessionParameters) userSessionPars).getServerLanguageId(); try { // retrieve internationalization settings (Resources object)... ServerResourcesFactory factory = (ServerResourcesFactory) context.getAttribute(Controller.RESOURCES_FACTORY); Resources resources = factory.getResources(userSessionPars.getLanguageId()); if (products.size() == 0) { return new VOListResponse(new ArrayList(), false, 0); } // fill in comps hashtable with the collection of required components... ItemPK pk = null; ProdOrderProductVO prodVO = null; ArrayList components = null; MaterialVO compVO = null; Response res = null; ProdOrderComponentVO componentVO = null; Hashtable comps = new Hashtable(); // collection of <component item code,ProdOrderComponentVO object> for (int i = 0; i < products.size(); i++) { // retrieve bill of materials for each product... prodVO = (ProdOrderProductVO) products.get(i); pk = new ItemPK(prodVO.getCompanyCodeSys01DOC23(), prodVO.getItemCodeItm01DOC23()); res = bean.getBillOfMaterials( conn, pk, userSessionPars, request, response, userSession, context); if (res.isError()) { return res; } // extract components only (leaf nodes)... components = getComponents( (DefaultMutableTreeNode) ((TreeModel) ((VOResponse) res).getVo()).getRoot()); for (int j = 0; j < components.size(); j++) { compVO = (MaterialVO) components.get(j); componentVO = (ProdOrderComponentVO) comps.get(compVO.getItemCodeItm01ITM03()); if (componentVO == null) { componentVO = new ProdOrderComponentVO(); comps.put(compVO.getItemCodeItm01ITM03(), componentVO); componentVO.setAvailableQty(new BigDecimal(0)); componentVO.setCompanyCodeSys01DOC24(compVO.getCompanyCodeSys01ITM03()); componentVO.setDescriptionSYS10(compVO.getDescriptionSYS10()); componentVO.setDocNumberDOC24(prodVO.getDocNumberDOC23()); componentVO.setDocYearDOC24(prodVO.getDocYearDOC23()); componentVO.setItemCodeItm01DOC24(compVO.getItemCodeItm01ITM03()); componentVO.setMinSellingQtyUmCodeReg02ITM01(compVO.getMinSellingQtyUmCodeReg02ITM01()); componentVO.setQtyDOC24(new BigDecimal(0)); } componentVO.setQtyDOC24( componentVO.getQtyDOC24().add(compVO.getQtyITM03().multiply(prodVO.getQtyDOC23()))); } } // check components availability in the specified warehouse... Enumeration en = comps.keys(); GridParams gridParams = new GridParams(); gridParams .getOtherGridParams() .put(ApplicationConsts.COMPANY_CODE_SYS01, prodVO.getCompanyCodeSys01DOC23()); gridParams .getOtherGridParams() .put(ApplicationConsts.WAREHOUSE_CODE, prodVO.getWarehouseCodeWar01DOC22()); gridParams.getOtherGridParams().put(ApplicationConsts.LOAD_ALL, Boolean.TRUE); ItemAvailabilityVO availVO = null; BigDecimal availability, altAvailability, delta; String itemCode = null; ArrayList list, availList; AltComponentVO altVO = null; ArrayList alternativeComps = new ArrayList(); ArrayList compsToRemove = new ArrayList(); ProdOrderComponentVO altComponentVO = null; HashSet altCodes = null; // list of alternative component item codes... BigDecimal altQty = null; while (en.hasMoreElements()) { itemCode = en.nextElement().toString(); componentVO = (ProdOrderComponentVO) comps.get(itemCode); gridParams .getOtherGridParams() .put( ApplicationConsts.ITEM_PK, new ItemPK(prodVO.getCompanyCodeSys01DOC23(), itemCode)); res = avail.executeCommand( gridParams, userSessionPars, request, response, userSession, context); if (res.isError()) return res; availList = ((VOListResponse) res).getRows(); componentVO.setAvailabilities(availList); availability = new BigDecimal(0); for (int i = 0; i < availList.size(); i++) { availVO = (ItemAvailabilityVO) availList.get(i); availability = availability.add(availVO.getAvailableQtyWAR03()); } componentVO.setAvailableQty(availability); if (componentVO.getQtyDOC24().doubleValue() > componentVO.getAvailableQty().doubleValue()) { // check if there exist some alternative component... res = altComps.executeCommand( gridParams, userSessionPars, request, response, userSession, context); if (res.isError()) return res; list = ((VOListResponse) res).getRows(); for (int i = 0; i < list.size(); i++) { altVO = (AltComponentVO) list.get(i); gridParams .getOtherGridParams() .put( ApplicationConsts.ITEM_PK, new ItemPK(prodVO.getCompanyCodeSys01DOC23(), altVO.getItemCodeItm01ITM04())); res = avail.executeCommand( gridParams, userSessionPars, request, response, userSession, context); if (res.isError()) return res; availList = ((VOListResponse) res).getRows(); altAvailability = new BigDecimal(0); for (int j = 0; j < availList.size(); j++) { availVO = (ItemAvailabilityVO) availList.get(j); altAvailability = altAvailability.add(availVO.getAvailableQtyWAR03()); } if (altAvailability.doubleValue() > 0) { altComponentVO = new ProdOrderComponentVO(); altComponentVO.setAvailabilities(availList); altComponentVO.setAvailableQty(altAvailability); altComponentVO.setCompanyCodeSys01DOC24(altVO.getCompanyCodeSys01ITM04()); altComponentVO.setDescriptionSYS10(altVO.getDescriptionSYS10()); altComponentVO.setDocNumberDOC24(prodVO.getDocNumberDOC23()); altComponentVO.setDocYearDOC24(prodVO.getDocYearDOC23()); altComponentVO.setItemCodeItm01DOC24(altVO.getItemCodeItm01ITM04()); altComponentVO.setMinSellingQtyUmCodeReg02ITM01( altVO.getMinSellingQtyUmCodeReg02ITM01()); altQty = conv.convertQty( altVO.getMinSellingQtyUmCodeReg02ITM01(), componentVO.getMinSellingQtyUmCodeReg02ITM01(), altAvailability, userSessionPars, request, response, userSession, context); if (componentVO.getQtyDOC24().subtract(availability).doubleValue() > altQty.doubleValue()) { delta = altQty; altComponentVO.setQtyDOC24(altAvailability); } else { delta = componentVO.getQtyDOC24(); altComponentVO.setQtyDOC24( conv.convertQty( componentVO.getMinSellingQtyUmCodeReg02ITM01(), altVO.getMinSellingQtyUmCodeReg02ITM01(), delta, userSessionPars, request, response, userSession, context)); } componentVO.setQtyDOC24(componentVO.getQtyDOC24().subtract(delta)); alternativeComps.add(altComponentVO); altCodes = (HashSet) compAltComps.get(itemCode); if (altCodes == null) { altCodes = new HashSet(); compAltComps.put(itemCode, altCodes); } altCodes.add(altVO.getItemCodeItm01ITM04()); if (componentVO.getQtyDOC24().doubleValue() == 0) { compsToRemove.add(componentVO); break; } if (componentVO.getQtyDOC24().subtract(availability).doubleValue() == 0) break; } } } } list = new ArrayList(comps.values()); list.addAll(alternativeComps); list.removeAll(compsToRemove); return new VOListResponse(list, false, list.size()); } catch (Throwable ex) { Logger.error( userSessionPars.getUsername(), this.getClass().getName(), "checkComponentsAvailability", "Error while retrieving components availability for the specified production order", ex); return new ErrorResponse(ex.getMessage()); } }
/** * Analyze class fields and fill in "voSetterMethods","voGetterMethods","indexes",reverseIndexes" * attributes. * * @param prefix e.g. "attrx.attry." * @param parentMethods getter methods of parent v.o. * @param classType class to analyze */ private void analyzeClassFields(String prefix, Method[] parentMethods, Class classType) { try { if (prefix.split("\\.").length > ClientSettings.MAX_NR_OF_LOOPS_IN_ANALYZE_VO) return; // retrieve all getter and setter methods defined in the specified value object... String attributeName = null; Method[] methods = classType.getMethods(); String aName = null; for (int i = 0; i < methods.length; i++) { attributeName = methods[i].getName(); if (attributeName.startsWith("get") && methods[i].getParameterTypes().length == 0 && ValueObject.class.isAssignableFrom(methods[i].getReturnType())) { aName = getAttributeName(attributeName, classType); Method[] newparentMethods = new Method[parentMethods.length + 1]; System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length); newparentMethods[parentMethods.length] = methods[i]; analyzeClassFields(prefix + aName + ".", newparentMethods, methods[i].getReturnType()); } if (attributeName.startsWith("get") && methods[i].getParameterTypes().length == 0 && (methods[i].getReturnType().equals(String.class) || methods[i].getReturnType().equals(Long.class) || methods[i].getReturnType().equals(Long.TYPE) || methods[i].getReturnType().equals(Float.class) || methods[i].getReturnType().equals(Float.TYPE) || methods[i].getReturnType().equals(Short.class) || methods[i].getReturnType().equals(Short.TYPE) || methods[i].getReturnType().equals(Double.class) || methods[i].getReturnType().equals(Double.TYPE) || methods[i].getReturnType().equals(BigDecimal.class) || methods[i].getReturnType().equals(java.util.Date.class) || methods[i].getReturnType().equals(java.sql.Date.class) || methods[i].getReturnType().equals(java.sql.Timestamp.class) || methods[i].getReturnType().equals(Integer.class) || methods[i].getReturnType().equals(Integer.TYPE) || methods[i].getReturnType().equals(Character.class) || methods[i].getReturnType().equals(Boolean.class) || methods[i].getReturnType().equals(boolean.class) || methods[i].getReturnType().equals(ImageIcon.class) || methods[i].getReturnType().equals(Icon.class) || methods[i].getReturnType().equals(byte[].class) || methods[i].getReturnType().equals(Object.class) || ValueObject.class.isAssignableFrom(methods[i].getReturnType()))) { attributeName = getAttributeName(attributeName, classType); // try { // if // (classType.getMethod("set"+attributeName.substring(0,1).toUpperCase()+attributeName.substring(1),new Class[]{methods[i].getReturnType()})!=null) Method[] newparentMethods = new Method[parentMethods.length + 1]; System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length); newparentMethods[parentMethods.length] = methods[i]; voGetterMethods.put(prefix + attributeName, newparentMethods); // } catch (NoSuchMethodException ex) { // } } else if (attributeName.startsWith("is") && methods[i].getParameterTypes().length == 0 && (methods[i].getReturnType().equals(Boolean.class) || methods[i].getReturnType().equals(boolean.class))) { attributeName = getAttributeName(attributeName, classType); Method[] newparentMethods = new Method[parentMethods.length + 1]; System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length); newparentMethods[parentMethods.length] = methods[i]; voGetterMethods.put(prefix + attributeName, newparentMethods); } else if (attributeName.startsWith("set") && methods[i].getParameterTypes().length == 1) { attributeName = getAttributeName(attributeName, classType); try { if (classType.getMethod( "get" + attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1), new Class[0]) != null) { Method[] newparentMethods = new Method[parentMethods.length + 1]; System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length); newparentMethods[parentMethods.length] = methods[i]; voSetterMethods.put(prefix + attributeName, newparentMethods); } } catch (NoSuchMethodException ex) { try { if (classType.getMethod( "is" + attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1), new Class[0]) != null) { Method[] newparentMethods = new Method[parentMethods.length + 1]; System.arraycopy(parentMethods, 0, newparentMethods, 0, parentMethods.length); newparentMethods[parentMethods.length] = methods[i]; voSetterMethods.put(prefix + attributeName, newparentMethods); } } catch (NoSuchMethodException exx) { } } } } // fill in indexes with the colProperties indexes first; after them, it will be added the // other indexes (of attributes not mapped with grid column...) HashSet alreadyAdded = new HashSet(); int i = 0; for (i = 0; i < colProperties.length; i++) { indexes.put(new Integer(i), colProperties[i].getColumnName()); reverseIndexes.put(colProperties[i].getColumnName(), new Integer(i)); alreadyAdded.add(colProperties[i].getColumnName()); } Enumeration en = voGetterMethods.keys(); while (en.hasMoreElements()) { attributeName = en.nextElement().toString(); if (!alreadyAdded.contains(attributeName)) { indexes.put(new Integer(i), attributeName); reverseIndexes.put(attributeName, new Integer(i)); i++; } } } catch (Exception ex) { ex.printStackTrace(); } }