svn commit: r1835892 - in /ofbiz/ofbiz-framework/branches/release17.12: ./ applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1835892 - in /ofbiz/ofbiz-framework/branches/release17.12: ./ applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java

jleroux@apache.org
Author: jleroux
Date: Sat Jul 14 09:53:00 2018
New Revision: 1835892

URL: http://svn.apache.org/viewvc?rev=1835892&view=rev
Log:
"Applied fix from trunk for revision: 1835891  "
------------------------------------------------------------------------
r1835891 | jleroux | 2018-07-14 11:52:26 +0200 (sam. 14 juil. 2018) | 35 lignes

Fixed: Refactor ContentWorkerInterface methods signatures
(OFBIZ-9164)

If you go at: catalog/control/main then open the lookup on the left for category
 id, click the first category (20111) and then click on search, you will be
prompted with this:
java.lang.IllegalArgumentException: Error running script at location
[component://product/groovyScripts/catalog/find/KeywordSearch.groovy]:
java.lang.NullPointerException

This is the result of the changes I made for this issue 1.5 years ago.

I missed the case where a null is passed instead of a dispatcher in
getProductCategoryContentAsText()
which is then used inside of getProductCategoryContentAsText:
ContentWorker.renderContentAsText()
The problem is, that the method renderContentAsText as a result of my changes
uses the dispatcher to get the delegator.
Because the dispatcher is a given a null value at this point, this results in a
null pointer.

The solution was to introduce and abstract prettyPrintConstraint method with a
LocalDispatcher as argument and to implement it in CategoryConstraint class.

Other implementations don't use getProductCategoryContentAsText so can simply
return null.

CatalogConstraint.prettyPrintConstraint with a delegator is now not
used OOTB but I prefer to keep its implementation for custom projects which
might use it in other circumstances. I though put a TODO to possibly simply
return null.

Also while at it remove a unused requestParams variable in ProductSearchSession

Thanks: Dennis Balkir for the detailed reporting
------------------------------------------------------------------------

Modified:
    ofbiz/ofbiz-framework/branches/release17.12/   (props changed)
    ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java
    ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java

Propchange: ofbiz/ofbiz-framework/branches/release17.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 14 09:53:00 2018
@@ -10,4 +10,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1823467,1823562,1823876,1824314,1824316,1824732,1824803,1824847,1824855,1825192,1825211,1825216,1825233,1825450,1826374,1826502,1826592,1826671,1826674,1826805,1826938,1826997,1827439,1828255,1828316,1828346,1828424,1828512,1828514,1829690,1830936,1831074,1831078,1831234,1831608,1831831,1832577,1832662,1832756,1832800,1832944,1833173,1833211,1834181,1834191,1834736,1835235,1835887
+/ofbiz/ofbiz-framework/trunk:1819499,1819598,1819800,1819805,1819811,1820038,1820262,1820374-1820375,1820441,1820457,1820644,1820658,1820790,1820823,1820949,1820966,1821012,1821036,1821112,1821115,1821144,1821186,1821219,1821226,1821230,1821386,1821613,1821628,1821965,1822125,1822310,1822377,1822383,1822393,1823467,1823562,1823876,1824314,1824316,1824732,1824803,1824847,1824855,1825192,1825211,1825216,1825233,1825450,1826374,1826502,1826592,1826671,1826674,1826805,1826938,1826997,1827439,1828255,1828316,1828346,1828424,1828512,1828514,1829690,1830936,1831074,1831078,1831234,1831608,1831831,1832577,1832662,1832756,1832800,1832944,1833173,1833211,1834181,1834191,1834736,1835235,1835887,1835891

Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java?rev=1835892&r1=1835891&r2=1835892&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java Sat Jul 14 09:53:00 2018
@@ -38,6 +38,7 @@ import org.apache.ofbiz.base.util.UtilPr
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.common.KeywordSearchUtil;
 import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericDelegator;
 import org.apache.ofbiz.entity.GenericEntityException;
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.condition.EntityComparisonOperator;
@@ -58,6 +59,7 @@ import org.apache.ofbiz.entity.util.Enti
 import org.apache.ofbiz.entity.util.EntityUtil;
 import org.apache.ofbiz.party.party.PartyHelper;
 import org.apache.ofbiz.product.category.CategoryContentWrapper;
+import org.apache.ofbiz.service.LocalDispatcher;
 
 
 /**
@@ -827,6 +829,7 @@ public class ProductSearch {
         public abstract void addConstraint(ProductSearchContext productSearchContext);
         /** pretty print for log messages and even UI stuff */
         public abstract String prettyPrintConstraint(Delegator delegator, boolean detailed, Locale locale);
+        public abstract String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale);
     }
 
 
@@ -921,6 +924,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -967,6 +978,7 @@ public class ProductSearch {
         }
 
         /** pretty print for log messages and even UI stuff */
+        // TODO This is not used OOTB since OFBIZ-9164 and could simply return null, kept for custom projects
         @Override
         public String prettyPrintConstraint(Delegator delegator, boolean detailed, Locale locale) {
             GenericValue productCategory = null;
@@ -995,6 +1007,36 @@ public class ProductSearch {
             return ppBuf.toString();
         }
 
+        /** pretty print for log messages and even UI stuff */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            GenericValue productCategory = null;
+            GenericDelegator delegator = (GenericDelegator) dispatcher.getDelegator();
+            try {
+                productCategory = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId", productCategoryId).cache().queryOne();
+            } catch (GenericEntityException e) {
+                Debug.logError(e, "Error finding ProductCategory information for constraint pretty print", module);
+            }
+            StringBuilder ppBuf = new StringBuilder();
+            ppBuf.append(UtilProperties.getMessage(resource, "ProductCategory", locale)).append(": ");
+            if (productCategory != null) {
+                String catInfo = CategoryContentWrapper.getProductCategoryContentAsText(productCategory, "CATEGORY_NAME", locale, dispatcher, "html");
+                if (UtilValidate.isEmpty(catInfo)) {
+                    catInfo = CategoryContentWrapper.getProductCategoryContentAsText(productCategory, "DESCRIPTION", locale, dispatcher, "html");
+                }
+                ppBuf.append(catInfo);
+            }
+            if (productCategory == null || detailed) {
+                ppBuf.append(" [");
+                ppBuf.append(productCategoryId);
+                ppBuf.append("]");
+            }
+            if (includeSubCategories) {
+                ppBuf.append(" (").append(UtilProperties.getMessage(resource, "ProductIncludeAllSubCategories", locale)).append(")");
+            }
+            return ppBuf.toString();
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
@@ -1138,6 +1180,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
 
@@ -1239,6 +1289,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1338,6 +1396,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
 
@@ -1452,6 +1518,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1588,6 +1662,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1651,6 +1733,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1745,6 +1835,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1870,6 +1968,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1932,6 +2038,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     @SuppressWarnings("serial")
@@ -1976,6 +2090,14 @@ public class ProductSearch {
             }
             return true;
         }
+
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
     }
 
     @SuppressWarnings("serial")
@@ -2020,6 +2142,14 @@ public class ProductSearch {
             }
             return true;
         }
+
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
     }
 
     @SuppressWarnings("serial")
@@ -2126,6 +2256,14 @@ public class ProductSearch {
             }
             return true;
         }
+
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
     }
 
     @SuppressWarnings("serial")
@@ -2189,6 +2327,14 @@ public class ProductSearch {
             return true;
         }
 
+        /* (non-Javadoc)
+         * @see org.apache.ofbiz.product.product.ProductSearch.ProductSearchConstraint#prettyPrintConstraint(org.apache.ofbiz.service.LocalDispatcher, boolean, java.util.Locale)
+         */
+        @Override
+        public String prettyPrintConstraint(LocalDispatcher dispatcher, boolean detailed, Locale locale) {
+            return null;
+        }
+
     }
 
     // ======================================================================

Modified: ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java?rev=1835892&r1=1835891&r2=1835892&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java Sat Jul 14 09:53:00 2018
@@ -64,6 +64,7 @@ import org.apache.ofbiz.product.product.
 import org.apache.ofbiz.product.product.ProductSearch.ResultSortOrder;
 import org.apache.ofbiz.product.product.ProductSearch.SortKeywordRelevancy;
 import org.apache.ofbiz.product.store.ProductStoreWorker;
+import org.apache.ofbiz.service.LocalDispatcher;
 import org.apache.ofbiz.webapp.control.RequestHandler;
 import org.apache.ofbiz.webapp.stats.VisitHandler;
 
@@ -297,6 +298,25 @@ public class ProductSearchSession {
             }
             return constraintStrings;
         }
+        public List<String> searchGetConstraintStrings(boolean detailed, LocalDispatcher dispatcher, Locale locale) {
+            List<ProductSearchConstraint> productSearchConstraintList = this.getConstraintList();
+            List<String> constraintStrings = new LinkedList<>();
+            if (productSearchConstraintList == null) {
+                return constraintStrings;
+            }
+            for (ProductSearchConstraint productSearchConstraint: productSearchConstraintList) {
+                if (productSearchConstraint == null) {
+                    continue;
+                }                
+                String constraintString = productSearchConstraint.prettyPrintConstraint(dispatcher, detailed, locale);
+                if (UtilValidate.isNotEmpty(constraintString)) {
+                    constraintStrings.add(constraintString);
+                } else {
+                    constraintStrings.add("Description not available");
+                }
+            }
+            return constraintStrings;
+        }
     }
 
     public static ProductSearchOptions getProductSearchOptions(HttpSession session) {
@@ -379,7 +399,6 @@ public class ProductSearchSession {
     public static final String checkDoKeywordOverride(HttpServletRequest request, HttpServletResponse response) {
         HttpSession session = request.getSession();
         Delegator delegator = (Delegator) request.getAttribute("delegator");
-        Map<String, Object> requestParams = UtilHttp.getParameterMap(request);
 
         // get the current productStoreId
         String productStoreId = ProductStoreWorker.getProductStoreId(request);
@@ -470,7 +489,8 @@ public class ProductSearchSession {
     public static List<String> searchGetConstraintStrings(boolean detailed, HttpSession session, Delegator delegator) {
         Locale locale = UtilHttp.getLocale(session);
         ProductSearchOptions productSearchOptions = getProductSearchOptions(session);
-        return productSearchOptions.searchGetConstraintStrings(detailed, delegator, locale);
+        LocalDispatcher dispatcher = (LocalDispatcher) session.getAttribute("dispatcher");
+        return productSearchOptions.searchGetConstraintStrings(detailed, dispatcher, locale);
     }
 
     public static String searchGetSortOrderString(boolean detailed, HttpServletRequest request) {