Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java?rev=712917&r1=712916&r2=712917&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java Mon Nov 10 18:18:07 2008 @@ -56,31 +56,31 @@ * ProductCategory -> ProductFeatureCategoryAppl -> ProductFeatureCategory -> ProductFeature. * Returns a Map of Lists of ProductFeature GenericValue objects organized by productFeatureTypeId. */ - public static Map makeCategoryFeatureLists(String productCategoryId, GenericDelegator delegator) { + public static Map<String, List<GenericValue>> makeCategoryFeatureLists(String productCategoryId, GenericDelegator delegator) { return makeCategoryFeatureLists(productCategoryId, delegator, DEFAULT_PER_TYPE_MAX_SIZE); } - public static Map makeCategoryFeatureLists(String productCategoryId, GenericDelegator delegator, int perTypeMaxSize) { - Map productFeaturesByTypeMap = FastMap.newInstance(); + public static Map<String, List<GenericValue>> makeCategoryFeatureLists(String productCategoryId, GenericDelegator delegator, int perTypeMaxSize) { + Map<String, Map<String, GenericValue>> productFeaturesByTypeMap = FastMap.newInstance(); try { - List productFeatureCategoryAppls = delegator.findByAndCache("ProductFeatureCategoryAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); + List<GenericValue> productFeatureCategoryAppls = delegator.findByAndCache("ProductFeatureCategoryAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); productFeatureCategoryAppls = EntityUtil.filterByDate(productFeatureCategoryAppls, true); if (productFeatureCategoryAppls != null) { - Iterator pfcasIter = productFeatureCategoryAppls.iterator(); + Iterator<GenericValue> pfcasIter = productFeatureCategoryAppls.iterator(); while (pfcasIter.hasNext()) { - GenericValue productFeatureCategoryAppl = (GenericValue) pfcasIter.next(); - List productFeatures = delegator.findByAndCache("ProductFeature", UtilMisc.toMap("productFeatureCategoryId", productFeatureCategoryAppl.get("productFeatureCategoryId"))); - Iterator pfsIter = productFeatures.iterator(); + GenericValue productFeatureCategoryAppl = pfcasIter.next(); + List<GenericValue> productFeatures = delegator.findByAndCache("ProductFeature", UtilMisc.toMap("productFeatureCategoryId", productFeatureCategoryAppl.get("productFeatureCategoryId"))); + Iterator<GenericValue> pfsIter = productFeatures.iterator(); while (pfsIter.hasNext()) { - GenericValue productFeature = (GenericValue) pfsIter.next(); + GenericValue productFeature = pfsIter.next(); String productFeatureTypeId = productFeature.getString("productFeatureTypeId"); - Map featuresByType = (Map) productFeaturesByTypeMap.get(productFeatureTypeId); + Map<String, GenericValue> featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId); if (featuresByType == null) { featuresByType = FastMap.newInstance(); productFeaturesByTypeMap.put(productFeatureTypeId, featuresByType); } if (featuresByType.size() < perTypeMaxSize) { - featuresByType.put(productFeature.get("productFeatureId"), productFeature); + featuresByType.put(productFeature.getString("productFeatureId"), productFeature); } } } @@ -90,26 +90,26 @@ } try { - List productFeatureCatGrpAppls = delegator.findByAndCache("ProductFeatureCatGrpAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); + List<GenericValue> productFeatureCatGrpAppls = delegator.findByAndCache("ProductFeatureCatGrpAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); productFeatureCatGrpAppls = EntityUtil.filterByDate(productFeatureCatGrpAppls, true); if (productFeatureCatGrpAppls != null) { - Iterator pfcgasIter = productFeatureCatGrpAppls.iterator(); + Iterator<GenericValue> pfcgasIter = productFeatureCatGrpAppls.iterator(); while (pfcgasIter.hasNext()) { - GenericValue productFeatureCatGrpAppl = (GenericValue) pfcgasIter.next(); - List productFeatureGroupAppls = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", productFeatureCatGrpAppl.get("productFeatureGroupId"))); - Iterator pfgaasIter = productFeatureGroupAppls.iterator(); + GenericValue productFeatureCatGrpAppl = pfcgasIter.next(); + List<GenericValue> productFeatureGroupAppls = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", productFeatureCatGrpAppl.get("productFeatureGroupId"))); + Iterator<GenericValue> pfgaasIter = productFeatureGroupAppls.iterator(); while (pfgaasIter.hasNext()) { - GenericValue productFeatureGroupAppl = (GenericValue) pfgaasIter.next(); + GenericValue productFeatureGroupAppl = pfgaasIter.next(); GenericValue productFeature = delegator.findByPrimaryKeyCache("ProductFeature", UtilMisc.toMap("productFeatureId", productFeatureGroupAppl.get("productFeatureId"))); String productFeatureTypeId = productFeature.getString("productFeatureTypeId"); - Map featuresByType = (Map) productFeaturesByTypeMap.get(productFeatureTypeId); + Map<String, GenericValue> featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId); if (featuresByType == null) { featuresByType = FastMap.newInstance(); productFeaturesByTypeMap.put(productFeatureTypeId, featuresByType); } if (featuresByType.size() < perTypeMaxSize) { - featuresByType.put(productFeature.get("productFeatureId"), productFeature); + featuresByType.put(productFeature.getString("productFeatureId"), productFeature); } } } @@ -119,28 +119,29 @@ } // now before returning, order the features in each list by description - Iterator productFeatureTypeEntries = productFeaturesByTypeMap.entrySet().iterator(); + Map<String, List<GenericValue>> productFeaturesByTypeMapSorted = FastMap.newInstance(); + Iterator<Map.Entry<String, Map<String, GenericValue>>> productFeatureTypeEntries = productFeaturesByTypeMap.entrySet().iterator(); while (productFeatureTypeEntries.hasNext()) { - Map.Entry entry = (Map.Entry) productFeatureTypeEntries.next(); - List sortedFeatures = EntityUtil.orderBy(((Map) entry.getValue()).values(), UtilMisc.toList("description")); - productFeaturesByTypeMap.put(entry.getKey(), sortedFeatures); + Map.Entry<String, Map<String, GenericValue>> entry = productFeatureTypeEntries.next(); + List<GenericValue> sortedFeatures = EntityUtil.orderBy(entry.getValue().values(), UtilMisc.toList("description")); + productFeaturesByTypeMapSorted.put(entry.getKey(), sortedFeatures); } - return productFeaturesByTypeMap; + return productFeaturesByTypeMapSorted; } - public static Map getAllFeaturesByType(GenericDelegator delegator) { + public static Map<String, List<GenericValue>> getAllFeaturesByType(GenericDelegator delegator) { return getAllFeaturesByType(delegator, DEFAULT_PER_TYPE_MAX_SIZE); } - public static Map getAllFeaturesByType(GenericDelegator delegator, int perTypeMaxSize) { - Map productFeaturesByTypeMap = FastMap.newInstance(); + public static Map<String, List<GenericValue>> getAllFeaturesByType(GenericDelegator delegator, int perTypeMaxSize) { + Map<String, List<GenericValue>> productFeaturesByTypeMap = FastMap.newInstance(); try { - Set typesWithOverflowMessages = FastSet.newInstance(); + Set<String> typesWithOverflowMessages = FastSet.newInstance(); EntityListIterator productFeatureEli = delegator.find("ProductFeature", null, null, null, UtilMisc.toList("description"), null); GenericValue productFeature = null; - while ((productFeature = (GenericValue) productFeatureEli.next()) != null) { + while ((productFeature = productFeatureEli.next()) != null) { String productFeatureTypeId = productFeature.getString("productFeatureTypeId"); - List featuresByType = (List) productFeaturesByTypeMap.get(productFeatureTypeId); + List<GenericValue> featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId); if (featuresByType == null) { featuresByType = FastList.newInstance(); productFeaturesByTypeMap.put(productFeatureTypeId, featuresByType); @@ -161,19 +162,20 @@ return productFeaturesByTypeMap; } - public static Map makeFeatureIdByTypeMap(ServletRequest request) { - Map parameters = UtilHttp.getParameterMap((HttpServletRequest) request); + public static Map<String, String> makeFeatureIdByTypeMap(ServletRequest request) { + Map<String, Object> parameters = UtilHttp.getParameterMap((HttpServletRequest) request); return makeFeatureIdByTypeMap(parameters); } /** Handles parameters coming in prefixed with "pft_" where the text in the key following the prefix is a productFeatureTypeId and the value is a productFeatureId; meant to be used with drop-downs and such */ - public static Map makeFeatureIdByTypeMap(Map parameters) { - Map featureIdByType = FastMap.newInstance(); + public static Map<String, String> makeFeatureIdByTypeMap(Map<String, Object> parameters) { + Map<String, String> featureIdByType = FastMap.newInstance(); if (parameters == null) return featureIdByType; - Iterator parameterNameIter = parameters.keySet().iterator(); + + Iterator<String> parameterNameIter = parameters.keySet().iterator(); while (parameterNameIter.hasNext()) { - String parameterName = (String) parameterNameIter.next(); + String parameterName = parameterNameIter.next(); if (parameterName.startsWith("pft_")) { String productFeatureTypeId = parameterName.substring(4); String productFeatureId = (String) parameters.get(parameterName); @@ -187,13 +189,13 @@ } /** Handles parameters coming in prefixed with "SEARCH_FEAT" where the parameter value is a productFeatureId; meant to be used with text entry boxes or check-boxes and such */ - public static List makeFeatureIdListFromPrefixed(Map parameters) { - List featureIdList = FastList.newInstance(); + public static List<String> makeFeatureIdListFromPrefixed(Map<String, Object> parameters) { + List<String> featureIdList = FastList.newInstance(); if (parameters == null) return featureIdList; - Iterator parameterNameIter = parameters.keySet().iterator(); + Iterator<String> parameterNameIter = parameters.keySet().iterator(); while (parameterNameIter.hasNext()) { - String parameterName = (String) parameterNameIter.next(); + String parameterName = parameterNameIter.next(); if (parameterName.startsWith("SEARCH_FEAT")) { String productFeatureId = (String) parameters.get(parameterName); if (productFeatureId != null && productFeatureId.length() > 0) { @@ -205,23 +207,23 @@ return featureIdList; } - public static String makeFeatureIdByTypeString(Map featureIdByType) { + public static String makeFeatureIdByTypeString(Map<String, String> featureIdByType) { if (featureIdByType == null || featureIdByType.size() == 0) { return ""; } StringBuilder outSb = new StringBuilder(); - Iterator fbtIter = featureIdByType.entrySet().iterator(); + Iterator<Map.Entry<String, String>> fbtIter = featureIdByType.entrySet().iterator(); while (fbtIter.hasNext()) { - Map.Entry entry = (Map.Entry) fbtIter.next(); - String productFeatureTypeId = (String) entry.getKey(); - String productFeatureId = (String) entry.getValue(); + Map.Entry<String, String> entry = fbtIter.next(); + if (outSb.length() > 0) { + outSb.append('&'); + } + String productFeatureTypeId = entry.getKey(); + String productFeatureId = entry.getValue(); outSb.append(productFeatureTypeId); outSb.append('='); outSb.append(productFeatureId); - if (fbtIter.hasNext()) { - outSb.append('&'); - } } return outSb.toString(); @@ -232,13 +234,13 @@ * where the parameter value is a productFeatureCategoryId; * meant to be used with text entry boxes or check-boxes and such **/ - public static List makeProductFeatureCategoryIdListFromPrefixed(Map parameters) { - List prodFeatureCategoryIdList = FastList.newInstance(); + public static List<String> makeProductFeatureCategoryIdListFromPrefixed(Map<String, Object> parameters) { + List<String> prodFeatureCategoryIdList = FastList.newInstance(); if (parameters == null) return prodFeatureCategoryIdList; - Iterator parameterNameIter = parameters.keySet().iterator(); + Iterator<String> parameterNameIter = parameters.keySet().iterator(); while (parameterNameIter.hasNext()) { - String parameterName = (String) parameterNameIter.next(); + String parameterName = parameterNameIter.next(); if (parameterName.startsWith("SEARCH_PROD_FEAT_CAT")) { String productFeatureCategoryId = (String) parameters.get(parameterName); if (productFeatureCategoryId != null && productFeatureCategoryId.length() > 0) { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java?rev=712917&r1=712916&r2=712917&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java Mon Nov 10 18:18:07 2008 @@ -22,11 +22,14 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javolution.util.FastList; import javolution.util.FastMap; +import javolution.util.FastSet; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; @@ -57,8 +60,8 @@ * the results are from ProductFeatureGroupAndAppl. Otherwise, if there is a productId, the results are from ProductFeatureAndAppl. * The optional productFeatureApplTypeId causes results to be filtered by this parameter--only used in conjunction with productId. */ - public static Map getProductFeaturesByType(DispatchContext dctx, Map context) { - Map results = FastMap.newInstance(); + public static Map<String, Object> getProductFeaturesByType(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> results = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); /* because we might need to search either for product features or for product features of a product, the search code has to be generic. @@ -69,7 +72,7 @@ String entityToSearch = "ProductFeature"; String fieldToSearch = "productFeatureCategoryId"; - List orderBy = UtilMisc.toList("productFeatureTypeId", "description"); + List<String> orderBy = UtilMisc.toList("productFeatureTypeId", "description"); if (valueToSearch == null && context.get("productFeatureGroupId") != null) { entityToSearch = "ProductFeatureGroupAndAppl"; @@ -89,24 +92,25 @@ try { // get all product features in this feature category - List allFeatures = delegator.findByAnd(entityToSearch, UtilMisc.toMap(fieldToSearch, valueToSearch), orderBy); + List<GenericValue> allFeatures = delegator.findByAnd(entityToSearch, UtilMisc.toMap(fieldToSearch, valueToSearch), orderBy); if (entityToSearch.equals("ProductFeatureAndAppl") && productFeatureApplTypeId != null) allFeatures = EntityUtil.filterByAnd(allFeatures, UtilMisc.toMap("productFeatureApplTypeId", productFeatureApplTypeId)); - List featureTypes = FastList.newInstance(); // or LinkedList? - Map featuresByType = new LinkedHashMap(); + List<String> featureTypes = FastList.newInstance(); + Map<String, List<GenericValue>> featuresByType = new LinkedHashMap<String, List<GenericValue>>(); GenericValue feature = null; - for (Iterator featuresIter = allFeatures.iterator(); featuresIter.hasNext(); ) { - feature = (GenericValue) featuresIter.next(); + for (Iterator<GenericValue> featuresIter = allFeatures.iterator(); featuresIter.hasNext(); ) { + feature = featuresIter.next(); String featureType = feature.getString("productFeatureTypeId"); if (!featureTypes.contains(featureType)) { featureTypes.add(featureType); } - if (!featuresByType.containsKey(featureType)) { - featuresByType.put(featureType, FastList.newInstance()); + List<GenericValue> features = featuresByType.get(featureType); + if (features == null) { + features = FastList.newInstance(); + featuresByType.put(featureType, features); } - List features = (List)featuresByType.get(featureType); features.add(feature); } @@ -124,13 +128,13 @@ * Parameter: productId, productFeatureAppls (a List of ProductFeatureAndAppl entities of features applied to productId) * Result: variantProductIds: a List of productIds of variants with those features */ - public static Map getAllExistingVariants(DispatchContext dctx, Map context) { - Map results = FastMap.newInstance(); + public static Map<String, Object> getAllExistingVariants(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> results = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); String productId = (String) context.get("productId"); - List curProductFeatureAndAppls = (List) context.get("productFeatureAppls"); - List existingVariantProductIds = FastList.newInstance(); + List<String> curProductFeatureAndAppls = UtilGenerics.checkList(context.get("productFeatureAppls")); + List<String> existingVariantProductIds = FastList.newInstance(); try { /* @@ -138,23 +142,23 @@ * see if it has every single feature in the list of productFeatureAppls as a STANDARD_FEATURE. If so, then * it qualifies and add it to the list of existingVariantProductIds. */ - List productAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"))); - Iterator productAssocIter = productAssocs.iterator(); + List<GenericValue> productAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"))); + Iterator<GenericValue> productAssocIter = productAssocs.iterator(); while (productAssocIter.hasNext()) { - GenericEntity productAssoc = (GenericEntity) productAssocIter.next(); + GenericEntity productAssoc = productAssocIter.next(); //for each associated product, if it has all standard features, display it's productId boolean hasAllFeatures = true; - Iterator curProductFeatureAndApplIter = curProductFeatureAndAppls.iterator(); + Iterator<String> curProductFeatureAndApplIter = curProductFeatureAndAppls.iterator(); while (curProductFeatureAndApplIter.hasNext()) { - String productFeatureAndAppl = (String) curProductFeatureAndApplIter.next(); - Map findByMap = UtilMisc.toMap("productId", productAssoc.getString("productIdTo"), + String productFeatureAndAppl = curProductFeatureAndApplIter.next(); + Map<String, String> findByMap = UtilMisc.toMap("productId", productAssoc.getString("productIdTo"), "productFeatureId", productFeatureAndAppl, "productFeatureApplTypeId", "STANDARD_FEATURE"); //Debug.log("Using findByMap: " + findByMap); - List standardProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", findByMap)); + List<GenericValue> standardProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", findByMap)); if (UtilValidate.isEmpty(standardProductFeatureAndAppls)) { // Debug.log("Does NOT have this standard feature"); hasAllFeatures = false; @@ -166,7 +170,7 @@ if (hasAllFeatures) { // add to list of existing variants: productId=productAssoc.productIdTo - existingVariantProductIds.add(productAssoc.get("productIdTo")); + existingVariantProductIds.add(productAssoc.getString("productIdTo")); } } results = ServiceUtil.returnSuccess(); @@ -183,33 +187,33 @@ * Result: featureCombinations, a List of Maps containing, for each possible variant of the productid: * {defaultVariantProductId: id of this variant; curProductFeatureAndAppls: features applied to this variant; existingVariantProductIds: List of productIds which are already variants with these features } */ - public static Map getVariantCombinations(DispatchContext dctx, Map context) { - Map results = FastMap.newInstance(); + public static Map<String, Object> getVariantCombinations(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> results = FastMap.newInstance(); LocalDispatcher dispatcher = dctx.getDispatcher(); String productId = (String) context.get("productId"); try { - Map featuresResults = dispatcher.runSync("getProductFeaturesByType", UtilMisc.toMap("productId", productId)); - Map features = FastMap.newInstance(); + Map<String, Object> featuresResults = dispatcher.runSync("getProductFeaturesByType", UtilMisc.toMap("productId", productId)); + Map<String, List<GenericValue>> features; if (featuresResults.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS)) { - features = (Map) featuresResults.get("productFeaturesByType"); + features = UtilGenerics.checkMap(featuresResults.get("productFeaturesByType")); } else { return ServiceUtil.returnError((String) featuresResults.get(ModelService.ERROR_MESSAGE_LIST)); } // need to keep 2 lists, oldCombinations and newCombinations, and keep swapping them after each looping. Otherwise, you'll get a // concurrent modification exception - List oldCombinations = FastList.newInstance(); + List<Map<String, Object>> oldCombinations = FastList.newInstance(); // loop through each feature type - for (Iterator fi = features.keySet().iterator(); fi.hasNext(); ) { - String currentFeatureType = (String) fi.next(); - List currentFeatures = (List) features.get(currentFeatureType); + for (Iterator<String> fi = features.keySet().iterator(); fi.hasNext(); ) { + String currentFeatureType = fi.next(); + List<GenericValue> currentFeatures = features.get(currentFeatureType); - List newCombinations = FastList.newInstance(); - List combinations; + List<Map<String, Object>> newCombinations = FastList.newInstance(); + List<Map<String, Object>> combinations; // start with either existing combinations or from scratch if (oldCombinations.size() > 0) { @@ -223,12 +227,12 @@ // of the next variant. just a matter of whether we're starting with an // existing list of features and id code or from scratch. if (combinations.size()==0) { - for (Iterator cFi = currentFeatures.iterator(); cFi.hasNext(); ) { - GenericEntity currentFeature = (GenericEntity) cFi.next(); + for (Iterator<GenericValue> cFi = currentFeatures.iterator(); cFi.hasNext(); ) { + GenericValue currentFeature = cFi.next(); if (currentFeature.getString("productFeatureApplTypeId").equals("SELECTABLE_FEATURE")) { - Map newCombination = FastMap.newInstance(); - List newFeatures = FastList.newInstance(); - List newFeatureIds = FastList.newInstance(); + Map<String, Object> newCombination = FastMap.newInstance(); + List<GenericValue> newFeatures = FastList.newInstance(); + List<String> newFeatureIds = FastList.newInstance(); if (currentFeature.getString("idCode") != null) { newCombination.put("defaultVariantProductId", productId + currentFeature.getString("idCode")); } else { @@ -242,16 +246,16 @@ } } } else { - for (Iterator comboIt = combinations.iterator(); comboIt.hasNext(); ) { - Map combination = (Map) comboIt.next(); - for (Iterator cFi = currentFeatures.iterator(); cFi.hasNext(); ) { - GenericEntity currentFeature = (GenericEntity) cFi.next(); + for (Iterator<Map<String, Object>> comboIt = combinations.iterator(); comboIt.hasNext(); ) { + Map<String, Object> combination = comboIt.next(); + for (Iterator<GenericValue> cFi = currentFeatures.iterator(); cFi.hasNext(); ) { + GenericValue currentFeature = cFi.next(); if (currentFeature.getString("productFeatureApplTypeId").equals("SELECTABLE_FEATURE")) { - Map newCombination = FastMap.newInstance(); + Map<String, Object> newCombination = FastMap.newInstance(); // .clone() is important, or you'll keep adding to the same List for all the variants // have to cast twice: once from get() and once from clone() - List newFeatures = UtilMisc.makeListWritable((List) combination.get("curProductFeatureAndAppls")); - List newFeatureIds = UtilMisc.makeListWritable((List) combination.get("curProductFeatureIds")); + List<GenericValue> newFeatures = UtilMisc.makeListWritable(UtilGenerics.<GenericValue>checkList(combination.get("curProductFeatureAndAppls"))); + List<String> newFeatureIds = UtilMisc.makeListWritable(UtilGenerics.<String>checkList(combination.get("curProductFeatureIds"))); if (currentFeature.getString("idCode") != null) { newCombination.put("defaultVariantProductId", combination.get("defaultVariantProductId") + currentFeature.getString("idCode")); } else { @@ -272,18 +276,18 @@ } int defaultCodeCounter = 1; - Map defaultVariantProductIds = FastMap.newInstance(); // this map will contain the codes already used (as keys) - defaultVariantProductIds.put(productId, null); + Set<String> defaultVariantProductIds = FastSet.newInstance(); // this map will contain the codes already used (as keys) + defaultVariantProductIds.add(productId); // now figure out which of these combinations already have productIds associated with them - for (Iterator fCi = oldCombinations.iterator(); fCi.hasNext(); ) { - Map combination = (Map) fCi.next(); + for (Iterator<Map<String, Object>> fCi = oldCombinations.iterator(); fCi.hasNext(); ) { + Map<String, Object> combination = fCi.next(); // Verify if the default code is already used, if so add a numeric suffix - if (defaultVariantProductIds.containsKey(combination.get("defaultVariantProductId"))) { + if (defaultVariantProductIds.contains((String) combination.get("defaultVariantProductId"))) { combination.put("defaultVariantProductId", combination.get("defaultVariantProductId") + (defaultCodeCounter < 10? "0" + defaultCodeCounter: "" + defaultCodeCounter)); defaultCodeCounter++; } - defaultVariantProductIds.put(combination.get("defaultVariantProductId"), null); + defaultVariantProductIds.add((String) combination.get("defaultVariantProductId")); results = dispatcher.runSync("getAllExistingVariants", UtilMisc.toMap("productId", productId, "productFeatureAppls", combination.get("curProductFeatureIds"))); combination.put("existingVariantProductIds", results.get("variantProductIds")); @@ -302,15 +306,15 @@ * Parameters: productCategoryId (String) and productFeatures (a List of ProductFeature GenericValues) * Result: products (a List of Product GenericValues) */ - public static Map getCategoryVariantProducts(DispatchContext dctx, Map context) { - Map results = FastMap.newInstance(); + public static Map<String, Object> getCategoryVariantProducts(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> results = FastMap.newInstance(); LocalDispatcher dispatcher = dctx.getDispatcher(); - List productFeatures = (List) context.get("productFeatures"); + List<GenericValue> productFeatures = UtilGenerics.checkList(context.get("productFeatures")); String productCategoryId = (String) context.get("productCategoryId"); // get all the product members of the product category - Map result = FastMap.newInstance(); + Map result; try { result = dispatcher.runSync("getProductCategoryMembers", UtilMisc.toMap("categoryId", productCategoryId)); } catch (GenericServiceException ex) { @@ -318,19 +322,19 @@ return ServiceUtil.returnError(ex.getMessage()); } - List memberProducts = (List) result.get("categoryMembers"); + List<GenericValue> memberProducts = UtilGenerics.checkList(result.get("categoryMembers")); if ((memberProducts != null) && (memberProducts.size() > 0)) { // construct a Map of productFeatureTypeId -> productFeatureId from the productFeatures List - Map featuresByType = FastMap.newInstance(); - for (Iterator pFi = productFeatures.iterator(); pFi.hasNext(); ) { - GenericValue nextFeature = (GenericValue) pFi.next(); + Map<String, String> featuresByType = FastMap.newInstance(); + for (Iterator<GenericValue> pFi = productFeatures.iterator(); pFi.hasNext(); ) { + GenericValue nextFeature = pFi.next(); featuresByType.put(nextFeature.getString("productFeatureTypeId"), nextFeature.getString("productFeatureId")); } - List products = FastList.newInstance(); // final list of variant products - for (Iterator mPi = memberProducts.iterator(); mPi.hasNext(); ) { + List<GenericValue> products = FastList.newInstance(); // final list of variant products + for (Iterator<GenericValue> mPi = memberProducts.iterator(); mPi.hasNext(); ) { // find variants for each member product of the category - GenericValue memberProduct = (GenericValue) mPi.next(); + GenericValue memberProduct = mPi.next(); try { result = dispatcher.runSync("getProductVariant", UtilMisc.toMap("productId", memberProduct.getString("productId"), "selectedFeatures", featuresByType)); @@ -339,7 +343,7 @@ return ServiceUtil.returnError(ex.getMessage()); } - List variantProducts = (List) result.get("products"); + List<GenericValue> variantProducts = UtilGenerics.checkList(result.get("products")); if ((variantProducts != null) && (variantProducts.size() > 0)) { products.addAll(variantProducts); } else { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java?rev=712917&r1=712916&r2=712917&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java Mon Nov 10 18:18:07 2008 @@ -30,6 +30,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; @@ -54,7 +55,7 @@ public final static String module = InventoryServices.class.getName(); - public static Map prepareInventoryTransfer(DispatchContext dctx, Map context) { + public static Map<String, Object> prepareInventoryTransfer(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); String inventoryItemId = (String) context.get("inventoryItemId"); Double xferQty = (Double) context.get("xferQty"); @@ -73,7 +74,7 @@ } try { - Map results = ServiceUtil.returnSuccess(); + Map<String, Object> results = ServiceUtil.returnSuccess(); String inventoryType = inventoryItem.getString("inventoryItemTypeId"); if (inventoryType.equals("NON_SERIAL_INV_ITEM")) { @@ -117,17 +118,17 @@ results.put("inventoryItemId", newItem.get("inventoryItemId")); // TODO: how do we get this here: "inventoryTransferId", inventoryTransferId - Map createNewDetailMap = UtilMisc.toMap("availableToPromiseDiff", xferQty, "quantityOnHandDiff", xferQty, + Map<String, Object> createNewDetailMap = UtilMisc.toMap("availableToPromiseDiff", xferQty, "quantityOnHandDiff", xferQty, "inventoryItemId", newItem.get("inventoryItemId"), "userLogin", userLogin); - Map createUpdateDetailMap = UtilMisc.toMap("availableToPromiseDiff", negXferQty, "quantityOnHandDiff", negXferQty, + Map<String, Object> createUpdateDetailMap = UtilMisc.toMap("availableToPromiseDiff", negXferQty, "quantityOnHandDiff", negXferQty, "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin); try { - Map resultNew = dctx.getDispatcher().runSync("createInventoryItemDetail", createNewDetailMap); + Map<String, Object> resultNew = dctx.getDispatcher().runSync("createInventoryItemDetail", createNewDetailMap); if (ServiceUtil.isError(resultNew)) { return ServiceUtil.returnError("Inventory Item Detail create problem in prepare inventory transfer", null, null, resultNew); } - Map resultUpdate = dctx.getDispatcher().runSync("createInventoryItemDetail", createUpdateDetailMap); + Map<String, Object> resultUpdate = dctx.getDispatcher().runSync("createInventoryItemDetail", createUpdateDetailMap); if (ServiceUtil.isError(resultNew)) { return ServiceUtil.returnError("Inventory Item Detail create problem in prepare inventory transfer", null, null, resultUpdate); } @@ -152,10 +153,10 @@ inventoryItemToClear.refresh(); double atp = inventoryItemToClear.get("availableToPromiseTotal") == null ? 0 : inventoryItemToClear.getDouble("availableToPromiseTotal").doubleValue(); if (atp != 0) { - Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(-atp), + Map<String, Object> createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(-atp), "inventoryItemId", inventoryItemToClear.get("inventoryItemId"), "userLogin", userLogin); try { - Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); + Map<String, Object> result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError("Inventory Item Detail create problem in complete inventory transfer", null, null, result); } @@ -184,7 +185,7 @@ } } - public static Map completeInventoryTransfer(DispatchContext dctx, Map context) { + public static Map<String, Object> completeInventoryTransfer(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); String inventoryTransferId = (String) context.get("inventoryTransferId"); GenericValue inventoryTransfer = null; @@ -216,10 +217,10 @@ // add an adjusting InventoryItemDetail so set ATP back to QOH: ATP = ATP + (QOH - ATP), diff = QOH - ATP double atp = inventoryItem.get("availableToPromiseTotal") == null ? 0 : inventoryItem.getDouble("availableToPromiseTotal").doubleValue(); double qoh = inventoryItem.get("quantityOnHandTotal") == null ? 0 : inventoryItem.getDouble("quantityOnHandTotal").doubleValue(); - Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(qoh - atp), + Map<String, Object> createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(qoh - atp), "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin); try { - Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); + Map<String, Object> result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError("Inventory Item Detail create problem in complete inventory transfer", null, null, result); } @@ -234,7 +235,7 @@ } // set the fields on the item - Map updateInventoryItemMap = UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"), + Map<String, Object> updateInventoryItemMap = UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"), "facilityId", inventoryTransfer.get("facilityIdTo"), "containerId", inventoryTransfer.get("containerIdTo"), "locationSeqId", inventoryTransfer.get("locationSeqIdTo"), @@ -256,7 +257,7 @@ } } try { - Map result = dctx.getDispatcher().runSync("updateInventoryItem", updateInventoryItemMap); + Map<String, Object> result = dctx.getDispatcher().runSync("updateInventoryItem", updateInventoryItemMap); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError("Inventory item store problem", null, null, result); } @@ -277,7 +278,7 @@ return ServiceUtil.returnSuccess(); } - public static Map cancelInventoryTransfer(DispatchContext dctx, Map context) { + public static Map<String, Object> cancelInventoryTransfer(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); String inventoryTransferId = (String) context.get("inventoryTransferId"); GenericValue inventoryTransfer = null; @@ -306,11 +307,11 @@ // add an adjusting InventoryItemDetail so set ATP back to QOH: ATP = ATP + (QOH - ATP), diff = QOH - ATP double atp = inventoryItem.get("availableToPromiseTotal") == null ? 0 : inventoryItem.getDouble("availableToPromiseTotal").doubleValue(); double qoh = inventoryItem.get("quantityOnHandTotal") == null ? 0 : inventoryItem.getDouble("quantityOnHandTotal").doubleValue(); - Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(qoh - atp), + Map<String, Object> createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(qoh - atp), "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin); try { - Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); + Map<String, Object> result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError("Inventory Item Detail create problem in cancel inventory transfer", null, null, result); } @@ -341,7 +342,7 @@ } /** In spite of the generic name this does the very specific task of checking availability of all back-ordered items and sends notices, etc */ - public static Map checkInventoryAvailability(DispatchContext dctx, Map context) { + public static Map<String, Object> checkInventoryAvailability(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); @@ -354,11 +355,11 @@ } */ - Map ordersToUpdate = FastMap.newInstance(); - Map ordersToCancel = FastMap.newInstance(); + Map<String, Map<String, Timestamp>> ordersToUpdate = FastMap.newInstance(); + Map<String, Map<String, Timestamp>> ordersToCancel = FastMap.newInstance(); // find all inventory items w/ a negative ATP - List inventoryItems = null; + List<GenericValue> inventoryItems = null; try { EntityExpr ee = EntityCondition.makeCondition("availableToPromiseTotal", EntityOperator.LESS_THAN, Double.valueOf(0)); inventoryItems = delegator.findList("InventoryItem", ee, null, null, null, false); @@ -374,12 +375,11 @@ Debug.log("OOS Inventory Items: " + inventoryItems.size(), module); - Iterator itemsIter = inventoryItems.iterator(); + Iterator<GenericValue> itemsIter = inventoryItems.iterator(); while (itemsIter.hasNext()) { - GenericValue inventoryItem = (GenericValue) itemsIter.next(); - + GenericValue inventoryItem = itemsIter.next(); // get the incomming shipment information for the item - List shipmentAndItems = null; + List<GenericValue> shipmentAndItems = null; try { List<EntityExpr> exprs = FastList.newInstance(); exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, inventoryItem.get("productId"))); @@ -395,7 +395,7 @@ } // get the reservations in order of newest first - List reservations = null; + List<GenericValue> reservations = null; try { reservations = inventoryItem.getRelated("OrderItemShipGrpInvRes", null, UtilMisc.toList("-reservedDatetime")); } catch (GenericEntityException e) { @@ -414,9 +414,9 @@ double availableBeforeReserved = inventoryItem.getDouble("availableToPromiseTotal").doubleValue(); // go through all the reservations in order - Iterator ri = reservations.iterator(); + Iterator<GenericValue> ri = reservations.iterator(); while (ri.hasNext()) { - GenericValue reservation = (GenericValue) ri.next(); + GenericValue reservation = ri.next(); String orderId = reservation.getString("orderId"); String orderItemSeqId = reservation.getString("orderItemSeqId"); Timestamp promisedDate = reservation.getTimestamp("promisedDatetime"); @@ -436,9 +436,9 @@ // find the next possible ship date Timestamp nextShipDate = null; double availableAtTime = 0.00; - Iterator si = shipmentAndItems.iterator(); + Iterator<GenericValue> si = shipmentAndItems.iterator(); while (si.hasNext()) { - GenericValue shipmentItem = (GenericValue) si.next(); + GenericValue shipmentItem = si.next(); availableAtTime += shipmentItem.getDouble("quantity").doubleValue(); if (availableAtTime >= availableBeforeReserved) { nextShipDate = shipmentItem.getTimestamp("estimatedArrivalDate"); @@ -466,7 +466,7 @@ } else { // we cannot ship by the promised date; need to notify the customer Debug.log("We won't ship on time, getting notification info", module); - Map notifyItems = (Map) ordersToUpdate.get(orderId); + Map<String, Timestamp> notifyItems = ordersToUpdate.get(orderId); if (notifyItems == null) { notifyItems = FastMap.newInstance(); } @@ -494,7 +494,7 @@ if (needToCancel) { // queue the item to be cancelled Debug.log("Flagging the item to auto-cancel", module); - Map cancelItems = (Map) ordersToCancel.get(orderId); + Map<String, Timestamp> cancelItems = ordersToCancel.get(orderId); if (cancelItems == null) { cancelItems = FastMap.newInstance(); } @@ -518,17 +518,17 @@ } // all items to cancel will also be in the notify list so start with that - List ordersToNotify = FastList.newInstance(); - Set orderSet = ordersToUpdate.keySet(); - Iterator orderIter = orderSet.iterator(); + List<String> ordersToNotify = FastList.newInstance(); + Set<String> orderSet = ordersToUpdate.keySet(); + Iterator<String> orderIter = orderSet.iterator(); while (orderIter.hasNext()) { - String orderId = (String) orderIter.next(); - Map backOrderedItems = (Map) ordersToUpdate.get(orderId); - Map cancelItems = (Map) ordersToCancel.get(orderId); + String orderId = orderIter.next(); + Map<String, Timestamp> backOrderedItems = ordersToUpdate.get(orderId); + Map<String, Timestamp> cancelItems = ordersToCancel.get(orderId); boolean cancelAll = false; Timestamp cancelAllTime = null; - List orderItemShipGroups = null; + List<GenericValue> orderItemShipGroups = null; try { orderItemShipGroups= delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId)); @@ -536,11 +536,11 @@ Debug.logError(e, "Cannot get OrderItemShipGroups from orderId" + orderId, module); } - Iterator orderItemShipGroupsIter = orderItemShipGroups.iterator(); + Iterator<GenericValue> orderItemShipGroupsIter = orderItemShipGroups.iterator(); while (orderItemShipGroupsIter.hasNext()) { - GenericValue orderItemShipGroup = (GenericValue)orderItemShipGroupsIter.next(); - List orderItems = new java.util.Vector(); - List orderItemShipGroupAssoc = null; + GenericValue orderItemShipGroup = orderItemShipGroupsIter.next(); + List<GenericValue> orderItems = FastList.newInstance(); + List<GenericValue> orderItemShipGroupAssoc = null; try { orderItemShipGroupAssoc = delegator.findByAnd("OrderItemShipGroupAssoc", @@ -549,9 +549,9 @@ "orderId", orderId)); - Iterator assocIter = orderItemShipGroupAssoc.iterator(); + Iterator<GenericValue> assocIter = orderItemShipGroupAssoc.iterator(); while (assocIter.hasNext()) { - GenericValue assoc = (GenericValue)assocIter.next(); + GenericValue assoc = assocIter.next(); GenericValue orderItem = assoc.getRelatedOne("OrderItem"); if (orderItem != null) { orderItems.add(orderItem); @@ -581,10 +581,10 @@ } if (orderItems != null) { - List toBeStored = FastList.newInstance(); - Iterator orderItemsIter = orderItems.iterator(); + List<GenericValue> toBeStored = FastList.newInstance(); + Iterator<GenericValue> orderItemsIter = orderItems.iterator(); while (orderItemsIter.hasNext()) { - GenericValue orderItem = (GenericValue) orderItemsIter.next(); + GenericValue orderItem = orderItemsIter.next(); String orderItemSeqId = orderItem.getString("orderItemSeqId"); Timestamp shipDate = (Timestamp) backOrderedItems.get(orderItemSeqId); Timestamp cancelDate = (Timestamp) cancelItems.get(orderItemSeqId); @@ -624,9 +624,9 @@ } // send off a notification for each order - Iterator orderNotifyIter = ordersToNotify.iterator(); + Iterator<String> orderNotifyIter = ordersToNotify.iterator(); while (orderNotifyIter.hasNext()) { - String orderId = (String) orderNotifyIter.next(); + String orderId = orderNotifyIter.next(); try { dispatcher.runAsync("sendOrderBackorderNotification", UtilMisc.<String, Object>toMap("orderId", orderId, "userLogin", userLogin)); @@ -643,9 +643,9 @@ * Get Inventory Available for a Product based on the list of associated products. The final ATP and QOH will * be the minimum of all the associated products' inventory divided by their ProductAssoc.quantity * */ - public static Map getProductInventoryAvailableFromAssocProducts(DispatchContext dctx, Map context) { + public static Map<String, Object> getProductInventoryAvailableFromAssocProducts(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); - List productAssocList = (List) context.get("assocProducts"); + List<GenericValue> productAssocList = UtilGenerics.checkList(context.get("assocProducts")); String facilityId = (String)context.get("facilityId"); String statusId = (String)context.get("statusId"); @@ -659,7 +659,7 @@ // loop through each associated product. for (int i = 0; productAssocList.size() > i; i++) { - GenericValue productAssoc = (GenericValue) productAssocList.get(i); + GenericValue productAssoc = productAssocList.get(i); String productIdTo = productAssoc.getString("productIdTo"); Double assocQuantity = productAssoc.getDouble("quantity"); @@ -670,9 +670,9 @@ } // figure out the inventory available for this associated product - Map resultOutput = null; + Map<String, Object> resultOutput = null; try { - Map inputMap = UtilMisc.toMap("productId", productIdTo, "statusId", statusId); + Map<String, String> inputMap = UtilMisc.toMap("productId", productIdTo, "statusId", statusId); if (facilityId != null) { inputMap.put("facilityId", facilityId); resultOutput = dispatcher.runSync("getInventoryAvailableByFacility", inputMap); @@ -708,26 +708,26 @@ availableToPromiseTotal = Double.valueOf(minAvailableToPromiseTotal); } - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("availableToPromiseTotal", availableToPromiseTotal); result.put("quantityOnHandTotal", quantityOnHandTotal); return result; } - public static Map getProductInventorySummaryForItems(DispatchContext dctx, Map context) { + public static Map<String, Object> getProductInventorySummaryForItems(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - List orderItems = (List) context.get("orderItems"); + List<GenericValue> orderItems = UtilGenerics.checkList(context.get("orderItems")); String facilityId = (String) context.get("facilityId"); - Map atpMap = FastMap.newInstance(); - Map qohMap = FastMap.newInstance(); - Map mktgPkgAtpMap = FastMap.newInstance(); - Map mktgPkgQohMap = FastMap.newInstance(); - Map results = ServiceUtil.returnSuccess(); + Map<String, Double> atpMap = FastMap.newInstance(); + Map<String, Double> qohMap = FastMap.newInstance(); + Map<String, Double> mktgPkgAtpMap = FastMap.newInstance(); + Map<String, Double> mktgPkgQohMap = FastMap.newInstance(); + Map<String, Object> results = ServiceUtil.returnSuccess(); // get a list of all available facilities for looping - List facilities = null; + List<GenericValue> facilities = null; try { if (facilityId != null) { facilities = delegator.findByAnd("Facility", UtilMisc.toMap("facilityId", facilityId)); @@ -739,9 +739,9 @@ } // loop through all the order items - Iterator iter = orderItems.iterator(); + Iterator<GenericValue> iter = orderItems.iterator(); while (iter.hasNext()) { - GenericValue orderItem = (GenericValue) iter.next(); + GenericValue orderItem = iter.next(); String productId = orderItem.getString("productId"); if ((productId == null) || productId.equals("")) continue; @@ -758,13 +758,13 @@ double qoh = 0.0; double mktgPkgAtp = 0.0; double mktgPkgQoh = 0.0; - Iterator facilityIter = facilities.iterator(); + Iterator<GenericValue> facilityIter = facilities.iterator(); // loop through all the facilities while (facilityIter.hasNext()) { - GenericValue facility = (GenericValue) facilityIter.next(); - Map invResult = null; - Map mktgPkgInvResult = null; + GenericValue facility = facilityIter.next(); + Map<String, Object> invResult = null; + Map<String, Object> mktgPkgInvResult = null; // get both the real ATP/QOH available and the quantities available from marketing packages try { @@ -808,7 +808,7 @@ } - public static Map getProductInventoryAndFacilitySummary(DispatchContext dctx, Map context) { + public static Map<String, Object> getProductInventoryAndFacilitySummary(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Timestamp checkTime = (Timestamp)context.get("checkTime"); @@ -817,10 +817,10 @@ String minimumStock = (String)context.get("minimumStock"); String statusId = (String)context.get("statusId"); - Map result = FastMap.newInstance(); - Map resultOutput = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); + Map<String, Object> resultOutput = FastMap.newInstance(); - Map contextInput = UtilMisc.toMap("productId", productId, "facilityId", facilityId, "statusId", statusId); + Map<String, String> contextInput = UtilMisc.toMap("productId", productId, "facilityId", facilityId, "statusId", statusId); GenericValue product = null; try { product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); @@ -870,17 +870,17 @@ result.put("offsetQOHQtyAvailable", Integer.valueOf(offsetQOHQtyAvailable)); result.put("offsetATPQtyAvailable", Integer.valueOf(offsetATPQtyAvailable)); - List productPrices = null; + List<GenericValue> productPrices = null; try { - productPrices = (List)delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId",productId), UtilMisc.toList("-fromDate")); + productPrices = delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId",productId), UtilMisc.toList("-fromDate")); } catch (GenericEntityException e) { // TODO Auto-generated catch block e.printStackTrace(); } - Iterator pricesIt = productPrices.iterator(); + Iterator<GenericValue> pricesIt = productPrices.iterator(); //change this for product price while (pricesIt.hasNext()) { - GenericValue onePrice = (GenericValue)pricesIt.next(); + GenericValue onePrice = pricesIt.next(); if(onePrice.getString("productPriceTypeId").equals("DEFAULT_PRICE")){ //defaultPrice result.put("defultPrice", onePrice.getDouble("price")); }else if(onePrice.getString("productPriceTypeId").equals("WHOLESALE_PRICE")){// @@ -951,7 +951,7 @@ // Sum the sales usage quantities found double salesUsageQuantity = 0; GenericValue salesUsageItem = null; - while((salesUsageItem = (GenericValue) salesUsageIt.next()) != null) { + while((salesUsageItem = salesUsageIt.next()) != null) { if (salesUsageItem.get("quantity") != null) { try { salesUsageQuantity += salesUsageItem.getDouble("quantity").doubleValue(); @@ -988,7 +988,7 @@ // Sum the production usage quantities found double productionUsageQuantity = 0; GenericValue productionUsageItem = null; - while((productionUsageItem = (GenericValue) productionUsageIt.next()) != null) { + while((productionUsageItem = productionUsageIt.next()) != null) { if (productionUsageItem.get("quantity") != null) { try { productionUsageQuantity += productionUsageItem.getDouble("quantity").doubleValue(); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java?rev=712917&r1=712916&r2=712917&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java Mon Nov 10 18:18:07 2008 @@ -47,9 +47,9 @@ * @param delegator * @return */ - public static List getOutstandingPurchaseOrders(String productId, GenericDelegator delegator) { + public static List<GenericValue> getOutstandingPurchaseOrders(String productId, GenericDelegator delegator) { try { - List purchaseOrderConditions = UtilMisc.toList(EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED"), + List<EntityCondition> purchaseOrderConditions = UtilMisc.<EntityCondition>toList(EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED"), EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED"), EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"), EntityCondition.makeCondition("itemStatusId", EntityOperator.NOT_EQUAL, "ITEM_COMPLETED"), @@ -57,7 +57,7 @@ EntityCondition.makeCondition("itemStatusId", EntityOperator.NOT_EQUAL, "ITEM_REJECTED")); purchaseOrderConditions.add(EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "PURCHASE_ORDER")); purchaseOrderConditions.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId)); - List purchaseOrders = delegator.findList("OrderHeaderAndItems", EntityCondition.makeCondition(purchaseOrderConditions, EntityOperator.AND), + List<GenericValue> purchaseOrders = delegator.findList("OrderHeaderAndItems", EntityCondition.makeCondition(purchaseOrderConditions, EntityOperator.AND), null, UtilMisc.toList("estimatedDeliveryDate DESC", "orderDate"), null, false); return purchaseOrders; } catch (GenericEntityException ex) { @@ -74,12 +74,12 @@ */ public static double getOutstandingPurchasedQuantity(String productId, GenericDelegator delegator) { double qty = 0.0; - List purchaseOrders = getOutstandingPurchaseOrders(productId, delegator); + List<GenericValue> purchaseOrders = getOutstandingPurchaseOrders(productId, delegator); if (UtilValidate.isEmpty(purchaseOrders)) { return qty; } else { - for (Iterator pOi = purchaseOrders.iterator(); pOi.hasNext();) { - GenericValue nextOrder = (GenericValue) pOi.next(); + for (Iterator<GenericValue> pOi = purchaseOrders.iterator(); pOi.hasNext();) { + GenericValue nextOrder = pOi.next(); if (nextOrder.get("quantity") != null) { double itemQuantity = nextOrder.getDouble("quantity").doubleValue(); double cancelQuantity = 0.0; @@ -106,9 +106,9 @@ * @param delegator The delegator to use * @return Map of productIds to quantities outstanding. */ - public static Map getOutstandingProductQuantities(Collection productIds, String orderTypeId, GenericDelegator delegator) { - Set fieldsToSelect = UtilMisc.toSet("productId", "quantityOpen"); - List condList = UtilMisc.toList( + public static Map<String, Double> getOutstandingProductQuantities(Collection<String> productIds, String orderTypeId, GenericDelegator delegator) { + Set<String> fieldsToSelect = UtilMisc.toSet("productId", "quantityOpen"); + List<EntityCondition> condList = UtilMisc.<EntityCondition>toList( EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, orderTypeId), EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED"), EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"), @@ -122,11 +122,11 @@ condList.add(EntityCondition.makeCondition("orderItemStatusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED")); EntityConditionList conditions = EntityCondition.makeCondition(condList, EntityOperator.AND); - Map results = FastMap.newInstance(); + Map<String, Double> results = FastMap.newInstance(); try { - List orderedProducts = delegator.findList("OrderItemQuantityReportGroupByProduct", conditions, fieldsToSelect, null, null, false); - for (Iterator iter = orderedProducts.iterator(); iter.hasNext(); ) { - GenericValue value = (GenericValue) iter.next(); + List<GenericValue> orderedProducts = delegator.findList("OrderItemQuantityReportGroupByProduct", conditions, fieldsToSelect, null, null, false); + for (Iterator<GenericValue> iter = orderedProducts.iterator(); iter.hasNext(); ) { + GenericValue value = iter.next(); results.put(value.getString("productId"), value.getDouble("quantityOpen")); } } catch (GenericEntityException e) { @@ -136,12 +136,12 @@ } /** As above, but for sales orders */ - public static Map getOutstandingProductQuantitiesForSalesOrders(Collection productIds, GenericDelegator delegator) { + public static Map<String, Double> getOutstandingProductQuantitiesForSalesOrders(Collection<String> productIds, GenericDelegator delegator) { return getOutstandingProductQuantities(productIds, "SALES_ORDER", delegator); } /** As above, but for purhcase orders */ - public static Map getOutstandingProductQuantitiesForPurchaseOrders(Collection productIds, GenericDelegator delegator) { + public static Map<String, Double> getOutstandingProductQuantitiesForPurchaseOrders(Collection<String> productIds, GenericDelegator delegator) { return getOutstandingProductQuantities(productIds, "PURCHASE_ORDER", delegator); } } |
Free forum by Nabble | Edit this page |