⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productsearchsession.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    public static void clearSearchOptionsHistoryList(HttpSession session) {        session.removeAttribute("_PRODUCT_SEARCH_OPTIONS_HISTORY_");    }        public static void setCurrentSearchFromHistory(int index, boolean removeOld, HttpSession session) {        List searchOptionsHistoryList = getSearchOptionsHistoryList(session);        if (index < searchOptionsHistoryList.size()) {            ProductSearchOptions productSearchOptions = (ProductSearchOptions) searchOptionsHistoryList.get(index);            if (removeOld) {                searchOptionsHistoryList.remove(index);            }            if (productSearchOptions != null) {                session.setAttribute("_PRODUCT_SEARCH_OPTIONS_CURRENT_", new ProductSearchOptions(productSearchOptions));            }        } else {            throw new IllegalArgumentException("Could not set current search options to history index [" + index + "], only [" + searchOptionsHistoryList.size() + "] entries in the history list.");        }    }    public static String clearSearchOptionsHistoryList(HttpServletRequest request, HttpServletResponse response) {        HttpSession session = request.getSession();        clearSearchOptionsHistoryList(session);        return "success";    }        public static String setCurrentSearchFromHistory(HttpServletRequest request, HttpServletResponse response) {        HttpSession session = request.getSession();        String searchHistoryIndexStr = request.getParameter("searchHistoryIndex");        String removeOldStr = request.getParameter("removeOld");                if (UtilValidate.isEmpty(searchHistoryIndexStr)) {            request.setAttribute("_ERROR_MESSAGE_", "No search history index passed, cannot set current search to previous.");            return "error";        }                try {            int searchHistoryIndex = Integer.parseInt(searchHistoryIndexStr);            boolean removeOld = true;            if (UtilValidate.isNotEmpty(removeOldStr)) {                removeOld = !"false".equals(removeOldStr);            }            setCurrentSearchFromHistory(searchHistoryIndex, removeOld, session);        } catch (Exception e) {            request.setAttribute("_ERROR_MESSAGE_", e.toString());            return "error";        }                return "success";    }        /** A ControlServlet event method used to check to see if there is an override for any of the current keywords in the search */    public static final String checkDoKeywordOverride(HttpServletRequest request, HttpServletResponse response) {        HttpSession session = request.getSession();        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        Map requestParams = UtilHttp.getParameterMap(request);        ProductSearchSession.processSearchParameters(requestParams, session);        // get the current productStoreId        String productStoreId = ProductStoreWorker.getProductStoreId(request);        if (productStoreId != null) {            // get a Set of all keywords in the search, if there are any...            Set keywords = new HashSet();            List constraintList = ProductSearchOptions.getConstraintList(session);            if (constraintList != null) {                Iterator constraintIter = constraintList.iterator();                while (constraintIter.hasNext()) {                    Object constraint = constraintIter.next();                    if (constraint instanceof KeywordConstraint) {                        KeywordConstraint keywordConstraint = (KeywordConstraint) constraint;                        Set keywordSet = keywordConstraint.makeFullKeywordSet(delegator);                        if (keywordSet != null) keywords.addAll(keywordSet);                    }                }            }            if (keywords.size() > 0) {                List productStoreKeywordOvrdList = null;                try {                    productStoreKeywordOvrdList = delegator.findByAndCache("ProductStoreKeywordOvrd", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("-fromDate"));                    productStoreKeywordOvrdList = EntityUtil.filterByDate(productStoreKeywordOvrdList, true);                } catch (GenericEntityException e) {                    Debug.logError(e, "Error reading ProductStoreKeywordOvrd list, not doing keyword override", module);                }                if (productStoreKeywordOvrdList != null && productStoreKeywordOvrdList.size() > 0) {                    Iterator productStoreKeywordOvrdIter = productStoreKeywordOvrdList.iterator();                    while (productStoreKeywordOvrdIter.hasNext()) {                        GenericValue productStoreKeywordOvrd = (GenericValue) productStoreKeywordOvrdIter.next();                        String ovrdKeyword = productStoreKeywordOvrd.getString("keyword");                        if (keywords.contains(ovrdKeyword)) {                            String targetTypeEnumId = productStoreKeywordOvrd.getString("targetTypeEnumId");                            String target = productStoreKeywordOvrd.getString("target");                            ServletContext ctx = (ServletContext) request.getAttribute("servletContext");                            RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");                            if ("KOTT_PRODCAT".equals(targetTypeEnumId)) {                                String requestName = "/category/~category_id=" + target;                                target = rh.makeLink(request, response, requestName, false, false, false);                            } else if ("KOTT_PRODUCT".equals(targetTypeEnumId)) {                                String requestName = "/product/~product_id=" + target;                                target = rh.makeLink(request, response, requestName, false, false, false);                            } else if ("KOTT_OFBURL".equals(targetTypeEnumId)) {                                target = rh.makeLink(request, response, target, false, false, false);                            } else if ("KOTT_AURL".equals(targetTypeEnumId)) {                                // do nothing, is absolute URL                            } else {                                Debug.logError("The targetTypeEnumId [] is not recognized, not doing keyword override", module);                                // might as well see if there are any others...                                continue;                            }                            try {                                response.sendRedirect(target);                                return "none";                            } catch (IOException e) {                                Debug.logError(e, "Could not send redirect to: " + target, module);                                continue;                            }                        }                    }                }            }        }        return "success";    }    public static ArrayList searchDo(HttpSession session, GenericDelegator delegator, String prodCatalogId) {        String visitId = VisitHandler.getVisitId(session);        ProductSearchOptions productSearchOptions = getProductSearchOptions(session);        List productSearchConstraintList = productSearchOptions.getConstraintList();        if (productSearchConstraintList == null || productSearchConstraintList.size() == 0) {            // no constraints, don't do a search...            return new ArrayList();        }        // make sure the view allow category is included        productSearchConstraintList = ensureViewAllowConstraint(productSearchConstraintList, prodCatalogId, delegator);        ResultSortOrder resultSortOrder = productSearchOptions.getResultSortOrder();        // if the search options have changed since the last search, put at the beginning of the options history list        checkSaveSearchOptionsHistory(session);                return ProductSearch.searchProducts(productSearchConstraintList, resultSortOrder, delegator, visitId);    }    public static List ensureViewAllowConstraint(List productSearchConstraintList, String prodCatalogId, GenericDelegator delegator) {        String viewProductCategoryId = CatalogWorker.getCatalogViewAllowCategoryId(delegator, prodCatalogId);        if (UtilValidate.isNotEmpty(viewProductCategoryId)) {            ProductSearchConstraint viewAllowConstraint = new CategoryConstraint(viewProductCategoryId, true);            if (!productSearchConstraintList.contains(viewAllowConstraint)) {                // don't add to same list, will modify the one in the session, create new list                productSearchConstraintList = new ArrayList(productSearchConstraintList);                productSearchConstraintList.add(viewAllowConstraint);            }        }        return productSearchConstraintList;    }    public static void searchClear(HttpSession session) {        ProductSearchOptions.clearSearchOptions(session);    }        public static List searchGetConstraintStrings(boolean detailed, HttpSession session, GenericDelegator delegator) {        ProductSearchOptions productSearchOptions = getProductSearchOptions(session);        return productSearchOptions.searchGetConstraintStrings(detailed, delegator);    }    public static String searchGetSortOrderString(boolean detailed, HttpSession session) {        ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(session);        if (resultSortOrder == null) return "";        return resultSortOrder.prettyPrintSortOrder(detailed);    }    public static void searchSetSortOrder(ResultSortOrder resultSortOrder, HttpSession session) {        ProductSearchOptions.setResultSortOrder(resultSortOrder, session);    }    public static void searchAddFeatureIdConstraints(Collection featureIds, HttpSession session) {        if (featureIds == null || featureIds.size() == 0) {            return;        }        Iterator featureIdIter = featureIds.iterator();        while (featureIdIter.hasNext()) {            String productFeatureId = (String) featureIdIter.next();            searchAddConstraint(new FeatureConstraint(productFeatureId), session);        }    }    public static void searchAddConstraint(ProductSearchConstraint productSearchConstraint, HttpSession session) {        ProductSearchOptions.addConstraint(productSearchConstraint, session);    }    public static void searchRemoveConstraint(int index, HttpSession session) {        List productSearchConstraintList = ProductSearchOptions.getConstraintList(session);        if (productSearchConstraintList == null) {            return;        } else if (index >= productSearchConstraintList.size()) {            return;        } else {            productSearchConstraintList.remove(index);        }    }    public static void processSearchParameters(Map parameters, HttpSession session) {        boolean constraintsChanged = false;                // clear search? by default yes, but if the clearSearch parameter is N then don't

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -