📄 productevents.java
字号:
String reason = request.getParameter("REASON");
String instruction = request.getParameter("INSTRUCTION");
String quantityStr = request.getParameter("QUANTITY");
String sequenceNumStr = request.getParameter("SEQUENCE_NUM");
Timestamp thruDate = null;
Double quantity = null;
Long sequenceNum = null;
if (UtilValidate.isNotEmpty(thruDateStr)) {
try {
thruDate = Timestamp.valueOf(thruDateStr);
} catch (Exception e) {
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.thru_date_not_formatted_correctly", UtilHttp.getLocale(request)));
}
}
if (UtilValidate.isNotEmpty(quantityStr)) {
try {
quantity = Double.valueOf(quantityStr);
} catch (Exception e) {
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.quantity_not_formatted_correctly", UtilHttp.getLocale(request)));
}
}
if (UtilValidate.isNotEmpty(sequenceNumStr)) {
try {
sequenceNum = Long.valueOf(sequenceNumStr);
} catch (Exception e) {
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.sequenceNum_not_formatted_correctly", 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";
}
tempProductAssoc.set("thruDate", thruDate);
tempProductAssoc.set("reason", reason);
tempProductAssoc.set("instruction", instruction);
tempProductAssoc.set("quantity", quantity);
tempProductAssoc.set("sequenceNum", sequenceNum);
if (updateMode.equals("CREATE")) {
// if no from date specified, set to now
if (fromDate == null) {
fromDate = new Timestamp(new java.util.Date().getTime());
tempProductAssoc.set("fromDate", fromDate);
request.setAttribute("ProductAssocCreateFromDate", fromDate);
}
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_create_product_association_exists", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
try {
productAssoc = tempProductAssoc.create();
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_product_association_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateProductAssoc] Could not create product association (write error); message: " + e.getMessage(), module);
return "error";
}
} else if (updateMode.equals("UPDATE")) {
try {
tempProductAssoc.store();
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_update_product_association_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateProductAssoc] Could not update product association (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";
}
public static String updateAttribute(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("[CategoryEvents.updateCategory] 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 attrName = request.getParameter("ATTRIBUTE_NAME");
String attrValue = request.getParameter("ATTRIBUTE_VALUE");
String attrType = request.getParameter("ATTRIBUTE_TYPE");
if (!UtilValidate.isNotEmpty(productId))
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.product_ID_missing", UtilHttp.getLocale(request)));
if (!UtilValidate.isNotEmpty(productId))
errMsg += ("<li>" + UtilProperties.getMessage(resource,"productevents.attribute_name_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";
}
List toBeStored = new LinkedList();
GenericValue attribute = delegator.makeValue("ProductAttribute", null);
toBeStored.add(attribute);
attribute.set("productId", productId);
attribute.set("attrName", attrName);
attribute.set("attrValue", attrValue);
attribute.set("attrType", attrType);
if (updateMode.equals("CREATE")) {
try {
delegator.storeAll(toBeStored);
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_attribute_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
} else if (updateMode.equals("UPDATE")) {
try {
delegator.storeAll(toBeStored);
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_update_attribute_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateAttribute] Could not update attribute (write error); message: " + e.getMessage(), module);
return "error";
}
} else if (updateMode.equals("DELETE")) {
try {
delegator.removeByAnd("ProductAttribute", UtilMisc.toMap("productId", productId, "attrName", attrName));
} catch (GenericEntityException e) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_delete_attribute_write", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
Debug.logWarning("[ProductEvents.updateAttribute] Could not delete attribute (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";
}
public static String tellAFriend(HttpServletRequest request, HttpServletResponse response) {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
GenericValue productStore = ProductStoreWorker.getProductStore(request);
GenericValue productStoreEmail = null;
String emailType = "PRDS_TELL_FRIEND";
try {
productStoreEmail =
delegator.findByPrimaryKey(
"ProductStoreEmailSetting",
UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), "emailType", emailType));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get product store email setting for tell-a-friend", module);
return "error";
}
if (productStoreEmail == null) {
return "error";
}
Map paramMap = UtilHttp.getParameterMap(request);
String subjectString = productStoreEmail.getString("subject");
subjectString = FlexibleStringExpander.expandString(subjectString, paramMap);
String ofbizHome = System.getProperty("ofbiz.home");
Map context = new HashMap();
context.put("templateName", ofbizHome + productStoreEmail.get("templatePath"));
context.put("templateData", paramMap);
context.put("sendTo", paramMap.get("sendTo"));
context.put("contentType", productStoreEmail.get("contentType"));
context.put("sendFrom", productStoreEmail.get("fromAddress"));
context.put("sendCc", productStoreEmail.get("ccAddress"));
context.put("sendBcc", productStoreEmail.get("bccAddress"));
context.put("subject", subjectString);
try {
dispatcher.runAsync("sendGenericNotificationEmail", context);
} catch (GenericServiceException e) {
Debug.logError(e, "Problem sending mail", module);
return "error";
}
return "success";
}
/** Simple event to set the users initial locale and currency Uom based on website product store */
public static String setDefaultStoreSettings(HttpServletRequest request, HttpServletResponse response) {
GenericValue productStore = ProductStoreWorker.getProductStore(request);
if (productStore != null) {
// request.getSession().setAttribute("productStoreGroupId", productStore.getString("primaryStoreGroupId"));
UtilHttp.setLocale(request, productStore.getString("defaultLocaleString"));
UtilHttp.setCurrencyUom(request, productStore.getString("defaultCurrencyUomId"));
}
return "success";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -