Author: jleroux
Date: Sat Oct 15 17:12:28 2016
New Revision: 1765094

URL: http://svn.apache.org/viewvc?rev=1765094&view=rev
Log:
Fixed: You cannot edit an image in content
(OFBIZ-7000)

If you get to
content/control/EditLayout?drDataResourceId=NOCONTENTFOUND&contentId=NOCONTENTFOUND
When trying to editing you get an error

Mohammed Rehan Khan explored the issue and found that there is a condition in 
DataResourceWorker method to render content of 'text' mime type only, for others
 it returns exception.

We can fix this by setting up mimeTypeID as null in request param

Question: Why setting up mimeTypeTypeId as 'null' is fixing this issue?
Answer: As we don't have image specific worker method for rendering these type 
of contents, so we are using DataResourceWorker.renderDataResourceAsText() 
to render image type content as well. Due to following condition, 
targetMimeTypeId is setting up as "text/html" if sent null and hence not 
throwing the exception reported in the ticket.

Thanks: Mohammed Rehan Khan for the patch

Modified:
    ofbiz/trunk/applications/content/groovyScripts/layout/EditSubContent.groovy
    
ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
    ofbiz/trunk/applications/content/template/mime-type/Image.ftl

Modified: 
ofbiz/trunk/applications/content/groovyScripts/layout/EditSubContent.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/groovyScripts/layout/EditSubContent.groovy?rev=1765094&r1=1765093&r2=1765094&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/groovyScripts/layout/EditSubContent.groovy 
(original)
+++ ofbiz/trunk/applications/content/groovyScripts/layout/EditSubContent.groovy 
Sat Oct 15 17:12:28 2016
@@ -47,7 +47,7 @@ if (currentValue) {
         templateRoot.context = ctx;
         out = new StringWriter();
         currentValue.drDataTemplateTypeId = "NONE";
-        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, mimeTypeId, false);
+        DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, 
out, templateRoot, locale, null, false);
         textData = out.toString();
         context.textData = textData;
     }

Modified: 
ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java?rev=1765094&r1=1765093&r2=1765094&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
 (original)
+++ 
ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/ContentManagementServices.java
 Sat Oct 15 17:12:28 2016
@@ -610,6 +610,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=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)) {
@@ -643,6 +653,16 @@ public class ContentManagementServices {
               }
           } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
           } else if (dataResourceTypeId.startsWith("SURVEY")) {
+          } else if (dataResourceTypeId.indexOf("_FILE") >=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);
@@ -655,17 +675,6 @@ public class ContentManagementServices {
               }
           }
       }
-      if (dataResourceTypeId.indexOf("_FILE") >=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);
-      }
       result.put("dataResourceId", dataResourceId);
       result.put("drDataResourceId", dataResourceId);
       context.put("dataResourceId", dataResourceId);

Modified: ofbiz/trunk/applications/content/template/mime-type/Image.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/template/mime-type/Image.ftl?rev=1765094&r1=1765093&r2=1765094&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/template/mime-type/Image.ftl (original)
+++ ofbiz/trunk/applications/content/template/mime-type/Image.ftl Sat Oct 15 
17:12:28 2016
@@ -16,4 +16,4 @@
   specific language governing permissions and limitations
   under the License.
   -->
-<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId}</@ofbizUrl>"/>
\ No newline at end of file
+<img src="<@ofbizUrl 
secure="${request.isSecure()?string}">stream?contentId=${contentId!}</@ofbizUrl>"/>
\ No newline at end of file


Reply via email to