diff --git a/applications/product/script/org/ofbiz/product/product/ProductServices.xml b/applications/product/script/org/ofbiz/product/product/ProductServices.xml index 98059f73a8..5bafd65623 100644 --- a/applications/product/script/org/ofbiz/product/product/ProductServices.xml +++ b/applications/product/script/org/ofbiz/product/product/ProductServices.xml @@ -884,4 +884,20 @@ under the License. + + + + + + + + + + + + + + + + diff --git a/applications/product/servicedef/services.xml b/applications/product/servicedef/services.xml index 3987b366c0..9f01a530e0 100644 --- a/applications/product/servicedef/services.xml +++ b/applications/product/servicedef/services.xml @@ -1094,4 +1094,25 @@ under the License. + + + Create a ProductAttribute + + + + + + Update a ProductAttribute + + + + + + Delete a ProductAttribute + + + diff --git a/applications/product/src/org/ofbiz/product/product/KeywordSearch.java b/applications/product/src/org/ofbiz/product/product/KeywordSearch.java deleted file mode 100644 index 6af9fc5577..0000000000 --- a/applications/product/src/org/ofbiz/product/product/KeywordSearch.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.product.product; - -import org.ofbiz.entity.GenericEntityException; -import org.ofbiz.entity.GenericValue; - -/** - * These are left over utlity methods from the product search code, just calling over to KeywordIndex now; can probably remove soon. - */ -public class KeywordSearch { - - public static final String module = KeywordSearch.class.getName(); - - public static void induceKeywords(GenericValue product) throws GenericEntityException { - if (product == null) return; - KeywordIndex.indexKeywords(product, false); - } - - public static void induceKeywords(GenericValue product, boolean doAll) throws GenericEntityException { - if (product == null) return; - KeywordIndex.indexKeywords(product, doAll); - } -} diff --git a/applications/product/src/org/ofbiz/product/product/ProductEvents.java b/applications/product/src/org/ofbiz/product/product/ProductEvents.java index 507ab340d9..86a102b580 100644 --- a/applications/product/src/org/ofbiz/product/product/ProductEvents.java +++ b/applications/product/src/org/ofbiz/product/product/ProductEvents.java @@ -64,205 +64,6 @@ 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"); - List errMsgList = new LinkedList(); - - 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)) { - errMsgList.add(UtilProperties.getMessage(resource,"productevents.product_ID_missing", UtilHttp.getLocale(request))); - } - if (!UtilValidate.isNotEmpty(keyword)) { - errMsgList.add(UtilProperties.getMessage(resource,"productevents.keyword_missing", UtilHttp.getLocale(request))); - } - if (errMsgList.size() > 0) { - request.setAttribute("_ERROR_MESSAGE_LIST_", errMsgList); - 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)); - request.setAttribute("_ERROR_MESSAGE_", errMsg); - return "error"; - } - - GenericValue product = null; - - try { - product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); - } catch (GenericEntityException e) { - Debug.logWarning(e.getMessage(), module); - product = null; - } - if (product == null) { - Map messageMap = UtilMisc.toMap("productId", productId); - errMsg = UtilProperties.getMessage(resource,"productevents.product_with_productId_not_found_keywords", messageMap, UtilHttp.getLocale(request)); - request.setAttribute("_ERROR_MESSAGE_", errMsg); - return "error"; - } - - if (updateMode.equals("CREATE")) { - try { - KeywordSearch.induceKeywords(product, true); - } catch (GenericEntityException e) { - errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_keywords_write", UtilHttp.getLocale(request)); - request.setAttribute("_ERROR_MESSAGE_", errMsg); - return "error"; - } - } else if (updateMode.equals("DELETE")) { - try { - 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 * @@ -330,7 +131,7 @@ public class ProductEvents { GenericValue product; while ((product = (GenericValue) entityListIterator.next()) != null) { try { - KeywordSearch.induceKeywords(product, "Y".equals(doAll)); + KeywordIndex.indexKeywords(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); @@ -586,88 +387,6 @@ public class ProductEvents { return "success"; } - public static String updateAttribute(HttpServletRequest request, HttpServletResponse response) { - String errMsg = ""; - List errMsgList = new LinkedList(); - 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)) - errMsgList.add(UtilProperties.getMessage(resource,"productevents.product_ID_missing", UtilHttp.getLocale(request))); - if (!UtilValidate.isNotEmpty(attrName)) - errMsgList.add(UtilProperties.getMessage(resource,"productevents.attribute_name_missing", UtilHttp.getLocale(request))); - if (errMsgList.size() > 0) { - request.setAttribute("_ERROR_MESSAGE_LIST_", errMsgList); - 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"; - } - /** Event to clear the last viewed categories */ public static String clearLastViewedCategories(HttpServletRequest request, HttpServletResponse response) { // just store a new empty list in the session diff --git a/applications/product/webapp/catalog/WEB-INF/controller.xml b/applications/product/webapp/catalog/WEB-INF/controller.xml index 173c064395..965e99c934 100644 --- a/applications/product/webapp/catalog/WEB-INF/controller.xml +++ b/applications/product/webapp/catalog/WEB-INF/controller.xml @@ -754,25 +754,42 @@ under the License. - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -829,9 +846,21 @@ under the License. - + - + + + + + + + + + + + + + diff --git a/applications/product/webapp/catalog/product/EditProductAttributes.ftl b/applications/product/webapp/catalog/product/EditProductAttributes.ftl index 8ddef651a7..e69de29bb2 100644 --- a/applications/product/webapp/catalog/product/EditProductAttributes.ftl +++ b/applications/product/webapp/catalog/product/EditProductAttributes.ftl @@ -1,57 +0,0 @@ -<#-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> -<#if productId?exists && product?exists> - - - ${uiLabelMap.ProductName} - ${uiLabelMap.ProductValueType} - - <#list productAttributes as productAttribute> - - ${(productAttribute.attrName)?if_exists} - - - - - - - - - - - - - [${uiLabelMap.CommonDelete}] - - - #list> - - - - - - - - ${uiLabelMap.ProductAddProductAttributeNameValueType}: - - - - - -#if> diff --git a/applications/product/webapp/catalog/product/ProductForms.xml b/applications/product/webapp/catalog/product/ProductForms.xml index 12809c53f7..26d5d04c95 100644 --- a/applications/product/webapp/catalog/product/ProductForms.xml +++ b/applications/product/webapp/catalog/product/ProductForms.xml @@ -249,15 +249,14 @@ under the License. - + - - - - - + + + + + @@ -269,11 +268,11 @@ under the License. - + - + @@ -1378,8 +1377,7 @@ under the License. - + @@ -1391,20 +1389,33 @@ under the License. - + + - - - - + + - - + + + + + + + + + + + + + + + + - diff --git a/applications/product/widget/catalog/ProductScreens.xml b/applications/product/widget/catalog/ProductScreens.xml index ba183007da..65cb840760 100644 --- a/applications/product/widget/catalog/ProductScreens.xml +++ b/applications/product/widget/catalog/ProductScreens.xml @@ -438,8 +438,8 @@ under the License. - - + + ${uiLabelMap.ProductAddProductKeyword} @@ -713,10 +713,12 @@ under the License. - - - - + + + ${uiLabelMap.ProductAddProductAttributeNameValueType} + + +