svn commit: r689772 - in /ofbiz/trunk: applications/product/data/ applications/product/servicedef/ applications/product/src/org/ofbiz/product/product/ applications/product/webapp/catalog/WEB-INF/ applications/product/webapp/catalog/WEB-INF/actions/prod...

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

svn commit: r689772 - in /ofbiz/trunk: applications/product/data/ applications/product/servicedef/ applications/product/src/org/ofbiz/product/product/ applications/product/webapp/catalog/WEB-INF/ applications/product/webapp/catalog/WEB-INF/actions/prod...

jleroux@apache.org
Author: jleroux
Date: Thu Aug 28 03:02:47 2008
New Revision: 689772

URL: http://svn.apache.org/viewvc?rev=689772&view=rev
Log:
A patch from Mridul Pathak "Added support for uploading additional Product Views (images)" (https://issues.apache.org/jira/browse/OFBIZ-1930) - OFBIZ-1930

I fixed an, unrelated to patch, problem in EditProductContentContent.groovy. This is not the 1st time I cross this type of issue. I checked it does not appear on demo server and I guess it was not appearing with bsh  before. I'm not sure of its origin but it seems related to my configuration. I use, from my machine default, "Central European Summer Time" and demo server uses "Central Daylight Time". But I can't see why it affects my machine and not the demo server : there is no origin here (maybe GMT, but obviously it's not the case)
The lines I added are (+ import)
} else {
    fromDate = ObjectType.simpleTypeConvert(fromDate, "Timestamp", null, null, false)    
}
(I intentionnaly let the line without semi-colon as it's not mandatory in Groovy)

Added:
    ofbiz/trunk/framework/images/webapp/images/products/additional/
Modified:
    ofbiz/trunk/applications/product/data/ProductTypeData.xml
    ofbiz/trunk/applications/product/servicedef/services.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContentContent.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
    ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml

Modified: ofbiz/trunk/applications/product/data/ProductTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/data/ProductTypeData.xml?rev=689772&r1=689771&r2=689772&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/data/ProductTypeData.xml (original)
+++ ofbiz/trunk/applications/product/data/ProductTypeData.xml Thu Aug 28 03:02:47 2008
@@ -231,6 +231,10 @@
     <ProductContentType description="Image Alt Text - Medium" hasTable="N" parentTypeId="" productContentTypeId="MEDIUM_IMAGE_ALT"/>
     <ProductContentType description="Image Alt Text - Large" hasTable="N" parentTypeId="" productContentTypeId="LARGE_IMAGE_ALT"/>
     <ProductContentType description="Image Alt Text - Detail" hasTable="N" parentTypeId="" productContentTypeId="DETAIL_IMAGE_ALT"/>
+    <ProductContentType description="Image - Additional View 1" hasTable="N" parentTypeId="" productContentTypeId="ADDITIONAL_IMAGE_1"/>
+    <ProductContentType description="Image - Additional View 2" hasTable="N" parentTypeId="" productContentTypeId="ADDITIONAL_IMAGE_2"/>
+    <ProductContentType description="Image - Additional View 3" hasTable="N" parentTypeId="" productContentTypeId="ADDITIONAL_IMAGE_3"/>
+    <ProductContentType description="Image - Additional View 4" hasTable="N" parentTypeId="" productContentTypeId="ADDITIONAL_IMAGE_4"/>
     <ProductContentType description="Add To Cart Label" hasTable="N" parentTypeId="" productContentTypeId="ADDTOCART_LABEL"/>
     <ProductContentType description="Add To Cart Image" hasTable="N" parentTypeId="" productContentTypeId="ADDTOCART_IMAGE"/>
     <ProductContentType description="Short Sales Pitch" hasTable="N" parentTypeId="" productContentTypeId="SHORT_SALES_PITCH"/>

Modified: ofbiz/trunk/applications/product/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?rev=689772&r1=689771&r2=689772&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services.xml Thu Aug 28 03:02:47 2008
@@ -414,6 +414,16 @@
         <override name="localeString" optional="false"/>
         <override name="contentId" mode="INOUT"/>
     </service>
+    
+    <service name="addAdditionalViewForProduct" default-entity-name="ProductContent" engine="java"
+        location="org.ofbiz.product.product.ProductServices" invoke="addAdditionalViewForProduct" auth="true">
+        <implements service="uploadFileInterface"/>
+        <auto-attributes include="pk" mode="IN" optional="true"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+        <attribute mode="IN" name="contentId" optional="true" type="String"/>
+        <override name="productContentTypeId" optional="false"/>
+        <override name="productId" optional="false"/>
+    </service>
 
     <!-- SupplierProduct Services -->
     <service name="createSupplierProduct" default-entity-name="SupplierProduct" engine="simple"

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java?rev=689772&r1=689771&r2=689772&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java Thu Aug 28 03:02:47 2008
@@ -18,14 +18,23 @@
  *******************************************************************************/
 package org.ofbiz.product.product;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
 import java.sql.Timestamp;
 import java.util.*;
 
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
@@ -934,5 +943,163 @@
 
         return ServiceUtil.returnSuccess();
     }
+    
+    public static Map addAdditionalViewForProduct(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String productId = (String) context.get("productId");
+        String productContentTypeId = (String) context.get("productContentTypeId");
+        ByteBuffer imageData = (ByteBuffer) context.get("uploadedFile");
+        
+        if (UtilValidate.isNotEmpty((String) context.get("_uploadedFile_fileName"))) {
+            String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format");
+            String imageServerPath = UtilProperties.getPropertyValue("catalog", "image.server.path");
+            String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
+            
+            FlexibleStringExpander filenameExpander = FlexibleStringExpander.getInstance(imageFilenameFormat);
+            String id = productId + "_View_" + productContentTypeId.charAt(productContentTypeId.length() - 1);
+            String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "type", "additional", "id", id));
+            String filePathPrefix = "";
+            String filenameToUse = fileLocation;
+            if (fileLocation.lastIndexOf("/") != -1) {
+                filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
+                filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1);
+            }
+            
+            List fileExtension = FastList.newInstance();
+            try {
+                fileExtension = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", (String) context.get("_uploadedFile_contentType")));
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+                ServiceUtil.returnError(e.getMessage());
+            }
+            
+            GenericValue extension = EntityUtil.getFirst(fileExtension);
+            if (extension != null) {
+                filenameToUse += "." + extension.getString("fileExtensionId");
+            }
+            
+            File file = new File(imageServerPath + "/" + filePathPrefix + filenameToUse);
+            
+            try {
+                RandomAccessFile out = new RandomAccessFile(file, "rw");
+                out.write(imageData.array());
+                out.close();
+            } catch (FileNotFoundException e) {
+                Debug.logError(e, module);
+                return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath());
+            } catch (IOException e) {
+                Debug.logError(e, module);
+                return ServiceUtil.returnError("Unable to write binary data to: " + file.getAbsolutePath());
+            }
+            
+            String imageUrl = imageUrlPrefix + "/" + filePathPrefix + filenameToUse;
+                
+            if (UtilValidate.isNotEmpty(imageUrl) && imageUrl.length() > 0) {
+                String contentId = (String) context.get("contentId");
+                
+                Map dataResourceCtx = FastMap.newInstance();
+                dataResourceCtx.put("objectInfo", imageUrl);
+                dataResourceCtx.put("dataResourceName", (String) context.get("_uploadedFile_fileName"));
+                dataResourceCtx.put("userLogin", userLogin);
+                
+                Map productContentCtx = FastMap.newInstance();
+                productContentCtx.put("productId", productId);
+                productContentCtx.put("productContentTypeId", productContentTypeId);
+                productContentCtx.put("fromDate", (Timestamp) context.get("fromDate"));
+                productContentCtx.put("thruDate", (Timestamp) context.get("thruDate"));
+                productContentCtx.put("userLogin", userLogin);
+                
+                if (UtilValidate.isNotEmpty(contentId)) {
+                    GenericValue content = null;
+                    try {
+                        content = delegator.findOne("Content", UtilMisc.toMap("contentId", contentId), false);
+                    } catch (GenericEntityException e) {
+                        Debug.logError(e, module);
+                        ServiceUtil.returnError(e.getMessage());
+                    }
+                        
+                    if (content != null) {
+                        GenericValue dataResource = null;
+                        try {
+                            dataResource = content.getRelatedOne("DataResource");
+                        } catch (GenericEntityException e) {
+                            Debug.logError(e, module);
+                            ServiceUtil.returnError(e.getMessage());
+                        }
+                    
+                        if (dataResource != null) {
+                            dataResourceCtx.put("dataResourceId", dataResource.getString("dataResourceId"));
+                            try {
+                                Map dataResourceResult = dispatcher.runSync("updateDataResource", dataResourceCtx);
+                            } catch (GenericServiceException e) {
+                                Debug.logError(e, module);
+                                ServiceUtil.returnError(e.getMessage());
+                            }
+                        } else {
+                            dataResourceCtx.put("dataResourceTypeId", "URL_RESOURCE");
+                            Map dataResourceResult = FastMap.newInstance();
+                            try {
+                                dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx);
+                            } catch (GenericServiceException e) {
+                                Debug.logError(e, module);
+                                ServiceUtil.returnError(e.getMessage());
+                            }
+                            
+                            Map contentCtx = FastMap.newInstance();
+                            contentCtx.put("contentId", contentId);
+                            contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId"));
+                            contentCtx.put("userLogin", userLogin);
+                            try {
+                                Map contentResult = dispatcher.runSync("updateContent", contentCtx);
+                            } catch (GenericServiceException e) {
+                                Debug.logError(e, module);
+                                ServiceUtil.returnError(e.getMessage());
+                            }
+                        }
+                            
+                        productContentCtx.put("contentId", contentId);
+                        try {
+                            Map productContentResult = dispatcher.runSync("updateProductContent", productContentCtx);
+                        } catch (GenericServiceException e) {
+                            Debug.logError(e, module);
+                            ServiceUtil.returnError(e.getMessage());
+                        }
+                    }
+                } else {
+                    dataResourceCtx.put("dataResourceTypeId", "URL_RESOURCE");
+                    Map dataResourceResult = FastMap.newInstance();
+                    try {
+                        dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx);
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, module);
+                        ServiceUtil.returnError(e.getMessage());
+                    }
+
+                    Map contentCtx = FastMap.newInstance();
+                    contentCtx.put("contentTypeId", "DOCUMENT");
+                    contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId"));
+                    contentCtx.put("userLogin", userLogin);
+                    Map contentResult = FastMap.newInstance();
+                    try {
+                        contentResult = dispatcher.runSync("createContent", contentCtx);
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, module);
+                        ServiceUtil.returnError(e.getMessage());
+                    }
+                    
+                    productContentCtx.put("contentId", contentResult.get("contentId"));
+                    try {
+                        Map productContentResult = dispatcher.runSync("createProductContent", productContentCtx);
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, module);
+                        ServiceUtil.returnError(e.getMessage());
+                    }
+                }
+            }
+        }
+       return ServiceUtil.returnSuccess();
+    }
 }
 

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContentContent.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContentContent.groovy?rev=689772&r1=689771&r2=689772&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContentContent.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductContentContent.groovy Thu Aug 28 03:02:47 2008
@@ -22,6 +22,7 @@
 import org.ofbiz.entity.util.*;
 import org.ofbiz.base.util.*;
 import java.sql.Timestamp;
+import org.ofbiz.base.util.ObjectType
 
 contentId = request.getParameter("contentId");
 if ("".equals(contentId)) {
@@ -33,8 +34,11 @@
 fromDate = request.getParameter("fromDate");
 if ("".equals(fromDate)) {
     fromDate = null;
+} else {
+    fromDate = ObjectType.simpleTypeConvert(fromDate, "Timestamp", null, null, false)    
 }
 
+
 description = request.getParameter("description");
 if ("".equals(description)) {
     description = null;
@@ -115,6 +119,8 @@
     context.downloadData = downloadData;
 } else if ("FULFILLMENT_EXTERNAL".equals(productContentTypeId)) {
     context.contentFormName = "EditProductContentExternal";
+} else if (productContentTypeId.indexOf("ADDITIONAL_IMAGE") > -1) {
+ context.contentFormName = "EditProductAdditionalImageContent";
 } else {
     //Assume it is a generic simple text content
     textData = [:];
@@ -134,4 +140,4 @@
 
 context.productContentData = productContentData;
 context.content = content;
-context.contentId = contentId;
\ No newline at end of file
+context.contentId = contentId;

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml?rev=689772&r1=689771&r2=689772&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml Thu Aug 28 03:02:47 2008
@@ -700,6 +700,12 @@
         <response name="success" type="view" value="EditProductContent"/>
         <response name="error" type="view" value="EditProductContentContent"/>
     </request-map>
+    <request-map uri="addAdditionalImageContentForProduct">
+        <security https="true" auth="true"/>
+        <event type="service" path="" invoke="addAdditionalViewForProduct"/>
+        <response name="success" type="view" value="EditProductContent"/>
+        <response name="error" type="view" value="EditProductContentContent"/>
+    </request-map>
 
     <!-- ================ Product GoodIdentification Requests ================= -->
     <request-map uri="EditProductGoodIdentifications">

Modified: ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml?rev=689772&r1=689771&r2=689772&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml Thu Aug 28 03:02:47 2008
@@ -662,6 +662,26 @@
         <field use-when="contentId == null" name="submitButton" title="${uiLabelMap.CommonCreate}" widget-style="smallSubmit"><submit button-type="button"/></field>
         <field use-when="contentId != null" name="submitButton" title="${uiLabelMap.CommonUpdate}" widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
+    
+    <form name="EditProductAdditionalImageContent" type="upload" target="addAdditionalImageContentForProduct" title="">
+        <auto-fields-entity entity-name="ProductContent" map-name="productContentData"/>
+        <field name="productContentTypeId"><display-entity entity-name="ProductContentType" also-hidden="true"/></field>
+        <field name="fromDate" use-when="contentId==null" title="${uiLabelMap.CommonFromDate}*" ><date-time/></field>
+        <field name="fromDate" use-when="contentId!=null" title="${uiLabelMap.CommonFromDate}" ><display/></field>
+        <field name="thruDate" title="${uiLabelMap.CommonThruDate}"></field>
+        <field use-when="contentId == null" name="contentId"><ignored/></field>
+        <field use-when="contentId != null" name="contentId" tooltip="${uiLabelMap.ProductNotModificationRecrationProductContentAssociation}" map-name="productContentData" ><display/></field>
+        <field name="useTime"><hidden/></field>
+        <field name="useTimeUomId"><hidden/></field>
+        <field name="useRoleTypeId"><hidden/></field>
+        <field name="useCountLimit"><hidden/></field>
+        <field name="purchaseThruDate"><hidden/></field>
+        <field name="purchaseFromDate"><hidden/></field>
+        <field name="uploadedFile" title="${uiLabelMap.ProductFile}"><file/></field>
+        <field name="productId"><hidden/></field>
+        <field use-when="contentId == null" name="submitButton" title="${uiLabelMap.CommonCreate}" widget-style="smallSubmit"><submit button-type="button"/></field>
+        <field use-when="contentId != null" name="submitButton" title="${uiLabelMap.CommonUpdate}" widget-style="smallSubmit"><submit button-type="button"/></field>
+    </form>
 
     <!-- SupplierProduct -->
     <form name="AddSupplierProduct" type="single" target="updateSupplierProduct" title="" default-map-name="supplierProduct"