📄 productevents.java
字号:
/* * $Id: ProductEvents.java 6367 2005-12-19 05:41:37Z jonesde $ * * Copyright (c) 2001-2005 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.product;import java.sql.Timestamp;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javolution.util.FastMap;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilParse;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericPK;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.transaction.GenericTransactionException;import org.ofbiz.entity.transaction.TransactionUtil;import org.ofbiz.entity.util.EntityListIterator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.security.Security;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;/** * Product Information Related Events * * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version $Rev: 6367 $ * @since 2.0 */public class ProductEvents { public static final String module = ProductEvents.class.getName(); public static final String resource = "ProductUiLabels"; /** * Updates ProductKeyword information according to UPDATE_MODE parameter, only support CREATE and DELETE, no modify becuse all fields are PKs * * @param request * The HTTPRequest object for the current request * @param response * The HTTPResponse object for the current request * @return String specifying the exit status of this event */ public static String updateProductKeyword(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); Security security = (Security) request.getAttribute("security"); String updateMode = request.getParameter("UPDATE_MODE"); if (updateMode == null || updateMode.length() <= 0) { String errMsg = UtilProperties.getMessage(resource,"productevents.updatemode_not_specified", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); Debug.logWarning("[ProductEvents.updateProductKeyword] Update Mode was not specified, but is required", module); return "error"; } // check permissions before moving on... if (!security.hasEntityPermission("CATALOG", "_" + updateMode, request.getSession())) { Map messageMap = UtilMisc.toMap("updateMode", updateMode); String errMsg = UtilProperties.getMessage(resource,"productevents.not_sufficient_permissions", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } String productId = request.getParameter("PRODUCT_ID"); String keyword = request.getParameter("KEYWORD"); String relevancyWeightString = request.getParameter("relevancyWeight"); Long relevancyWeight = null; if (UtilValidate.isNotEmpty(relevancyWeightString)) { try { relevancyWeight = Long.valueOf(relevancyWeightString); } catch (NumberFormatException e) { String errMsg = "Bad format for relevancyWeight [" + relevancyWeightString + "]: " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } String errMsgTemp = ""; if (!UtilValidate.isNotEmpty(productId)) { errMsgTemp += ("<li>" + UtilProperties.getMessage(resource,"productevents.product_ID_missing", UtilHttp.getLocale(request))); } if (!UtilValidate.isNotEmpty(keyword)) { errMsgTemp += ("<li>" + UtilProperties.getMessage(resource,"productevents.keyword_missing", UtilHttp.getLocale(request))); } if (errMsgTemp.length() > 0) { errMsgTemp += ("<b>" + UtilProperties.getMessage(resource,"productevents.following_errors_occurred", UtilHttp.getLocale(request))); errMsgTemp += ("</b><br/><ul>" + errMsgTemp + "</ul>"); request.setAttribute("_ERROR_MESSAGE_", errMsgTemp); return "error"; } if (updateMode.equals("CREATE")) { keyword = keyword.toLowerCase(); GenericValue productKeyword = delegator.makeValue("ProductKeyword", UtilMisc.toMap("productId", productId, "keyword", keyword, "relevancyWeight", relevancyWeight)); GenericValue newValue = null; try { newValue = delegator.findByPrimaryKey(productKeyword.getPrimaryKey()); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); newValue = null; } if (newValue != null) { String errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_productkeyword_entry_exists", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } try { productKeyword = productKeyword.create(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); productKeyword = null; } if (productKeyword == null) { String errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_productkeyword_entry_write", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } } else if (updateMode.equals("DELETE")) { GenericValue productKeyword = null; try { productKeyword = delegator.findByPrimaryKey("ProductKeyword", UtilMisc.toMap("productId", productId, "keyword", keyword)); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); productKeyword = null; } if (productKeyword == null) { String errMsg = UtilProperties.getMessage(resource,"productevents.could_not_remove_productkeyword_entry_notexists", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } try { productKeyword.remove(); } catch (GenericEntityException e) { String errMsg = UtilProperties.getMessage(resource,"productevents.could_not_remove_productkeyword_entry_writeerror", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); Debug.logWarning("[ProductEvents.updateProductKeyword] Could not remove product-keyword (write error); message: " + e.getMessage(), module); return "error"; } } else { Map messageMap = UtilMisc.toMap("updateMode", updateMode); String errMsg = UtilProperties.getMessage(resource,"productevents.specified_update_mode_not_supported", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } return "success"; } /** * Update (create/induce or delete) all keywords for a given Product * * @param request * The HTTPRequest object for the current request * @param response * The HTTPResponse object for the current request * @return String specifying the exit status of this event */ public static String updateProductKeywords(HttpServletRequest request, HttpServletResponse response) { String errMsg = ""; GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); Security security = (Security) request.getAttribute("security"); String updateMode = request.getParameter("UPDATE_MODE"); if (updateMode == null || updateMode.length() <= 0) { errMsg = UtilProperties.getMessage(resource,"productevents.updatemode_not_specified", UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); Debug.logWarning("[ProductEvents.updateProductKeywords] Update Mode was not specified, but is required", module); return "error"; } // check permissions before moving on... if (!security.hasEntityPermission("CATALOG", "_" + updateMode, request.getSession())) { errMsg = UtilProperties.getMessage(resource,"productevents.not_sufficient_permissions", UtilHttp.getLocale(request)); request.setAttribute( "_ERROR_MESSAGE_", errMsg); return "error"; } String productId = request.getParameter("PRODUCT_ID"); if (!UtilValidate.isNotEmpty(productId)) { errMsg = UtilProperties.getMessage(resource,"productevents.no_product_ID_specified_keywords", UtilHttp.getLocale(request));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -