📄 productevents.java
字号:
product.removeRelated("ProductKeyword");
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_remove_keywords_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateProductKeywords] Could not remove product-keywords (write error); message: " + e.getMessage(), module);
return "error";
}
} else {
Map messageMap = UtilMisc.toMap("updateMode", updateMode);
errMsg = UtilProperties.getMessage(resource,"productevents.specified_update_mode_not_supported", messageMap, UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
return "success";
}
/**
* Updates/adds keywords for all products
*
* @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 updateAllKeywords(HttpServletRequest request, HttpServletResponse response) {
//String errMsg = "";
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
Security security = (Security) request.getAttribute("security");
Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
String updateMode = "CREATE";
String errMsg=null;
String doAll = request.getParameter("doAll");
// check permissions before moving on...
if (!security.hasEntityPermission("CATALOG", "_" + updateMode, request.getSession())) {
Map messageMap = UtilMisc.toMap("updateMode", updateMode);
errMsg = UtilProperties.getMessage(resource,"productevents.not_sufficient_permissions", messageMap, UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
EntityCondition condition = null;
if (!"Y".equals(doAll)) {
condition = new EntityConditionList(UtilMisc.toList(
new EntityExpr(new EntityExpr("isVariant", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("isVariant", EntityOperator.NOT_EQUAL, "Y")),
new EntityExpr(new EntityExpr("autoCreateKeywords", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("autoCreateKeywords", EntityOperator.NOT_EQUAL, "N")),
new EntityExpr(new EntityExpr("salesDiscontinuationDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("salesDiscontinuationDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp))
), EntityOperator.AND);
} else {
condition = new EntityExpr(new EntityExpr("autoCreateKeywords", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("autoCreateKeywords", EntityOperator.NOT_EQUAL, "N"));
}
EntityListIterator entityListIterator = null;
try {
if (Debug.infoOn()) {
long count = delegator.findCountByCondition("Product", condition, null);
Debug.logInfo("========== Found " + count + " products to index ==========", module);
}
entityListIterator = delegator.findListIteratorByCondition("Product", condition, null, null);
} catch (GenericEntityException gee) {
Debug.logWarning(gee, gee.getMessage(), module);
Map messageMap = UtilMisc.toMap("gee", gee.toString());
errMsg = UtilProperties.getMessage(resource,"productevents.error_getting_product_list", messageMap, UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
int numProds = 0;
int errProds = 0;
GenericValue product = null;
while ((product = (GenericValue) entityListIterator.next()) != null) {
try {
KeywordSearch.induceKeywords(product, "Y".equals(doAll));
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_keywords_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateAllKeywords] Could not create product-keyword (write error); message: " + e.getMessage(), module);
try {
entityListIterator.close();
} catch (GenericEntityException gee) {
Debug.logError(gee, "Error closing EntityListIterator when indexing product keywords.", module);
}
errProds++;
}
numProds++;
if (numProds % 500 == 0) {
Debug.logInfo("Keywords indexed for " + numProds + " so far", module);
}
}
if (entityListIterator != null) {
try {
entityListIterator.close();
} catch (GenericEntityException gee) {
Debug.logError(gee, "Error closing EntityListIterator when indexing product keywords.", module);
}
}
if (errProds == 0) {
Map messageMap = UtilMisc.toMap("numProds", Integer.toString(numProds));
errMsg = UtilProperties.getMessage(resource,"productevents.keyword_creation_complete_for_products", messageMap, UtilHttp.getLocale(request));
request.setAttribute("_EVENT_MESSAGE_", errMsg);
return "success";
} else {
Map messageMap = UtilMisc.toMap("numProds", Integer.toString(numProds));
messageMap.put("errProds", Integer.toString(errProds));
errMsg = UtilProperties.getMessage(resource,"productevents.keyword_creation_complete_for_products_with_errors", messageMap, UtilHttp.getLocale(request));
request.setAttribute( "_ERROR_MESSAGE_", errMsg);
return "error";
}
}
/**
* Updates ProductAssoc information according to UPDATE_MODE parameter
*
* @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 updateProductAssoc(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.updateProductAssoc] 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);
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 productIdTo = request.getParameter("PRODUCT_ID_TO");
String productAssocTypeId = request.getParameter("PRODUCT_ASSOC_TYPE_ID");
String fromDateStr = request.getParameter("FROM_DATE");
Timestamp fromDate = null;
try {
if (delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)) == null) {
Map messageMap = UtilMisc.toMap("productId", productId);
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.product_with_id_not_found", messageMap, UtilHttp.getLocale(request)));
}
if (delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productIdTo)) == null) {
Map messageMap = UtilMisc.toMap("productIdTo", productIdTo);
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.product_To_with_id_not_found", messageMap, UtilHttp.getLocale(request)));
}
} catch (GenericEntityException e) {
// if there is an exception for either, the other probably wont work
Debug.logWarning(e, module);
}
if (UtilValidate.isNotEmpty(fromDateStr)) {
try {
fromDate = Timestamp.valueOf(fromDateStr);
} catch (Exception e) {
errMsg += "<li>From Date not formatted correctly.";
}
}
if (!UtilValidate.isNotEmpty(productId))
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.product_ID_missing", UtilHttp.getLocale(request)));
if (!UtilValidate.isNotEmpty(productIdTo))
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.product_ID_To_missing", UtilHttp.getLocale(request)));
if (!UtilValidate.isNotEmpty(productAssocTypeId))
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.association_type_ID_missing", UtilHttp.getLocale(request)));
// from date is only required if update mode is not CREATE
if (!updateMode.equals("CREATE") && !UtilValidate.isNotEmpty(fromDateStr))
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.from_date_missing", UtilHttp.getLocale(request)));
if (errMsg.length() > 0) {
errMsg += ("<b>" + UtilProperties.getMessage(resource,"productevents.following_errors_occurred", UtilHttp.getLocale(request)));
errMsg += ("</b><br><ul>" + errMsg + "</ul>");
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
// clear some cache entries
delegator.clearCacheLine("ProductAssoc", UtilMisc.toMap("productId", productId));
delegator.clearCacheLine("ProductAssoc", UtilMisc.toMap("productId", productId, "productAssocTypeId", productAssocTypeId));
delegator.clearCacheLine("ProductAssoc", UtilMisc.toMap("productIdTo", productIdTo));
delegator.clearCacheLine("ProductAssoc", UtilMisc.toMap("productIdTo", productIdTo, "productAssocTypeId", productAssocTypeId));
delegator.clearCacheLine("ProductAssoc", UtilMisc.toMap("productAssocTypeId", productAssocTypeId));
delegator.clearCacheLine("ProductAssoc", UtilMisc.toMap("productId", productId, "productIdTo", productIdTo, "productAssocTypeId", productAssocTypeId, "fromDate", fromDate));
GenericValue tempProductAssoc = delegator.makeValue("ProductAssoc", UtilMisc.toMap("productId", productId, "productIdTo", productIdTo, "productAssocTypeId", productAssocTypeId, "fromDate", fromDate));
if (updateMode.equals("DELETE")) {
GenericValue productAssoc = null;
try {
productAssoc = delegator.findByPrimaryKey(tempProductAssoc.getPrimaryKey());
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
productAssoc = null;
}
if (productAssoc == null) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_remove_product_association_exist", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
try {
productAssoc.remove();
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_remove_product_association_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateProductAssoc] Could not remove product association (write error); message: " + e.getMessage(), module);
return "error";
}
return "success";
}
String thruDateStr = request.getParameter("THRU_DATE");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -