Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java?rev=712916&r1=712915&r2=712916&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java Mon Nov 10 18:16:46 2008 @@ -83,16 +83,16 @@ int numRemoved = 0; GenericValue searchResultView = null; - while ((searchResultView = (GenericValue) eli.next()) != null) { + while ((searchResultView = eli.next()) != null) { String productId = searchResultView.getString("mainProductId"); numRemoved += delegator.removeByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId )) ; } eli.close(); - Map messageMap = UtilMisc.toMap("numRemoved", Integer.toString(numRemoved)); + Map<String, String> messageMap = UtilMisc.toMap("numRemoved", Integer.toString(numRemoved)); errMsg = UtilProperties.getMessage(resource,"productsearchevents.removed_x_items", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_EVENT_MESSAGE_", errMsg); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -102,7 +102,7 @@ TransactionUtil.commit(beganTransaction); } } catch (GenericTransactionException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -126,7 +126,7 @@ try { thruDate = Timestamp.valueOf(thruDateStr); } catch (RuntimeException e) { - Map messageMap = UtilMisc.toMap("errDateFormat", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errDateFormat", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.thruDate_not_formatted_properly", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -145,15 +145,15 @@ GenericValue searchResultView = null; int numExpired=0; - while ((searchResultView = (GenericValue) eli.next()) != null) { + while ((searchResultView = eli.next()) != null) { String productId = searchResultView.getString("mainProductId"); //get all tuples that match product and category - List pcmList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId )); + List<GenericValue> pcmList = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId )); //set those thrudate to that specificed maybe remove then add new one - Iterator pcmListIter=pcmList.iterator(); + Iterator<GenericValue> pcmListIter=pcmList.iterator(); while (pcmListIter.hasNext()) { - GenericValue pcm = (GenericValue) pcmListIter.next(); + GenericValue pcm = pcmListIter.next(); if (pcm.get("thruDate") == null) { pcm.set("thruDate", thruDate); pcm.store(); @@ -161,12 +161,12 @@ } } } - Map messageMap = UtilMisc.toMap("numExpired", Integer.toString(numExpired)); + Map<String, String> messageMap = UtilMisc.toMap("numExpired", Integer.toString(numExpired)); errMsg = UtilProperties.getMessage(resource,"productsearchevents.expired_x_items", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_EVENT_MESSAGE_", errMsg); eli.close(); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -176,7 +176,7 @@ TransactionUtil.commit(beganTransaction); } } catch (GenericTransactionException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -201,7 +201,7 @@ try { fromDate = Timestamp.valueOf(fromDateStr); } catch (RuntimeException e) { - Map messageMap = UtilMisc.toMap("errDateFormat", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errDateFormat", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.fromDate_not_formatted_properly", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; @@ -231,12 +231,12 @@ numAdded++; } - Map messageMap = UtilMisc.toMap("numAdded", Integer.toString(numAdded)); + Map<String, String> messageMap = UtilMisc.toMap("numAdded", Integer.toString(numAdded)); errMsg = UtilProperties.getMessage(resource,"productsearchevents.added_x_product_category_members", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_EVENT_MESSAGE_", errMsg); eli.close(); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -246,7 +246,7 @@ TransactionUtil.commit(beganTransaction); } } catch (GenericTransactionException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -322,7 +322,7 @@ pfa.create(); numAdded++; } - Map messageMap = UtilMisc.toMap("numAdded", Integer.valueOf(numAdded), "productFeatureId", productFeatureId); + Map<String, String> messageMap = UtilMisc.toMap("numAdded", Integer.valueOf(numAdded), "productFeatureId", productFeatureId); String eventMsg = UtilProperties.getMessage(resource, "productSearchEvents.added_param_features", messageMap, locale) + "."; request.setAttribute("_EVENT_MESSAGE_", eventMsg); eli.close(); @@ -372,7 +372,7 @@ String productId = searchResultView.getString("mainProductId"); numRemoved += delegator.removeByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId)); } - Map messageMap = UtilMisc.toMap("numRemoved", Integer.valueOf(numRemoved), "productFeatureId", productFeatureId); + Map<String, String> messageMap = UtilMisc.toMap("numRemoved", Integer.valueOf(numRemoved), "productFeatureId", productFeatureId); String eventMsg = UtilProperties.getMessage(resource, "productSearchEvents.removed_param_features", messageMap, locale) + "."; request.setAttribute("_EVENT_MESSAGE_", eventMsg); eli.close(); @@ -403,7 +403,7 @@ public static String searchExportProductList(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); String errMsg = null; - List productExportList = FastList.newInstance(); + List<Map<String, Object>> productExportList = FastList.newInstance(); try { boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT); @@ -416,26 +416,26 @@ } GenericValue searchResultView = null; - while ((searchResultView = (GenericValue) eli.next()) != null) { - Map productMap = FastMap.newInstance(); + while ((searchResultView = eli.next()) != null) { + Map<String, Object> productMap = FastMap.newInstance(); String productId = searchResultView.getString("mainProductId"); productMap.put("productId", productId); - List productFeaturesCustomRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "HAZMAT") ); - List productFeaturesCustom = EntityUtil.filterByDate(productFeaturesCustomRaw); + List<GenericValue> productFeaturesCustomRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "HAZMAT") ); + List<GenericValue> productFeaturesCustom = EntityUtil.filterByDate(productFeaturesCustomRaw); productMap.put("productFeatureCustom", EntityUtil.getFirst(productFeaturesCustom)); - List productCategoriesRaw = delegator.findByAnd("ProductCategoryAndMember", UtilMisc.toMap("productId", productId)); - List productCategories = EntityUtil.filterByDate(productCategoriesRaw); + List<GenericValue> productCategoriesRaw = delegator.findByAnd("ProductCategoryAndMember", UtilMisc.toMap("productId", productId)); + List<GenericValue> productCategories = EntityUtil.filterByDate(productCategoriesRaw); productMap.put("productCategories", productCategories); - List productFeaturesRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId) ); - List productFeatures = EntityUtil.filterByDate(productFeaturesRaw); + List<GenericValue> productFeaturesRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId) ); + List<GenericValue> productFeatures = EntityUtil.filterByDate(productFeaturesRaw); productMap.put("productFeatures", productFeatures); productExportList.add(productMap); } eli.close(); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -445,7 +445,7 @@ TransactionUtil.commit(beganTransaction); } } catch (GenericTransactionException e) { - Map messageMap = UtilMisc.toMap("errSearchResult", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errSearchResult", e.toString()); errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request)); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -461,7 +461,7 @@ GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); String visitId = VisitHandler.getVisitId(session); - List productSearchConstraintList = ProductSearchSession.ProductSearchOptions.getConstraintList(session); + List<ProductSearch.ProductSearchConstraint> productSearchConstraintList = ProductSearchSession.ProductSearchOptions.getConstraintList(session); // if no constraints, don't do a search... if (UtilValidate.isNotEmpty(productSearchConstraintList)) { ResultSortOrder resultSortOrder = ProductSearchSession.ProductSearchOptions.getResultSortOrder(request); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java?rev=712916&r1=712915&r2=712916&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Mon Nov 10 18:16:46 2008 @@ -39,6 +39,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; @@ -72,7 +73,7 @@ public static final String module = ProductSearchSession.class.getName(); public static class ProductSearchOptions implements java.io.Serializable { - protected List constraintList = null; + protected List<ProductSearchConstraint> constraintList = null; protected String topProductCategoryId = null; protected ResultSortOrder resultSortOrder = null; protected Integer viewIndex = null; @@ -96,10 +97,10 @@ this.previousViewSize = productSearchOptions.previousViewSize; } - public List getConstraintList() { + public List<ProductSearchConstraint> getConstraintList() { return this.constraintList; } - public static List getConstraintList(HttpSession session) { + public static List<ProductSearchConstraint> getConstraintList(HttpSession session) { return getProductSearchOptions(session).constraintList; } public static void addConstraint(ProductSearchConstraint productSearchConstraint, HttpSession session) { @@ -262,15 +263,15 @@ } } - public List searchGetConstraintStrings(boolean detailed, GenericDelegator delegator, Locale locale) { - List productSearchConstraintList = this.getConstraintList(); - List constraintStrings = FastList.newInstance(); + public List<String> searchGetConstraintStrings(boolean detailed, GenericDelegator delegator, Locale locale) { + List<ProductSearchConstraint> productSearchConstraintList = this.getConstraintList(); + List<String> constraintStrings = FastList.newInstance(); if (productSearchConstraintList == null) { return constraintStrings; } - Iterator productSearchConstraintIter = productSearchConstraintList.iterator(); + Iterator<ProductSearchConstraint> productSearchConstraintIter = productSearchConstraintList.iterator(); while (productSearchConstraintIter.hasNext()) { - ProductSearchConstraint productSearchConstraint = (ProductSearchConstraint) productSearchConstraintIter.next(); + ProductSearchConstraint productSearchConstraint = productSearchConstraintIter.next(); if (productSearchConstraint == null) continue; String constraintString = productSearchConstraint.prettyPrintConstraint(delegator, detailed, locale); if (UtilValidate.isNotEmpty(constraintString)) { @@ -296,13 +297,13 @@ ProductSearchOptions productSearchOptions = getProductSearchOptions(session); // if the options have changed since the last search, add it to the beginning of the search options history if (productSearchOptions.changed) { - List optionsHistoryList = getSearchOptionsHistoryList(session); + List<ProductSearchOptions> optionsHistoryList = getSearchOptionsHistoryList(session); optionsHistoryList.add(0, new ProductSearchOptions(productSearchOptions)); productSearchOptions.changed = false; } } - public static List getSearchOptionsHistoryList(HttpSession session) { - List optionsHistoryList = (List) session.getAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_"); + public static List<ProductSearchOptions> getSearchOptionsHistoryList(HttpSession session) { + List<ProductSearchOptions> optionsHistoryList = UtilGenerics.checkList(session.getAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_")); if (optionsHistoryList == null) { optionsHistoryList = FastList.newInstance(); session.setAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_", optionsHistoryList); @@ -314,9 +315,9 @@ } public static void setCurrentSearchFromHistory(int index, boolean removeOld, HttpSession session) { - List searchOptionsHistoryList = getSearchOptionsHistoryList(session); + List<ProductSearchOptions> searchOptionsHistoryList = getSearchOptionsHistoryList(session); if (index < searchOptionsHistoryList.size()) { - ProductSearchOptions productSearchOptions = (ProductSearchOptions) searchOptionsHistoryList.get(index); + ProductSearchOptions productSearchOptions = searchOptionsHistoryList.get(index); if (removeOld) { searchOptionsHistoryList.remove(index); } @@ -363,29 +364,29 @@ public static final String checkDoKeywordOverride(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); - Map requestParams = UtilHttp.getParameterMap(request); + Map<String, Object> requestParams = UtilHttp.getParameterMap(request); ProductSearchSession.processSearchParameters(requestParams, request); // get the current productStoreId String productStoreId = ProductStoreWorker.getProductStoreId(request); if (productStoreId != null) { // get a Set of all keywords in the search, if there are any... - Set keywords = FastSet.newInstance(); - List constraintList = ProductSearchOptions.getConstraintList(session); + Set<String> keywords = FastSet.newInstance(); + List<ProductSearchConstraint> constraintList = ProductSearchOptions.getConstraintList(session); if (constraintList != null) { - Iterator constraintIter = constraintList.iterator(); + Iterator<ProductSearchConstraint> constraintIter = constraintList.iterator(); while (constraintIter.hasNext()) { - Object constraint = constraintIter.next(); + ProductSearchConstraint constraint = constraintIter.next(); if (constraint instanceof KeywordConstraint) { KeywordConstraint keywordConstraint = (KeywordConstraint) constraint; - Set keywordSet = keywordConstraint.makeFullKeywordSet(delegator); + Set<String> keywordSet = keywordConstraint.makeFullKeywordSet(delegator); if (keywordSet != null) keywords.addAll(keywordSet); } } } if (keywords.size() > 0) { - List productStoreKeywordOvrdList = null; + List<GenericValue> productStoreKeywordOvrdList = null; try { productStoreKeywordOvrdList = delegator.findByAndCache("ProductStoreKeywordOvrd", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("-fromDate")); productStoreKeywordOvrdList = EntityUtil.filterByDate(productStoreKeywordOvrdList, true); @@ -394,9 +395,9 @@ } if (UtilValidate.isNotEmpty(productStoreKeywordOvrdList)) { - Iterator productStoreKeywordOvrdIter = productStoreKeywordOvrdList.iterator(); + Iterator<GenericValue> productStoreKeywordOvrdIter = productStoreKeywordOvrdList.iterator(); while (productStoreKeywordOvrdIter.hasNext()) { - GenericValue productStoreKeywordOvrd = (GenericValue) productStoreKeywordOvrdIter.next(); + GenericValue productStoreKeywordOvrd = productStoreKeywordOvrdIter.next(); String ovrdKeyword = productStoreKeywordOvrd.getString("keyword"); if (keywords.contains(ovrdKeyword)) { String targetTypeEnumId = productStoreKeywordOvrd.getString("targetTypeEnumId"); @@ -434,13 +435,13 @@ return "success"; } - public static ArrayList searchDo(HttpSession session, GenericDelegator delegator, String prodCatalogId) { + public static ArrayList<String> searchDo(HttpSession session, GenericDelegator delegator, String prodCatalogId) { String visitId = VisitHandler.getVisitId(session); ProductSearchOptions productSearchOptions = getProductSearchOptions(session); - List productSearchConstraintList = productSearchOptions.getConstraintList(); + List<ProductSearchConstraint> productSearchConstraintList = productSearchOptions.getConstraintList(); if (productSearchConstraintList == null || productSearchConstraintList.size() == 0) { // no constraints, don't do a search... - return new ArrayList(); + return new ArrayList<String>(); } ResultSortOrder resultSortOrder = productSearchOptions.getResultSortOrder(); @@ -455,7 +456,7 @@ ProductSearchOptions.clearSearchOptions(session); } - public static List searchGetConstraintStrings(boolean detailed, HttpSession session, GenericDelegator delegator) { + public static List<String> searchGetConstraintStrings(boolean detailed, HttpSession session, GenericDelegator delegator) { Locale locale = UtilHttp.getLocale(session); ProductSearchOptions productSearchOptions = getProductSearchOptions(session); return productSearchOptions.searchGetConstraintStrings(detailed, delegator, locale); @@ -472,14 +473,14 @@ ProductSearchOptions.setResultSortOrder(resultSortOrder, session); } - public static void searchAddFeatureIdConstraints(Collection featureIds, Boolean exclude, HttpServletRequest request) { + public static void searchAddFeatureIdConstraints(Collection<String> featureIds, Boolean exclude, HttpServletRequest request) { HttpSession session = request.getSession(); if (featureIds == null || featureIds.size() == 0) { return; } - Iterator featureIdIter = featureIds.iterator(); + Iterator<String> featureIdIter = featureIds.iterator(); while (featureIdIter.hasNext()) { - String productFeatureId = (String) featureIdIter.next(); + String productFeatureId = featureIdIter.next(); searchAddConstraint(new FeatureConstraint(productFeatureId, exclude), session); } } @@ -489,7 +490,7 @@ } public static void searchRemoveConstraint(int index, HttpSession session) { - List productSearchConstraintList = ProductSearchOptions.getConstraintList(session); + List<ProductSearchConstraint> productSearchConstraintList = ProductSearchOptions.getConstraintList(session); if (productSearchConstraintList == null) { return; } else if (index >= productSearchConstraintList.size()) { @@ -499,7 +500,7 @@ } } - public static void processSearchParameters(Map parameters, HttpServletRequest request) { + public static void processSearchParameters(Map<String, Object> parameters, HttpServletRequest request) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); Boolean alreadyRun = (Boolean) request.getAttribute("processSearchParametersAlreadyRun"); if (Boolean.TRUE.equals(alreadyRun)) { @@ -584,7 +585,7 @@ if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_CATALOG_ID"))) { String searchCatalogId = (String) parameters.get("SEARCH_CATALOG_ID"); if (searchCatalogId != null && !searchCatalogId.equalsIgnoreCase("")) { - List categories = CategoryWorker.getRelatedCategoriesRet(request, "topLevelList", CatalogWorker.getCatalogTopCategoryId(request, searchCatalogId), true, false, true); + List<GenericValue> categories = CategoryWorker.getRelatedCategoriesRet(request, "topLevelList", CatalogWorker.getCatalogTopCategoryId(request, searchCatalogId), true, false, true); searchAddConstraint(new ProductSearch.CatalogConstraint(searchCatalogId, categories), session); constraintsChanged = true; } @@ -611,9 +612,9 @@ } } - 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") && !parameterName.startsWith("SEARCH_FEAT_EXC")) { String productFeatureId = (String) parameters.get(parameterName); if (productFeatureId != null && productFeatureId.length() > 0) { @@ -686,7 +687,7 @@ } // if features were selected add a constraint for each - Map featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(parameters); + Map<String, String> featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(parameters); if (featureIdByType.size() > 0) { constraintsChanged = true; searchAddFeatureIdConstraints(featureIdByType.values(), null, request); @@ -868,9 +869,9 @@ highIndex = (viewIndex + 1) * viewSize; // ========== Do the actual search - List productIds = FastList.newInstance(); + List<String> productIds = FastList.newInstance(); String visitId = VisitHandler.getVisitId(session); - List productSearchConstraintList = ProductSearchOptions.getConstraintList(session); + List<ProductSearchConstraint> productSearchConstraintList = ProductSearchOptions.getConstraintList(session); // if no constraints, don't do a search... if (UtilValidate.isNotEmpty(productSearchConstraintList)) { // if the search options have changed since the last search, put at the beginning of the options history list @@ -878,11 +879,11 @@ int addOnTopTotalListSize = 0; int addOnTopListSize = 0; - List addOnTopProductCategoryMembers = FastList.newInstance(); + List<GenericValue> addOnTopProductCategoryMembers = FastList.newInstance(); if (UtilValidate.isNotEmpty(addOnTopProdCategoryId)) { // always include the members of the addOnTopProdCategoryId Timestamp now = UtilDateTime.nowTimestamp(); - List addOnTopProdCondList = FastList.newInstance(); + List<EntityCondition> addOnTopProdCondList = FastList.newInstance(); addOnTopProdCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, now))); addOnTopProdCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN, now)); addOnTopProdCondList.add(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, addOnTopProdCategoryId)); @@ -893,7 +894,7 @@ addOnTopProductCategoryMembers = pli.getPartialList(lowIndex, viewSize); addOnTopListSize = addOnTopProductCategoryMembers.size(); for (int i = 0; i < addOnTopProductCategoryMembers.size(); i++) { - GenericValue alwaysAddProductCategoryMember = (GenericValue)addOnTopProductCategoryMembers.get(i); + GenericValue alwaysAddProductCategoryMember = addOnTopProductCategoryMembers.get(i); productIds.add(alwaysAddProductCategoryMember.getString("productId")); } // attempt to get the full size @@ -930,7 +931,7 @@ productSearchContext.setResultOffset(resultOffset); productSearchContext.setMaxResults(maxResults); - List foundProductIds = productSearchContext.doSearch(); + List<String> foundProductIds = productSearchContext.doSearch(); if (maxResultsInt > 0) { productIds.addAll(foundProductIds); } @@ -946,11 +947,11 @@ } // ========== Setup other display info - List searchConstraintStrings = searchGetConstraintStrings(false, session, delegator); + List<String> searchConstraintStrings = searchGetConstraintStrings(false, session, delegator); String searchSortOrderString = searchGetSortOrderString(false, request); // ========== populate the result Map - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); result.put("productIds", productIds); result.put("viewIndex", Integer.valueOf(viewIndex)); @@ -972,8 +973,9 @@ public static String makeSearchParametersString(ProductSearchOptions productSearchOptions) { StringBuilder searchParamString = new StringBuilder(); - List constraintList = productSearchOptions.getConstraintList(); - Iterator constraintIter = constraintList.iterator(); + List<ProductSearchConstraint> constraintList = productSearchOptions.getConstraintList(); + Iterator<ProductSearchConstraint> constraintIter = constraintList.iterator(); + int categoriesCount = 0; int featuresCount = 0; int featureCategoriesCount = 0; @@ -981,7 +983,7 @@ int keywordsCount = 0; boolean isNotFirst = false; while (constraintIter.hasNext()) { - ProductSearchConstraint psc = (ProductSearchConstraint) constraintIter.next(); + ProductSearchConstraint psc = constraintIter.next(); if (psc instanceof ProductSearch.CategoryConstraint) { ProductSearch.CategoryConstraint cc = (ProductSearch.CategoryConstraint) psc; categoriesCount++; Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java?rev=712916&r1=712915&r2=712916&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java Mon Nov 10 18:16:46 2008 @@ -32,6 +32,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.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -59,37 +60,38 @@ /** * Creates a Collection of product entities which are variant products from the specified product ID. */ - public static Map prodFindAllVariants(DispatchContext dctx, Map context) { + public static Map<String, Object> prodFindAllVariants(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Parent (virtual) product ID - context.put("type", "PRODUCT_VARIANT"); - return prodFindAssociatedByType(dctx, context); + Map<String, Object> subContext = UtilMisc.makeMapWritable(context); + subContext.put("type", "PRODUCT_VARIANT"); + return prodFindAssociatedByType(dctx, subContext); } /** * Finds a specific product or products which contain the selected features. */ - public static Map prodFindSelectedVariant(DispatchContext dctx, Map context) { + public static Map<String, Object> prodFindSelectedVariant(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Parent (virtual) product ID // * Map selectedFeatures -- Selected features GenericDelegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); String productId = (String) context.get("productId"); - Map selectedFeatures = (Map) context.get("selectedFeatures"); - List products = FastList.newInstance(); + Map selectedFeatures = UtilGenerics.checkMap(context.get("selectedFeatures")); + List<GenericValue> products = FastList.newInstance(); // All the variants for this products are retrieved - Map resVariants = prodFindAllVariants(dctx, context); - List variants = (List)resVariants.get("assocProducts"); + Map<String, Object> resVariants = prodFindAllVariants(dctx, context); + List<GenericValue> variants = UtilGenerics.checkList(resVariants.get("assocProducts")); GenericValue oneVariant = null; - Iterator variantsIt = variants.iterator(); + Iterator<GenericValue> variantsIt = variants.iterator(); while (variantsIt.hasNext()) { + oneVariant = variantsIt.next(); // For every variant, all the standard features are retrieved - oneVariant = (GenericValue)variantsIt.next(); - Map feaContext = FastMap.newInstance(); - feaContext.put("productId", oneVariant.get("productIdTo")); + Map<String, String> feaContext = FastMap.newInstance(); + feaContext.put("productId", oneVariant.getString("productIdTo")); feaContext.put("type", "STANDARD_FEATURE"); - Map resFeatures = prodGetFeatures(dctx, feaContext); - List features = (List)resFeatures.get("productFeatures"); - Iterator featuresIt = features.iterator(); + Map<String, Object> resFeatures = prodGetFeatures(dctx, feaContext); + List<GenericValue> features = UtilGenerics.checkList(resFeatures.get("productFeatures")); + Iterator<GenericValue> featuresIt = features.iterator(); GenericValue oneFeature = null; boolean variantFound = true; // The variant is discarded if at least one of its standard features @@ -101,7 +103,7 @@ // Variant3: (COLOR, Black), (SIZE, Small), (IMAGE, SkyLine) --> ok // Variant4: (COLOR, Black), (IMAGE, SkyLine) --> ok while (featuresIt.hasNext()) { - oneFeature = (GenericValue)featuresIt.next(); + oneFeature = featuresIt.next(); if (selectedFeatures.containsKey(oneFeature.getString("productFeatureTypeId"))) { if (!selectedFeatures.containsValue(oneFeature.getString("productFeatureId"))) { variantFound = false; @@ -113,7 +115,7 @@ try { products.add(delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", oneVariant.getString("productIdTo")))); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errProductFeatures", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errProductFeatures", e.toString()); String errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features_errors", messageMap, locale); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); @@ -121,7 +123,7 @@ } } - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("products", products); return result; } @@ -129,7 +131,7 @@ /** * Finds product variants based on a product ID and a distinct feature. */ - public static Map prodFindDistinctVariants(DispatchContext dctx, Map context) { + public static Map<String, Object> prodFindDistinctVariants(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Parent (virtual) product ID // * String feature -- Distinct feature name GenericDelegator delegator = dctx.getDelegator(); @@ -142,25 +144,25 @@ /** * Finds a Set of feature types in sequence. */ - public static Map prodFindFeatureTypes(DispatchContext dctx, Map context) { + public static Map<String, Object> prodFindFeatureTypes(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Product ID to look up feature types GenericDelegator delegator = dctx.getDelegator(); String productId = (String) context.get("productId"); Locale locale = (Locale) context.get("locale"); String errMsg=null; - Set featureSet = new LinkedHashSet(); + Set<String> featureSet = new LinkedHashSet<String>(); try { - Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"); - List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); - List features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order); - Iterator i = features.iterator(); + Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"); + List<String> order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); + List<GenericValue> features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order); + Iterator<GenericValue> i = features.iterator(); while (i.hasNext()) { - featureSet.add(((GenericValue) i.next()).getString("productFeatureTypeId")); + featureSet.add(i.next().getString("productFeatureTypeId")); } //if (Debug.infoOn()) Debug.logInfo("" + featureSet, module); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errProductFeatures", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errProductFeatures", e.toString()); errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features_errors", messageMap, locale); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); @@ -172,7 +174,7 @@ Debug.logWarning(errMsg + " for product " + productId, module); //return ServiceUtil.returnError(errMsg); } - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("featureSet", featureSet); return result; } @@ -180,7 +182,7 @@ /** * Builds a variant feature tree. */ - public static Map prodMakeFeatureTree(DispatchContext dctx, Map context) { + public static Map<String, Object> prodMakeFeatureTree(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Parent (virtual) product ID // * List featureOrder -- Order of features // * String productStoreId -- Product Store ID for Inventory @@ -189,24 +191,24 @@ GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - Map result = FastMap.newInstance(); - List featureOrder = UtilMisc.makeListWritable((Collection) context.get("featureOrder")); + Map<String, Object> result = FastMap.newInstance(); + List<String> featureOrder = UtilMisc.makeListWritable(UtilGenerics.<String>checkList(context.get("featureOrder"))); if (featureOrder == null || featureOrder.size() == 0) { return ServiceUtil.returnError("Empty list of features passed"); } - Collection variants = (Collection) prodFindAllVariants(dctx, context).get("assocProducts"); - List virtualVariant = FastList.newInstance(); + List<GenericValue> variants = UtilGenerics.checkList(prodFindAllVariants(dctx, context).get("assocProducts")); + List<String> virtualVariant = FastList.newInstance(); if (variants == null || variants.size() == 0) { return ServiceUtil.returnSuccess(); } - List items = FastList.newInstance(); - Iterator i = variants.iterator(); + List<String> items = FastList.newInstance(); + Iterator<GenericValue> i = variants.iterator(); while (i.hasNext()) { - String productIdTo = (String) ((GenericValue) i.next()).get("productIdTo"); + String productIdTo = i.next().getString("productIdTo"); // first check to see if intro and discontinue dates are within range GenericValue productTo = null; @@ -215,7 +217,7 @@ productTo = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productIdTo)); } catch (GenericEntityException e) { Debug.logError(e, module); - Map messageMap = UtilMisc.toMap("productIdTo", productIdTo, "errMessage", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("productIdTo", productIdTo, "errMessage", e.toString()); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "productservices.error_finding_associated_variant_with_ID_error", messageMap, locale)); } if (productTo == null) { @@ -249,7 +251,7 @@ // next check inventory for each item: if inventory is not required or is available try { - Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", Double.valueOf(1.0))); + Map<String, Object> invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", Double.valueOf(1.0))); if (ServiceUtil.isError(invReqResult)) { return ServiceUtil.returnError("Error calling the isStoreInventoryRequired when building the variant product tree.", null, null, invReqResult); } else if ("Y".equals((String) invReqResult.get("availableOrNotRequired"))) { @@ -268,10 +270,10 @@ String productId = (String) context.get("productId"); // Make the selectable feature list - List selectableFeatures = null; + List<GenericValue> selectableFeatures = null; try { - Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"); - List sort = UtilMisc.toList("sequenceNum"); + Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE"); + List<String> sort = UtilMisc.toList("sequenceNum"); selectableFeatures = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort); selectableFeatures = EntityUtil.filterByDate(selectableFeatures, true); @@ -279,20 +281,20 @@ Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource,"productservices.empty_list_of_selectable_features_found", locale)); } - Map features = FastMap.newInstance(); - Iterator sFIt = selectableFeatures.iterator(); + Map<String, List<String>> features = FastMap.newInstance(); + Iterator<GenericValue> sFIt = selectableFeatures.iterator(); while (sFIt.hasNext()) { - GenericValue v = (GenericValue) sFIt.next(); + GenericValue v = sFIt.next(); String featureType = v.getString("productFeatureTypeId"); String feature = v.getString("description"); if (!features.containsKey(featureType)) { - List featureList = FastList.newInstance(); + List<String> featureList = FastList.newInstance(); featureList.add(feature); features.put(featureType, featureList); } else { - List featureList = (LinkedList) features.get(featureType); + List<String> featureList = features.get(featureType); featureList.add(feature); features.put(featureType, featureList); } @@ -314,9 +316,9 @@ result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } - Map sample = null; + Map<String, GenericValue> sample = null; try { - sample = makeVariantSample(dctx.getDelegator(), features, items, (String) featureOrder.get(0)); + sample = makeVariantSample(dctx.getDelegator(), features, items, featureOrder.get(0)); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); } @@ -330,22 +332,22 @@ /** * Gets the product features of a product. */ - public static Map prodGetFeatures(DispatchContext dctx, Map context) { + public static Map<String, Object> prodGetFeatures(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Product ID to fond // * String type -- Type of feature (STANDARD_FEATURE, SELECTABLE_FEATURE) // * String distinct -- Distinct feature (SIZE, COLOR) GenericDelegator delegator = dctx.getDelegator(); - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); String productId = (String) context.get("productId"); String distinct = (String) context.get("distinct"); String type = (String) context.get("type"); Locale locale = (Locale) context.get("locale"); String errMsg=null; - Collection features = null; + List<GenericValue> features = null; try { - Map fields = UtilMisc.toMap("productId", productId); - List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); + Map<String, String> fields = UtilMisc.toMap("productId", productId); + List<String> order = UtilMisc.toList("sequenceNum", "productFeatureTypeId"); if (distinct != null) fields.put("productFeatureTypeId", distinct); if (type != null) fields.put("productFeatureApplTypeId", type); @@ -353,7 +355,7 @@ result.put("productFeatures", features); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errMessage", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString()); errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_feature_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -364,10 +366,10 @@ /** * Finds a product by product ID. */ - public static Map prodFindProduct(DispatchContext dctx, Map context) { + public static Map<String, Object> prodFindProduct(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Product ID to find GenericDelegator delegator = dctx.getDelegator(); - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); String productId = (String) context.get("productId"); Locale locale = (Locale) context.get("locale"); String errMsg = null; @@ -384,13 +386,13 @@ GenericValue mainProduct = product; if (product.get("isVariant") != null && product.getString("isVariant").equalsIgnoreCase("Y")) { - List c = product.getRelatedByAndCache("AssocProductAssoc", + List<GenericValue> c = product.getRelatedByAndCache("AssocProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT")); //if (Debug.infoOn()) Debug.logInfo("Found related: " + c, module); c = EntityUtil.filterByDate(c); //if (Debug.infoOn()) Debug.logInfo("Found Filtered related: " + c, module); if (c.size() > 0) { - GenericValue asV = (GenericValue) c.iterator().next(); + GenericValue asV = c.iterator().next(); //if (Debug.infoOn()) Debug.logInfo("ASV: " + asV, module); mainProduct = asV.getRelatedOneCache("MainProduct"); @@ -401,7 +403,7 @@ result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { e.printStackTrace(); - Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); + Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -413,11 +415,11 @@ /** * Finds associated products by product ID and association ID. */ - public static Map prodFindAssociatedByType(DispatchContext dctx, Map context) { + public static Map<String, Object> prodFindAssociatedByType(DispatchContext dctx, Map<String, ? extends Object> context) { // * String productId -- Current Product ID // * String type -- Type of association (ie PRODUCT_UPGRADE, PRODUCT_COMPLEMENT, PRODUCT_VARIANT) GenericDelegator delegator = dctx.getDelegator(); - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); String productId = (String) context.get("productId"); String productIdTo = (String) context.get("productIdTo"); String type = (String) context.get("type"); @@ -448,7 +450,7 @@ try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); + Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"productservices.productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -463,7 +465,7 @@ } try { - List productAssocs = null; + List<GenericValue> productAssocs = null; if (productIdTo == null) { productAssocs = product.getRelatedCache("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", type), UtilMisc.toList("sequenceNum")); @@ -488,7 +490,7 @@ result.put("assocProducts", productAssocs); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { - Map messageMap = UtilMisc.toMap("errMessage", e.getMessage()); + Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage()); errMsg = UtilProperties.getMessage(resource,"productservices.problems_product_association_relation_error", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -499,11 +501,11 @@ } // Builds a product feature tree - private static Map makeGroup(GenericDelegator delegator, Map featureList, List items, List order, int index) + private static Map<String, Object> makeGroup(GenericDelegator delegator, Map<String, List<String>> featureList, List<String> items, List<String> order, int index) throws IllegalArgumentException, IllegalStateException { //List featureKey = FastList.newInstance(); - Map tempGroup = FastMap.newInstance(); - Map group = new LinkedHashMap(); + Map<String, List<String>> tempGroup = FastMap.newInstance(); + Map<String, Object> group = new LinkedHashMap<String, Object>(); String orderKey = (String) order.get(index); if (featureList == null) { @@ -518,21 +520,21 @@ } // loop through items and make the lists - Iterator itemIterator = items.iterator(); + Iterator<String> itemIterator = items.iterator(); while (itemIterator.hasNext()) { // ------------------------------- // Gather the necessary data // ------------------------------- - String thisItem = (String) itemIterator.next(); + String thisItem = itemIterator.next(); if (Debug.verboseOn()) Debug.logVerbose("ThisItem: " + thisItem, module); - List features = null; + List<GenericValue> features = null; try { - Map fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey, + Map<String, String> fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey, "productFeatureApplTypeId", "STANDARD_FEATURE"); - List sort = UtilMisc.toList("sequenceNum"); + List<String> sort = UtilMisc.toList("sequenceNum"); // get the features and filter out expired dates features = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort); @@ -543,19 +545,19 @@ if (Debug.verboseOn()) Debug.logVerbose("Features: " + features, module); // ------------------------------- - Iterator featuresIterator = features.iterator(); + Iterator<GenericValue> featuresIterator = features.iterator(); while (featuresIterator.hasNext()) { - GenericValue item = (GenericValue) featuresIterator.next(); - Object itemKey = item.get("description"); + GenericValue item = featuresIterator.next(); + String itemKey = item.getString("description"); if (tempGroup.containsKey(itemKey)) { - List itemList = (List) tempGroup.get(itemKey); + List<String> itemList = tempGroup.get(itemKey); if (!itemList.contains(thisItem)) itemList.add(thisItem); } else { - List itemList = UtilMisc.toList(thisItem); + List<String> itemList = UtilMisc.toList(thisItem); tempGroup.put(itemKey, itemList); } @@ -564,16 +566,16 @@ if (Debug.verboseOn()) Debug.logVerbose("TempGroup: " + tempGroup, module); // Loop through the feature list and order the keys in the tempGroup - List orderFeatureList = (List) featureList.get(orderKey); + List<String> orderFeatureList = featureList.get(orderKey); if (orderFeatureList == null) { throw new IllegalArgumentException("Cannot build feature tree: orderFeatureList is null for orderKey=" + orderKey); } - Iterator featureListIt = orderFeatureList.iterator(); + Iterator<String> featureListIt = orderFeatureList.iterator(); while (featureListIt.hasNext()) { - String featureStr = (String) featureListIt.next(); + String featureStr = featureListIt.next(); if (tempGroup.containsKey(featureStr)) group.put(featureStr, tempGroup.get(featureStr)); @@ -592,13 +594,13 @@ } // loop through the keysets and get the sub-groups - Iterator groupIterator = group.keySet().iterator(); + Iterator<String> groupIterator = group.keySet().iterator(); while (groupIterator.hasNext()) { - Object key = groupIterator.next(); - List itemList = (List) group.get(key); + String key = groupIterator.next(); + List<String> itemList = UtilGenerics.checkList(group.get(key)); if (UtilValidate.isNotEmpty(itemList)) { - Map subGroup = makeGroup(delegator, featureList, itemList, order, index + 1); + Map<String, Object> subGroup = makeGroup(delegator, featureList, itemList, order, index + 1); group.put(key, subGroup); } else { // do nothing, ie put nothing in the Map @@ -609,19 +611,19 @@ } // builds a variant sample (a single sku for a featureType) - private static Map makeVariantSample(GenericDelegator delegator, Map featureList, List items, String feature) { - Map tempSample = FastMap.newInstance(); - Map sample = new LinkedHashMap(); - Iterator itemIt = items.iterator(); + private static Map<String, GenericValue> makeVariantSample(GenericDelegator delegator, Map<String, List<String>> featureList, List<String> items, String feature) { + Map<String, GenericValue> tempSample = FastMap.newInstance(); + Map<String, GenericValue> sample = new LinkedHashMap<String, GenericValue>(); + Iterator<String> itemIt = items.iterator(); while (itemIt.hasNext()) { - String productId = (String) itemIt.next(); - List features = null; + String productId = itemIt.next(); + List<GenericValue> features = null; try { - Map fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature, + Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature, "productFeatureApplTypeId", "STANDARD_FEATURE"); - List sort = UtilMisc.toList("sequenceNum", "description"); + List<String> sort = UtilMisc.toList("sequenceNum", "description"); // get the features and filter out expired dates features = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort); @@ -629,10 +631,10 @@ } catch (GenericEntityException e) { throw new IllegalStateException("Problem reading relation: " + e.getMessage()); } - Iterator featureIt = features.iterator(); + Iterator<GenericValue> featureIt = features.iterator(); while (featureIt.hasNext()) { - GenericValue featureAppl = (GenericValue) featureIt.next(); + GenericValue featureAppl = featureIt.next(); try { GenericValue product = delegator.findByPrimaryKeyCache("Product", @@ -646,11 +648,11 @@ } // Sort the sample based on the feature list. - List features = (LinkedList) featureList.get(feature); - Iterator fi = features.iterator(); + List<String> features = featureList.get(feature); + Iterator<String> fi = features.iterator(); while (fi.hasNext()) { - String f = (String) fi.next(); + String f = fi.next(); if (tempSample.containsKey(f)) sample.put(f, tempSample.get(f)); @@ -659,9 +661,9 @@ return sample; } - public static Map quickAddVariant(DispatchContext dctx, Map context) { + public static Map<String, Object> quickAddVariant(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); - Map result = FastMap.newInstance(); + Map<String, Object> result = FastMap.newInstance(); Locale locale = (Locale) context.get("locale"); String errMsg=null; String productId = (String) context.get("productId"); @@ -673,7 +675,7 @@ // read the product, duplicate it with the given id GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); if (product == null) { - Map messageMap = UtilMisc.toMap("productId", productId); + Map<String, String> messageMap = UtilMisc.toMap("productId", productId); errMsg = UtilProperties.getMessage(resource,"productservices.product_not_found_with_ID", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -708,7 +710,7 @@ "productFeatureApplTypeId", "STANDARD_FEATURE")); } // add an association from productId to variantProductId of the PRODUCT_VARIANT - Map productAssocMap = UtilMisc.toMap("productId", productId, "productIdTo", variantProductId, + Map<String, Object> productAssocMap = UtilMisc.toMap("productId", productId, "productIdTo", variantProductId, "productAssocTypeId", "PRODUCT_VARIANT", "fromDate", UtilDateTime.nowTimestamp()); if (prodAssocSeqNum != null) { @@ -738,7 +740,7 @@ } catch (GenericEntityException e) { Debug.logError(e, "Entity error creating quick add variant data", module); - Map messageMap = UtilMisc.toMap("errMessage", e.toString()); + Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString()); errMsg = UtilProperties.getMessage(resource,"productservices.entity_error_quick_add_variant_data", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -752,7 +754,7 @@ * This will create a virtual product and return its ID, and associate all of the variants with it. * It will not put the selectable features on the virtual or standard features on the variant. */ - public static Map quickCreateVirtualWithVariants(DispatchContext dctx, Map context) { + public static Map<String, Object> quickCreateVirtualWithVariants(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = dctx.getDelegator(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); @@ -762,7 +764,7 @@ String productFeatureIdTwo = (String) context.get("productFeatureIdTwo"); String productFeatureIdThree = (String) context.get("productFeatureIdThree"); - Map successResult = ServiceUtil.returnSuccess(); + Map<String, Object> successResult = ServiceUtil.returnSuccess(); try { // Generate new virtual productId, prefix with "VP", put in successResult @@ -791,17 +793,17 @@ // separate variantProductIdsBag into a Set of variantProductIds //note: can be comma, tab, or white-space delimited - Set prelimVariantProductIds = FastSet.newInstance(); - List splitIds = Arrays.asList(variantProductIdsBag.split("[,\\p{Space}]")); + Set<String> prelimVariantProductIds = FastSet.newInstance(); + List<String> splitIds = Arrays.asList(variantProductIdsBag.split("[,\\p{Space}]")); Debug.logInfo("Variants: bag=" + variantProductIdsBag, module); Debug.logInfo("Variants: split=" + splitIds, module); prelimVariantProductIds.addAll(splitIds); //note: should support both direct productIds and GoodIdentification entries (what to do if more than one GoodID? Add all? - Map variantProductsById = FastMap.newInstance(); - Iterator variantProductIdIter = prelimVariantProductIds.iterator(); + Map<String, GenericValue> variantProductsById = FastMap.newInstance(); + Iterator<String> variantProductIdIter = prelimVariantProductIds.iterator(); while (variantProductIdIter.hasNext()) { - String variantProductId = (String) variantProductIdIter.next(); + String variantProductId = variantProductIdIter.next(); if (UtilValidate.isEmpty(variantProductId)) { // not sure why this happens, but seems to from time to time with the split method continue; @@ -812,7 +814,7 @@ variantProductsById.put(variantProductId, variantProduct); } else { // is a GoodIdentification.idValue? - List goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId)); + List<GenericValue> goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId)); if (goodIdentificationList == null || goodIdentificationList.size() == 0) { // whoops, nothing found... return error return ServiceUtil.returnError("Error creating a virtual with variants: the ID [" + variantProductId + "] is not a valid Product.productId or a GoodIdentification.idValue"); @@ -823,32 +825,32 @@ Debug.logWarning("Warning creating a virtual with variants: the ID [" + variantProductId + "] was not a productId and resulted in [" + goodIdentificationList.size() + "] GoodIdentification records: " + goodIdentificationList, module); } - Iterator goodIdentificationIter = goodIdentificationList.iterator(); + Iterator<GenericValue> goodIdentificationIter = goodIdentificationList.iterator(); while (goodIdentificationIter.hasNext()) { - GenericValue goodIdentification = (GenericValue) goodIdentificationIter.next(); + GenericValue goodIdentification = goodIdentificationIter.next(); GenericValue giProduct = goodIdentification.getRelatedOne("Product"); if (giProduct != null) { - variantProductsById.put(giProduct.get("productId"), giProduct); + variantProductsById.put(giProduct.getString("productId"), giProduct); } } } } // Attach productFeatureIdOne, Two, Three to the new virtual and all variant products as a standard feature - Set featureProductIds = FastSet.newInstance(); + Set<String> featureProductIds = FastSet.newInstance(); featureProductIds.add(productId); featureProductIds.addAll(variantProductsById.keySet()); - Set productFeatureIds = FastSet.newInstance(); + Set<String> productFeatureIds = FastSet.newInstance(); productFeatureIds.add(productFeatureIdOne); productFeatureIds.add(productFeatureIdTwo); productFeatureIds.add(productFeatureIdThree); - Iterator featureProductIdIter = featureProductIds.iterator(); + Iterator<String> featureProductIdIter = featureProductIds.iterator(); while (featureProductIdIter.hasNext()) { - Iterator productFeatureIdIter = productFeatureIds.iterator(); - String featureProductId = (String) featureProductIdIter.next(); + Iterator<String> productFeatureIdIter = productFeatureIds.iterator(); + String featureProductId = featureProductIdIter.next(); while (productFeatureIdIter.hasNext()) { - String productFeatureId = (String) productFeatureIdIter.next(); + String productFeatureId = productFeatureIdIter.next(); if (UtilValidate.isNotEmpty(productFeatureId)) { GenericValue productFeatureAppl = delegator.makeValue("ProductFeatureAppl", UtilMisc.toMap("productId", featureProductId, "productFeatureId", productFeatureId, @@ -858,10 +860,10 @@ } } - Iterator variantProductIter = variantProductsById.values().iterator(); + Iterator<GenericValue> variantProductIter = variantProductsById.values().iterator(); while (variantProductIter.hasNext()) { // for each variant product set: isVirtual=N, isVariant=Y, introductionDate=now - GenericValue variantProduct = (GenericValue) variantProductIter.next(); + GenericValue variantProduct = variantProductIter.next(); variantProduct.set("isVirtual", "N"); variantProduct.set("isVariant", "Y"); variantProduct.set("introductionDate", nowTimestamp); @@ -881,7 +883,7 @@ return successResult; } - public static Map updateProductIfAvailableFromShipment(DispatchContext dctx, Map context) { + public static Map<String, Object> updateProductIfAvailableFromShipment(DispatchContext dctx, Map<String, ? extends Object> context) { if ("Y".equals(UtilProperties.getPropertyValue("catalog.properties", "reactivate.product.from.receipt", "N"))) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); @@ -909,7 +911,7 @@ if (product != null) { Timestamp salesDiscontinuationDate = product.getTimestamp("salesDiscontinuationDate"); if (salesDiscontinuationDate != null && salesDiscontinuationDate.before(UtilDateTime.nowTimestamp())) { - Map invRes = null; + Map<String, Object> invRes = null; try { invRes = dispatcher.runSync("getProductInventoryAvailable", UtilMisc.<String, Object>toMap("productId", productId, "userLogin", userLogin)); } catch (GenericServiceException e) { @@ -945,7 +947,7 @@ return ServiceUtil.returnSuccess(); } - public static Map addAdditionalViewForProduct(DispatchContext dctx, Map context) { + public static Map<String, Object> addAdditionalViewForProduct(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); @@ -968,7 +970,7 @@ filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1); } - List fileExtension = FastList.newInstance(); + List<GenericValue> fileExtension = FastList.newInstance(); try { fileExtension = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", (String) context.get("_uploadedFile_contentType"))); } catch (GenericEntityException e) { @@ -1000,12 +1002,12 @@ if (UtilValidate.isNotEmpty(imageUrl) && imageUrl.length() > 0) { String contentId = (String) context.get("contentId"); - Map dataResourceCtx = FastMap.newInstance(); + Map<String, Object> dataResourceCtx = FastMap.newInstance(); dataResourceCtx.put("objectInfo", imageUrl); dataResourceCtx.put("dataResourceName", (String) context.get("_uploadedFile_fileName")); dataResourceCtx.put("userLogin", userLogin); - Map productContentCtx = FastMap.newInstance(); + Map<String, Object> productContentCtx = FastMap.newInstance(); productContentCtx.put("productId", productId); productContentCtx.put("productContentTypeId", productContentTypeId); productContentCtx.put("fromDate", (Timestamp) context.get("fromDate")); @@ -1033,14 +1035,14 @@ if (dataResource != null) { dataResourceCtx.put("dataResourceId", dataResource.getString("dataResourceId")); try { - Map dataResourceResult = dispatcher.runSync("updateDataResource", dataResourceCtx); + dispatcher.runSync("updateDataResource", dataResourceCtx); } catch (GenericServiceException e) { Debug.logError(e, module); ServiceUtil.returnError(e.getMessage()); } } else { dataResourceCtx.put("dataResourceTypeId", "URL_RESOURCE"); - Map dataResourceResult = FastMap.newInstance(); + Map<String, Object> dataResourceResult = FastMap.newInstance(); try { dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx); } catch (GenericServiceException e) { @@ -1048,12 +1050,12 @@ ServiceUtil.returnError(e.getMessage()); } - Map contentCtx = FastMap.newInstance(); + Map<String, Object> contentCtx = FastMap.newInstance(); contentCtx.put("contentId", contentId); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); try { - Map contentResult = dispatcher.runSync("updateContent", contentCtx); + dispatcher.runSync("updateContent", contentCtx); } catch (GenericServiceException e) { Debug.logError(e, module); ServiceUtil.returnError(e.getMessage()); @@ -1062,7 +1064,7 @@ productContentCtx.put("contentId", contentId); try { - Map productContentResult = dispatcher.runSync("updateProductContent", productContentCtx); + Map<String, Object> productContentResult = dispatcher.runSync("updateProductContent", productContentCtx); } catch (GenericServiceException e) { Debug.logError(e, module); ServiceUtil.returnError(e.getMessage()); @@ -1070,7 +1072,7 @@ } } else { dataResourceCtx.put("dataResourceTypeId", "URL_RESOURCE"); - Map dataResourceResult = FastMap.newInstance(); + Map<String, Object> dataResourceResult = FastMap.newInstance(); try { dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx); } catch (GenericServiceException e) { @@ -1078,11 +1080,11 @@ ServiceUtil.returnError(e.getMessage()); } - Map contentCtx = FastMap.newInstance(); + Map<String, Object> contentCtx = FastMap.newInstance(); contentCtx.put("contentTypeId", "DOCUMENT"); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); - Map contentResult = FastMap.newInstance(); + Map<String, Object> contentResult = FastMap.newInstance(); try { contentResult = dispatcher.runSync("createContent", contentCtx); } catch (GenericServiceException e) { @@ -1092,7 +1094,7 @@ productContentCtx.put("contentId", contentResult.get("contentId")); try { - Map productContentResult = dispatcher.runSync("createProductContent", productContentCtx); + Map<String, Object> productContentResult = dispatcher.runSync("createProductContent", productContentCtx); } catch (GenericServiceException e) { Debug.logError(e, module); ServiceUtil.returnError(e.getMessage()); |
Free forum by Nabble | Edit this page |