[ofbiz-framework] branch release17.12 updated: Fixed: Inconsistent String Comparisons (OFBIZ-9254) & Uploading image to data resource (OFBIZ-10834)

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

[ofbiz-framework] branch release17.12 updated: Fixed: Inconsistent String Comparisons (OFBIZ-9254) & Uploading image to data resource (OFBIZ-10834)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release17.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release17.12 by this push:
     new 95d3aad  Fixed: Inconsistent String Comparisons (OFBIZ-9254) & Uploading image to data resource (OFBIZ-10834)
95d3aad is described below

commit 95d3aadcb5f34c98741f7ac877b893fd75044f5b
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Mon Jul 27 09:20:21 2020 +0200

    Fixed: Inconsistent String Comparisons (OFBIZ-9254) & Uploading image to data resource (OFBIZ-10834)
   
    Changes made in startsWith and indexOf methods in ContentManagementServices
    for OFBIZ-9254  where wrong (reversed). Fortunately only place where this happened.
   
    I added a comment to make clear why we have 2 empty else if
   
    I'll backport later, conflicts to handle by hand...
   
    Thanks: Ankush Upadhyay for spotting the bug
   
    Conflicts handled by hand
---
 .../ofbiz/content/ContentManagementServices.java   | 190 +++++++++++----------
 1 file changed, 96 insertions(+), 94 deletions(-)

diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java b/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
index 6543e23..1ff7829 100644
--- a/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
+++ b/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
@@ -583,100 +583,102 @@ public class ContentManagementServices {
           newDrContext.put("mimeTypeId", mimeTypeId);
       }
 
-      if (!dataResourceExists) { // Create
-          Map<String, Object> thisResult = dispatcher.runSync("createDataResource", newDrContext);
-          String errorMsg = ServiceUtil.getErrorMessage(thisResult);
-          if (UtilValidate.isNotEmpty(errorMsg)) {
-              throw(new Exception(errorMsg));
-          }
-          dataResourceId = (String)thisResult.get("dataResourceId");
-          if (Debug.infoOn()) {
-              Debug.logInfo("in persist... dataResourceId(0):" + dataResourceId, module);
-          }
-          dataResource = (GenericValue)thisResult.get("dataResource");
-          Map<String, Object> fileContext = new HashMap<String, Object>();
-          fileContext.put("userLogin", userLogin);
-          if ("IMAGE_OBJECT".equals(dataResourceTypeId)) {
-              if (imageDataBytes != null) {
-                  fileContext.put("dataResourceId", dataResourceId);
-                  fileContext.put("imageData", imageDataBytes);
-                  thisResult = dispatcher.runSync("createImage", fileContext);
-                  errorMsg = ServiceUtil.getErrorMessage(thisResult);
-                  if (UtilValidate.isNotEmpty(errorMsg)) {
-                      return ServiceUtil.returnError(errorMsg);
-                  }
-              }
-          } else if ("SHORT_TEXT".equals(dataResourceTypeId)) {
-          } else if ("SURVEY".startsWith(dataResourceTypeId)) {
-          } else if ("_FILE".indexOf(dataResourceTypeId) >=0) {
-              Map<String, Object> uploadImage = new HashMap<String, Object>();
-              uploadImage.put("userLogin", userLogin);
-              uploadImage.put("dataResourceId", dataResourceId);
-              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
-              uploadImage.put("rootDir", context.get("objectInfo"));
-              uploadImage.put("uploadedFile", imageDataBytes);
-              uploadImage.put("_uploadedFile_fileName", (String) context.get("_imageData_fileName"));
-              uploadImage.put("_uploadedFile_contentType", (String) context.get("_imageData_contentType"));
-              dispatcher.runSync("attachUploadToDataResource", uploadImage);
-          } else {
-              // assume ELECTRONIC_TEXT
-              if (UtilValidate.isNotEmpty(textData)) {
-                  fileContext.put("dataResourceId", dataResourceId);
-                  fileContext.put("textData", textData);
-                  thisResult = dispatcher.runSync("createElectronicText", fileContext);
-                  errorMsg = ServiceUtil.getErrorMessage(thisResult);
-                  if (UtilValidate.isNotEmpty(errorMsg)) {
-                      return ServiceUtil.returnError(errorMsg);
-                  }
-              }
-          }
-      } else { // Update
-          Map<String, Object> thisResult = dispatcher.runSync("updateDataResource", newDrContext);
-          String errorMsg = ServiceUtil.getErrorMessage(thisResult);
-          if (UtilValidate.isNotEmpty(errorMsg)) {
-              return ServiceUtil.returnError(errorMsg);
-          }
-          Map<String, Object> fileContext = new HashMap<String, Object>();
-          fileContext.put("userLogin", userLogin);
-          String forceElectronicText = (String)context.get("forceElectronicText");
-          if ("IMAGE_OBJECT".equals(dataResourceTypeId)) {
-              if (imageDataBytes != null || "true".equalsIgnoreCase(forceElectronicText)) {
-                  fileContext.put("dataResourceId", dataResourceId);
-                  fileContext.put("imageData", imageDataBytes);
-                  thisResult = dispatcher.runSync("updateImage", fileContext);
-                  errorMsg = ServiceUtil.getErrorMessage(thisResult);
-                  if (UtilValidate.isNotEmpty(errorMsg)) {
-                      return ServiceUtil.returnError(errorMsg);
-                  }
-              }
-          } else if ("SHORT_TEXT".equals(dataResourceTypeId)) {
-          } else if ("SURVEY".startsWith(dataResourceTypeId)) {
-          } else if ("_FILE".indexOf(dataResourceTypeId) >=0) {
-              Map<String, Object> uploadImage = new HashMap<String, Object>();
-              uploadImage.put("userLogin", userLogin);
-              uploadImage.put("dataResourceId", dataResourceId);
-              uploadImage.put("dataResourceTypeId", dataResourceTypeId);
-              uploadImage.put("rootDir", context.get("objectInfo"));
-              uploadImage.put("uploadedFile", imageDataBytes);
-              uploadImage.put("_uploadedFile_fileName", (String) context.get("_imageData_fileName"));
-              uploadImage.put("_uploadedFile_contentType", (String) context.get("_imageData_contentType"));
-              dispatcher.runSync("attachUploadToDataResource", uploadImage);
-          } else {
-              if (UtilValidate.isNotEmpty(textData) || "true".equalsIgnoreCase(forceElectronicText)) {
-                  fileContext.put("dataResourceId", dataResourceId);
-                  fileContext.put("textData", textData);
-                  thisResult = dispatcher.runSync("updateElectronicText", fileContext);
-                  errorMsg = ServiceUtil.getErrorMessage(thisResult);
-                  if (UtilValidate.isNotEmpty(errorMsg)) {
-                      return ServiceUtil.returnError(errorMsg);
-                  }
-              }
-          }
-      }
-      result.put("dataResourceId", dataResourceId);
-      result.put("drDataResourceId", dataResourceId);
-      context.put("dataResourceId", dataResourceId);
-      return result;
+        if (!dataResourceExists) { // Create
+            Map<String, Object> thisResult = dispatcher.runSync("createDataResource", newDrContext);
+            if (ServiceUtil.isError(thisResult)) {
+                throw (new GenericServiceException(ServiceUtil.getErrorMessage(thisResult)));
+            }
+            dataResourceId = (String) thisResult.get("dataResourceId");
+            if (Debug.infoOn()) {
+                Debug.logInfo("in persist... dataResourceId(0):" + dataResourceId, module);
+            }
+            dataResource = (GenericValue) thisResult.get("dataResource");
+            Map<String, Object> fileContext = new HashMap<>();
+            fileContext.put("userLogin", userLogin);
+            if ("IMAGE_OBJECT".equals(dataResourceTypeId)) {
+                if (imageDataBytes != null) {
+                    fileContext.put("dataResourceId", dataResourceId);
+                    fileContext.put("imageData", imageDataBytes);
+                    thisResult = dispatcher.runSync("createImage", fileContext);
+                    if (ServiceUtil.isError(thisResult)) {
+                        return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+                    }
+                }
+                // We don't want SHORT_TEXT and SURVEY to be caught by the last else if, hence the 2 empty else if
+            } else if ("SHORT_TEXT".equals(dataResourceTypeId)) {
+            } else if (dataResourceTypeId.startsWith("SURVEY")) {
+            } else if (dataResourceTypeId.indexOf("_FILE") >= 0) {
+                Map<String, Object> uploadImage = new HashMap<>();
+                uploadImage.put("userLogin", userLogin);
+                uploadImage.put("dataResourceId", dataResourceId);
+                uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+                uploadImage.put("rootDir", context.get("objectInfo"));
+                uploadImage.put("uploadedFile", imageDataBytes);
+                uploadImage.put("_uploadedFile_fileName", context.get("_imageData_fileName"));
+                uploadImage.put("_uploadedFile_contentType", context.get("_imageData_contentType"));
+                thisResult = dispatcher.runSync("attachUploadToDataResource", uploadImage);
+                if (ServiceUtil.isError(thisResult)) {
+                    return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+                }
+            } else {
+                // assume ELECTRONIC_TEXT
+                if (UtilValidate.isNotEmpty(textData)) {
+                    fileContext.put("dataResourceId", dataResourceId);
+                    fileContext.put("textData", textData);
+                    thisResult = dispatcher.runSync("createElectronicText", fileContext);
+                    if (ServiceUtil.isError(thisResult)) {
+                        return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+                    }
+                }
+            }
+        } else { // Update
+            Map<String, Object> thisResult = dispatcher.runSync("updateDataResource", newDrContext);
+            if (ServiceUtil.isError(thisResult)) {
+                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+            }
+            Map<String, Object> fileContext = new HashMap<>();
+            fileContext.put("userLogin", userLogin);
+            String forceElectronicText = (String) context.get("forceElectronicText");
+            if ("IMAGE_OBJECT".equals(dataResourceTypeId)) {
+                if (imageDataBytes != null || "true".equalsIgnoreCase(forceElectronicText)) {
+                    fileContext.put("dataResourceId", dataResourceId);
+                    fileContext.put("imageData", imageDataBytes);
+                    thisResult = dispatcher.runSync("updateImage", fileContext);
+                    if (ServiceUtil.isError(thisResult)) {
+                        return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+                    }
+                }
+                // We don't want SHORT_TEXT and SURVEY to be caught by the last else if, hence the 2 empty else if
+            } else if ("SHORT_TEXT".equals(dataResourceTypeId)) {
+            } else if (dataResourceTypeId.startsWith("SURVEY")) {
+            } else if (dataResourceTypeId.indexOf("_FILE") >= 0) {
+                Map<String, Object> uploadImage = new HashMap<>();
+                uploadImage.put("userLogin", userLogin);
+                uploadImage.put("dataResourceId", dataResourceId);
+                uploadImage.put("dataResourceTypeId", dataResourceTypeId);
+                uploadImage.put("rootDir", context.get("objectInfo"));
+                uploadImage.put("uploadedFile", imageDataBytes);
+                uploadImage.put("_uploadedFile_fileName", context.get("_imageData_fileName"));
+                uploadImage.put("_uploadedFile_contentType", context.get("_imageData_contentType"));
+                thisResult = dispatcher.runSync("attachUploadToDataResource", uploadImage);
+                if (ServiceUtil.isError(thisResult)) {
+                    return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+                }
+            } else {
+                if (UtilValidate.isNotEmpty(textData) || "true".equalsIgnoreCase(forceElectronicText)) {
+                    fileContext.put("dataResourceId", dataResourceId);
+                    fileContext.put("textData", textData);
+                    thisResult = dispatcher.runSync("updateElectronicText", fileContext);
+                    if (ServiceUtil.isError(thisResult)) {
+                        return ServiceUtil.returnError(ServiceUtil.getErrorMessage(thisResult));
+                    }
+                }
+            }
+        }
+        result.put("dataResourceId", dataResourceId);
+        result.put("drDataResourceId", dataResourceId);
+        context.put("dataResourceId", dataResourceId);
+        return result;
     }
 
     public static void addRoleToUser(Delegator delegator, LocalDispatcher dispatcher, Map<String, Object> serviceContext) throws GenericServiceException, GenericEntityException {