📄 catalogworker.java
字号:
/* * $Id: CatalogWorker.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.product.catalog;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import javax.servlet.ServletRequest;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.webapp.website.WebSiteWorker;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.product.category.CategoryWorker;import org.ofbiz.product.store.ProductStoreWorker;/** * CatalogWorker - Worker class for catalog related functionality * * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version $Rev: 5462 $ * @since 2.0 */public class CatalogWorker { public static final String module = CatalogWorker.class.getName(); public static String getWebSiteId(ServletRequest request) { return WebSiteWorker.getWebSiteId(request); } public static GenericValue getWebSite(ServletRequest request) { return WebSiteWorker.getWebSite(request); } public static List getAllCatalogIds(ServletRequest request) { List catalogIds = new ArrayList(); List catalogs = null; GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); try { catalogs = delegator.findAll("ProdCatalog", UtilMisc.toList("catalogName")); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up all catalogs", module); } if (catalogs != null) { Iterator i = catalogs.iterator(); while (i.hasNext()) { GenericValue c = (GenericValue) i.next(); catalogIds.add(c.getString("prodCatalogId")); } } return catalogIds; } 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) { try { return EntityUtil.filterByDate(delegator.findByAndCache("ProductStoreCatalog", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "prodCatalogId")), true); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up store catalogs for store with id " + productStoreId, module); } return null; } 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"); if (userLogin == null) return null; String partyId = userLogin.getString("partyId"); if (partyId == null) return null; GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); return getPartyCatalogs(delegator, partyId); } public static List getPartyCatalogs(GenericDelegator delegator, String partyId) { if (delegator == null || partyId == null) { return null; } try { return EntityUtil.filterByDate(delegator.findByAndCache("ProdCatalogRole", UtilMisc.toMap("partyId", partyId, "roleTypeId", "CUSTOMER"), UtilMisc.toList("sequenceNum", "prodCatalogId")), true); } catch (GenericEntityException e) { Debug.logError(e, "Error looking up ProdCatalog Roles for party with id " + partyId, module); } return null; } 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) { try { List prodCatalogCategories = EntityUtil.filterByDate(delegator.findByAndCache("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", prodCatalogId), UtilMisc.toList("sequenceNum", "productCategoryId")), true); if (UtilValidate.isNotEmpty(prodCatalogCategoryTypeId) && prodCatalogCategories != null) { prodCatalogCategories = EntityUtil.filterByAnd(prodCatalogCategories, UtilMisc.toMap("prodCatalogCategoryTypeId", prodCatalogCategoryTypeId)); } return prodCatalogCategories; } catch (GenericEntityException e) { Debug.logError(e, "Error looking up ProdCatalogCategories for prodCatalog with id " + prodCatalogId, module); } return null; } /** * Retrieves the current prodCatalogId. First it will attempt to find it from a special * request parameter or session attribute named CURRENT_CATALOG_ID. Failing that, it will * get the first catalog from the database as specified in getCatalogIdsAvailable(). * If this behavior is undesired, give the user a selectable list of catalogs. */ public static String getCurrentCatalogId(ServletRequest request) { HttpSession session = ((HttpServletRequest) request).getSession(); Map requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); String prodCatalogId = null; boolean fromSession = false; // first see if a new catalog was specified as a parameter prodCatalogId = (String) requestParameters.get("CURRENT_CATALOG_ID"); // if no parameter, try from session if (prodCatalogId == null) { prodCatalogId = (String) session.getAttribute("CURRENT_CATALOG_ID"); if (prodCatalogId != null) fromSession = true; } // get it from the database if (prodCatalogId == null) { List catalogIds = getCatalogIdsAvailable(request); if (catalogIds != null && catalogIds.size() > 0) prodCatalogId = (String) 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, new ArrayList()); } return prodCatalogId; } 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); return getCatalogIdsAvailable(partyCatalogs, storeCatalogs); } public static List getCatalogIdsAvailable(List partyCatalogs, List storeCatalogs) { List categoryIds = new LinkedList(); List allCatalogLinks = new ArrayList((storeCatalogs == null ? 0 : storeCatalogs.size()) + (partyCatalogs == null ? 0 : partyCatalogs.size())); if (partyCatalogs != null) allCatalogLinks.addAll(partyCatalogs); if (storeCatalogs != null) allCatalogLinks.addAll(storeCatalogs); if (allCatalogLinks.size() > 0) { Iterator aclIter = allCatalogLinks.iterator(); while (aclIter.hasNext()) { GenericValue catalogLink = (GenericValue) aclIter.next();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -