svn commit: r1817742 - /ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/

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

svn commit: r1817742 - /ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/

mbrohl
Author: mbrohl
Date: Mon Dec 11 06:07:50 2017
New Revision: 1817742

URL: http://svn.apache.org/viewvc?rev=1817742&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.content.
(OFBIZ-9858)

The patch was modified. The changes in ContentWorker#checkConditions
would have changed the logic and have to be reworked.

Thanks Dennis Balkir for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentKeywordIndex.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentMapFacade.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentPermissionServices.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServicesComplex.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/PermissionRecorder.java
    ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/UploadContentAndImage.java

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentKeywordIndex.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentKeywordIndex.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentKeywordIndex.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentKeywordIndex.java Mon Dec 11 06:07:50 2017
@@ -21,6 +21,7 @@ package org.apache.ofbiz.content.content
 import java.io.IOException;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
@@ -56,7 +57,6 @@ public class ContentKeywordIndex {
         if (content == null) return;
         
         Delegator delegator = content.getDelegator();
-        if (delegator == null) return;
         String contentId = content.getString("contentId");
 
         // get these in advance just once since they will be used many times for the multiple strings to index
@@ -70,7 +70,7 @@ public class ContentKeywordIndex {
         List<String> strings = new LinkedList<String>();
 
         int pidWeight = 1;
-        keywords.put(content.getString("contentId").toLowerCase(), Long.valueOf(pidWeight));
+        keywords.put(content.getString("contentId").toLowerCase(Locale.getDefault()), Long.valueOf(pidWeight));
 
         addWeightedKeywordSourceString(content, "dataResourceId", strings);
         addWeightedKeywordSourceString(content, "contentName", strings);

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentMapFacade.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentMapFacade.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentMapFacade.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentMapFacade.java Mon Dec 11 06:07:50 2017
@@ -51,7 +51,7 @@ public class ContentMapFacade implements
 
     public static final String module = ContentMapFacade.class.getName();
 
-    protected static final Set<String> mapKeySet = new HashSet<String>();
+    private static final Set<String> mapKeySet = new HashSet<String>();
     static {
         mapKeySet.add("fields");
         mapKeySet.add("link");
@@ -370,9 +370,6 @@ public class ContentMapFacade implements
             return false;
         }
 
-        public abstract Object get(Object object);
-
-
         public Object put(Object name, Object value) {
             Debug.logWarning("This [put()] method is not implemented in ContentMapFacade.AbstractInfo", module);
             return null;
@@ -415,7 +412,7 @@ public class ContentMapFacade implements
                 return null;
             }
             String name = (String) key;
-            if (name.toLowerCase().startsWith("id_")) {
+            if (name.toLowerCase(Locale.getDefault()).startsWith("id_")) {
                 name = name.substring(3);
             }
 
@@ -448,7 +445,7 @@ public class ContentMapFacade implements
                 return null;
             }
             String name = (String) key;
-            if (name.toLowerCase().startsWith("id_")) {
+            if (name.toLowerCase(Locale.getDefault()).startsWith("id_")) {
                 name = name.substring(3);
             }
 

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentPermissionServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentPermissionServices.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentPermissionServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentPermissionServices.java Mon Dec 11 06:07:50 2017
@@ -178,7 +178,7 @@ public class ContentPermissionServices {
 
         String entityAction = (String) context.get("entityOperation");
         if (entityAction == null) entityAction = "_ADMIN";
-        if (userLogin != null && entityAction != null) {
+        if (userLogin != null) {
             passed = security.hasEntityPermission("CONTENTMGR", entityAction, userLogin);
         }
 
@@ -235,15 +235,11 @@ public class ContentPermissionServices {
                  errBuf.append("\n    entityIds:");
                  errBuf.append(entityIds);
 
-                 if (auxGetter != null) {
-                     errBuf.append("\n    auxList:");
-                     errBuf.append(auxGetter.getList());
-                 }
-
-                 if (roleGetter != null) {
-                     errBuf.append("\n    roleList:");
-                     errBuf.append(roleGetter.getList());
-                 }
+                 errBuf.append("\n    auxList:");
+                 errBuf.append(auxGetter.getList());
+
+                 errBuf.append("\n    roleList:");
+                 errBuf.append(roleGetter.getList());
               }
 
             }

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentSearch.java Mon Dec 11 06:07:50 2017
@@ -561,6 +561,7 @@ public class ContentSearch {
 
         @Override
         public boolean equals(Object obj) {
+            if (!(obj instanceof ContentSearchConstraint)) return false;
             ContentSearchConstraint psc = (ContentSearchConstraint) obj;
             if (psc instanceof ContentAssocConstraint) {
                 ContentAssocConstraint that = (ContentAssocConstraint) psc;
@@ -590,6 +591,16 @@ public class ContentSearch {
                 return false;
             }
         }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((contentAssocTypeId == null) ? 0 : contentAssocTypeId.hashCode());
+            result = prime * result + ((contentId == null) ? 0 : contentId.hashCode());
+            result = prime * result + (includeSubContents ? 1231 : 1237);
+            return result;
+        }
     }
 
     @SuppressWarnings("serial")
@@ -682,34 +693,47 @@ public class ContentSearch {
 
         @Override
         public boolean equals(Object obj) {
-            ContentSearchConstraint psc = (ContentSearchConstraint) obj;
-            if (psc instanceof KeywordConstraint) {
-                KeywordConstraint that = (KeywordConstraint) psc;
-                if (this.anyPrefix != that.anyPrefix) {
-                    return false;
-                }
-                if (this.anySuffix != that.anySuffix) {
-                    return false;
-                }
-                if (this.isAnd != that.isAnd) {
-                    return false;
-                }
-                if (this.removeStems != that.removeStems) {
-                    return false;
-                }
-                if (this.keywordsString == null) {
-                    if (that.keywordsString != null) {
+            if ((obj instanceof ContentSearchConstraint)) {
+                ContentSearchConstraint psc = (ContentSearchConstraint) obj;
+                if (psc instanceof KeywordConstraint) {
+                    KeywordConstraint that = (KeywordConstraint) psc;
+                    if (this.anyPrefix != that.anyPrefix) {
                         return false;
                     }
-                } else {
-                    if (!this.keywordsString.equals(that.keywordsString)) {
+                    if (this.anySuffix != that.anySuffix) {
+                        return false;
+                    }
+                    if (this.isAnd != that.isAnd) {
+                        return false;
+                    }
+                    if (this.removeStems != that.removeStems) {
                         return false;
                     }
+                    if (this.keywordsString == null) {
+                        if (that.keywordsString != null) {
+                            return false;
+                        }
+                    } else {
+                        if (!this.keywordsString.equals(that.keywordsString)) {
+                            return false;
+                        }
+                    }
+                    return true;
                 }
-                return true;
-            } else {
-                return false;
             }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + (anyPrefix ? 1231 : 1237);
+            result = prime * result + (anySuffix ? 1231 : 1237);
+            result = prime * result + (isAnd ? 1231 : 1237);
+            result = prime * result + ((keywordsString == null) ? 0 : keywordsString.hashCode());
+            result = prime * result + (removeStems ? 1231 : 1237);
+            return result;
         }
     }
 
@@ -720,8 +744,8 @@ public class ContentSearch {
         protected Timestamp thruDate;
 
         public LastUpdatedRangeConstraint(Timestamp fromDate, Timestamp thruDate) {
-            this.fromDate = fromDate;
-            this.thruDate = thruDate;
+            this.fromDate = fromDate != null ? (Timestamp) fromDate.clone() : null;
+            this.thruDate = thruDate != null ? (Timestamp) thruDate.clone() : null;
         }
 
         @Override
@@ -767,34 +791,43 @@ public class ContentSearch {
             return ppBuf.toString();
         }
 
-
         @Override
         public boolean equals(Object obj) {
-            ContentSearchConstraint psc = (ContentSearchConstraint) obj;
-            if (psc instanceof LastUpdatedRangeConstraint) {
-                LastUpdatedRangeConstraint that = (LastUpdatedRangeConstraint) psc;
-                if (this.fromDate == null) {
-                    if (that.fromDate != null) {
-                        return false;
-                    }
-                } else {
-                    if (!this.fromDate.equals(that.fromDate)) {
-                        return false;
+            if (obj instanceof ContentSearchConstraint) {
+                ContentSearchConstraint psc = (ContentSearchConstraint) obj;
+                if (psc instanceof LastUpdatedRangeConstraint) {
+                    LastUpdatedRangeConstraint that = (LastUpdatedRangeConstraint) psc;
+                    if (this.fromDate == null) {
+                        if (that.fromDate != null) {
+                            return false;
+                        }
+                    } else {
+                        if (!this.fromDate.equals(that.fromDate)) {
+                            return false;
+                        }
+                    }
+                    if (this.thruDate == null) {
+                        if (that.thruDate != null) {
+                            return false;
+                        }
+                    } else {
+                        if (!this.thruDate.equals(that.thruDate)) {
+                            return false;
+                        }
                     }
+                    return true;
                 }
-                if (this.thruDate == null) {
-                    if (that.thruDate != null) {
-                        return false;
-                    }
-                } else {
-                    if (!this.thruDate.equals(that.thruDate)) {
-                        return false;
-                    }
-                }
-                return true;
-            } else {
-                return false;
             }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((fromDate == null) ? 0 : fromDate.hashCode());
+            result = prime * result + ((thruDate == null) ? 0 : thruDate.hashCode());
+            return result;
         }
     }
 

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServices.java Mon Dec 11 06:07:50 2017
@@ -75,7 +75,7 @@ public class ContentServices {
         if (toFrom == null) {
             toFrom = "TO";
         } else {
-            toFrom = toFrom.toUpperCase();
+            toFrom = toFrom.toUpperCase(Locale.getDefault());
         }
 
         List<String> assocTypes = UtilGenerics.checkList(context.get("contentAssocTypeList"));
@@ -832,10 +832,6 @@ public class ContentServices {
         if (templateContext != null && locale == null) {
             locale = (Locale) templateContext.get("locale");
         }
-        GenericValue subContentDataResourceView = (GenericValue) context.get("subContentDataResourceView");
-        if (templateContext != null && subContentDataResourceView == null) {
-            subContentDataResourceView = (GenericValue) templateContext.get("subContentDataResourceView");
-        }
 
         Writer out = (Writer) context.get("outWriter");
         Writer outWriter = new StringWriter();

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServicesComplex.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServicesComplex.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServicesComplex.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentServicesComplex.java Mon Dec 11 06:07:50 2017
@@ -228,10 +228,6 @@ public class ContentServicesComplex {
             conditionList.add(EntityCondition.makeCondition("caContentAssocTypeId", EntityOperator.IN, assocTypes));
         }
 
-        if (fromDate == null && fromDateStr != null) {
-            fromDate = UtilDateTime.toTimestamp(fromDateStr);
-        }
-
         List<GenericValue> contentAssocsTypeFiltered = EntityQuery.use(delegator).from(viewName)
                 .where(conditionList).orderBy("caSequenceNum", "-caFromDate").cache().queryList();
 

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/ContentUrlFilter.java Mon Dec 11 06:07:50 2017
@@ -59,7 +59,7 @@ public class ContentUrlFilter implements
         String urlContentId = null;
         String pathInfo = UtilHttp.getFullRequestUrl(httpRequest);
         if (UtilValidate.isNotEmpty(pathInfo)) {
-            String alternativeUrl = pathInfo.substring(pathInfo.lastIndexOf("/"));
+            String alternativeUrl = pathInfo.substring(pathInfo.lastIndexOf('/'));
             if (alternativeUrl.endsWith("-content")) {
                 try {
                     GenericValue contentDataResourceView = EntityQuery.use(delegator).from("ContentDataResourceView")

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/PermissionRecorder.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/PermissionRecorder.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/PermissionRecorder.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/PermissionRecorder.java Mon Dec 11 06:07:50 2017
@@ -21,6 +21,7 @@ package org.apache.ofbiz.content.content
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import org.apache.ofbiz.base.util.UtilGenerics;
@@ -50,8 +51,8 @@ public class PermissionRecorder {
 
     public static final String module = PermissionRecorder.class.getName();
 
-    public static final String [] opFields = { "contentPurposeTypeId", "contentOperationId", "roleTypeId", "statusId", "privilegeEnumId"};
-    public static final String [] fieldTitles = { "Purpose", "Operation", "Role", "Status", "Privilege"};
+    private static final String [] opFields = { "contentPurposeTypeId", "contentOperationId", "roleTypeId", "statusId", "privilegeEnumId"};
+    private static final String [] fieldTitles = { "Purpose", "Operation", "Role", "Status", "Privilege"};
 
     public PermissionRecorder() {
         isOn = UtilProperties.propertyValueEqualsIgnoreCase("content", "permissionRecorderOn", "true");
@@ -90,7 +91,7 @@ public class PermissionRecorder {
     }
 
     public GenericValue [] getContentPurposeOperations() {
-       return contentPurposeOperations;
+       return contentPurposeOperations != null ? contentPurposeOperations.clone() : null;
     }
 
     public void setContentPurposeOperations(List<GenericValue> opList) {
@@ -106,7 +107,7 @@ public class PermissionRecorder {
     }
 
     public String [] getStatusTargets() {
-       return statusTargets;
+       return statusTargets != null ? statusTargets.clone() : null;
     }
 
     public void setStatusTargets(List<String> opList) {
@@ -114,7 +115,7 @@ public class PermissionRecorder {
     }
 
     public String [] getTargetOperations() {
-       return targetOperations;
+       return targetOperations != null ? targetOperations.clone() : null;
     }
 
     public void setTargetOperations(List<String> opList) {
@@ -284,7 +285,7 @@ public class PermissionRecorder {
             sb.append("</td>");
         }
         String passFailCls = (isPass) ? "pass" : "fail";
-        sb.append("<td class=\"" + passFailCls +"\">" + passFailCls.toUpperCase() + "</td>");
+        sb.append("<td class=\"" + passFailCls +"\">" + passFailCls.toUpperCase(Locale.getDefault()) + "</td>");
         sb.append("</tr>");
 
         return sb.toString();

Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/UploadContentAndImage.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/UploadContentAndImage.java?rev=1817742&r1=1817741&r2=1817742&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/UploadContentAndImage.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/content/UploadContentAndImage.java Mon Dec 11 06:07:50 2017
@@ -42,6 +42,7 @@ import org.apache.ofbiz.base.util.UtilMi
 import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericEntityException;
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.model.ModelEntity;
 import org.apache.ofbiz.entity.transaction.GenericTransactionException;
@@ -312,7 +313,7 @@ public class UploadContentAndImage {
             request.setAttribute("nodeTrailCsv", newTrail);
             request.setAttribute("passedParams", passedParams);
             TransactionUtil.commit();
-        } catch (Exception e) {
+        } catch (GenericEntityException | GenericServiceException e) {
             Debug.logError(e, "[UploadContentAndImage] " , module);
             request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
             try {
@@ -350,7 +351,7 @@ public class UploadContentAndImage {
             Map<String, Object> passedParams = new HashMap<String, Object>();
             FileItem fi = null;
             FileItem imageFi = null;
-            byte[] imageBytes = {};
+            byte[] imageBytes;
             passedParams.put("userLogin", userLogin);
             for (int i = 0; i < lst.size(); i++) {
                 fi = lst.get(i);
@@ -398,7 +399,7 @@ public class UploadContentAndImage {
                 }
             }
             TransactionUtil.commit();
-        } catch (Exception e) {
+        } catch (GenericTransactionException | GenericServiceException e) {
             Debug.logError(e, "[UploadContentAndImage] " , module);
             request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
             try {