diff --git a/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java b/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java index 1737025259..bd047b92b6 100644 --- a/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java +++ b/applications/product/src/org/ofbiz/product/catalog/CatalogWorker.java @@ -57,9 +57,9 @@ public class CatalogWorker { return WebSiteWorker.getWebSite(request); } - public static List getAllCatalogIds(ServletRequest request) { - List catalogIds = FastList.newInstance(); - List catalogs = null; + public static List getAllCatalogIds(ServletRequest request) { + List catalogIds = FastList.newInstance(); + List catalogs = null; GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); try { catalogs = delegator.findList("ProdCatalog", null, null, UtilMisc.toList("catalogName"), null, false); @@ -67,22 +67,22 @@ public class CatalogWorker { Debug.logError(e, "Error looking up all catalogs", module); } if (catalogs != null) { - Iterator i = catalogs.iterator(); + Iterator i = catalogs.iterator(); while (i.hasNext()) { - GenericValue c = (GenericValue) i.next(); + GenericValue c = i.next(); catalogIds.add(c.getString("prodCatalogId")); } } return catalogIds; } - public static List getStoreCatalogs(ServletRequest request) { + public static List getStoreCatalogs(ServletRequest request) { String productStoreId = ProductStoreWorker.getProductStoreId(request); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); return getStoreCatalogs(delegator, productStoreId); } - public static List getStoreCatalogs(GenericDelegator delegator, String productStoreId) { + public static List getStoreCatalogs(GenericDelegator delegator, String productStoreId) { try { return EntityUtil.filterByDate(delegator.findByAndCache("ProductStoreCatalog", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "prodCatalogId")), true); } catch (GenericEntityException e) { @@ -91,7 +91,7 @@ public class CatalogWorker { return null; } - public static List getPartyCatalogs(ServletRequest request) { + public static List getPartyCatalogs(ServletRequest request) { HttpSession session = ((HttpServletRequest) request).getSession(); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); if (userLogin == null) userLogin = (GenericValue) session.getAttribute("autoUserLogin"); @@ -102,7 +102,7 @@ public class CatalogWorker { return getPartyCatalogs(delegator, partyId); } - public static List getPartyCatalogs(GenericDelegator delegator, String partyId) { + public static List getPartyCatalogs(GenericDelegator delegator, String partyId) { if (delegator == null || partyId == null) { return null; } @@ -115,14 +115,14 @@ public class CatalogWorker { return null; } - public static List getProdCatalogCategories(ServletRequest request, String prodCatalogId, String prodCatalogCategoryTypeId) { + public static List getProdCatalogCategories(ServletRequest request, String prodCatalogId, String prodCatalogCategoryTypeId) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); return getProdCatalogCategories(delegator, prodCatalogId, prodCatalogCategoryTypeId); } - public static List getProdCatalogCategories(GenericDelegator delegator, String prodCatalogId, String prodCatalogCategoryTypeId) { + public static List getProdCatalogCategories(GenericDelegator delegator, String prodCatalogId, String prodCatalogCategoryTypeId) { try { - List prodCatalogCategories = EntityUtil.filterByDate(delegator.findByAndCache("ProdCatalogCategory", + List prodCatalogCategories = EntityUtil.filterByDate(delegator.findByAndCache("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", prodCatalogId), UtilMisc.toList("sequenceNum", "productCategoryId")), true); @@ -145,7 +145,7 @@ public class CatalogWorker { */ public static String getCurrentCatalogId(ServletRequest request) { HttpSession session = ((HttpServletRequest) request).getSession(); - Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); + Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); String prodCatalogId = null; boolean fromSession = false; @@ -158,40 +158,40 @@ public class CatalogWorker { } // get it from the database if (prodCatalogId == null) { - List catalogIds = getCatalogIdsAvailable(request); - if (catalogIds != null && catalogIds.size() > 0) prodCatalogId = (String) catalogIds.get(0); + List catalogIds = getCatalogIdsAvailable(request); + if (catalogIds != null && catalogIds.size() > 0) prodCatalogId = catalogIds.get(0); } if (!fromSession) { if (Debug.verboseOn()) Debug.logVerbose("[CatalogWorker.getCurrentCatalogId] Setting new catalog name: " + prodCatalogId, module); session.setAttribute("CURRENT_CATALOG_ID", prodCatalogId); - CategoryWorker.setTrail(request, FastList.newInstance()); + CategoryWorker.setTrail(request, FastList.newInstance()); } return prodCatalogId; } - public static List getCatalogIdsAvailable(ServletRequest request) { - List partyCatalogs = getPartyCatalogs(request); - List storeCatalogs = getStoreCatalogs(request); + public static List getCatalogIdsAvailable(ServletRequest request) { + List partyCatalogs = getPartyCatalogs(request); + List storeCatalogs = getStoreCatalogs(request); return getCatalogIdsAvailable(partyCatalogs, storeCatalogs); } - public static List getCatalogIdsAvailable(GenericDelegator delegator, String productStoreId, String partyId) { - List storeCatalogs = getStoreCatalogs(delegator, productStoreId); - List partyCatalogs = getPartyCatalogs(delegator, partyId); + public static List getCatalogIdsAvailable(GenericDelegator delegator, String productStoreId, String partyId) { + List storeCatalogs = getStoreCatalogs(delegator, productStoreId); + List partyCatalogs = getPartyCatalogs(delegator, partyId); return getCatalogIdsAvailable(partyCatalogs, storeCatalogs); } - public static List getCatalogIdsAvailable(List partyCatalogs, List storeCatalogs) { - List categoryIds = FastList.newInstance(); - List allCatalogLinks = FastList.newInstance(); + public static List getCatalogIdsAvailable(List partyCatalogs, List storeCatalogs) { + List categoryIds = FastList.newInstance(); + List allCatalogLinks = FastList.newInstance(); if (partyCatalogs != null) allCatalogLinks.addAll(partyCatalogs); if (storeCatalogs != null) allCatalogLinks.addAll(storeCatalogs); if (allCatalogLinks.size() > 0) { - Iterator aclIter = allCatalogLinks.iterator(); + Iterator aclIter = allCatalogLinks.iterator(); while (aclIter.hasNext()) { - GenericValue catalogLink = (GenericValue) aclIter.next(); + GenericValue catalogLink = aclIter.next(); categoryIds.add(catalogLink.getString("prodCatalogId")); } } @@ -260,7 +260,7 @@ public class CatalogWorker { public static String getCatalogTopCategoryId(ServletRequest request, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - List prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_BROWSE_ROOT"); + List prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_BROWSE_ROOT"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { GenericValue prodCatalogCategory = EntityUtil.getFirst(prodCatalogCategories); @@ -281,7 +281,7 @@ public class CatalogWorker { public static String getCatalogSearchCategoryId(GenericDelegator delegator, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - List prodCatalogCategories = getProdCatalogCategories(delegator, prodCatalogId, "PCCT_SEARCH"); + List prodCatalogCategories = getProdCatalogCategories(delegator, prodCatalogId, "PCCT_SEARCH"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { GenericValue prodCatalogCategory = EntityUtil.getFirst(prodCatalogCategories); return prodCatalogCategory.getString("productCategoryId"); @@ -293,7 +293,7 @@ public class CatalogWorker { public static String getCatalogViewAllowCategoryId(GenericDelegator delegator, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - List prodCatalogCategories = getProdCatalogCategories(delegator, prodCatalogId, "PCCT_VIEW_ALLW"); + List prodCatalogCategories = getProdCatalogCategories(delegator, prodCatalogId, "PCCT_VIEW_ALLW"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { GenericValue prodCatalogCategory = EntityUtil.getFirst(prodCatalogCategories); return prodCatalogCategory.getString("productCategoryId"); @@ -305,7 +305,7 @@ public class CatalogWorker { public static String getCatalogPurchaseAllowCategoryId(GenericDelegator delegator, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - List prodCatalogCategories = getProdCatalogCategories(delegator, prodCatalogId, "PCCT_PURCH_ALLW"); + List prodCatalogCategories = getProdCatalogCategories(delegator, prodCatalogId, "PCCT_PURCH_ALLW"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { GenericValue prodCatalogCategory = EntityUtil.getFirst(prodCatalogCategories); return prodCatalogCategory.getString("productCategoryId"); @@ -321,7 +321,7 @@ public class CatalogWorker { public static String getCatalogPromotionsCategoryId(ServletRequest request, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - List prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_PROMOTIONS"); + List prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_PROMOTIONS"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { GenericValue prodCatalogCategory = EntityUtil.getFirst(prodCatalogCategories); @@ -359,7 +359,7 @@ public class CatalogWorker { public static String getCatalogQuickaddCategoryPrimary(ServletRequest request, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - List prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_QUICK_ADD"); + List prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_QUICK_ADD"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { GenericValue prodCatalogCategory = EntityUtil.getFirst(prodCatalogCategories); @@ -370,22 +370,22 @@ public class CatalogWorker { } } - public static Collection getCatalogQuickaddCategories(ServletRequest request) { + public static Collection getCatalogQuickaddCategories(ServletRequest request) { return getCatalogQuickaddCategories(request, getCurrentCatalogId(request)); } - public static Collection getCatalogQuickaddCategories(ServletRequest request, String prodCatalogId) { + public static Collection getCatalogQuickaddCategories(ServletRequest request, String prodCatalogId) { if (prodCatalogId == null || prodCatalogId.length() <= 0) return null; - Collection categoryIds = FastList.newInstance(); + Collection categoryIds = FastList.newInstance(); - Collection prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_QUICK_ADD"); + Collection prodCatalogCategories = getProdCatalogCategories(request, prodCatalogId, "PCCT_QUICK_ADD"); if (UtilValidate.isNotEmpty(prodCatalogCategories)) { - Iterator pccIter = prodCatalogCategories.iterator(); + Iterator pccIter = prodCatalogCategories.iterator(); while (pccIter.hasNext()) { - GenericValue prodCatalogCategory = (GenericValue) pccIter.next(); + GenericValue prodCatalogCategory = pccIter.next(); categoryIds.add(prodCatalogCategory.getString("productCategoryId")); } diff --git a/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java b/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java index 353859231e..1ffad29549 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryContentWrapper.java @@ -139,12 +139,12 @@ public class CategoryContentWrapper implements ContentWrapper { } } - List categoryContentList = delegator.findByAndCache("ProductCategoryContent", UtilMisc.toMap("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId), UtilMisc.toList("-fromDate")); + List categoryContentList = delegator.findByAndCache("ProductCategoryContent", UtilMisc.toMap("productCategoryId", productCategoryId, "prodCatContentTypeId", prodCatContentTypeId), UtilMisc.toList("-fromDate")); categoryContentList = EntityUtil.filterByDate(categoryContentList); GenericValue categoryContent = EntityUtil.getFirst(categoryContentList); if (categoryContent != null) { // when rendering the category content, always include the Product Category and ProductCategoryContent records that this comes from - Map inContext = FastMap.newInstance(); + Map inContext = FastMap.newInstance(); inContext.put("productCategory", productCategory); inContext.put("categoryContent", categoryContent); ContentWorker.renderContentAsText(dispatcher, delegator, categoryContent.getString("contentId"), outWriter, inContext, locale, mimeTypeId, false); diff --git a/applications/product/src/org/ofbiz/product/category/CategoryServices.java b/applications/product/src/org/ofbiz/product/category/CategoryServices.java index b2cea04791..b0501f1d7a 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryServices.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryServices.java @@ -28,6 +28,7 @@ import javolution.util.FastMap; 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; @@ -52,11 +53,11 @@ public class CategoryServices { public static final String module = CategoryServices.class.getName(); - public static Map getCategoryMembers(DispatchContext dctx, Map context) { + public static Map getCategoryMembers(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String categoryId = (String) context.get("categoryId"); GenericValue productCategory = null; - List members = null; + List members = null; try { productCategory = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", categoryId)); @@ -67,13 +68,13 @@ public class CategoryServices { Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } - Map result = ServiceUtil.returnSuccess(); + Map result = ServiceUtil.returnSuccess(); result.put("category", productCategory); result.put("categoryMembers", members); return result; } - public static Map getPreviousNextProducts(DispatchContext dctx, Map context) { + public static Map getPreviousNextProducts(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String categoryId = (String) context.get("categoryId"); String productId = (String) context.get("productId"); @@ -84,12 +85,12 @@ public class CategoryServices { return ServiceUtil.returnError("Both Index and ProductID cannot be null."); } - List orderByFields = (List) context.get("orderByFields"); + List orderByFields = UtilGenerics.checkList(context.get("orderByFields")); if (orderByFields == null) orderByFields = FastList.newInstance(); String entityName = getCategoryFindEntityName(delegator, orderByFields); GenericValue productCategory; - List productCategoryMembers; + List productCategoryMembers; try { productCategory = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", categoryId)); productCategoryMembers = delegator.findByAndCache(entityName, UtilMisc.toMap("productCategoryId", categoryId), orderByFields); @@ -104,9 +105,9 @@ public class CategoryServices { if (productId != null && index == null) { - Iterator i = productCategoryMembers.iterator(); + Iterator i = productCategoryMembers.iterator(); while (i.hasNext()) { - GenericValue v = (GenericValue) i.next(); + GenericValue v = i.next(); if (v.getString("productId").equals(productId)) { index = Integer.valueOf(productCategoryMembers.indexOf(v)); } @@ -118,31 +119,31 @@ public class CategoryServices { return ServiceUtil.returnSuccess("Product not found in the current category."); } - Map result = ServiceUtil.returnSuccess(); + Map result = ServiceUtil.returnSuccess(); result.put("category", productCategory); String previous = null; String next = null; if (index.intValue() - 1 >= 0 && index.intValue() - 1 < productCategoryMembers.size()) { - previous = ((GenericValue) productCategoryMembers.get(index.intValue() - 1)).getString("productId"); + previous = productCategoryMembers.get(index.intValue() - 1).getString("productId"); result.put("previousProductId", previous); } else { - previous = ((GenericValue) productCategoryMembers.get(productCategoryMembers.size() - 1)).getString("productId"); + previous = productCategoryMembers.get(productCategoryMembers.size() - 1).getString("productId"); result.put("previousProductId", previous); } if (index.intValue() + 1 < productCategoryMembers.size()) { - next = ((GenericValue) productCategoryMembers.get(index.intValue() + 1)).getString("productId"); + next = productCategoryMembers.get(index.intValue() + 1).getString("productId"); result.put("nextProductId", next); } else { - next = ((GenericValue) productCategoryMembers.get(0)).getString("productId"); + next = productCategoryMembers.get(0).getString("productId"); result.put("nextProductId", next); } return result; } - private static String getCategoryFindEntityName(GenericDelegator delegator, List orderByFields) { + private static String getCategoryFindEntityName(GenericDelegator delegator, List orderByFields) { // allow orderByFields to contain fields from the Product entity, if there are such fields String entityName = "ProductCategoryMember"; if (orderByFields == null) { @@ -155,10 +156,9 @@ public class CategoryServices { ModelEntity productModel = delegator.getModelEntity("Product"); ModelEntity productCategoryMemberModel = delegator.getModelEntity("ProductCategoryMember"); - Iterator orderByFieldIter = orderByFields.iterator(); + Iterator orderByFieldIter = orderByFields.iterator(); while (orderByFieldIter.hasNext()) { - String orderByField = (String) orderByFieldIter.next(); - + String orderByField = orderByFieldIter.next(); // Get the real field name from the order by field removing ascending/descending order if (UtilValidate.isNotEmpty(orderByField)) { int startPos = 0, endPos = orderByField.length(); @@ -191,13 +191,13 @@ public class CategoryServices { return entityName; } - public static Map getProductCategoryAndLimitedMembers(DispatchContext dctx, Map context) { + public static Map getProductCategoryAndLimitedMembers(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String productCategoryId = (String) context.get("productCategoryId"); boolean limitView = ((Boolean) context.get("limitView")).booleanValue(); int defaultViewSize = ((Integer) context.get("defaultViewSize")).intValue(); - List orderByFields = (List) context.get("orderByFields"); + List orderByFields = UtilGenerics.checkList(context.get("orderByFields")); if (orderByFields == null) orderByFields = FastList.newInstance(); String entityName = getCategoryFindEntityName(delegator, orderByFields); @@ -252,7 +252,7 @@ public class CategoryServices { highIndex = 0; } - List productCategoryMembers = null; + List productCategoryMembers = null; if (productCategory != null) { try { if (useCacheForMembers) { @@ -281,7 +281,8 @@ public class CategoryServices { highIndex = listSize; } } else { - List mainCondList = UtilMisc.toList(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, productCategory.getString("productCategoryId"))); + List mainCondList = FastList.newInstance(); + mainCondList.add(EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, productCategory.getString("productCategoryId"))); if (activeOnly) { mainCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp)); mainCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, nowTimestamp))); @@ -302,7 +303,7 @@ public class CategoryServices { int chunkSize = 0; listSize = 0; - while ((nextValue = (GenericValue) pli.next()) != null) { + while ((nextValue = pli.next()) != null) { String productId = nextValue.getString("productId"); if (CategoryWorker.isProductInCategory(delegator, productId, viewProductCategoryId)) { if (listSize + 1 >= lowIndex && chunkSize < viewSize) { @@ -348,7 +349,7 @@ public class CategoryServices { } } - Map result = FastMap.newInstance(); + Map result = FastMap.newInstance(); result.put("viewIndex", Integer.valueOf(viewIndex)); result.put("viewSize", Integer.valueOf(viewSize)); result.put("lowIndex", Integer.valueOf(lowIndex)); diff --git a/applications/product/src/org/ofbiz/product/category/CategoryWorker.java b/applications/product/src/org/ofbiz/product/category/CategoryWorker.java index 80689d3af8..45c8a2aa3c 100644 --- a/applications/product/src/org/ofbiz/product/category/CategoryWorker.java +++ b/applications/product/src/org/ofbiz/product/category/CategoryWorker.java @@ -33,6 +33,7 @@ import javolution.util.FastList; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; @@ -90,18 +91,18 @@ public class CategoryWorker { public static void getCategoriesWithNoParent(ServletRequest request, String attributeName) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); - Collection results = FastList.newInstance(); + Collection results = FastList.newInstance(); try { - Collection allCategories = delegator.findList("ProductCategory", null, null, null, null, false); + Collection allCategories = delegator.findList("ProductCategory", null, null, null, null, false); if (allCategories == null) return; - Iterator aciter = allCategories.iterator(); + Iterator aciter = allCategories.iterator(); while (aciter.hasNext()) { - GenericValue curCat = (GenericValue) aciter.next(); - Collection parentCats = curCat.getRelatedCache("CurrentProductCategoryRollup"); + GenericValue curCat = aciter.next(); + Collection parentCats = curCat.getRelatedCache("CurrentProductCategoryRollup"); if (parentCats == null || parentCats.size() <= 0) results.add(curCat); @@ -118,7 +119,7 @@ public class CategoryWorker { } public static void getRelatedCategories(ServletRequest request, String attributeName, boolean limitView) { - Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); + Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); String requestId = null; requestId = UtilFormatOut.checkNull((String)requestParameters.get("catalog_id"), (String)requestParameters.get("CATALOG_ID"), @@ -140,32 +141,32 @@ public class CategoryWorker { } public static void getRelatedCategories(ServletRequest request, String attributeName, String parentId, boolean limitView, boolean excludeEmpty) { - List categories = getRelatedCategoriesRet(request, attributeName, parentId, limitView, excludeEmpty); + List categories = getRelatedCategoriesRet(request, attributeName, parentId, limitView, excludeEmpty); if (categories.size() > 0) request.setAttribute(attributeName, categories); } /** @deprecated */ - public static List getRelatedCategoriesRet(PageContext pageContext, String attributeName, String parentId, boolean limitView) { + public static List getRelatedCategoriesRet(PageContext pageContext, String attributeName, String parentId, boolean limitView) { return getRelatedCategoriesRet(pageContext.getRequest(), attributeName, parentId, limitView); } - public static List getRelatedCategoriesRet(ServletRequest request, String attributeName, String parentId, boolean limitView) { + public static List getRelatedCategoriesRet(ServletRequest request, String attributeName, String parentId, boolean limitView) { return getRelatedCategoriesRet(request, attributeName, parentId, limitView, false); } - public static List getRelatedCategoriesRet(ServletRequest request, String attributeName, String parentId, boolean limitView, boolean excludeEmpty) { + public static List getRelatedCategoriesRet(ServletRequest request, String attributeName, String parentId, boolean limitView, boolean excludeEmpty) { return getRelatedCategoriesRet(request, attributeName, parentId, limitView, excludeEmpty, false); } - public static List getRelatedCategoriesRet(ServletRequest request, String attributeName, String parentId, boolean limitView, boolean excludeEmpty, boolean recursive) { - List categories = FastList.newInstance(); + public static List getRelatedCategoriesRet(ServletRequest request, String attributeName, String parentId, boolean limitView, boolean excludeEmpty, boolean recursive) { + List categories = FastList.newInstance(); if (Debug.verboseOn()) Debug.logVerbose("[CategoryWorker.getRelatedCategories] ParentID: " + parentId, module); GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); - List rollups = null; + List rollups = null; try { rollups = delegator.findByAndCache("ProductCategoryRollup", @@ -180,10 +181,10 @@ public class CategoryWorker { } if (UtilValidate.isNotEmpty(rollups)) { // Debug.log("Rollup size: " + rollups.size(), module); - Iterator ri = rollups.iterator(); + Iterator ri = rollups.iterator(); while (ri.hasNext()) { - GenericValue parent = (GenericValue) ri.next(); + GenericValue parent = ri.next(); // Debug.log("Adding child of: " + parent.getString("parentProductCategoryId"), module); GenericValue cv = null; @@ -258,12 +259,12 @@ public class CategoryWorker { } private static EntityCondition buildCountCondition(String fieldName, String fieldValue) { - List orCondList = FastList.newInstance(); + List orCondList = FastList.newInstance(); orCondList.add(EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, UtilDateTime.nowTimestamp())); orCondList.add(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null)); EntityCondition orCond = EntityCondition.makeCondition(orCondList, EntityOperator.OR); - List andCondList = FastList.newInstance(); + List andCondList = FastList.newInstance(); andCondList.add(EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN, UtilDateTime.nowTimestamp())); andCondList.add(EntityCondition.makeCondition(fieldName, EntityOperator.EQUALS, fieldValue)); andCondList.add(orCond); @@ -278,7 +279,7 @@ public class CategoryWorker { } public static void setTrail(ServletRequest request, String currentCategory) { - Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); + Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); String previousCategory = (String) requestParameters.get("pcategory"); if (Debug.verboseOn()) Debug.logVerbose("[CategoryWorker.setTrail] Start: previousCategory=" + previousCategory + @@ -289,7 +290,7 @@ public class CategoryWorker { return; // always get the last crumb list - List crumb = getTrail(request); + List crumb = getTrail(request); if (crumb == null) { crumb = FastList.newInstance(); @@ -303,7 +304,7 @@ public class CategoryWorker { if (cindex < (crumb.size() - 1)) { for (int i = crumb.size() - 1; i > cindex; i--) { - String deadCat = (String) crumb.remove(i); + String deadCat = crumb.remove(i); if (Debug.infoOn()) Debug.logInfo("[CategoryWorker.setTrail] Removed after current category index: " + i + " catname: " + deadCat, module); @@ -336,7 +337,7 @@ public class CategoryWorker { if (index < (crumb.size() - 1)) { for (int i = crumb.size() - 1; i > index; i--) { - String deadCat = (String) crumb.remove(i); + String deadCat = crumb.remove(i); if (Debug.infoOn()) Debug.logInfo("[CategoryWorker.setTrail] Removed after previous category index: " + i + " catname: " + deadCat, module); @@ -351,22 +352,22 @@ public class CategoryWorker { } /** @deprecated */ - public static List getTrail(PageContext pageContext) { + public static List getTrail(PageContext pageContext) { return getTrail(pageContext.getRequest()); } - public static List getTrail(ServletRequest request) { + public static List getTrail(ServletRequest request) { HttpSession session = ((HttpServletRequest) request).getSession(); - List crumb = (List) session.getAttribute("_BREAD_CRUMB_TRAIL_"); + List crumb = UtilGenerics.checkList(session.getAttribute("_BREAD_CRUMB_TRAIL_")); return crumb; } /** @deprecated */ - public static List setTrail(PageContext pageContext, List crumb) { + public static List setTrail(PageContext pageContext, List crumb) { return setTrail(pageContext.getRequest(), crumb); } - public static List setTrail(ServletRequest request, List crumb) { + public static List setTrail(ServletRequest request, List crumb) { HttpSession session = ((HttpServletRequest) request).getSession(); session.setAttribute("_BREAD_CRUMB_TRAIL_", crumb); return crumb; @@ -378,7 +379,7 @@ public class CategoryWorker { } public static boolean checkTrailItem(ServletRequest request, String category) { - List crumb = getTrail(request); + List crumb = getTrail(request); if (crumb != null && crumb.contains(category)) return true; @@ -392,10 +393,10 @@ public class CategoryWorker { } public static String lastTrailItem(ServletRequest request) { - List crumb = getTrail(request); + List crumb = getTrail(request); if (UtilValidate.isNotEmpty(crumb)) { - return (String) crumb.get(crumb.size() - 1); + return crumb.get(crumb.size() - 1); } else { return null; } @@ -405,17 +406,17 @@ public class CategoryWorker { if (productCategoryId == null) return false; if (productId == null || productId.length() == 0) return false; - List productCategoryMembers = EntityUtil.filterByDate(delegator.findByAndCache("ProductCategoryMember", + List productCategoryMembers = EntityUtil.filterByDate(delegator.findByAndCache("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId, "productId", productId)), true); if (productCategoryMembers == null || productCategoryMembers.size() == 0) { //before giving up see if this is a variant product, and if so look up the virtual product and check it... GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); - List productAssocs = ProductWorker.getVariantVirtualAssocs(product); + List productAssocs = ProductWorker.getVariantVirtualAssocs(product); //this does take into account that a product could be a variant of multiple products, but this shouldn't ever really happen... if (UtilValidate.isNotEmpty(productAssocs)) { - Iterator pasIter = productAssocs.iterator(); + Iterator pasIter = productAssocs.iterator(); while (pasIter.hasNext()) { - GenericValue productAssoc = (GenericValue) pasIter.next(); + GenericValue productAssoc = pasIter.next(); if (isProductInCategory(delegator, productAssoc.getString("productId"), productCategoryId)) { return true; } @@ -428,19 +429,19 @@ public class CategoryWorker { } } - public static List filterProductsInCategory(GenericDelegator delegator, List valueObjects, String productCategoryId) throws GenericEntityException { + public static List filterProductsInCategory(GenericDelegator delegator, List valueObjects, String productCategoryId) throws GenericEntityException { return filterProductsInCategory(delegator, valueObjects, productCategoryId, "productId"); } - public static List filterProductsInCategory(GenericDelegator delegator, List valueObjects, String productCategoryId, String productIdFieldName) throws GenericEntityException { - List newList = FastList.newInstance(); + public static List filterProductsInCategory(GenericDelegator delegator, List valueObjects, String productCategoryId, String productIdFieldName) throws GenericEntityException { + List newList = FastList.newInstance(); if (productCategoryId == null) return newList; if (valueObjects == null) return null; - Iterator valIter = valueObjects.iterator(); + Iterator valIter = valueObjects.iterator(); while (valIter.hasNext()) { - GenericValue curValue = (GenericValue) valIter.next(); + GenericValue curValue = valIter.next(); String productId = curValue.getString(productIdFieldName); if (isProductInCategory(delegator, productId, productCategoryId)) { newList.add(curValue); @@ -449,13 +450,13 @@ public class CategoryWorker { return newList; } - public static void getCategoryContentWrappers(Map catContentWrappers, List categoryList, HttpServletRequest request) throws GenericEntityException { + public static void getCategoryContentWrappers(Map catContentWrappers, List categoryList, HttpServletRequest request) throws GenericEntityException { if (catContentWrappers == null || categoryList == null) { return; } - Iterator catIterator = categoryList.iterator(); - while(catIterator.hasNext()) { - GenericValue cat = (GenericValue) catIterator.next(); + Iterator catIterator = categoryList.iterator(); + while (catIterator.hasNext()) { + GenericValue cat = catIterator.next(); String productCategoryId = (String) cat.get("productCategoryId"); if (catContentWrappers.containsKey(productCategoryId)) { @@ -465,8 +466,7 @@ public class CategoryWorker { CategoryContentWrapper catContentWrapper = new CategoryContentWrapper(cat, request); catContentWrappers.put(productCategoryId, catContentWrapper); - List subCat = FastList.newInstance(); - subCat = getRelatedCategoriesRet(request, "subCatList", productCategoryId, true); + List subCat = getRelatedCategoriesRet(request, "subCatList", productCategoryId, true); if(subCat != null) { getCategoryContentWrappers(catContentWrappers, subCat, request ); } diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java b/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java index 58654e18fa..0cdfee8915 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java @@ -134,12 +134,12 @@ public class ProductConfigItemContentWrapper implements java.io.Serializable { } } - List productConfigItemContentList = delegator.findByAndCache("ProdConfItemContent", UtilMisc.toMap("configItemId", configItemId, "confItemContentTypeId", confItemContentTypeId), UtilMisc.toList("-fromDate")); + List productConfigItemContentList = delegator.findByAndCache("ProdConfItemContent", UtilMisc.toMap("configItemId", configItemId, "confItemContentTypeId", confItemContentTypeId), UtilMisc.toList("-fromDate")); productConfigItemContentList = EntityUtil.filterByDate(productConfigItemContentList); GenericValue productConfigItemContent = EntityUtil.getFirst(productConfigItemContentList); if (productConfigItemContent != null) { // when rendering the product config item content, always include the ProductConfigItem and ProdConfItemContent records that this comes from - Map inContext = FastMap.newInstance(); + Map inContext = FastMap.newInstance(); inContext.put("productConfigItem", productConfigItem); inContext.put("productConfigItemContent", productConfigItemContent); ContentWorker.renderContentAsText(dispatcher, delegator, productConfigItemContent.getString("contentId"), outWriter, inContext, locale, mimeTypeId, false); diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java b/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java index 02addc8fa5..3d09386ea1 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigWorker.java @@ -51,7 +51,7 @@ public class ProductConfigWorker { public static final String resource = "ProductUiLabels"; public static final String SEPARATOR = "::"; // cache key separator - public static UtilCache productConfigCache = new UtilCache("product.config", true); // use soft reference to free up memory if needed + public static UtilCache productConfigCache = new UtilCache("product.config", true); // use soft reference to free up memory if needed public static ProductConfigWrapper getProductConfigWrapper(String productId, String currencyUomId, HttpServletRequest request) { ProductConfigWrapper configWrapper = null; @@ -72,7 +72,7 @@ public class ProductConfigWorker { autoUserLogin); productConfigCache.put(cacheKey, new ProductConfigWrapper(configWrapper)); } else { - configWrapper = new ProductConfigWrapper((ProductConfigWrapper)productConfigCache.get(cacheKey)); + configWrapper = new ProductConfigWrapper(productConfigCache.get(cacheKey)); } } catch(ProductConfigWrapperException we) { configWrapper = null; @@ -85,11 +85,11 @@ public class ProductConfigWorker { public static void fillProductConfigWrapper(ProductConfigWrapper configWrapper, HttpServletRequest request) { int numOfQuestions = configWrapper.getQuestions().size(); for (int k = 0; k < numOfQuestions; k++) { - String[] opts = request.getParameterValues("" + k); + String[] opts = request.getParameterValues(Integer.toString(k)); if (opts == null) { // check for standard item comments - ProductConfigWrapper.ConfigItem question = (ProductConfigWrapper.ConfigItem) configWrapper.getQuestions().get(k); + ProductConfigWrapper.ConfigItem question = configWrapper.getQuestions().get(k); if (question.isStandard()) { int i = 0; while (i <= (question.getOptions().size() -1)) { @@ -123,10 +123,10 @@ public class ProductConfigWorker { // set selected variant products if (UtilValidate.isNotEmpty(option) && (option.hasVirtualComponent())) { - List components = option.getComponents(); + List components = option.getComponents(); int variantIndex = 0; for (int i = 0; i < components.size(); i++) { - GenericValue component = (GenericValue)components.get(i); + GenericValue component = components.get(i); if (option.isVirtualComponent(component)) { String productParamName = "add_product_id" + k + "_" + cnt + "_" + variantIndex; String selectedProdcutId = request.getParameter(productParamName); @@ -138,7 +138,7 @@ public class ProductConfigWorker { if (ProductWorker.isVirtual((GenericDelegator)request.getAttribute("delegator"), selectedProdcutId)) { if ("VV_FEATURETREE".equals(ProductWorker.getProductvirtualVariantMethod((GenericDelegator)request.getAttribute("delegator"), selectedProdcutId))) { // get the selected features - List selectedFeatures = FastList.newInstance(); + List selectedFeatures = FastList.newInstance(); Enumeration paramNames = request.getParameterNames(); while(paramNames.hasMoreElements()) { String paramName = (String)paramNames.nextElement(); @@ -183,21 +183,21 @@ public class ProductConfigWorker { public static void storeProductConfigWrapper(ProductConfigWrapper configWrapper, GenericDelegator delegator) { if (configWrapper == null || (!configWrapper.isCompleted())) return; String configId = null; - List questions = configWrapper.getQuestions(); - List configsToCheck = FastList.newInstance(); + List questions = configWrapper.getQuestions(); + List configsToCheck = FastList.newInstance(); int selectedOptionSize = 0; for (int i = 0; i < questions.size(); i++) { String configItemId = null; Long sequenceNum = null; - List selectedOptions = FastList.newInstance(); - ConfigItem ci = (ConfigItem)questions.get(i); - List options = ci.getOptions(); + List selectedOptions = FastList.newInstance(); + ConfigItem ci = questions.get(i); + List options = ci.getOptions(); if (ci.isStandard()) { selectedOptions.addAll(options); } else { - Iterator availOptions = options.iterator(); + Iterator availOptions = options.iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { selectedOptions.add(oneOption); } @@ -209,13 +209,13 @@ public class ProductConfigWorker { configItemId = ci.getConfigItemAssoc().getString("configItemId"); sequenceNum = ci.getConfigItemAssoc().getLong("sequenceNum"); try { - List configs = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configItemId",configItemId,"sequenceNum", sequenceNum)); - Iterator configIt = configs.iterator(); + List configs = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configItemId",configItemId,"sequenceNum", sequenceNum)); + Iterator configIt = configs.iterator(); while (configIt.hasNext()) { GenericValue productConfigConfig = configIt.next(); - Iterator selOpIt = selectedOptions.iterator(); + Iterator selOpIt = selectedOptions.iterator(); while (selOpIt.hasNext()) { - ConfigOption oneOption = (ConfigOption)selOpIt.next(); + ConfigOption oneOption = selOpIt.next(); String configOptionId = oneOption.configOption.getString("configOptionId"); if (productConfigConfig.getString("configOptionId").equals(configOptionId)) { String comments = oneOption.getComments() != null ? oneOption.getComments() : ""; @@ -233,12 +233,12 @@ public class ProductConfigWorker { } } if (UtilValidate.isNotEmpty(configsToCheck)) { - Iterator ctci = configsToCheck.iterator(); + Iterator ctci = configsToCheck.iterator(); while (ctci.hasNext()) { GenericValue productConfigConfig = ctci.next(); String tempConfigId = productConfigConfig.getString("configId"); try { - List tempResult = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configId",tempConfigId)); + List tempResult = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configId",tempConfigId)); if (tempResult.size() == selectedOptionSize && configsToCheck.containsAll(tempResult)) { List configOptionProductOptions = delegator.findByAnd("ConfigOptionProductOption", UtilMisc.toMap("configId",tempConfigId)); if (UtilValidate.isNotEmpty(configOptionProductOptions)) { @@ -247,15 +247,15 @@ public class ProductConfigWorker { for (int i = 0; i < questions.size(); i++) { String configItemId = null; Long sequenceNum = null; - List selectedOptions = FastList.newInstance(); - ConfigItem ci = (ConfigItem)questions.get(i); - List options = ci.getOptions(); + List selectedOptions = FastList.newInstance(); + ConfigItem ci = questions.get(i); + List options = ci.getOptions(); if (ci.isStandard()) { selectedOptions.addAll(options); } else { - Iterator availOptions = options.iterator(); + Iterator availOptions = options.iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { selectedOptions.add(oneOption); } @@ -268,9 +268,9 @@ public class ProductConfigWorker { List components = anOption.getComponents(); for (GenericValue aComponent : components) { if (anOption.isVirtualComponent(aComponent)) { - Map componentOptions = anOption.getComponentOptions(); + Map componentOptions = anOption.getComponentOptions(); String optionProductId = aComponent.getString("productId"); - String optionProductOptionId = (String)componentOptions.get(optionProductId); + String optionProductOptionId = componentOptions.get(optionProductId); String configOptionId = anOption.configOption.getString("configOptionId"); configItemId = ci.getConfigItemAssoc().getString("configItemId"); sequenceNum = ci.getConfigItemAssoc().getLong("sequenceNum"); @@ -316,15 +316,15 @@ public class ProductConfigWorker { for (int i = 0; i < questions.size(); i++) { String configItemId = null; Long sequenceNum = null; - List selectedOptions = FastList.newInstance(); - ConfigItem ci = (ConfigItem)questions.get(i); - List options = ci.getOptions(); + List selectedOptions = FastList.newInstance(); + ConfigItem ci = questions.get(i); + List options = ci.getOptions(); if (ci.isStandard()) { selectedOptions.addAll(options); } else { - Iterator availOptions = options.iterator(); + Iterator availOptions = options.iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { selectedOptions.add(oneOption); } @@ -339,10 +339,10 @@ public class ProductConfigWorker { } configItemId = ci.getConfigItemAssoc().getString("configItemId"); sequenceNum = ci.getConfigItemAssoc().getLong("sequenceNum"); - Iterator selOpIt = selectedOptions.iterator(); + Iterator selOpIt = selectedOptions.iterator(); while (selOpIt.hasNext()) { - List toBeStored = FastList.newInstance(); - ConfigOption oneOption = (ConfigOption)selOpIt.next(); + List toBeStored = FastList.newInstance(); + ConfigOption oneOption = selOpIt.next(); String configOptionId = oneOption.configOption.getString("configOptionId"); String description = oneOption.getComments(); GenericValue productConfigConfig = delegator.makeValue("ProductConfigConfig"); @@ -354,9 +354,9 @@ public class ProductConfigWorker { toBeStored.add(productConfigConfig); if (oneOption.hasVirtualComponent()) { - List components = oneOption.getComponents(); + List components = oneOption.getComponents(); for (int j = 0; j < components.size(); j++) { - GenericValue component = (GenericValue)components.get(j); + GenericValue component = (GenericValue)components.get(j); if (oneOption.isVirtualComponent(component)) { String componentOption = (String)oneOption.componentOptions.get(component.getString("productId")); GenericValue configOptionProductOption = delegator.makeValue("ConfigOptionProductOption"); diff --git a/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java b/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java index 63ef0d7710..172907be2e 100644 --- a/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java +++ b/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java @@ -60,7 +60,7 @@ public class ProductConfigWrapper implements Serializable { protected double basePrice = 0.0; protected double defaultPrice = 0.0; protected String configId = null; // Id of persisted ProductConfigWrapper - protected List questions = null; // ProductConfigs + protected List questions = null; // ProductConfigs /** Creates a new instance of ProductConfigWrapper */ public ProductConfigWrapper() { @@ -83,7 +83,7 @@ public class ProductConfigWrapper implements Serializable { delegator = pcw.delegator; autoUserLogin = pcw.autoUserLogin; for (int i = 0; i < pcw.questions.size(); i++) { - questions.add(new ConfigItem((ConfigItem)pcw.questions.get(i))); + questions.add(new ConfigItem(pcw.questions.get(i))); } } @@ -101,22 +101,21 @@ public class ProductConfigWrapper implements Serializable { this.autoUserLogin = autoUserLogin; // get the base price - Map priceContext = UtilMisc.toMap("product", product, "prodCatalogId", catalogId, "webSiteId", webSiteId, "productStoreId", productStoreId, + Map priceContext = UtilMisc.toMap("product", product, "prodCatalogId", catalogId, "webSiteId", webSiteId, "productStoreId", productStoreId, "currencyUomId", currencyUomId, "autoUserLogin", autoUserLogin); - Map priceMap = dispatcher.runSync("calculateProductPrice", priceContext); + Map priceMap = dispatcher.runSync("calculateProductPrice", priceContext); Double price = (Double)priceMap.get("price"); if (price != null) { basePrice = price.doubleValue(); } questions = FastList.newInstance(); - List questionsValues = FastList.newInstance(); if (product.getString("productTypeId") != null && product.getString("productTypeId").equals("AGGREGATED")) { - questionsValues = delegator.findByAnd("ProductConfig", UtilMisc.toMap("productId", productId), UtilMisc.toList("sequenceNum")); + List questionsValues = delegator.findByAnd("ProductConfig", UtilMisc.toMap("productId", productId), UtilMisc.toList("sequenceNum")); questionsValues = EntityUtil.filterByDate(questionsValues); - Iterator questionsValuesIt = questionsValues.iterator(); - Set itemIds = FastSet.newInstance(); + Set itemIds = FastSet.newInstance(); + Iterator questionsValuesIt = questionsValues.iterator(); while (questionsValuesIt.hasNext()) { - ConfigItem oneQuestion = new ConfigItem((GenericValue)questionsValuesIt.next()); + ConfigItem oneQuestion = new ConfigItem(questionsValuesIt.next()); oneQuestion.setContent(locale, "text/html"); // TODO: mime-type shouldn't be hardcoded if (itemIds.contains(oneQuestion.getConfigItem().getString("configItemId"))) { oneQuestion.setFirst(false); @@ -124,10 +123,10 @@ public class ProductConfigWrapper implements Serializable { itemIds.add(oneQuestion.getConfigItem().getString("configItemId")); } questions.add(oneQuestion); - List configOptions = delegator.findByAnd("ProductConfigOption", UtilMisc.toMap("configItemId", oneQuestion.getConfigItemAssoc().getString("configItemId")), UtilMisc.toList("sequenceNum")); - Iterator configOptionsIt = configOptions.iterator(); + List configOptions = delegator.findByAnd("ProductConfigOption", UtilMisc.toMap("configItemId", oneQuestion.getConfigItemAssoc().getString("configItemId")), UtilMisc.toList("sequenceNum")); + Iterator configOptionsIt = configOptions.iterator(); while (configOptionsIt.hasNext()) { - ConfigOption option = new ConfigOption(delegator, dispatcher, (GenericValue)configOptionsIt.next(), oneQuestion, catalogId, webSiteId, currencyUomId, autoUserLogin); + ConfigOption option = new ConfigOption(delegator, dispatcher, configOptionsIt.next(), oneQuestion, catalogId, webSiteId, currencyUomId, autoUserLogin); oneQuestion.addOption(option); } } @@ -139,11 +138,11 @@ public class ProductConfigWrapper implements Serializable { //configure ProductConfigWrapper according to ProductConfigConfig entity if (UtilValidate.isNotEmpty(configId)) { this.configId = configId; - List productConfigConfig = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configId", configId)); + List productConfigConfig = delegator.findByAnd("ProductConfigConfig", UtilMisc.toMap("configId", configId)); if (UtilValidate.isNotEmpty(productConfigConfig)) { - Iterator pccIt = productConfigConfig.iterator(); + Iterator pccIt = productConfigConfig.iterator(); while (pccIt.hasNext()) { - GenericValue pcc =(GenericValue) pccIt.next(); + GenericValue pcc = pccIt.next(); String configItemId = pcc.getString("configItemId"); String configOptionId = pcc.getString("configOptionId"); Long sequenceNum = pcc.getLong("sequenceNum"); @@ -156,11 +155,11 @@ public class ProductConfigWrapper implements Serializable { public void setSelected(String configItemId, Long sequenceNum, String configOptionId, String comments) throws Exception { for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); if (ci.configItemAssoc.getString("configItemId").equals(configItemId) && ci.configItemAssoc.getLong("sequenceNum").equals(sequenceNum)) { - List avalOptions = ci.getOptions(); + List avalOptions = ci.getOptions(); for (int j = 0; j < avalOptions.size(); j++) { - ConfigOption oneOption = (ConfigOption)avalOptions.get(j); + ConfigOption oneOption = avalOptions.get(j); if (oneOption.configOption.getString("configOptionId").equals(configOptionId)) { setSelected(i, j, comments); break; @@ -172,11 +171,11 @@ public class ProductConfigWrapper implements Serializable { public void resetConfig() { for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); if (!ci.isStandard()) { - List options = ci.getOptions(); + List options = ci.getOptions(); for (int j = 0; j < options.size(); j++) { - ConfigOption co = (ConfigOption)options.get(j); + ConfigOption co = options.get(j); co.setSelected(false); co.setComments(null); } @@ -187,13 +186,13 @@ public class ProductConfigWrapper implements Serializable { public void setDefaultConfig() { resetConfig(); for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); if (ci.isMandatory()) { ConfigOption co = ci.getDefault(); if(co != null){ co.setSelected(true); }else if (ci.getOptions().size() > 0) { - co = (ConfigOption)ci.getOptions().get(0); + co = ci.getOptions().get(0); co.setSelected(true); } } @@ -205,19 +204,19 @@ public class ProductConfigWrapper implements Serializable { } public boolean equals(Object obj) { - if (obj == null || !(obj instanceof ProductConfigWrapper)) { + if (!(obj instanceof ProductConfigWrapper)) { return false; } ProductConfigWrapper cw = (ProductConfigWrapper)obj; if (!product.getString("productId").equals(cw.getProduct().getString("productId"))) { return false; } - List cwq = cw.getQuestions(); + List cwq = cw.getQuestions(); if (questions.size() != cwq.size()) { return false; } for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); if (!ci.equals(cwq.get(i))) { return false; } @@ -226,10 +225,10 @@ public class ProductConfigWrapper implements Serializable { } public String toString() { - return "" + questions; + return questions.toString(); } - public List getQuestions() { + public List getQuestions() { return questions; } @@ -238,8 +237,8 @@ public class ProductConfigWrapper implements Serializable { } public void setSelected(int question, int option, String comments) throws Exception { - ConfigItem ci = (ConfigItem)questions.get(question); - List avalOptions = ci.getOptions(); + ConfigItem ci = questions.get(question); + List avalOptions = ci.getOptions(); if (ci.isSingleChoice()) { for (int j = 0; j < avalOptions.size(); j++) { ConfigOption oneOption = (ConfigOption)avalOptions.get(j); @@ -249,7 +248,7 @@ public class ProductConfigWrapper implements Serializable { } ConfigOption theOption = null; if (option >= 0 && option < avalOptions.size()) { - theOption = (ConfigOption)avalOptions.get(option); + theOption = avalOptions.get(option); } if (theOption != null) { theOption.setSelected(true); @@ -260,8 +259,8 @@ public class ProductConfigWrapper implements Serializable { public void setSelected(int question, int option, int component, String componentOption) throws Exception { // set variant products ConfigOption theOption = getItemOtion(question, option); - List components = theOption.getComponents(); - GenericValue oneComponent = (GenericValue)components.get(component); + List components = theOption.getComponents(); + GenericValue oneComponent = components.get(component); if (theOption.isVirtualComponent(oneComponent)) { if (theOption.componentOptions == null) { theOption.componentOptions = FastMap.newInstance(); @@ -274,16 +273,16 @@ public class ProductConfigWrapper implements Serializable { } } - public List getSelectedOptions() { - List selectedOptions = FastList.newInstance(); + public List getSelectedOptions() { + List selectedOptions = FastList.newInstance(); for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); if (ci.isStandard()) { selectedOptions.addAll(ci.getOptions()); } else { - Iterator availOptions = ci.getOptions().iterator(); + Iterator availOptions = ci.getOptions().iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { selectedOptions.add(oneOption); } @@ -293,10 +292,10 @@ public class ProductConfigWrapper implements Serializable { return selectedOptions; } - public List getDefaultOptions() { - List defaultOptions = FastList.newInstance(); + public List getDefaultOptions() { + List defaultOptions = FastList.newInstance(); for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); ConfigOption co = ci.getDefault(); if (co != null){ defaultOptions.add(co); @@ -307,9 +306,9 @@ public class ProductConfigWrapper implements Serializable { public double getTotalPrice() { double totalPrice = basePrice; - List options = getSelectedOptions(); + List options = getSelectedOptions(); for (int i = 0; i < options.size(); i++) { - ConfigOption oneOption = (ConfigOption)options.get(i); + ConfigOption oneOption = options.get(i); totalPrice += oneOption.getPrice(); } return totalPrice; @@ -317,9 +316,9 @@ public class ProductConfigWrapper implements Serializable { private void setDefaultPrice() { double totalPrice = basePrice; - List options = getDefaultOptions(); + List options = getDefaultOptions(); for (int i = 0; i < options.size(); i++) { - ConfigOption oneOption = (ConfigOption)options.get(i); + ConfigOption oneOption = options.get(i); totalPrice += oneOption.getPrice(); } defaultPrice = totalPrice; @@ -332,11 +331,11 @@ public class ProductConfigWrapper implements Serializable { public boolean isCompleted() { boolean completed = true; for (int i = 0; i < questions.size(); i++) { - ConfigItem ci = (ConfigItem)questions.get(i); + ConfigItem ci = questions.get(i); if (!ci.isStandard() && ci.isMandatory()) { - Iterator availOptions = ci.getOptions().iterator(); + Iterator availOptions = ci.getOptions().iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { completed = true; break; @@ -354,10 +353,10 @@ public class ProductConfigWrapper implements Serializable { public ConfigOption getItemOtion(int itemIndex, int optionIndex) { if (questions.size() > itemIndex) { - ConfigItem ci = (ConfigItem)questions.get(itemIndex); - List options = ci.getOptions(); + ConfigItem ci = questions.get(itemIndex); + List options = ci.getOptions(); if (options.size() > optionIndex) { - ConfigOption co = (ConfigOption)options.get(optionIndex); + ConfigOption co = options.get(optionIndex); return co; } } @@ -369,7 +368,7 @@ public class ProductConfigWrapper implements Serializable { GenericValue configItem = null; GenericValue configItemAssoc = null; ProductConfigItemContentWrapper content = null; - List options = null; + List options = null; boolean first = true; public ConfigItem(GenericValue questionAssoc) throws Exception { @@ -383,7 +382,7 @@ public class ProductConfigWrapper implements Serializable { configItemAssoc = GenericValue.create(ci.configItemAssoc); options = FastList.newInstance(); for (int i = 0; i < ci.options.size(); i++) { - options.add(new ConfigOption((ConfigOption)ci.options.get(i))); + options.add(new ConfigOption(ci.options.get(i))); } first = ci.first; content = ci.content; // FIXME: this should be cloned @@ -429,7 +428,7 @@ public class ProductConfigWrapper implements Serializable { options.add(option); } - public List getOptions() { + public List getOptions() { return options; } @@ -463,9 +462,9 @@ public class ProductConfigWrapper implements Serializable { public boolean isSelected() { if (isStandard()) return true; - Iterator availOptions = getOptions().iterator(); + Iterator availOptions = getOptions().iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { return true; } @@ -474,9 +473,9 @@ public class ProductConfigWrapper implements Serializable { } public ConfigOption getSelected() { - Iterator availOptions = getOptions().iterator(); + Iterator availOptions = getOptions().iterator(); while (availOptions.hasNext()) { - ConfigOption oneOption = (ConfigOption)availOptions.next(); + ConfigOption oneOption = availOptions.next(); if (oneOption.isSelected()) { return oneOption; } @@ -487,7 +486,7 @@ public class ProductConfigWrapper implements Serializable { public ConfigOption getDefault(){ String defaultConfigOptionId = configItemAssoc.getString("defaultConfigOptionId"); if(UtilValidate.isNotEmpty(defaultConfigOptionId)){ - for(ConfigOption oneOption : (List)getOptions()) { + for(ConfigOption oneOption : getOptions()) { String currentConfigOptionId = oneOption.getId(); if (defaultConfigOptionId.compareToIgnoreCase(currentConfigOptionId) == 0 ){ return oneOption; @@ -505,12 +504,12 @@ public class ProductConfigWrapper implements Serializable { if (!configItem.getString("configItemId").equals(ci.getConfigItem().getString("configItemId"))) { return false; } - List opts = ci.getOptions(); + List opts = ci.getOptions(); if (options.size() != opts.size()) { return false; } for (int i = 0; i < options.size(); i++) { - ConfigOption co = (ConfigOption)options.get(i); + ConfigOption co = options.get(i); if (!co.equals(opts.get(i))) { return false; } @@ -526,8 +525,8 @@ public class ProductConfigWrapper implements Serializable { public class ConfigOption implements java.io.Serializable { double optionPrice = 0; Date availabilityDate = null; - List componentList = null; // lists of ProductConfigProduct - Map componentOptions = null; + List componentList = null; // lists of ProductConfigProduct + Map componentOptions = null; GenericValue configOption = null; boolean selected = false; boolean available = true; @@ -538,14 +537,14 @@ public class ProductConfigWrapper implements Serializable { configOption = option; parentConfigItem = configItem; componentList = option.getRelated("ConfigOptionProductConfigProduct"); - Iterator componentsIt = componentList.iterator(); + Iterator componentsIt = componentList.iterator(); while (componentsIt.hasNext()) { double price = 0; - GenericValue oneComponent = (GenericValue)componentsIt.next(); + GenericValue oneComponent = componentsIt.next(); // Get the component's price - Map fieldMap = UtilMisc.toMap("product", oneComponent.getRelatedOne("ProductProduct"), "prodCatalogId", catalogId, "webSiteId", webSiteId, + Map fieldMap = UtilMisc.toMap("product", oneComponent.getRelatedOne("ProductProduct"), "prodCatalogId", catalogId, "webSiteId", webSiteId, "currencyUomId", currencyUomId, "productPricePurposeId", "COMPONENT_PRICE", "autoUserLogin", autoUserLogin); - Map priceMap = dispatcher.runSync("calculateProductPrice", fieldMap); + Map priceMap = dispatcher.runSync("calculateProductPrice", fieldMap); Double componentPrice = (Double) priceMap.get("price"); Boolean validPriceFound = (Boolean)priceMap.get("validPriceFound"); double mult = 1; @@ -559,7 +558,7 @@ public class ProductConfigWrapper implements Serializable { price = componentPrice.doubleValue(); } else { fieldMap.put("productPricePurposeId", "PURCHASE"); - Map purchasePriceResultMap = dispatcher.runSync("calculateProductPrice", fieldMap); + Map purchasePriceResultMap = dispatcher.runSync("calculateProductPrice", fieldMap); Double purchasePrice = (Double) purchasePriceResultMap.get("price"); if (purchasePrice != null) { price = purchasePrice.doubleValue(); @@ -574,7 +573,7 @@ public class ProductConfigWrapper implements Serializable { configOption = GenericValue.create(co.configOption); componentList = FastList.newInstance(); for (int i = 0; i < co.componentList.size(); i++) { - componentList.add(GenericValue.create((GenericValue)co.componentList.get(i))); + componentList.add(GenericValue.create(co.componentList.get(i))); } optionPrice = co.optionPrice; available = co.available; @@ -584,21 +583,21 @@ public class ProductConfigWrapper implements Serializable { public void recalculateOptionPrice(ProductConfigWrapper pcw) throws Exception { optionPrice = 0; - Iterator componentsIt = componentList.iterator(); + Iterator componentsIt = componentList.iterator(); while (componentsIt.hasNext()) { double price = 0; - GenericValue oneComponent = (GenericValue)componentsIt.next(); + GenericValue oneComponent = componentsIt.next(); GenericValue oneComponentProduct = oneComponent.getRelatedOne("ProductProduct"); - String variantProductId = (String)componentOptions.get(oneComponent.getString("productId")); + String variantProductId = componentOptions.get(oneComponent.getString("productId")); if (UtilValidate.isNotEmpty(variantProductId)) { oneComponentProduct = pcw.delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", variantProductId)); } // Get the component's price - Map fieldMap = UtilMisc.toMap("product", oneComponentProduct, "prodCatalogId", pcw.catalogId, "webSiteId", pcw.webSiteId, + Map fieldMap = UtilMisc.toMap("product", oneComponentProduct, "prodCatalogId", pcw.catalogId, "webSiteId", pcw.webSiteId, "currencyUomId", pcw.currencyUomId, "productPricePurposeId", "COMPONENT_PRICE", "autoUserLogin", pcw.autoUserLogin); - Map priceMap = dispatcher.runSync("calculateProductPrice", fieldMap); + Map priceMap = dispatcher.runSync("calculateProductPrice", fieldMap); Double componentPrice = (Double) priceMap.get("price"); Boolean validPriceFound = (Boolean)priceMap.get("validPriceFound"); double mult = 1; @@ -612,7 +611,7 @@ public class ProductConfigWrapper implements Serializable { price = componentPrice.doubleValue(); } else { fieldMap.put("productPricePurposeId", "PURCHASE"); - Map purchasePriceResultMap = dispatcher.runSync("calculateProductPrice", fieldMap); + Map purchasePriceResultMap = dispatcher.runSync("calculateProductPrice", fieldMap); Double purchasePrice = (Double) purchasePriceResultMap.get("price"); if (purchasePrice != null) { price = purchasePrice.doubleValue(); @@ -701,11 +700,11 @@ public class ProductConfigWrapper implements Serializable { available = newValue; } - public List getComponents() { + public List getComponents() { return componentList; } - public Map getComponentOptions() { + public Map getComponentOptions() { return componentOptions; } diff --git a/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java b/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java index fa55488c41..102c402c77 100644 --- a/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java +++ b/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java @@ -56,31 +56,31 @@ public class ParametricSearch { * 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> 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> makeCategoryFeatureLists(String productCategoryId, GenericDelegator delegator, int perTypeMaxSize) { + Map> productFeaturesByTypeMap = FastMap.newInstance(); try { - List productFeatureCategoryAppls = delegator.findByAndCache("ProductFeatureCategoryAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); + List productFeatureCategoryAppls = delegator.findByAndCache("ProductFeatureCategoryAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); productFeatureCategoryAppls = EntityUtil.filterByDate(productFeatureCategoryAppls, true); if (productFeatureCategoryAppls != null) { - Iterator pfcasIter = productFeatureCategoryAppls.iterator(); + Iterator 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 productFeatures = delegator.findByAndCache("ProductFeature", UtilMisc.toMap("productFeatureCategoryId", productFeatureCategoryAppl.get("productFeatureCategoryId"))); + Iterator 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 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 @@ public class ParametricSearch { } try { - List productFeatureCatGrpAppls = delegator.findByAndCache("ProductFeatureCatGrpAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); + List productFeatureCatGrpAppls = delegator.findByAndCache("ProductFeatureCatGrpAppl", UtilMisc.toMap("productCategoryId", productCategoryId)); productFeatureCatGrpAppls = EntityUtil.filterByDate(productFeatureCatGrpAppls, true); if (productFeatureCatGrpAppls != null) { - Iterator pfcgasIter = productFeatureCatGrpAppls.iterator(); + Iterator 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 productFeatureGroupAppls = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", productFeatureCatGrpAppl.get("productFeatureGroupId"))); + Iterator 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 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 @@ public class ParametricSearch { } // now before returning, order the features in each list by description - Iterator productFeatureTypeEntries = productFeaturesByTypeMap.entrySet().iterator(); + Map> productFeaturesByTypeMapSorted = FastMap.newInstance(); + Iterator>> 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> entry = productFeatureTypeEntries.next(); + List 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> 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> getAllFeaturesByType(GenericDelegator delegator, int perTypeMaxSize) { + Map> productFeaturesByTypeMap = FastMap.newInstance(); try { - Set typesWithOverflowMessages = FastSet.newInstance(); + Set 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 featuresByType = productFeaturesByTypeMap.get(productFeatureTypeId); if (featuresByType == null) { featuresByType = FastList.newInstance(); productFeaturesByTypeMap.put(productFeatureTypeId, featuresByType); @@ -161,19 +162,20 @@ public class ParametricSearch { return productFeaturesByTypeMap; } - public static Map makeFeatureIdByTypeMap(ServletRequest request) { - Map parameters = UtilHttp.getParameterMap((HttpServletRequest) request); + public static Map makeFeatureIdByTypeMap(ServletRequest request) { + Map 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 makeFeatureIdByTypeMap(Map parameters) { + Map featureIdByType = FastMap.newInstance(); if (parameters == null) return featureIdByType; - Iterator parameterNameIter = parameters.keySet().iterator(); + + Iterator 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 @@ public class ParametricSearch { } /** 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 makeFeatureIdListFromPrefixed(Map parameters) { + List featureIdList = FastList.newInstance(); if (parameters == null) return featureIdList; - Iterator parameterNameIter = parameters.keySet().iterator(); + Iterator 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 @@ public class ParametricSearch { return featureIdList; } - public static String makeFeatureIdByTypeString(Map featureIdByType) { + public static String makeFeatureIdByTypeString(Map featureIdByType) { if (featureIdByType == null || featureIdByType.size() == 0) { return ""; } StringBuilder outSb = new StringBuilder(); - Iterator fbtIter = featureIdByType.entrySet().iterator(); + Iterator> 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 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 @@ public class ParametricSearch { * 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 makeProductFeatureCategoryIdListFromPrefixed(Map parameters) { + List prodFeatureCategoryIdList = FastList.newInstance(); if (parameters == null) return prodFeatureCategoryIdList; - Iterator parameterNameIter = parameters.keySet().iterator(); + Iterator 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) { diff --git a/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java b/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java index 5fd79337ae..10560892bf 100644 --- a/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java +++ b/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java @@ -22,11 +22,14 @@ import java.util.Iterator; 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 @@ public class ProductFeatureServices { * 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 getProductFeaturesByType(DispatchContext dctx, Map context) { + Map 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 @@ public class ProductFeatureServices { String entityToSearch = "ProductFeature"; String fieldToSearch = "productFeatureCategoryId"; - List orderBy = UtilMisc.toList("productFeatureTypeId", "description"); + List orderBy = UtilMisc.toList("productFeatureTypeId", "description"); if (valueToSearch == null && context.get("productFeatureGroupId") != null) { entityToSearch = "ProductFeatureGroupAndAppl"; @@ -89,24 +92,25 @@ public class ProductFeatureServices { try { // get all product features in this feature category - List allFeatures = delegator.findByAnd(entityToSearch, UtilMisc.toMap(fieldToSearch, valueToSearch), orderBy); + List 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 featureTypes = FastList.newInstance(); + Map> featuresByType = new LinkedHashMap>(); GenericValue feature = null; - for (Iterator featuresIter = allFeatures.iterator(); featuresIter.hasNext(); ) { - feature = (GenericValue) featuresIter.next(); + for (Iterator 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 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 @@ public class ProductFeatureServices { * 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 getAllExistingVariants(DispatchContext dctx, Map context) { + Map results = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); String productId = (String) context.get("productId"); - List curProductFeatureAndAppls = (List) context.get("productFeatureAppls"); - List existingVariantProductIds = FastList.newInstance(); + List curProductFeatureAndAppls = UtilGenerics.checkList(context.get("productFeatureAppls")); + List existingVariantProductIds = FastList.newInstance(); try { /* @@ -138,23 +142,23 @@ public class ProductFeatureServices { * 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 productAssocs = EntityUtil.filterByDate(delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", "PRODUCT_VARIANT"))); + Iterator 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 curProductFeatureAndApplIter = curProductFeatureAndAppls.iterator(); while (curProductFeatureAndApplIter.hasNext()) { - String productFeatureAndAppl = (String) curProductFeatureAndApplIter.next(); - Map findByMap = UtilMisc.toMap("productId", productAssoc.getString("productIdTo"), + String productFeatureAndAppl = curProductFeatureAndApplIter.next(); + Map 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 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 @@ public class ProductFeatureServices { 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 @@ public class ProductFeatureServices { * 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 getVariantCombinations(DispatchContext dctx, Map context) { + Map 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 featuresResults = dispatcher.runSync("getProductFeaturesByType", UtilMisc.toMap("productId", productId)); + Map> 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> 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 fi = features.keySet().iterator(); fi.hasNext(); ) { + String currentFeatureType = fi.next(); + List currentFeatures = features.get(currentFeatureType); - List newCombinations = FastList.newInstance(); - List combinations; + List> newCombinations = FastList.newInstance(); + List> combinations; // start with either existing combinations or from scratch if (oldCombinations.size() > 0) { @@ -223,12 +227,12 @@ public class ProductFeatureServices { // 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 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 newCombination = FastMap.newInstance(); + List newFeatures = FastList.newInstance(); + List newFeatureIds = FastList.newInstance(); if (currentFeature.getString("idCode") != null) { newCombination.put("defaultVariantProductId", productId + currentFeature.getString("idCode")); } else { @@ -242,16 +246,16 @@ public class ProductFeatureServices { } } } 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> comboIt = combinations.iterator(); comboIt.hasNext(); ) { + Map combination = comboIt.next(); + for (Iterator cFi = currentFeatures.iterator(); cFi.hasNext(); ) { + GenericValue currentFeature = cFi.next(); if (currentFeature.getString("productFeatureApplTypeId").equals("SELECTABLE_FEATURE")) { - Map newCombination = FastMap.newInstance(); + Map 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 newFeatures = UtilMisc.makeListWritable(UtilGenerics.checkList(combination.get("curProductFeatureAndAppls"))); + List newFeatureIds = UtilMisc.makeListWritable(UtilGenerics.checkList(combination.get("curProductFeatureIds"))); if (currentFeature.getString("idCode") != null) { newCombination.put("defaultVariantProductId", combination.get("defaultVariantProductId") + currentFeature.getString("idCode")); } else { @@ -272,18 +276,18 @@ public class ProductFeatureServices { } int defaultCodeCounter = 1; - Map defaultVariantProductIds = FastMap.newInstance(); // this map will contain the codes already used (as keys) - defaultVariantProductIds.put(productId, null); + Set 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> fCi = oldCombinations.iterator(); fCi.hasNext(); ) { + Map 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 @@ public class ProductFeatureServices { * 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 getCategoryVariantProducts(DispatchContext dctx, Map context) { + Map results = FastMap.newInstance(); LocalDispatcher dispatcher = dctx.getDispatcher(); - List productFeatures = (List) context.get("productFeatures"); + List 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 @@ public class ProductFeatureServices { return ServiceUtil.returnError(ex.getMessage()); } - List memberProducts = (List) result.get("categoryMembers"); + List 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 featuresByType = FastMap.newInstance(); + for (Iterator 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 products = FastList.newInstance(); // final list of variant products + for (Iterator 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 @@ public class ProductFeatureServices { return ServiceUtil.returnError(ex.getMessage()); } - List variantProducts = (List) result.get("products"); + List variantProducts = UtilGenerics.checkList(result.get("products")); if ((variantProducts != null) && (variantProducts.size() > 0)) { products.addAll(variantProducts); } else { diff --git a/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java b/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java index 4fa3ae79a3..7371e94e95 100644 --- a/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java +++ b/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java @@ -30,6 +30,7 @@ import javolution.util.FastMap; 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 class InventoryServices { public final static String module = InventoryServices.class.getName(); - public static Map prepareInventoryTransfer(DispatchContext dctx, Map context) { + public static Map prepareInventoryTransfer(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String inventoryItemId = (String) context.get("inventoryItemId"); Double xferQty = (Double) context.get("xferQty"); @@ -73,7 +74,7 @@ public class InventoryServices { } try { - Map results = ServiceUtil.returnSuccess(); + Map results = ServiceUtil.returnSuccess(); String inventoryType = inventoryItem.getString("inventoryItemTypeId"); if (inventoryType.equals("NON_SERIAL_INV_ITEM")) { @@ -117,17 +118,17 @@ public class InventoryServices { results.put("inventoryItemId", newItem.get("inventoryItemId")); // TODO: how do we get this here: "inventoryTransferId", inventoryTransferId - Map createNewDetailMap = UtilMisc.toMap("availableToPromiseDiff", xferQty, "quantityOnHandDiff", xferQty, + Map createNewDetailMap = UtilMisc.toMap("availableToPromiseDiff", xferQty, "quantityOnHandDiff", xferQty, "inventoryItemId", newItem.get("inventoryItemId"), "userLogin", userLogin); - Map createUpdateDetailMap = UtilMisc.toMap("availableToPromiseDiff", negXferQty, "quantityOnHandDiff", negXferQty, + Map createUpdateDetailMap = UtilMisc.toMap("availableToPromiseDiff", negXferQty, "quantityOnHandDiff", negXferQty, "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin); try { - Map resultNew = dctx.getDispatcher().runSync("createInventoryItemDetail", createNewDetailMap); + Map 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 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 @@ public class InventoryServices { 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 createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(-atp), "inventoryItemId", inventoryItemToClear.get("inventoryItemId"), "userLogin", userLogin); try { - Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); + Map 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 class InventoryServices { } } - public static Map completeInventoryTransfer(DispatchContext dctx, Map context) { + public static Map completeInventoryTransfer(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String inventoryTransferId = (String) context.get("inventoryTransferId"); GenericValue inventoryTransfer = null; @@ -216,10 +217,10 @@ public class InventoryServices { // 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 createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(qoh - atp), "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin); try { - Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); + Map 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 @@ public class InventoryServices { } // set the fields on the item - Map updateInventoryItemMap = UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"), + Map updateInventoryItemMap = UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"), "facilityId", inventoryTransfer.get("facilityIdTo"), "containerId", inventoryTransfer.get("containerIdTo"), "locationSeqId", inventoryTransfer.get("locationSeqIdTo"), @@ -256,7 +257,7 @@ public class InventoryServices { } } try { - Map result = dctx.getDispatcher().runSync("updateInventoryItem", updateInventoryItemMap); + Map result = dctx.getDispatcher().runSync("updateInventoryItem", updateInventoryItemMap); if (ServiceUtil.isError(result)) { return ServiceUtil.returnError("Inventory item store problem", null, null, result); } @@ -277,7 +278,7 @@ public class InventoryServices { return ServiceUtil.returnSuccess(); } - public static Map cancelInventoryTransfer(DispatchContext dctx, Map context) { + public static Map cancelInventoryTransfer(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String inventoryTransferId = (String) context.get("inventoryTransferId"); GenericValue inventoryTransfer = null; @@ -306,11 +307,11 @@ public class InventoryServices { // 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 createDetailMap = UtilMisc.toMap("availableToPromiseDiff", Double.valueOf(qoh - atp), "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin); try { - Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); + Map 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 @@ public class InventoryServices { } /** 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 checkInventoryAvailability(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); @@ -354,11 +355,11 @@ public class InventoryServices { } */ - Map ordersToUpdate = FastMap.newInstance(); - Map ordersToCancel = FastMap.newInstance(); + Map> ordersToUpdate = FastMap.newInstance(); + Map> ordersToCancel = FastMap.newInstance(); // find all inventory items w/ a negative ATP - List inventoryItems = null; + List 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 @@ public class InventoryServices { Debug.log("OOS Inventory Items: " + inventoryItems.size(), module); - Iterator itemsIter = inventoryItems.iterator(); + Iterator 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 shipmentAndItems = null; try { List exprs = FastList.newInstance(); exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, inventoryItem.get("productId"))); @@ -395,7 +395,7 @@ public class InventoryServices { } // get the reservations in order of newest first - List reservations = null; + List reservations = null; try { reservations = inventoryItem.getRelated("OrderItemShipGrpInvRes", null, UtilMisc.toList("-reservedDatetime")); } catch (GenericEntityException e) { @@ -414,9 +414,9 @@ public class InventoryServices { double availableBeforeReserved = inventoryItem.getDouble("availableToPromiseTotal").doubleValue(); // go through all the reservations in order - Iterator ri = reservations.iterator(); + Iterator 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 @@ public class InventoryServices { // find the next possible ship date Timestamp nextShipDate = null; double availableAtTime = 0.00; - Iterator si = shipmentAndItems.iterator(); + Iterator 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 @@ public class InventoryServices { } 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 notifyItems = ordersToUpdate.get(orderId); if (notifyItems == null) { notifyItems = FastMap.newInstance(); } @@ -494,7 +494,7 @@ public class InventoryServices { if (needToCancel) { // queue the item to be cancelled Debug.log("Flagging the item to auto-cancel", module); - Map cancelItems = (Map) ordersToCancel.get(orderId); + Map cancelItems = ordersToCancel.get(orderId); if (cancelItems == null) { cancelItems = FastMap.newInstance(); } @@ -518,17 +518,17 @@ public class InventoryServices { } // 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 ordersToNotify = FastList.newInstance(); + Set orderSet = ordersToUpdate.keySet(); + Iterator 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 backOrderedItems = ordersToUpdate.get(orderId); + Map cancelItems = ordersToCancel.get(orderId); boolean cancelAll = false; Timestamp cancelAllTime = null; - List orderItemShipGroups = null; + List orderItemShipGroups = null; try { orderItemShipGroups= delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId)); @@ -536,11 +536,11 @@ public class InventoryServices { Debug.logError(e, "Cannot get OrderItemShipGroups from orderId" + orderId, module); } - Iterator orderItemShipGroupsIter = orderItemShipGroups.iterator(); + Iterator 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 orderItems = FastList.newInstance(); + List orderItemShipGroupAssoc = null; try { orderItemShipGroupAssoc = delegator.findByAnd("OrderItemShipGroupAssoc", @@ -549,9 +549,9 @@ public class InventoryServices { "orderId", orderId)); - Iterator assocIter = orderItemShipGroupAssoc.iterator(); + Iterator 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 @@ public class InventoryServices { } if (orderItems != null) { - List toBeStored = FastList.newInstance(); - Iterator orderItemsIter = orderItems.iterator(); + List toBeStored = FastList.newInstance(); + Iterator 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 @@ public class InventoryServices { } // send off a notification for each order - Iterator orderNotifyIter = ordersToNotify.iterator(); + Iterator orderNotifyIter = ordersToNotify.iterator(); while (orderNotifyIter.hasNext()) { - String orderId = (String) orderNotifyIter.next(); + String orderId = orderNotifyIter.next(); try { dispatcher.runAsync("sendOrderBackorderNotification", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin)); @@ -643,9 +643,9 @@ public class InventoryServices { * 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 getProductInventoryAvailableFromAssocProducts(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); - List productAssocList = (List) context.get("assocProducts"); + List productAssocList = UtilGenerics.checkList(context.get("assocProducts")); String facilityId = (String)context.get("facilityId"); String statusId = (String)context.get("statusId"); @@ -659,7 +659,7 @@ public class InventoryServices { // 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 @@ public class InventoryServices { } // figure out the inventory available for this associated product - Map resultOutput = null; + Map resultOutput = null; try { - Map inputMap = UtilMisc.toMap("productId", productIdTo, "statusId", statusId); + Map inputMap = UtilMisc.toMap("productId", productIdTo, "statusId", statusId); if (facilityId != null) { inputMap.put("facilityId", facilityId); resultOutput = dispatcher.runSync("getInventoryAvailableByFacility", inputMap); @@ -708,26 +708,26 @@ public class InventoryServices { availableToPromiseTotal = Double.valueOf(minAvailableToPromiseTotal); } - Map result = ServiceUtil.returnSuccess(); + Map result = ServiceUtil.returnSuccess(); result.put("availableToPromiseTotal", availableToPromiseTotal); result.put("quantityOnHandTotal", quantityOnHandTotal); return result; } - public static Map getProductInventorySummaryForItems(DispatchContext dctx, Map context) { + public static Map getProductInventorySummaryForItems(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - List orderItems = (List) context.get("orderItems"); + List 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 atpMap = FastMap.newInstance(); + Map qohMap = FastMap.newInstance(); + Map mktgPkgAtpMap = FastMap.newInstance(); + Map mktgPkgQohMap = FastMap.newInstance(); + Map results = ServiceUtil.returnSuccess(); // get a list of all available facilities for looping - List facilities = null; + List facilities = null; try { if (facilityId != null) { facilities = delegator.findByAnd("Facility", UtilMisc.toMap("facilityId", facilityId)); @@ -739,9 +739,9 @@ public class InventoryServices { } // loop through all the order items - Iterator iter = orderItems.iterator(); + Iterator 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 @@ public class InventoryServices { double qoh = 0.0; double mktgPkgAtp = 0.0; double mktgPkgQoh = 0.0; - Iterator facilityIter = facilities.iterator(); + Iterator 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 invResult = null; + Map mktgPkgInvResult = null; // get both the real ATP/QOH available and the quantities available from marketing packages try { @@ -808,7 +808,7 @@ public class InventoryServices { } - public static Map getProductInventoryAndFacilitySummary(DispatchContext dctx, Map context) { + public static Map getProductInventoryAndFacilitySummary(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Timestamp checkTime = (Timestamp)context.get("checkTime"); @@ -817,10 +817,10 @@ public class InventoryServices { String minimumStock = (String)context.get("minimumStock"); String statusId = (String)context.get("statusId"); - Map result = FastMap.newInstance(); - Map resultOutput = FastMap.newInstance(); + Map result = FastMap.newInstance(); + Map resultOutput = FastMap.newInstance(); - Map contextInput = UtilMisc.toMap("productId", productId, "facilityId", facilityId, "statusId", statusId); + Map 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 @@ public class InventoryServices { result.put("offsetQOHQtyAvailable", Integer.valueOf(offsetQOHQtyAvailable)); result.put("offsetATPQtyAvailable", Integer.valueOf(offsetATPQtyAvailable)); - List productPrices = null; + List 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 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 @@ public class InventoryServices { // 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 @@ public class InventoryServices { // 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(); diff --git a/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java b/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java index ba3603e1f0..1cb3a4eacb 100644 --- a/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java +++ b/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java @@ -47,9 +47,9 @@ public class InventoryWorker { * @param delegator * @return */ - public static List getOutstandingPurchaseOrders(String productId, GenericDelegator delegator) { + public static List getOutstandingPurchaseOrders(String productId, GenericDelegator delegator) { try { - List purchaseOrderConditions = UtilMisc.toList(EntityCondition.makeCondition("orderStatusId", EntityOperator.NOT_EQUAL, "ORDER_COMPLETED"), + List purchaseOrderConditions = UtilMisc.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 @@ public class InventoryWorker { 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 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 class InventoryWorker { */ public static double getOutstandingPurchasedQuantity(String productId, GenericDelegator delegator) { double qty = 0.0; - List purchaseOrders = getOutstandingPurchaseOrders(productId, delegator); + List 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 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 @@ public class InventoryWorker { * @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 getOutstandingProductQuantities(Collection productIds, String orderTypeId, GenericDelegator delegator) { + Set fieldsToSelect = UtilMisc.toSet("productId", "quantityOpen"); + List condList = UtilMisc.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 @@ public class InventoryWorker { condList.add(EntityCondition.makeCondition("orderItemStatusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED")); EntityConditionList conditions = EntityCondition.makeCondition(condList, EntityOperator.AND); - Map results = FastMap.newInstance(); + Map 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 orderedProducts = delegator.findList("OrderItemQuantityReportGroupByProduct", conditions, fieldsToSelect, null, null, false); + for (Iterator iter = orderedProducts.iterator(); iter.hasNext(); ) { + GenericValue value = iter.next(); results.put(value.getString("productId"), value.getDouble("quantityOpen")); } } catch (GenericEntityException e) { @@ -136,12 +136,12 @@ public class InventoryWorker { } /** As above, but for sales orders */ - public static Map getOutstandingProductQuantitiesForSalesOrders(Collection productIds, GenericDelegator delegator) { + public static Map getOutstandingProductQuantitiesForSalesOrders(Collection 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 getOutstandingProductQuantitiesForPurchaseOrders(Collection productIds, GenericDelegator delegator) { return getOutstandingProductQuantities(productIds, "PURCHASE_ORDER", delegator); } } diff --git a/applications/product/src/org/ofbiz/product/price/PriceServices.java b/applications/product/src/org/ofbiz/product/price/PriceServices.java index d63d91c8dd..7f6b17f3ca 100644 --- a/applications/product/src/org/ofbiz/product/price/PriceServices.java +++ b/applications/product/src/org/ofbiz/product/price/PriceServices.java @@ -31,6 +31,7 @@ import javolution.util.FastMap; 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.UtilNumber; import org.ofbiz.base.util.UtilProperties; @@ -77,7 +78,7 @@ public class PriceServices { *
  • checkIncludeVat * */ - public static Map calculateProductPrice(DispatchContext dctx, Map context) { + public static Map calculateProductPrice(DispatchContext dctx, Map context) { boolean optimizeForLargeRuleSet = false; // UtilTimer utilTimer = new UtilTimer(); @@ -86,7 +87,7 @@ public class PriceServices { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - Map result = FastMap.newInstance(); + Map result = FastMap.newInstance(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); GenericValue product = (GenericValue) context.get("product"); @@ -95,7 +96,7 @@ public class PriceServices { String webSiteId = (String) context.get("webSiteId"); String checkIncludeVat = (String) context.get("checkIncludeVat"); String surveyResponseId = (String) context.get("surveyResponseId"); - Map customAttributes = (Map) context.get("customAttributes"); + Map customAttributes = UtilGenerics.checkMap(context.get("customAttributes")); String findAllQuantityPricesStr = (String) context.get("findAllQuantityPrices"); boolean findAllQuantityPrices = "Y".equals(findAllQuantityPricesStr); @@ -120,7 +121,7 @@ public class PriceServices { productStoreGroupId = productStore.getString("primaryStoreGroupId"); } else { // no ProductStore.primaryStoreGroupId, try ProductStoreGroupMember - List productStoreGroupMemberList = delegator.findByAndCache("ProductStoreGroupMember", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "-fromDate")); + List productStoreGroupMemberList = delegator.findByAndCache("ProductStoreGroupMember", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "-fromDate")); productStoreGroupMemberList = EntityUtil.filterByDate(productStoreGroupMemberList, true); if (productStoreGroupMemberList.size() > 0) { GenericValue productStoreGroupMember = EntityUtil.getFirst(productStoreGroupMemberList); @@ -169,7 +170,7 @@ public class PriceServices { } // get prices for virtual product if one is found; get all ProductPrice entities for this productId and currencyUomId - List virtualProductPrices = null; + List virtualProductPrices = null; if (virtualProductId != null) { try { virtualProductPrices = delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", virtualProductId, "currencyUomId", currencyUomId, "productStoreGroupId", productStoreGroupId), UtilMisc.toList("-fromDate")); @@ -198,7 +199,7 @@ public class PriceServices { Double amountDbl = (Double) context.get("amount"); - List productPriceEcList = FastList.newInstance(); + List productPriceEcList = FastList.newInstance(); productPriceEcList.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId)); // this funny statement is for backward compatibility purposes; the productPricePurposeId is a new pk field on the ProductPrice entity and in order databases may not be populated, until the pk is updated and such; this will ease the transition somewhat if ("PURCHASE".equals(productPricePurposeId)) { @@ -217,7 +218,7 @@ public class PriceServices { EntityCondition productPriceEc = EntityCondition.makeCondition(productPriceEcList, EntityOperator.AND); // for prices, get all ProductPrice entities for this productId and currencyUomId - List productPrices = null; + List productPrices = null; try { productPrices = delegator.findList("ProductPrice", productPriceEc, null, UtilMisc.toList("-fromDate"), null, true); } catch (GenericEntityException e) { @@ -226,13 +227,13 @@ public class PriceServices { productPrices = EntityUtil.filterByDate(productPrices, true); // ===== get the prices we need: list, default, average cost, promo, min, max ===== - List listPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); + List listPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); GenericValue listPriceValue = EntityUtil.getFirst(listPrices); if (listPrices != null && listPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module); } - List defaultPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); + List defaultPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); GenericValue defaultPriceValue = EntityUtil.getFirst(defaultPrices); if (defaultPrices != null && defaultPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module); @@ -243,7 +244,7 @@ public class PriceServices { // ProductPrice entity. if (UtilValidate.isNotEmpty(agreementId)) { try { - List agreementPrices = delegator.findByAnd("AgreementItemAndProductAppl", UtilMisc.toMap("agreementId", agreementId, "productId", productId, "currencyUomId", currencyUomId)); + List agreementPrices = delegator.findByAnd("AgreementItemAndProductAppl", UtilMisc.toMap("agreementId", agreementId, "productId", productId, "currencyUomId", currencyUomId)); GenericValue agreementPriceValue = EntityUtil.getFirst(agreementPrices); if (agreementPriceValue != null && agreementPriceValue.get("price") != null) { defaultPriceValue = agreementPriceValue; @@ -255,43 +256,43 @@ public class PriceServices { } } - List competitivePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE")); + List competitivePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE")); GenericValue competitivePriceValue = EntityUtil.getFirst(competitivePrices); if (competitivePrices != null && competitivePrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + competitivePriceValue.getDouble("price"), module); } - List averageCosts = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); + List averageCosts = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); GenericValue averageCostValue = EntityUtil.getFirst(averageCosts); if (averageCosts != null && averageCosts.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module); } - List promoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); + List promoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); GenericValue promoPriceValue = EntityUtil.getFirst(promoPrices); if (promoPrices != null && promoPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module); } - List minimumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); + List minimumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); GenericValue minimumPriceValue = EntityUtil.getFirst(minimumPrices); if (minimumPrices != null && minimumPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module); } - List maximumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); + List maximumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); GenericValue maximumPriceValue = EntityUtil.getFirst(maximumPrices); if (maximumPrices != null && maximumPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module); } - List wholesalePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); + List wholesalePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); GenericValue wholesalePriceValue = EntityUtil.getFirst(wholesalePrices); if (wholesalePrices != null && wholesalePrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module); } - List specialPromoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); + List specialPromoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); GenericValue specialPromoPriceValue = EntityUtil.getFirst(specialPromoPrices); if (specialPromoPrices != null && specialPromoPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + specialPromoPriceValue.getDouble("price"), module); @@ -300,56 +301,56 @@ public class PriceServices { // if any of these prices is missing and this product is a variant, default to the corresponding price on the virtual product if (UtilValidate.isNotEmpty(virtualProductPrices)) { if (listPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); listPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module); } } if (defaultPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); defaultPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module); } } if (averageCostValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); averageCostValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module); } } if (promoPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); promoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module); } } if (minimumPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); minimumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module); } } if (maximumPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); maximumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module); } } if (wholesalePriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module); } } if (specialPromoPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + specialPromoPriceValue.getDouble("price"), module); @@ -365,16 +366,16 @@ public class PriceServices { //use the cache to find the variant with the lowest default price try { - List variantAssocList = EntityUtil.filterByDate(delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"))); - Iterator variantAssocIter = variantAssocList.iterator(); + List variantAssocList = EntityUtil.filterByDate(delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"))); + Iterator variantAssocIter = variantAssocList.iterator(); double minDefaultPrice = Double.MAX_VALUE; - List variantProductPrices = null; + List variantProductPrices = null; String variantProductId = null; while (variantAssocIter.hasNext()) { - GenericValue variantAssoc = (GenericValue) variantAssocIter.next(); + GenericValue variantAssoc = variantAssocIter.next(); String curVariantProductId = variantAssoc.getString("productIdTo"); - List curVariantPriceList = EntityUtil.filterByDate(delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", curVariantProductId), UtilMisc.toList("-fromDate")), nowTimestamp); - List tempDefaultPriceList = EntityUtil.filterByAnd(curVariantPriceList, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); + List curVariantPriceList = EntityUtil.filterByDate(delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", curVariantProductId), UtilMisc.toList("-fromDate")), nowTimestamp); + List tempDefaultPriceList = EntityUtil.filterByAnd(curVariantPriceList, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); GenericValue curDefaultPriceValue = EntityUtil.getFirst(tempDefaultPriceList); if (curDefaultPriceValue != null) { Double curDefaultPrice = curDefaultPriceValue.getDouble("price"); @@ -397,63 +398,63 @@ public class PriceServices { if (variantProductPrices != null) { // we have some other options, give 'em a go... if (listPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE")); listPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module); } } if (defaultPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); defaultPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module); } } if (competitivePriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE")); competitivePriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + competitivePriceValue.getDouble("price"), module); } } if (averageCostValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); averageCostValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module); } } if (promoPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE")); promoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module); } } if (minimumPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE")); minimumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module); } } if (maximumPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE")); maximumPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module); } } if (wholesalePriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE")); wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module); } } if (specialPromoPriceValue == null) { - List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); + List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE")); specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices); if (virtualTempPrices != null && virtualTempPrices.size() > 1) { if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module); @@ -482,7 +483,7 @@ public class PriceServices { boolean validPriceFound = false; double defaultPrice = 0; - List orderItemPriceInfos = FastList.newInstance(); + List orderItemPriceInfos = FastList.newInstance(); if (defaultPriceValue != null) { // If a price calc formula (service) is specified, then use it to get the unit price if ("ProductPrice".equals(defaultPriceValue.getEntityName()) && UtilValidate.isNotEmpty(defaultPriceValue.getString("customPriceCalcService"))) { @@ -493,8 +494,8 @@ public class PriceServices { Debug.logError(gee, "An error occurred while getting the customPriceCalcService", module); } if (UtilValidate.isNotEmpty(customMethod) && UtilValidate.isNotEmpty(customMethod.getString("customMethodName"))) { - Map inMap = UtilMisc.toMap("userLogin", (GenericValue) context.get("userLogin"), "product", product); - inMap.put("initialPrice", (Double)defaultPriceValue.get("price")); + Map inMap = UtilMisc.toMap("userLogin", context.get("userLogin"), "product", product); + inMap.put("initialPrice", defaultPriceValue.get("price")); inMap.put("currencyUomId", currencyUomId); inMap.put("quantity", quantityDbl); inMap.put("amount", amountDbl); @@ -505,10 +506,10 @@ public class PriceServices { inMap.put("customAttributes", customAttributes); } try { - Map outMap = dispatcher.runSync(customMethod.getString("customMethodName"), inMap); + Map outMap = dispatcher.runSync(customMethod.getString("customMethodName"), inMap); if (!ServiceUtil.isError(outMap)) { Double calculatedDefaultPrice = (Double)outMap.get("price"); - orderItemPriceInfos = (List)outMap.get("orderItemPriceInfos"); + orderItemPriceInfos = UtilGenerics.checkList(outMap.get("orderItemPriceInfos")); if (UtilValidate.isNotEmpty(calculatedDefaultPrice)) { defaultPrice = calculatedDefaultPrice.doubleValue(); validPriceFound = true; @@ -554,30 +555,30 @@ public class PriceServices { result.put("isSale", Boolean.FALSE); result.put("orderItemPriceInfos", orderItemPriceInfos); - Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, + Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (errorResult != null) return errorResult; } else { try { - List allProductPriceRules = makeProducePriceRuleList(delegator, optimizeForLargeRuleSet, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, currencyUomId); + List allProductPriceRules = makeProducePriceRuleList(delegator, optimizeForLargeRuleSet, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, currencyUomId); - List quantityProductPriceRules = null; - List nonQuantityProductPriceRules = null; + List quantityProductPriceRules = null; + List nonQuantityProductPriceRules = null; if (findAllQuantityPrices) { // split into list with quantity conditions and list without, then iterate through each quantity cond one quantityProductPriceRules = FastList.newInstance(); nonQuantityProductPriceRules = FastList.newInstance(); - Iterator productPriceRulesIter = allProductPriceRules.iterator(); + Iterator productPriceRulesIter = allProductPriceRules.iterator(); while (productPriceRulesIter.hasNext()) { - GenericValue productPriceRule = (GenericValue) productPriceRulesIter.next(); - List productPriceCondList = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRule.get("productPriceRuleId"))); + GenericValue productPriceRule = productPriceRulesIter.next(); + List productPriceCondList = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRule.get("productPriceRuleId"))); boolean foundQuantityInputParam = false; // only consider a rule if all conditions except the quantity condition are true boolean allExceptQuantTrue = true; - Iterator productPriceCondIter = productPriceCondList.iterator(); + Iterator productPriceCondIter = productPriceCondList.iterator(); while (productPriceCondIter.hasNext()) { - GenericValue productPriceCond = (GenericValue) productPriceCondIter.next(); + GenericValue productPriceCond = productPriceCondIter.next(); if ("PRIP_QUANTITY".equals(productPriceCond.getString("inputParamEnumId"))) { foundQuantityInputParam = true; } else { @@ -596,23 +597,23 @@ public class PriceServices { } if (findAllQuantityPrices) { - List allQuantityPrices = FastList.newInstance(); + List> allQuantityPrices = FastList.newInstance(); // if findAllQuantityPrices then iterate through quantityProductPriceRules // foreach create an entry in the out list and eval that rule and all nonQuantityProductPriceRules rather than a single rule - Iterator quantityProductPriceRuleIter = quantityProductPriceRules.iterator(); + Iterator quantityProductPriceRuleIter = quantityProductPriceRules.iterator(); while (quantityProductPriceRuleIter.hasNext()) { - GenericValue quantityProductPriceRule = (GenericValue) quantityProductPriceRuleIter.next(); - - List ruleListToUse = FastList.newInstance(); + GenericValue quantityProductPriceRule = quantityProductPriceRuleIter.next(); + + List ruleListToUse = FastList.newInstance(); ruleListToUse.add(quantityProductPriceRule); ruleListToUse.addAll(nonQuantityProductPriceRules); - Map quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPriceDbl.doubleValue(), defaultPrice, promoPrice, + Map quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPriceDbl.doubleValue(), defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, null, currencyUomId, delegator, nowTimestamp); - Map quantErrorResult = addGeneralResults(quantCalcResults, competitivePriceValue, specialPromoPriceValue, productStore, + Map quantErrorResult = addGeneralResults(quantCalcResults, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (quantErrorResult != null) return quantErrorResult; @@ -624,7 +625,7 @@ public class PriceServices { result.put("allQuantityPrices", allQuantityPrices); // use a quantity 1 to get the main price, then fill in the quantity break prices - Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPriceDbl.doubleValue(), defaultPrice, promoPrice, + Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPriceDbl.doubleValue(), defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, Double.valueOf(1.0), currencyUomId, delegator, nowTimestamp); @@ -632,17 +633,17 @@ public class PriceServices { // The orderItemPriceInfos out parameter requires a special treatment: // the list of OrderItemPriceInfos generated by the price rule is appended to // the existing orderItemPriceInfos list and the aggregated list is returned. - List orderItemPriceInfosFromRule = (List)calcResults.get("orderItemPriceInfos"); + List orderItemPriceInfosFromRule = UtilGenerics.checkList(calcResults.get("orderItemPriceInfos")); if (UtilValidate.isNotEmpty(orderItemPriceInfosFromRule)) { orderItemPriceInfos.addAll(orderItemPriceInfosFromRule); } result.put("orderItemPriceInfos", orderItemPriceInfos); - Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, + Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (errorResult != null) return errorResult; } else { - Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPriceDbl.doubleValue(), defaultPrice, promoPrice, + Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPriceDbl.doubleValue(), defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, Double.valueOf(quantity), currencyUomId, delegator, nowTimestamp); @@ -650,13 +651,13 @@ public class PriceServices { // The orderItemPriceInfos out parameter requires a special treatment: // the list of OrderItemPriceInfos generated by the price rule is appended to // the existing orderItemPriceInfos list and the aggregated list is returned. - List orderItemPriceInfosFromRule = (List)calcResults.get("orderItemPriceInfos"); + List orderItemPriceInfosFromRule = UtilGenerics.checkList(calcResults.get("orderItemPriceInfos")); if (UtilValidate.isNotEmpty(orderItemPriceInfosFromRule)) { orderItemPriceInfos.addAll(orderItemPriceInfosFromRule); } result.put("orderItemPriceInfos", orderItemPriceInfos); - Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, + Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (errorResult != null) return errorResult; } @@ -670,7 +671,7 @@ public class PriceServices { return result; } - public static Map addGeneralResults(Map result, GenericValue competitivePriceValue, GenericValue specialPromoPriceValue, GenericValue productStore, + public static Map addGeneralResults(Map result, GenericValue competitivePriceValue, GenericValue specialPromoPriceValue, GenericValue productStore, String checkIncludeVat, String currencyUomId, String productId, double quantity, String partyId, LocalDispatcher dispatcher) { result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getDouble("price") : null); result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getDouble("price") : null); @@ -678,7 +679,7 @@ public class PriceServices { // okay, now we have the calculated price, see if we should add in tax and if so do it if ("Y".equals(checkIncludeVat) && productStore != null && "Y".equals(productStore.getString("showPricesWithVatTax"))) { - Map calcTaxForDisplayContext = UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), + Map calcTaxForDisplayContext = UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), "productId", productId, "quantity", BigDecimal.valueOf(quantity), "basePrice", BigDecimal.valueOf(((Double) result.get("price")).doubleValue())); if (UtilValidate.isNotEmpty(partyId)) { @@ -686,7 +687,7 @@ public class PriceServices { } try { - Map calcTaxForDisplayResult = dispatcher.runSync("calcTaxForDisplay", calcTaxForDisplayContext); + Map calcTaxForDisplayResult = dispatcher.runSync("calcTaxForDisplay", calcTaxForDisplayContext); if (ServiceUtil.isError(calcTaxForDisplayResult)) { return ServiceUtil.returnError("Error calculating VAT tax (with calcTaxForDisplay service)", null, null, calcTaxForDisplayResult); } @@ -721,8 +722,8 @@ public class PriceServices { return null; } - public static List makeProducePriceRuleList(GenericDelegator delegator, boolean optimizeForLargeRuleSet, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, String webSiteId, String partyId, String currencyUomId) throws GenericEntityException { - List productPriceRules = null; + public static List makeProducePriceRuleList(GenericDelegator delegator, boolean optimizeForLargeRuleSet, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, String webSiteId, String partyId, String currencyUomId) throws GenericEntityException { + List productPriceRules = null; // At this point we have two options: optimize for large ruleset, or optimize for small ruleset // NOTE: This only effects the way that the rules to be evaluated are selected. @@ -731,28 +732,28 @@ public class PriceServices { if (optimizeForLargeRuleSet) { // ========= find all rules that must be run for each input type; this is kind of like a pre-filter to slim down the rules to run ========= // utilTimer.timerString("Before create rule id list", module); - TreeSet productPriceRuleIds = new TreeSet(); + TreeSet productPriceRuleIds = new TreeSet(); // ------- These are all of the conditions that DON'T depend on the current inputs ------- // by productCategoryId // for we will always include any rules that go by category, shouldn't be too many to iterate through each time and will save on cache entries // note that we always want to put the category, quantity, etc ones that find all rules with these conditions in separate cache lists so that they can be easily cleared - Collection productCategoryIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CAT_ID")); + Collection productCategoryIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CAT_ID")); if (UtilValidate.isNotEmpty(productCategoryIdConds)) { - Iterator productCategoryIdCondsIter = productCategoryIdConds.iterator(); + Iterator productCategoryIdCondsIter = productCategoryIdConds.iterator(); while (productCategoryIdCondsIter.hasNext()) { - GenericValue productCategoryIdCond = (GenericValue) productCategoryIdCondsIter.next(); + GenericValue productCategoryIdCond = productCategoryIdCondsIter.next(); productPriceRuleIds.add(productCategoryIdCond.getString("productPriceRuleId")); } } // by productFeatureId - Collection productFeatureIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_FEAT_ID")); + Collection productFeatureIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_FEAT_ID")); if (UtilValidate.isNotEmpty(productFeatureIdConds)) { - Iterator productFeatureIdCondsIter = productFeatureIdConds.iterator(); + Iterator productFeatureIdCondsIter = productFeatureIdConds.iterator(); while (productFeatureIdCondsIter.hasNext()) { - GenericValue productFeatureIdCond = (GenericValue) productFeatureIdCondsIter.next(); + GenericValue productFeatureIdCond = productFeatureIdCondsIter.next(); productPriceRuleIds.add(productFeatureIdCond.getString("productPriceRuleId")); } } @@ -760,21 +761,21 @@ public class PriceServices { // by quantity -- should we really do this one, ie is it necessary? // we could say that all rules with quantity on them must have one of these other values // but, no we'll do it the other way, any that have a quantity will always get compared - Collection quantityConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_QUANTITY")); + Collection quantityConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_QUANTITY")); if (UtilValidate.isNotEmpty(quantityConds)) { - Iterator quantityCondsIter = quantityConds.iterator(); + Iterator quantityCondsIter = quantityConds.iterator(); while (quantityCondsIter.hasNext()) { - GenericValue quantityCond = (GenericValue) quantityCondsIter.next(); + GenericValue quantityCond = quantityCondsIter.next(); productPriceRuleIds.add(quantityCond.getString("productPriceRuleId")); } } // by roleTypeId - Collection roleTypeIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_ROLE_TYPE")); + Collection roleTypeIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_ROLE_TYPE")); if (UtilValidate.isNotEmpty(roleTypeIdConds)) { - Iterator roleTypeIdCondsIter = roleTypeIdConds.iterator(); + Iterator roleTypeIdCondsIter = roleTypeIdConds.iterator(); while (roleTypeIdCondsIter.hasNext()) { - GenericValue roleTypeIdCond = (GenericValue) roleTypeIdCondsIter.next(); + GenericValue roleTypeIdCond = roleTypeIdCondsIter.next(); productPriceRuleIds.add(roleTypeIdCond.getString("productPriceRuleId")); } } @@ -784,11 +785,11 @@ public class PriceServices { // later: (by partyClassificationTypeId) // by listPrice - Collection listPriceConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_LIST_PRICE")); + Collection listPriceConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_LIST_PRICE")); if (UtilValidate.isNotEmpty(listPriceConds)) { - Iterator listPriceCondsIter = listPriceConds.iterator(); + Iterator listPriceCondsIter = listPriceConds.iterator(); while (listPriceCondsIter.hasNext()) { - GenericValue listPriceCond = (GenericValue) listPriceCondsIter.next(); + GenericValue listPriceCond = listPriceCondsIter.next(); productPriceRuleIds.add(listPriceCond.getString("productPriceRuleId")); } } @@ -796,22 +797,22 @@ public class PriceServices { // ------- These are all of them that DO depend on the current inputs ------- // by productId - Collection productIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId)); + Collection productIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", productId)); if (UtilValidate.isNotEmpty(productIdConds)) { - Iterator productIdCondsIter = productIdConds.iterator(); + Iterator productIdCondsIter = productIdConds.iterator(); while (productIdCondsIter.hasNext()) { - GenericValue productIdCond = (GenericValue) productIdCondsIter.next(); + GenericValue productIdCond = productIdCondsIter.next(); productPriceRuleIds.add(productIdCond.getString("productPriceRuleId")); } } // by virtualProductId, if not null if (virtualProductId != null) { - Collection virtualProductIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId)); + Collection virtualProductIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PRODUCT_ID", "condValue", virtualProductId)); if (UtilValidate.isNotEmpty(virtualProductIdConds)) { - Iterator virtualProductIdCondsIter = virtualProductIdConds.iterator(); + Iterator virtualProductIdCondsIter = virtualProductIdConds.iterator(); while (virtualProductIdCondsIter.hasNext()) { - GenericValue virtualProductIdCond = (GenericValue) virtualProductIdCondsIter.next(); + GenericValue virtualProductIdCond = virtualProductIdCondsIter.next(); productPriceRuleIds.add(virtualProductIdCond.getString("productPriceRuleId")); } } @@ -819,11 +820,11 @@ public class PriceServices { // by prodCatalogId - which is optional in certain cases if (UtilValidate.isNotEmpty(prodCatalogId)) { - Collection prodCatalogIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId)); + Collection prodCatalogIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_CLG_ID", "condValue", prodCatalogId)); if (UtilValidate.isNotEmpty(prodCatalogIdConds)) { - Iterator prodCatalogIdCondsIter = prodCatalogIdConds.iterator(); + Iterator prodCatalogIdCondsIter = prodCatalogIdConds.iterator(); while (prodCatalogIdCondsIter.hasNext()) { - GenericValue prodCatalogIdCond = (GenericValue) prodCatalogIdCondsIter.next(); + GenericValue prodCatalogIdCond = prodCatalogIdCondsIter.next(); productPriceRuleIds.add(prodCatalogIdCond.getString("productPriceRuleId")); } } @@ -831,11 +832,11 @@ public class PriceServices { // by productStoreGroupId if (UtilValidate.isNotEmpty(productStoreGroupId)) { - Collection storeGroupConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId)); + Collection storeGroupConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PROD_SGRP_ID", "condValue", productStoreGroupId)); if (UtilValidate.isNotEmpty(storeGroupConds)) { - Iterator storeGroupCondsIter = storeGroupConds.iterator(); + Iterator storeGroupCondsIter = storeGroupConds.iterator(); while (storeGroupCondsIter.hasNext()) { - GenericValue storeGroupCond = (GenericValue) storeGroupCondsIter.next(); + GenericValue storeGroupCond = storeGroupCondsIter.next(); productPriceRuleIds.add(storeGroupCond.getString("productPriceRuleId")); } } @@ -843,11 +844,11 @@ public class PriceServices { // by webSiteId if (UtilValidate.isNotEmpty(webSiteId)) { - Collection webSiteIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId)); + Collection webSiteIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_WEBSITE_ID", "condValue", webSiteId)); if (UtilValidate.isNotEmpty(webSiteIdConds)) { - Iterator webSiteIdCondsIter = webSiteIdConds.iterator(); + Iterator webSiteIdCondsIter = webSiteIdConds.iterator(); while (webSiteIdCondsIter.hasNext()) { - GenericValue webSiteIdCond = (GenericValue) webSiteIdCondsIter.next(); + GenericValue webSiteIdCond = webSiteIdCondsIter.next(); productPriceRuleIds.add(webSiteIdCond.getString("productPriceRuleId")); } } @@ -855,30 +856,30 @@ public class PriceServices { // by partyId if (UtilValidate.isNotEmpty(partyId)) { - Collection partyIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId)); + Collection partyIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_PARTY_ID", "condValue", partyId)); if (UtilValidate.isNotEmpty(partyIdConds)) { - Iterator partyIdCondsIter = partyIdConds.iterator(); + Iterator partyIdCondsIter = partyIdConds.iterator(); while (partyIdCondsIter.hasNext()) { - GenericValue partyIdCond = (GenericValue) partyIdCondsIter.next(); + GenericValue partyIdCond = partyIdCondsIter.next(); productPriceRuleIds.add(partyIdCond.getString("productPriceRuleId")); } } } // by currencyUomId - Collection currencyUomIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId)); + Collection currencyUomIdConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("inputParamEnumId", "PRIP_CURRENCY_UOMID", "condValue", currencyUomId)); if (UtilValidate.isNotEmpty(currencyUomIdConds)) { - Iterator currencyUomIdCondsIter = currencyUomIdConds.iterator(); + Iterator currencyUomIdCondsIter = currencyUomIdConds.iterator(); while (currencyUomIdCondsIter.hasNext()) { - GenericValue currencyUomIdCond = (GenericValue) currencyUomIdCondsIter.next(); + GenericValue currencyUomIdCond = currencyUomIdCondsIter.next(); productPriceRuleIds.add(currencyUomIdCond.getString("productPriceRuleId")); } } productPriceRules = FastList.newInstance(); - Iterator productPriceRuleIdsIter = productPriceRuleIds.iterator(); + Iterator productPriceRuleIdsIter = productPriceRuleIds.iterator(); while (productPriceRuleIdsIter.hasNext()) { - String productPriceRuleId = (String) productPriceRuleIdsIter.next(); + String productPriceRuleId = productPriceRuleIdsIter.next(); GenericValue productPriceRule = delegator.findByPrimaryKeyCache("ProductPriceRule", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); if (productPriceRule == null) continue; productPriceRules.add(productPriceRule); @@ -896,14 +897,14 @@ public class PriceServices { return productPriceRules; } - public static Map calcPriceResultFromRules(List productPriceRules, double listPrice, double defaultPrice, double promoPrice, + public static Map calcPriceResultFromRules(List productPriceRules, double listPrice, double defaultPrice, double promoPrice, double wholesalePrice, GenericValue maximumPriceValue, GenericValue minimumPriceValue, boolean validPriceFound, GenericValue averageCostValue, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, String webSiteId, String partyId, Double quantity, String currencyUomId, GenericDelegator delegator, Timestamp nowTimestamp) throws GenericEntityException { - Map calcResults = FastMap.newInstance(); + Map calcResults = FastMap.newInstance(); - List orderItemPriceInfos = FastList.newInstance(); + List orderItemPriceInfos = FastList.newInstance(); boolean isSale = false; // ========= go through each price rule by id and eval all conditions ========= @@ -919,9 +920,9 @@ public class PriceServices { // calculate running sum based on listPrice and rules found double price = listPrice; - Iterator productPriceRulesIter = productPriceRules.iterator(); + Iterator productPriceRulesIter = productPriceRules.iterator(); while (productPriceRulesIter.hasNext()) { - GenericValue productPriceRule = (GenericValue) productPriceRulesIter.next(); + GenericValue productPriceRule = productPriceRulesIter.next(); String productPriceRuleId = productPriceRule.getString("productPriceRuleId"); // check from/thru dates @@ -940,11 +941,11 @@ public class PriceServices { // check all conditions boolean allTrue = true; StringBuilder condsDescription = new StringBuilder(); - List productPriceConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); - Iterator productPriceCondsIter = UtilMisc.toIterator(productPriceConds); + List productPriceConds = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); + Iterator productPriceCondsIter = UtilMisc.toIterator(productPriceConds); while (productPriceCondsIter != null && productPriceCondsIter.hasNext()) { - GenericValue productPriceCond = (GenericValue) productPriceCondsIter.next(); + GenericValue productPriceCond = productPriceCondsIter.next(); totalConds++; @@ -985,11 +986,11 @@ public class PriceServices { isSale = true; } - Collection productPriceActions = delegator.findByAndCache("ProductPriceAction", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); - Iterator productPriceActionsIter = UtilMisc.toIterator(productPriceActions); + Collection productPriceActions = delegator.findByAndCache("ProductPriceAction", UtilMisc.toMap("productPriceRuleId", productPriceRuleId)); + Iterator productPriceActionsIter = UtilMisc.toIterator(productPriceActions); while (productPriceActionsIter != null && productPriceActionsIter.hasNext()) { - GenericValue productPriceAction = (GenericValue) productPriceActionsIter.next(); + GenericValue productPriceAction = productPriceActionsIter.next(); totalActions++; @@ -1109,10 +1110,9 @@ public class PriceServices { if (Debug.verboseOn()) { Debug.logVerbose("Unchecked Calculated price: " + price, module); Debug.logVerbose("PriceInfo:", module); - Iterator orderItemPriceInfosIter = orderItemPriceInfos.iterator(); + Iterator orderItemPriceInfosIter = orderItemPriceInfos.iterator(); while (orderItemPriceInfosIter.hasNext()) { - GenericValue orderItemPriceInfo = (GenericValue) orderItemPriceInfosIter.next(); - + GenericValue orderItemPriceInfo = orderItemPriceInfosIter.next(); Debug.logVerbose(" --- " + orderItemPriceInfo.toString(), module); } } @@ -1164,7 +1164,7 @@ public class PriceServices { } else if ("PRIP_PROD_CAT_ID".equals(productPriceCond.getString("inputParamEnumId"))) { // if a ProductCategoryMember exists for this productId and the specified productCategoryId String productCategoryId = productPriceCond.getString("condValue"); - List productCategoryMembers = delegator.findByAndCache("ProductCategoryMember", + List productCategoryMembers = delegator.findByAndCache("ProductCategoryMember", UtilMisc.toMap("productId", productId, "productCategoryId", productCategoryId)); // and from/thru date within range productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, nowTimestamp, null, null, true); @@ -1179,7 +1179,7 @@ public class PriceServices { // NOTE: this is important becuase of the common scenario where a virtual product is a member of a category but the variants will typically NOT be // NOTE: we may want to parameterize this in the future, ie with an indicator on the ProductPriceCond entity if (compare == 1 && UtilValidate.isNotEmpty(virtualProductId)) { - List virtualProductCategoryMembers = delegator.findByAndCache("ProductCategoryMember", + List virtualProductCategoryMembers = delegator.findByAndCache("ProductCategoryMember", UtilMisc.toMap("productId", virtualProductId, "productCategoryId", productCategoryId)); // and from/thru date within range virtualProductCategoryMembers = EntityUtil.filterByDate(virtualProductCategoryMembers, nowTimestamp, null, null, true); @@ -1193,7 +1193,7 @@ public class PriceServices { // if a ProductFeatureAppl exists for this productId and the specified productFeatureId String productFeatureId = productPriceCond.getString("condValue"); - List productFeatureAppls = delegator.findByAndCache("ProductFeatureAppl", + List productFeatureAppls = delegator.findByAndCache("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId)); // and from/thru date within range productFeatureAppls = EntityUtil.filterByDate(productFeatureAppls, nowTimestamp, null, null, true); @@ -1245,7 +1245,7 @@ public class PriceServices { compare = 0; } else { // look for PartyRelationship with partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is the group member, so the partyIdFrom is the groupPartyId - List partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP")); + List partyRelationshipList = delegator.findByAndCache("PartyRelationship", UtilMisc.toMap("partyIdFrom", groupPartyId, "partyIdTo", partyId, "partyRelationshipTypeId", "GROUP_ROLLUP")); // and from/thru date within range partyRelationshipList = EntityUtil.filterByDate(partyRelationshipList, nowTimestamp, null, null, true); // then 0 (equals), otherwise 1 (not equals) @@ -1253,7 +1253,7 @@ public class PriceServices { compare = 0; } else { // before setting 1 try one more query: look for a 2 hop relationship - List partyRelationshipTwoHopList = delegator.findByAndCache("PartyRelationshipToFrom", UtilMisc.toMap("onePartyIdFrom", groupPartyId, "twoPartyIdTo", partyId, "onePartyRelationshipTypeId", "GROUP_ROLLUP", "twoPartyRelationshipTypeId", "GROUP_ROLLUP")); + List partyRelationshipTwoHopList = delegator.findByAndCache("PartyRelationshipToFrom", UtilMisc.toMap("onePartyIdFrom", groupPartyId, "twoPartyIdTo", partyId, "onePartyRelationshipTypeId", "GROUP_ROLLUP", "twoPartyRelationshipTypeId", "GROUP_ROLLUP")); partyRelationshipTwoHopList = EntityUtil.filterByDate(partyRelationshipTwoHopList, nowTimestamp, "oneFromDate", "oneThruDate", true); partyRelationshipTwoHopList = EntityUtil.filterByDate(partyRelationshipTwoHopList, nowTimestamp, "twoFromDate", "twoThruDate", true); if (UtilValidate.isNotEmpty(partyRelationshipTwoHopList)) { @@ -1270,7 +1270,7 @@ public class PriceServices { } else { String partyClassificationGroupId = productPriceCond.getString("condValue"); // find any PartyClassification - List partyClassificationList = delegator.findByAndCache("PartyClassification", UtilMisc.toMap("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId)); + List partyClassificationList = delegator.findByAndCache("PartyClassification", UtilMisc.toMap("partyId", partyId, "partyClassificationGroupId", partyClassificationGroupId)); // and from/thru date within range partyClassificationList = EntityUtil.filterByDate(partyClassificationList, nowTimestamp, null, null, true); // then 0 (equals), otherwise 1 (not equals) @@ -1330,12 +1330,12 @@ public class PriceServices { /** * Calculates the purchase price of a product */ - public static Map calculatePurchasePrice(DispatchContext dctx, Map context) { + public static Map calculatePurchasePrice(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - Map result = FastMap.newInstance(); + Map result = FastMap.newInstance(); - List orderItemPriceInfos = FastList.newInstance(); + List orderItemPriceInfos = FastList.newInstance(); boolean validPriceFound = false; double price = 0.0; @@ -1350,23 +1350,23 @@ public class PriceServices { // b) If no price can be found, get the lastPrice from the SupplierProduct entity if (!validPriceFound) { - Map priceContext = UtilMisc.toMap("currencyUomId", currencyUomId, "partyId", partyId, "productId", productId, "quantity", quantity); - List productSuppliers = null; + Map priceContext = UtilMisc.toMap("currencyUomId", currencyUomId, "partyId", partyId, "productId", productId, "quantity", quantity); + List productSuppliers = null; try { - Map priceResult = dispatcher.runSync("getSuppliersForProduct", priceContext); + Map priceResult = dispatcher.runSync("getSuppliersForProduct", priceContext); if (ServiceUtil.isError(priceResult)) { String errMsg = ServiceUtil.getErrorMessage(priceResult); Debug.logError(errMsg, module); return ServiceUtil.returnError(errMsg); } - productSuppliers = (List) priceResult.get("supplierProducts"); + productSuppliers = UtilGenerics.checkList(priceResult.get("supplierProducts")); } catch(GenericServiceException gse) { Debug.logError(gse, module); return ServiceUtil.returnError(gse.getMessage()); } if (productSuppliers != null) { for (int i = 0; i < productSuppliers.size(); i++) { - GenericValue productSupplier = (GenericValue) productSuppliers.get(i); + GenericValue productSupplier = productSuppliers.get(i); if (!validPriceFound) { price = ((Double)productSupplier.get("lastPrice")).doubleValue(); validPriceFound = true; @@ -1375,8 +1375,8 @@ public class PriceServices { StringBuilder priceInfoDescription = new StringBuilder(); priceInfoDescription.append("SupplierProduct "); priceInfoDescription.append("[minimumOrderQuantity:"); - priceInfoDescription.append("" + productSupplier.getDouble("minimumOrderQuantity").doubleValue()); - priceInfoDescription.append(", lastPrice: " + productSupplier.getDouble("lastPrice").doubleValue()); + priceInfoDescription.append(productSupplier.getDouble("minimumOrderQuantity")); + priceInfoDescription.append(", lastPrice: ").append(productSupplier.getDouble("lastPrice")); priceInfoDescription.append("]"); GenericValue orderItemPriceInfo = delegator.makeValue("OrderItemPriceInfo"); //orderItemPriceInfo.set("productPriceRuleId", productPriceAction.get("productPriceRuleId")); @@ -1395,7 +1395,7 @@ public class PriceServices { // c) If no price can be found, get the averageCost from the ProductPrice entity if (!validPriceFound) { - List prices = null; + List prices = null; try { prices = delegator.findByAnd("ProductPrice", UtilMisc.toMap("productId", productId, "productPricePurposeId", "PURCHASE"), UtilMisc.toList("-fromDate")); @@ -1418,7 +1418,7 @@ public class PriceServices { prices = EntityUtil.filterByDate(prices); // first check for the AVERAGE_COST price type - List pricesToUse = EntityUtil.filterByAnd(prices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); + List pricesToUse = EntityUtil.filterByAnd(prices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST")); if (pricesToUse == null || pricesToUse.size() == 0) { // next go with default price pricesToUse = EntityUtil.filterByAnd(prices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE")); diff --git a/applications/product/src/org/ofbiz/product/promo/PromoServices.java b/applications/product/src/org/ofbiz/product/promo/PromoServices.java index f33af4aeda..45ee3fa867 100644 --- a/applications/product/src/org/ofbiz/product/promo/PromoServices.java +++ b/applications/product/src/org/ofbiz/product/promo/PromoServices.java @@ -48,7 +48,7 @@ public class PromoServices { public final static String module = PromoServices.class.getName(); - public static Map createProductPromoCodeSet(DispatchContext dctx, Map context) { + public static Map createProductPromoCodeSet(DispatchContext dctx, Map context) { //GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Long quantity = (Long) context.get("quantity"); @@ -59,7 +59,7 @@ public class PromoServices { StringBuilder bankOfNumbers = new StringBuilder(); for (long i = 0; i < quantity.longValue(); i++) { - Map createProductPromoCodeMap = null; + Map createProductPromoCodeMap = null; try { createProductPromoCodeMap = dispatcher.runSync("createProductPromoCode", dctx.makeValidContext("createProductPromoCode", "IN", context)); } catch (GenericServiceException err) { @@ -76,12 +76,12 @@ public class PromoServices { return ServiceUtil.returnSuccess(bankOfNumbers.toString()); } - public static Map purgeOldStoreAutoPromos(DispatchContext dctx, Map context) { + public static Map purgeOldStoreAutoPromos(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String productStoreId = (String) context.get("productStoreId"); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); - List condList = FastList.newInstance(); + List condList = FastList.newInstance(); if (UtilValidate.isEmpty(productStoreId)) { condList.add(EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, productStoreId)); } @@ -93,7 +93,7 @@ public class PromoServices { try { EntityListIterator eli = delegator.find("ProductStorePromoAndAppl", cond, null, null, null, null); GenericValue productStorePromoAndAppl = null; - while ((productStorePromoAndAppl = (GenericValue) eli.next()) != null) { + while ((productStorePromoAndAppl = eli.next()) != null) { GenericValue productStorePromo = delegator.makeValue("ProductStorePromoAppl"); productStorePromo.setAllFields(productStorePromoAndAppl, true, null, null); productStorePromo.remove(); @@ -108,7 +108,7 @@ public class PromoServices { return ServiceUtil.returnSuccess(); } - public static Map importPromoCodesFromFile(DispatchContext dctx, Map context) { + public static Map importPromoCodesFromFile(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); // check the uploaded file @@ -127,11 +127,11 @@ public class PromoServices { } // make a temp context for invocations - Map invokeCtx = promoModel.makeValid(context, ModelService.IN_PARAM); + Map invokeCtx = promoModel.makeValid(context, ModelService.IN_PARAM); // read the bytes into a reader BufferedReader reader = new BufferedReader(new StringReader(new String(wrapper))); - List errors = FastList.newInstance(); + List errors = FastList.newInstance(); int lines = 0; String line; @@ -142,10 +142,10 @@ public class PromoServices { if (line.length() > 0 && !line.startsWith("#")) { if (line.length() > 0 && line.length() <= 20) { // valid promo code - Map inContext = FastMap.newInstance(); + Map inContext = FastMap.newInstance(); inContext.putAll(invokeCtx); inContext.put("productPromoCodeId", line); - Map result = dispatcher.runSync("createProductPromoCode", inContext); + Map result = dispatcher.runSync("createProductPromoCode", inContext); if (result != null && ServiceUtil.isError(result)) { errors.add(line + ": " + ServiceUtil.getErrorMessage(result)); } @@ -180,7 +180,7 @@ public class PromoServices { return ServiceUtil.returnSuccess(); } - public static Map importPromoCodeEmailsFromFile(DispatchContext dctx, Map context) { + public static Map importPromoCodeEmailsFromFile(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); String productPromoCodeId = (String) context.get("productPromoCodeId"); @@ -193,7 +193,7 @@ public class PromoServices { // read the bytes into a reader BufferedReader reader = new BufferedReader(new StringReader(new String(wrapper))); - List errors = FastList.newInstance(); + List errors = FastList.newInstance(); int lines = 0; String line; @@ -203,7 +203,7 @@ public class PromoServices { if (line.length() > 0 && !line.startsWith("#")) { if (UtilValidate.isEmail(line)) { // valid email address - Map result = dispatcher.runSync("createProductPromoCodeEmail", UtilMisc.toMap("productPromoCodeId", + Map result = dispatcher.runSync("createProductPromoCodeEmail", UtilMisc.toMap("productPromoCodeId", productPromoCodeId, "emailAddress", line, "userLogin", userLogin)); if (result != null && ServiceUtil.isError(result)) { errors.add(line + ": " + ServiceUtil.getErrorMessage(result)); diff --git a/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java b/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java index 9ed2b3aa83..46bf51cffb 100644 --- a/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java +++ b/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java @@ -34,8 +34,8 @@ public class ImportProductHelper { static String module = ImportProductHelper.class.getName(); // prepare the product map - public static Map prepareProduct(String productId) { - Map fields = FastMap.newInstance(); + public static Map prepareProduct(String productId) { + Map fields = FastMap.newInstance(); fields.put("productId", productId); fields.put("productTypeId", "FINISHED_GOOD"); fields.put("internalName", "Product_" + productId); @@ -45,9 +45,9 @@ public class ImportProductHelper { } // prepare the inventoryItem map - public static Map prepareInventoryItem(String productId, + public static Map prepareInventoryItem(String productId, double quantityOnHand, String inventoryItemId) { - Map fields = FastMap.newInstance(); + Map fields = FastMap.newInstance(); fields.put("inventoryItemId", inventoryItemId); fields.put("inventoryItemTypeId", "NON_SERIAL_INV_ITEM"); fields.put("productId", productId); diff --git a/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java b/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java index 386fb0703e..280c06d147 100644 --- a/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java +++ b/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java @@ -57,13 +57,13 @@ public class ImportProductServices { * @param context * @return */ - public static Map productImportFromSpreadsheet(DispatchContext dctx, Map context) { + public static Map productImportFromSpreadsheet(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); - Map responseMsgs = FastMap.newInstance(); + Map responseMsgs = FastMap.newInstance(); // System.getProperty("user.dir") returns the path upto ofbiz home // directory String path = System.getProperty("user.dir") + "/spreadsheet"; - List fileItems = FastList.newInstance(); + List fileItems = FastList.newInstance(); if (path != null && path.length() > 0) { File importDir = new File(path); @@ -92,9 +92,9 @@ public class ImportProductServices { for (int i = 0; i < fileItems.size(); i++) { // read all xls file and create workbook one by one. - File item = (File) fileItems.get(i); - List products = FastList.newInstance(); - List inventoryItems = FastList.newInstance(); + File item = fileItems.get(i); + List> products = FastList.newInstance(); + List> inventoryItems = FastList.newInstance(); POIFSFileSystem fs = null; HSSFWorkbook wb = null; try { @@ -146,8 +146,8 @@ public class ImportProductServices { // create and store values in "Product" and "InventoryItem" entity // in database for (int j = 0; j < products.size(); j++) { - GenericValue productGV = delegator.makeValue("Product", (Map) products.get(j)); - GenericValue inventoryItemGV = delegator.makeValue("InventoryItem", (Map) inventoryItems.get(j)); + GenericValue productGV = delegator.makeValue("Product", products.get(j)); + GenericValue inventoryItemGV = delegator.makeValue("InventoryItem", inventoryItems.get(j)); if (!ImportProductHelper.checkProductExists(productGV.getString("productId"), delegator)) { try { delegator.create(productGV); diff --git a/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java b/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java index 8b1b3c05f1..080c8c9f9a 100644 --- a/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java +++ b/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java @@ -166,7 +166,7 @@ public class ProductStoreWorker { if (anyServiceType) { if (storePayment == null) { try { - List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId, "paymentMethodTypeId", paymentMethodTypeId)); + List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId, "paymentMethodTypeId", paymentMethodTypeId)); storePayment = EntityUtil.getFirst(storePayments); } catch (GenericEntityException e) { Debug.logError(e, "Problems looking up store payment settings", module); @@ -175,7 +175,7 @@ public class ProductStoreWorker { if (storePayment == null) { try { - List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId)); + List storePayments = delegator.findByAnd("ProductStorePaymentSetting", UtilMisc.toMap("productStoreId", productStoreId)); storePayment = EntityUtil.getFirst(storePayments); } catch (GenericEntityException e) { Debug.logError(e, "Problems looking up store payment settings", module); @@ -186,13 +186,13 @@ public class ProductStoreWorker { return storePayment; } - public static List getProductStoreShipmentMethods(GenericDelegator delegator, String productStoreId, + public static List getProductStoreShipmentMethods(GenericDelegator delegator, String productStoreId, String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId) { // check for an external service call - Map storeFields = UtilMisc.toMap("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId, + Map storeFields = UtilMisc.toMap("productStoreId", productStoreId, "shipmentMethodTypeId", shipmentMethodTypeId, "partyId", carrierPartyId, "roleTypeId", carrierRoleTypeId); - List storeShipMethods = null; + List storeShipMethods = null; try { storeShipMethods = delegator.findByAndCache("ProductStoreShipmentMeth", storeFields); } catch (GenericEntityException e) { @@ -209,11 +209,11 @@ public class ProductStoreWorker { return EntityUtil.getFirst(getProductStoreShipmentMethods(delegator, productStoreId, shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId)); } - public static List getAvailableStoreShippingMethods(GenericDelegator delegator, String productStoreId, GenericValue shippingAddress, List itemSizes, Map featureIdMap, double weight, double orderTotal) { + public static List getAvailableStoreShippingMethods(GenericDelegator delegator, String productStoreId, GenericValue shippingAddress, List itemSizes, Map featureIdMap, double weight, double orderTotal) { if (featureIdMap == null) { featureIdMap = FastMap.newInstance(); } - List shippingMethods = null; + List shippingMethods = null; try { shippingMethods = delegator.findByAndCache("ProductStoreShipmentMethView", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNumber")); } catch (GenericEntityException e) { @@ -222,12 +222,12 @@ public class ProductStoreWorker { } // clone the list for concurrent modification - List returnShippingMethods = UtilMisc.makeListWritable(shippingMethods); + List returnShippingMethods = UtilMisc.makeListWritable(shippingMethods); if (shippingMethods != null) { - Iterator i = shippingMethods.iterator(); + Iterator i = shippingMethods.iterator(); while (i.hasNext()) { - GenericValue method = (GenericValue) i.next(); + GenericValue method = i.next(); //Debug.logInfo("Checking Shipping Method : " + method.getString("shipmentMethodTypeId"), module); // test min/max weight first @@ -265,9 +265,9 @@ public class ProductStoreWorker { boolean allMatch = false; if (itemSizes != null) { allMatch = true; - Iterator isi = itemSizes.iterator(); + Iterator isi = itemSizes.iterator(); while (isi.hasNext()) { - Double size = (Double) isi.next(); + Double size = isi.next(); if (size.doubleValue() < minSize.doubleValue()) { allMatch = false; } @@ -283,9 +283,9 @@ public class ProductStoreWorker { boolean allMatch = false; if (itemSizes != null) { allMatch = true; - Iterator isi = itemSizes.iterator(); + Iterator isi = itemSizes.iterator(); while (isi.hasNext()) { - Double size = (Double) isi.next(); + Double size = isi.next(); if (size.doubleValue() > maxSize.doubleValue()) { allMatch = false; } @@ -350,7 +350,7 @@ public class ProductStoreWorker { } } if (includeGeoId != null && includeGeoId.length() > 0) { - List includeGeoGroup = GeoWorker.expandGeoGroup(includeGeoId, delegator); + List includeGeoGroup = GeoWorker.expandGeoGroup(includeGeoId, delegator); if (!GeoWorker.containsGeo(includeGeoGroup, shippingAddress.getString("countryGeoId"), delegator) && !GeoWorker.containsGeo(includeGeoGroup, shippingAddress.getString("stateProvinceGeoId"), delegator) && !GeoWorker.containsGeo(includeGeoGroup, shippingAddress.getString("postalCodeGeoId"), delegator)) { @@ -361,7 +361,7 @@ public class ProductStoreWorker { } } if (excludeGeoId != null && excludeGeoId.length() > 0) { - List excludeGeoGroup = GeoWorker.expandGeoGroup(excludeGeoId, delegator); + List excludeGeoGroup = GeoWorker.expandGeoGroup(excludeGeoId, delegator); if (GeoWorker.containsGeo(excludeGeoGroup, shippingAddress.getString("countryGeoId"), delegator) || GeoWorker.containsGeo(excludeGeoGroup, shippingAddress.getString("stateProvinceGeoId"), delegator) || GeoWorker.containsGeo(excludeGeoGroup, shippingAddress.getString("postalCodeGeoId"), delegator)) { @@ -376,7 +376,7 @@ public class ProductStoreWorker { String includeFeatures = method.getString("includeFeatureGroup"); String excludeFeatures = method.getString("excludeFeatureGroup"); if (includeFeatures != null && includeFeatures.length() > 0) { - List includedFeatures = null; + List includedFeatures = null; try { includedFeatures = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", includeFeatures)); } catch (GenericEntityException e) { @@ -384,9 +384,9 @@ public class ProductStoreWorker { } if (includedFeatures != null) { boolean foundOne = false; - Iterator ifet = includedFeatures.iterator(); + Iterator ifet = includedFeatures.iterator(); while (ifet.hasNext()) { - GenericValue appl = (GenericValue) ifet.next(); + GenericValue appl = ifet.next(); if (featureIdMap.containsKey(appl.getString("productFeatureId"))) { foundOne = true; break; @@ -400,16 +400,16 @@ public class ProductStoreWorker { } } if (excludeFeatures != null && excludeFeatures.length() > 0) { - List excludedFeatures = null; + List excludedFeatures = null; try { excludedFeatures = delegator.findByAndCache("ProductFeatureGroupAppl", UtilMisc.toMap("productFeatureGroupId", excludeFeatures)); } catch (GenericEntityException e) { Debug.logError(e, "Unable to lookup ProductFeatureGroupAppl records for group : " + excludeFeatures, module); } if (excludedFeatures != null) { - Iterator ifet = excludedFeatures.iterator(); + Iterator ifet = excludedFeatures.iterator(); while (ifet.hasNext()) { - GenericValue appl = (GenericValue) ifet.next(); + GenericValue appl = ifet.next(); if (featureIdMap.containsKey(appl.getString("productFeatureId"))) { returnShippingMethods.remove(method); //Debug.logInfo("Removed shipping method due to an exluded feature being found : " + appl.getString("productFeatureId"), module); @@ -437,34 +437,34 @@ public class ProductStoreWorker { } String partyId = userLogin != null ? userLogin.getString("partyId") : null; - Map passThruFields = UtilHttp.getParameterMap(((HttpServletRequest)request)); + Map passThruFields = UtilHttp.getParameterMap(((HttpServletRequest)request)); return getRandomSurveyWrapper(productStore.getDelegator(), productStore.getString("productStoreId"), groupName, partyId, passThruFields); } - public static ProductStoreSurveyWrapper getRandomSurveyWrapper(GenericDelegator delegator, String productStoreId, String groupName, String partyId, Map passThruFields) { - List randomSurveys = getSurveys(delegator, productStoreId, groupName, null, "RANDOM_POLL", null); + public static ProductStoreSurveyWrapper getRandomSurveyWrapper(GenericDelegator delegator, String productStoreId, String groupName, String partyId, Map passThruFields) { + List randomSurveys = getSurveys(delegator, productStoreId, groupName, null, "RANDOM_POLL", null); if (!UtilValidate.isEmpty(randomSurveys)) { Random rand = new Random(); int index = rand.nextInt(randomSurveys.size()); - GenericValue appl = (GenericValue) randomSurveys.get(index); + GenericValue appl = randomSurveys.get(index); return new ProductStoreSurveyWrapper(appl, partyId, passThruFields); } else { return null; } } - public static List getProductSurveys(GenericDelegator delegator, String productStoreId, String productId, String surveyApplTypeId) { + public static List getProductSurveys(GenericDelegator delegator, String productStoreId, String productId, String surveyApplTypeId) { return getSurveys(delegator, productStoreId, null, productId, surveyApplTypeId, null); } - public static List getProductSurveys(GenericDelegator delegator, String productStoreId, String productId, String surveyApplTypeId, String parentProductId) { + public static List getProductSurveys(GenericDelegator delegator, String productStoreId, String productId, String surveyApplTypeId, String parentProductId) { return getSurveys(delegator, productStoreId, null, productId, surveyApplTypeId,parentProductId); } - public static List getSurveys(GenericDelegator delegator, String productStoreId, String groupName, String productId, String surveyApplTypeId, String parentProductId) { - List surveys = FastList.newInstance(); - List storeSurveys = null; + public static List getSurveys(GenericDelegator delegator, String productStoreId, String groupName, String productId, String surveyApplTypeId, String parentProductId) { + List surveys = FastList.newInstance(); + List storeSurveys = null; try { storeSurveys = delegator.findByAndCache("ProductStoreSurveyAppl", UtilMisc.toMap("productStoreId", productStoreId, "surveyApplTypeId", surveyApplTypeId), UtilMisc.toList("sequenceNum")); } catch (GenericEntityException e) { @@ -483,9 +483,9 @@ public class ProductStoreWorker { Debug.log("getSurvey for product " + productId,module); // limit by product if (!UtilValidate.isEmpty(productId) && !UtilValidate.isEmpty(storeSurveys)) { - Iterator ssi = storeSurveys.iterator(); + Iterator ssi = storeSurveys.iterator(); while (ssi.hasNext()) { - GenericValue surveyAppl = (GenericValue) ssi.next(); + GenericValue surveyAppl = ssi.next(); GenericValue product = null; String virtualProductId = null; @@ -513,16 +513,16 @@ public class ProductStoreWorker { surveys.add(surveyAppl); } } else if (surveyAppl.get("productCategoryId") != null) { - List categoryMembers = null; + List categoryMembers = null; try { categoryMembers = delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", surveyAppl.get("productCategoryId"))); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get ProductCategoryMemebr records for survey application : " + surveyAppl, module); } if (categoryMembers != null) { - Iterator cmi = categoryMembers.iterator(); + Iterator cmi = categoryMembers.iterator(); while (cmi.hasNext()) { - GenericValue member = (GenericValue) cmi.next(); + GenericValue member = cmi.next(); if (productId != null && productId.equals(member.getString("productId"))) { surveys.add(surveyAppl); break; @@ -559,7 +559,7 @@ public class ProductStoreWorker { return -1; } - List surveyResponse = null; + List surveyResponse = null; try { surveyResponse = delegator.findByAnd("SurveyResponse", UtilMisc.toMap("surveyId", surveyId, "partyId", partyId)); } catch (GenericEntityException e) { @@ -611,7 +611,7 @@ public class ProductStoreWorker { try { Boolean requiredOkay = null; if (wantRequired != null) { - Map invReqResult = dispatcher.runSync("isStoreInventoryRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "productStore", productStore)); + Map invReqResult = dispatcher.runSync("isStoreInventoryRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "productStore", productStore)); if (ServiceUtil.isError(invReqResult)) { Debug.logError("Error calling isStoreInventoryRequired service, result is: " + invReqResult, module); return false; @@ -621,7 +621,7 @@ public class ProductStoreWorker { Boolean availableOkay = null; if (wantAvailable != null) { - Map invAvailResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "productStore", productStore, "quantity", quantity)); + Map invAvailResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.toMap("productStoreId", productStoreId, "productId", product.get("productId"), "product", product, "productStore", productStore, "quantity", quantity)); if (ServiceUtil.isError(invAvailResult)) { Debug.logError("Error calling isStoreInventoryAvailable service, result is: " + invAvailResult, module); return false; @@ -690,7 +690,7 @@ public class ProductStoreWorker { } else { GenericValue product = productConfig.getProduct(); - List productFacilities = null; + List productFacilities = null; try { productFacilities = delegator.getRelatedCache("ProductFacility", product); @@ -700,11 +700,11 @@ public class ProductStoreWorker { } if (UtilValidate.isNotEmpty(productFacilities)) { - Iterator pfIter = productFacilities.iterator(); + Iterator pfIter = productFacilities.iterator(); while (pfIter.hasNext()) { try { - GenericValue pfValue = (GenericValue) pfIter.next(); + GenericValue pfValue = pfIter.next(); isInventoryAvailable = ProductWorker.isProductInventoryAvailableByFacility(productConfig, pfValue.getString("facilityId"), quantity, dispatcher); if (isInventoryAvailable == true) { @@ -720,7 +720,7 @@ public class ProductStoreWorker { } } - protected static Map defaultProductStoreEmailScreenLocation = FastMap.newInstance(); + protected static Map defaultProductStoreEmailScreenLocation = FastMap.newInstance(); static { defaultProductStoreEmailScreenLocation.put("PRDS_ODR_CONFIRM", "component://ecommerce/widget/EmailOrderScreens.xml#OrderConfirmNotice"); @@ -747,6 +747,6 @@ public class ProductStoreWorker { } public static String getDefaultProductStoreEmailScreenLocation(String emailType) { - return (String) defaultProductStoreEmailScreenLocation.get(emailType); + return defaultProductStoreEmailScreenLocation.get(emailType); } } diff --git a/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java b/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java index 0f0cbe9372..1b75bdec6b 100644 --- a/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java +++ b/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java @@ -48,7 +48,7 @@ public class SubscriptionServices { public static final String module = SubscriptionServices.class.getName(); - public static Map processExtendSubscription(DispatchContext dctx, Map context) throws GenericServiceException{ + public static Map processExtendSubscription(DispatchContext dctx, Map context) throws GenericServiceException{ GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); @@ -65,14 +65,14 @@ public class SubscriptionServices { GenericValue lastSubscription = null; try { - Map subscriptionFindMap = UtilMisc.toMap("partyId", partyId, "subscriptionResourceId", subscriptionResourceId); + Map subscriptionFindMap = UtilMisc.toMap("partyId", partyId, "subscriptionResourceId", subscriptionResourceId); // if this subscription is attached to something the customer owns, filter by that too if (UtilValidate.isNotEmpty(inventoryItemId)) subscriptionFindMap.put("inventoryItemId", inventoryItemId); - List subscriptionList = delegator.findByAnd("Subscription", subscriptionFindMap); + List subscriptionList = delegator.findByAnd("Subscription", subscriptionFindMap); // DEJ20070718 DON'T filter by date, we want to consider all subscriptions: List listFiltered = EntityUtil.filterByDate(subscriptionList, true); - List listOrdered = EntityUtil.orderBy(subscriptionList, UtilMisc.toList("-fromDate")); + List listOrdered = EntityUtil.orderBy(subscriptionList, UtilMisc.toList("-fromDate")); if (listOrdered.size() > 0) { - lastSubscription = (GenericValue) listOrdered.get(0); + lastSubscription = listOrdered.get(0); } } catch (GenericEntityException e) { return ServiceUtil.returnError(e.toString()); @@ -125,32 +125,32 @@ public class SubscriptionServices { thruDate = new Timestamp(calendar.getTimeInMillis()); newSubscription.set("thruDate", thruDate); - Map result = ServiceUtil.returnSuccess(); + Map result = ServiceUtil.returnSuccess(); try { if (lastSubscription != null && !alwaysCreateNewRecord) { - Map updateSubscriptionMap = dctx.getModelService("updateSubscription").makeValid(newSubscription, ModelService.IN_PARAM); + Map updateSubscriptionMap = dctx.getModelService("updateSubscription").makeValid(newSubscription, ModelService.IN_PARAM); updateSubscriptionMap.put("userLogin", delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"))); - Map updateSubscriptionResult = dispatcher.runSync("updateSubscription", updateSubscriptionMap); + Map updateSubscriptionResult = dispatcher.runSync("updateSubscription", updateSubscriptionMap); result.put("subscriptionId", updateSubscriptionMap.get("subscriptionId")); if (ServiceUtil.isError(updateSubscriptionResult)) { return ServiceUtil.returnError("Error processing subscription update with ID [" + updateSubscriptionMap.get("subscriptionId") + "]", null, null, updateSubscriptionResult); } } else { - Map createPartyRoleMap = FastMap.newInstance(); + Map createPartyRoleMap = FastMap.newInstance(); if (UtilValidate.isNotEmpty(roleTypeId)) { createPartyRoleMap.put("partyId", partyId); createPartyRoleMap.put("roleTypeId", roleTypeId); createPartyRoleMap.put("userLogin", userLogin); - Map createPartyRoleResult = dispatcher.runSync("createPartyRole", createPartyRoleMap); + Map createPartyRoleResult = dispatcher.runSync("createPartyRole", createPartyRoleMap); if (ServiceUtil.isError(createPartyRoleResult)) { return ServiceUtil.returnError("Error creating new PartyRole while processing subscription update with resource ID [" + subscriptionResourceId + "]", null, null, createPartyRoleResult); } } - Map createSubscriptionMap = dctx.getModelService("createSubscription").makeValid(newSubscription, ModelService.IN_PARAM); + Map createSubscriptionMap = dctx.getModelService("createSubscription").makeValid(newSubscription, ModelService.IN_PARAM); createSubscriptionMap.put("userLogin", delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"))); - Map createSubscriptionResult = dispatcher.runSync("createSubscription", createSubscriptionMap); + Map createSubscriptionResult = dispatcher.runSync("createSubscription", createSubscriptionMap); if (ServiceUtil.isError(createSubscriptionResult)) { return ServiceUtil.returnError("Error creating subscription while processing with resource ID [" + subscriptionResourceId + "]", null, null, createSubscriptionResult); } @@ -164,7 +164,7 @@ public class SubscriptionServices { return result; } - public static Map processExtendSubscriptionByProduct(DispatchContext dctx, Map context) throws GenericServiceException{ + public static Map processExtendSubscriptionByProduct(DispatchContext dctx, Map context) throws GenericServiceException{ GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String productId = (String) context.get("productId"); @@ -178,7 +178,7 @@ public class SubscriptionServices { orderCreatedDate = UtilDateTime.nowTimestamp(); } try { - List productSubscriptionResourceList = delegator.findByAndCache("ProductSubscriptionResource", UtilMisc.toMap("productId", productId)); + List productSubscriptionResourceList = delegator.findByAndCache("ProductSubscriptionResource", UtilMisc.toMap("productId", productId)); productSubscriptionResourceList = EntityUtil.filterByDate(productSubscriptionResourceList, orderCreatedDate, null, null, true); productSubscriptionResourceList = EntityUtil.filterByDate(productSubscriptionResourceList, orderCreatedDate, "purchaseFromDate", "purchaseThruDate", true); @@ -188,25 +188,25 @@ public class SubscriptionServices { return ServiceUtil.returnError(msg); } - Iterator productSubscriptionResourceIter = productSubscriptionResourceList.iterator(); + Iterator productSubscriptionResourceIter = productSubscriptionResourceList.iterator(); while (productSubscriptionResourceIter.hasNext()) { - GenericValue productSubscriptionResource = (GenericValue) productSubscriptionResourceIter.next(); - - Long useTime = (Long) productSubscriptionResource.get("useTime"); + GenericValue productSubscriptionResource = productSubscriptionResourceIter.next(); + Long useTime = productSubscriptionResource.getLong("useTime"); Integer newUseTime = Integer.valueOf(0); if (useTime != null) { newUseTime = Integer.valueOf(useTime.intValue() * qty.intValue()); } - context.put("useTime", newUseTime); - context.put("useTimeUomId", productSubscriptionResource.get("useTimeUomId")); - context.put("useRoleTypeId", productSubscriptionResource.get("useRoleTypeId")); - context.put("subscriptionResourceId", productSubscriptionResource.get("subscriptionResourceId")); - context.put("automaticExtend", productSubscriptionResource.get("automaticExtend")); - context.put("canclAutmExtTime", productSubscriptionResource.get("canclAutmExtTime")); - context.put("canclAutmExtTimeUomId", productSubscriptionResource.get("canclAutmExtTimeUomId")); + Map subContext = UtilMisc.makeMapWritable(context); + subContext.put("useTime", newUseTime); + subContext.put("useTimeUomId", productSubscriptionResource.get("useTimeUomId")); + subContext.put("useRoleTypeId", productSubscriptionResource.get("useRoleTypeId")); + subContext.put("subscriptionResourceId", productSubscriptionResource.get("subscriptionResourceId")); + subContext.put("automaticExtend", productSubscriptionResource.get("automaticExtend")); + subContext.put("canclAutmExtTime", productSubscriptionResource.get("canclAutmExtTime")); + subContext.put("canclAutmExtTimeUomId", productSubscriptionResource.get("canclAutmExtTimeUomId")); - Map ctx = dctx.getModelService("processExtendSubscription").makeValid(context, ModelService.IN_PARAM); - Map processExtendSubscriptionResult = dispatcher.runSync("processExtendSubscription", ctx); + Map ctx = dctx.getModelService("processExtendSubscription").makeValid(subContext, ModelService.IN_PARAM); + Map processExtendSubscriptionResult = dispatcher.runSync("processExtendSubscription", ctx); if (ServiceUtil.isError(processExtendSubscriptionResult)) { return ServiceUtil.returnError("Error processing subscriptions for Product with ID [" + productId + "]", null, null, processExtendSubscriptionResult); } @@ -219,20 +219,21 @@ public class SubscriptionServices { return ServiceUtil.returnSuccess(); } - public static Map processExtendSubscriptionByOrder(DispatchContext dctx, Map context) throws GenericServiceException{ + public static Map processExtendSubscriptionByOrder(DispatchContext dctx, Map context) throws GenericServiceException{ GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); + Map subContext = UtilMisc.makeMapWritable(context); String orderId = (String) context.get("orderId"); Debug.logInfo("In processExtendSubscriptionByOrder service with orderId: " + orderId, module); GenericValue orderHeader = null; try { - List orderRoleList = delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", "END_USER_CUSTOMER")); + List orderRoleList = delegator.findByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", "END_USER_CUSTOMER")); if (orderRoleList.size() > 0 ) { - GenericValue orderRole = (GenericValue)orderRoleList.get(0); + GenericValue orderRole = orderRoleList.get(0); String partyId = (String) orderRole.get("partyId"); - context.put("partyId", partyId); + subContext.put("partyId", partyId); } else { String msg = "No OrderRole found for orderId:" + orderId; return ServiceUtil.returnFailure(msg); @@ -243,27 +244,27 @@ public class SubscriptionServices { return ServiceUtil.returnError(msg); } Timestamp orderCreatedDate = (Timestamp) orderHeader.get("orderDate"); - context.put("orderCreatedDate", orderCreatedDate); - List orderItemList = orderHeader.getRelated("OrderItem"); - Iterator orderItemIter = orderItemList.iterator(); + subContext.put("orderCreatedDate", orderCreatedDate); + List orderItemList = orderHeader.getRelated("OrderItem"); + Iterator orderItemIter = orderItemList.iterator(); while (orderItemIter.hasNext()) { - GenericValue orderItem = (GenericValue)orderItemIter.next(); - Double qty = (Double) orderItem.get("quantity"); - String productId = (String) orderItem.get("productId"); + GenericValue orderItem = orderItemIter.next(); + Double qty = orderItem.getDouble("quantity"); + String productId = orderItem.getString("productId"); if (UtilValidate.isEmpty(productId)) { continue; } - List productSubscriptionResourceList = delegator.findByAndCache("ProductSubscriptionResource", UtilMisc.toMap("productId", productId)); - List productSubscriptionResourceListFiltered = EntityUtil.filterByDate(productSubscriptionResourceList, true); + List productSubscriptionResourceList = delegator.findByAndCache("ProductSubscriptionResource", UtilMisc.toMap("productId", productId)); + List productSubscriptionResourceListFiltered = EntityUtil.filterByDate(productSubscriptionResourceList, true); if (productSubscriptionResourceListFiltered.size() > 0) { - context.put("subscriptionTypeId", "PRODUCT_SUBSCR"); - context.put("productId", productId); - context.put("orderId", orderId); - context.put("orderItemSeqId", orderItem.get("orderItemSeqId")); - context.put("inventoryItemId", orderItem.get("fromInventoryItemId")); - context.put("quantity", Integer.valueOf(qty.intValue())); - Map ctx = dctx.getModelService("processExtendSubscriptionByProduct").makeValid(context, ModelService.IN_PARAM); - Map thisResult = dispatcher.runSync("processExtendSubscriptionByProduct", ctx); + subContext.put("subscriptionTypeId", "PRODUCT_SUBSCR"); + subContext.put("productId", productId); + subContext.put("orderId", orderId); + subContext.put("orderItemSeqId", orderItem.get("orderItemSeqId")); + subContext.put("inventoryItemId", orderItem.get("fromInventoryItemId")); + subContext.put("quantity", Integer.valueOf(qty.intValue())); + Map ctx = dctx.getModelService("processExtendSubscriptionByProduct").makeValid(subContext, ModelService.IN_PARAM); + Map thisResult = dispatcher.runSync("processExtendSubscriptionByProduct", ctx); if (ServiceUtil.isError(thisResult)) { return ServiceUtil.returnError("Error processing subscriptions for Order with ID [" + orderId + "]", null, null, thisResult); } diff --git a/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java b/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java index 1caa3ccd04..119da8da48 100644 --- a/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java +++ b/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java @@ -29,6 +29,7 @@ import javolution.util.FastMap; 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,8 +55,8 @@ public class SupplierProductServices { * Result: a List of SupplierProduct entities for productId, * filtered by date and optionally by partyId, ordered with lowest price first */ - public static Map getSuppliersForProduct(DispatchContext dctx, Map context) { - Map results = FastMap.newInstance(); + public static Map getSuppliersForProduct(DispatchContext dctx, Map context) { + Map results = FastMap.newInstance(); GenericDelegator delegator = dctx.getDelegator(); GenericValue product = null; @@ -71,7 +72,7 @@ public class SupplierProductServices { results.put("supplierProducts",null); return results; } - List supplierProducts = product.getRelatedCache("SupplierProduct"); + List supplierProducts = product.getRelatedCache("SupplierProduct"); // if there were no related SupplierProduct entities and the item is a variant, then get the SupplierProducts of the virtual parent product if (supplierProducts.size() == 0 && product.getString("isVariant") != null && product.getString("isVariant").equals("Y")) { @@ -126,23 +127,23 @@ public class SupplierProductServices { * Service will convert each feature in the Collection, changing their idCode and description based on the * SupplierProduct entity for that supplier party and feature, and return it as convertedProductFeatures */ - public static Map convertFeaturesForSupplier(DispatchContext dctx, Map context) { - Map results = FastMap.newInstance(); + public static Map convertFeaturesForSupplier(DispatchContext dctx, Map context) { + Map results = FastMap.newInstance(); String partyId = (String) context.get("partyId"); - Collection features = (Collection) context.get("productFeatures"); + Collection features = UtilGenerics.checkList(context.get("productFeatures")); try { if (partyId != null && UtilValidate.isNotEmpty(features)) { // loop through all the features, find the related SupplierProductFeature for the given partyId, and // substitue description and idCode - for (Iterator fI = features.iterator(); fI.hasNext(); ) { - GenericValue nextFeature = (GenericValue) fI.next(); - List supplierFeatures = EntityUtil.filterByAnd(nextFeature.getRelated("SupplierProductFeature"), + for (Iterator fI = features.iterator(); fI.hasNext(); ) { + GenericValue nextFeature = fI.next(); + List supplierFeatures = EntityUtil.filterByAnd(nextFeature.getRelated("SupplierProductFeature"), UtilMisc.toMap("partyId", partyId)); GenericValue supplierFeature = null; if ((supplierFeatures != null) && (supplierFeatures.size() > 0)) { - supplierFeature = (GenericValue) supplierFeatures.get(0); + supplierFeature = supplierFeatures.get(0); if (supplierFeature.get("description") != null) { nextFeature.put("description", supplierFeature.get("description")); } diff --git a/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java b/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java index cf6fd46920..70b36b000a 100644 --- a/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java +++ b/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java @@ -53,7 +53,7 @@ public class InventoryItemTransferTest extends TestCase { } public void testCreateInventoryItemsTransfer() throws Exception { - Map ctx = FastMap.newInstance(); + Map ctx = FastMap.newInstance(); String statusId = "IXF_REQUESTED"; String inventoryItemId = "9005"; ctx.put("inventoryItemId", inventoryItemId); @@ -61,22 +61,22 @@ public class InventoryItemTransferTest extends TestCase { ctx.put("facilityId", "WebStoreWarehouse"); ctx.put("facilityIdTo", "WebStoreWarehouse"); ctx.put("receiveDate", UtilDateTime.nowTimestamp()); - ctx.put("xferQty", new Double (transferQty)); + ctx.put("xferQty", Double.valueOf(transferQty)); ctx.put("userLogin", userLogin); - Map resp = dispatcher.runSync("createInventoryTransfer", ctx); + Map resp = dispatcher.runSync("createInventoryTransfer", ctx); inventoryTransferId = (String) resp.get("inventoryTransferId"); assertNotNull(inventoryTransferId); } public void testUpdateInventoryItemTransfer() throws Exception { - Map ctx = FastMap.newInstance(); + Map ctx = FastMap.newInstance(); String statusId = "IXF_COMPLETE"; ctx.put("inventoryTransferId", inventoryTransferId); String inventoryItemId = delegator.findByPrimaryKey("InventoryTransfer", UtilMisc.toMap("inventoryTransferId", inventoryTransferId)).getString("inventoryItemId"); ctx.put("inventoryItemId", inventoryItemId); ctx.put("statusId", statusId); ctx.put("userLogin", userLogin); - Map resp = dispatcher.runSync("updateInventoryTransfer", ctx); + Map resp = dispatcher.runSync("updateInventoryTransfer", ctx); String respMsg = (String) resp.get("responseMessage"); assertNotSame("error", respMsg); } diff --git a/applications/product/src/org/ofbiz/product/test/StockMovesTest.java b/applications/product/src/org/ofbiz/product/test/StockMovesTest.java index 6f2a967926..5897efdd90 100644 --- a/applications/product/src/org/ofbiz/product/test/StockMovesTest.java +++ b/applications/product/src/org/ofbiz/product/test/StockMovesTest.java @@ -55,13 +55,13 @@ public class StockMovesTest extends TestCase { } public void testStockMoves() throws Exception { - Map fsmnCtx = FastMap.newInstance(); + Map fsmnCtx = FastMap.newInstance(); Map stockMoveHandled = null; List warningList = FastList.newInstance(); fsmnCtx.put("facilityId", "WebStoreWarehouse"); fsmnCtx.put("userLogin", userLogin); - Map respMap1 = dispatcher.runSync("findStockMovesNeeded", fsmnCtx); + Map respMap1 = dispatcher.runSync("findStockMovesNeeded", fsmnCtx); stockMoveHandled = (Map) respMap1.get("stockMoveHandled"); warningList = (List) respMap1.get("warningMessageList"); assertNull(warningList); @@ -69,17 +69,17 @@ public class StockMovesTest extends TestCase { if (stockMoveHandled != null) { fsmnCtx.put("stockMoveHandled", stockMoveHandled); } - Map respMap2 = dispatcher.runSync("findStockMovesRecommended", fsmnCtx); + Map respMap2 = dispatcher.runSync("findStockMovesRecommended", fsmnCtx); warningList = (List) respMap2.get("warningMessageList"); assertNull(warningList); - Map ppsmCtx = FastMap.newInstance(); + Map ppsmCtx = FastMap.newInstance(); ppsmCtx.put("productId", "GZ-2644"); ppsmCtx.put("facilityId", "WebStoreWarehouse"); ppsmCtx.put("locationSeqId","TLTLTLUL01" ); ppsmCtx.put("targetLocationSeqId", "TLTLTLLL01"); ppsmCtx.put("quantityMoved", Double.valueOf(5)); ppsmCtx.put("userLogin", userLogin); - Map respMap3 = dispatcher.runSync("processPhysicalStockMove", ppsmCtx); + Map respMap3 = dispatcher.runSync("processPhysicalStockMove", ppsmCtx); } }