On Aug 28, 2008, at 3:32 PM, [hidden email] wrote: > 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) I think we should stick to some guidelines on usage of groovy features especially semi-colon not mandatory, in OFBiz. This is just to make sure that code looks alike. My preference is to use semicolon. Thoughts ? - Vikas > > > 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" > > |
Administrator
|
I'm divided. The 1st time I saw that in groovy scripts I checked and saw that Groovy allows that.
My 1st reaction was, like you, to fix it. For me it was the same than not using {} for a single line in Java. It's like a bomb : sooner or later it may explode... But then I thought that there are other differences between Java and Goovy, why not allow this one ? As I outlined above it's a bit dangerous, even Groovy authors point it out ! Of course I will follow consensus... Jacques From: "Vikas Mayur" <[hidden email]> > > On Aug 28, 2008, at 3:32 PM, [hidden email] wrote: > >> 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) > > > I think we should stick to some guidelines on usage of groovy features especially semi-colon not mandatory, in OFBiz. This is > just to make sure that code looks alike. > My preference is to use semicolon. Thoughts ? > > - Vikas > > >> >> >> 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" >> >> > |
Yeah, it would be good to have consensus on usage of groovy features
not just on this semi-colon issue but others - if any (which I am not able to think of). - Vikas On Aug 28, 2008, at 4:38 PM, Jacques Le Roux wrote: > I'm divided. The 1st time I saw that in groovy scripts I checked and > saw that Groovy allows that. > My 1st reaction was, like you, to fix it. For me it was the same > than not using {} for a single line in Java. It's like a bomb : > sooner or later it may explode... > But then I thought that there are other differences between Java and > Goovy, why not allow this one ? > As I outlined above it's a bit dangerous, even Groovy authors point > it out ! > Of course I will follow consensus... > > Jacques > > From: "Vikas Mayur" <[hidden email]> >> >> On Aug 28, 2008, at 3:32 PM, [hidden email] wrote: >> >>> 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) >> >> >> I think we should stick to some guidelines on usage of groovy >> features especially semi-colon not mandatory, in OFBiz. This is >> just to make sure that code looks alike. >> My preference is to use semicolon. Thoughts ? >> >> - Vikas >> >> >>> >>> >>> 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" >>> >>> > |
In reply to this post by Vikas Mayur-3
Jacques,
I'm not clear on the problem you are trying to describe. Could you be more specific about what the expected behavior is and how it is different than what is happening? -Adrian [hidden email] wrote: > 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) |
Administrator
|
It's easy Adrian,
Just revert one of those commit and try without my change, you will see the bug. To find one of them,simply look for ObjectType.simpleTypeConvert in commits ML on Nabble (done by me last 3 months) http://www.nabble.com/forum/Search.jtp?query=ObjectType.simpleTypeConvert+groovy+jleroux&local=y&forum=15587&daterange=4&startdate=&enddate= The simpler/clearer being http://www.nabble.com/svn-commit%3A-r680698----ofbiz-trunk-applications-product-webapp-facility-WEB-INF-actions-facility-ViewFacilityInventoryByProduct.groovy-td18712849.html#a18712849 Jacques From: "Adrian Crum" <[hidden email]> > Jacques, > > I'm not clear on the problem you are trying to describe. Could you be more specific about what the expected behavior is and how it > is different than what is happening? > > -Adrian > > [hidden email] wrote: >> 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) > |
I don't have Postgres, so I'm not sure I'll see the bug.
From the commit log: "Log: Fix a bug : when searching Facility Inventory Items (menu Inventory) and using a date in "Show Products Sold Thru" it was working with Derby but not Postgres (at least 8.3 as I tested only this version)." What wasn't working? Did you get an exception? Did you get the wrong results? -Adrian Jacques Le Roux wrote: > It's easy Adrian, > > Just revert one of those commit and try without my change, you will see > the bug. To find one of them,simply look for > ObjectType.simpleTypeConvert in commits ML on Nabble (done by me last 3 > months) > > http://www.nabble.com/forum/Search.jtp?query=ObjectType.simpleTypeConvert+groovy+jleroux&local=y&forum=15587&daterange=4&startdate=&enddate= > > > The simpler/clearer being > http://www.nabble.com/svn-commit%3A-r680698----ofbiz-trunk-applications-product-webapp-facility-WEB-INF-actions-facility-ViewFacilityInventoryByProduct.groovy-td18712849.html#a18712849 > > > Jacques > > From: "Adrian Crum" <[hidden email]> >> Jacques, >> >> I'm not clear on the problem you are trying to describe. Could you be >> more specific about what the expected behavior is and how it is >> different than what is happening? >> >> -Adrian >> >> [hidden email] wrote: >>> 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) >> > > |
Administrator
|
In reply to this post by Vikas Mayur-3
From: "Vikas Mayur" <[hidden email]>
> Yeah, it would be good to have consensus on usage of groovy features not just on this semi-colon issue but others - if any (which > I am not able to think of). > > - Vikas This might help http://groovy.codehaus.org/Differences+from+Java For instance note the optional return in http://groovy.codehaus.org/Differences+from+Java#DifferencesfromJava-Thingstobeawareof This is interesting too http://groovy.codehaus.org/Runtime+vs+Compile+time%2C+Static+vs+Dynamic I also wondered if removing type when creating a variable was a good thing. It's obvious sometimes, somtimes not. But a rule for that would be boolean, so we would have to rewrite them all ... tedious... I had some other considerations, but, from the top of my head, the only one that really makes me hesitate was the semi-colon issue. Optional return maybe also but we don't use them much in script... Jacques > > On Aug 28, 2008, at 4:38 PM, Jacques Le Roux wrote: > >> I'm divided. The 1st time I saw that in groovy scripts I checked and saw that Groovy allows that. >> My 1st reaction was, like you, to fix it. For me it was the same than not using {} for a single line in Java. It's like a bomb >> : sooner or later it may explode... >> But then I thought that there are other differences between Java and Goovy, why not allow this one ? >> As I outlined above it's a bit dangerous, even Groovy authors point it out ! >> Of course I will follow consensus... >> >> Jacques >> >> From: "Vikas Mayur" <[hidden email]> >>> >>> On Aug 28, 2008, at 3:32 PM, [hidden email] wrote: >>> >>>> 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) >>> >>> >>> I think we should stick to some guidelines on usage of groovy features especially semi-colon not mandatory, in OFBiz. This is >>> just to make sure that code looks alike. >>> My preference is to use semicolon. Thoughts ? >>> >>> - Vikas >>> >>> >>>> >>>> >>>> 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" >>>> >>>> >> > |
Administrator
|
From: "Jacques Le Roux" <[hidden email]>
> From: "Vikas Mayur" <[hidden email]> >> Yeah, it would be good to have consensus on usage of groovy features not just on this semi-colon issue but others - if any >> (which >> I am not able to think of). >> >> - Vikas > > This might help http://groovy.codehaus.org/Differences+from+Java > For instance note the optional return in http://groovy.codehaus.org/Differences+from+Java#DifferencesfromJava-Thingstobeawareof > This is interesting too http://groovy.codehaus.org/Runtime+vs+Compile+time%2C+Static+vs+Dynamic > > I also wondered if removing type when creating a variable was a good thing. It's obvious sometimes, somtimes not. But a rule for > that would be boolean, so we would have to rewrite them all ... tedious... > I had some other considerations, but, from the top of my head, the only one that really makes me hesitate was the semi-colon > issue. Optional return maybe also but we don't use them much in script... > > Jacques I'm not sure anybody used it in OFBiz yet but there are also optional parenthesis http://groovy.codehaus.org/Statements#Statements-Optionalparenthesis (another interesting page :o) Jacques >> >> On Aug 28, 2008, at 4:38 PM, Jacques Le Roux wrote: >> >>> I'm divided. The 1st time I saw that in groovy scripts I checked and saw that Groovy allows that. >>> My 1st reaction was, like you, to fix it. For me it was the same than not using {} for a single line in Java. It's like a bomb >>> : sooner or later it may explode... >>> But then I thought that there are other differences between Java and Goovy, why not allow this one ? >>> As I outlined above it's a bit dangerous, even Groovy authors point it out ! >>> Of course I will follow consensus... >>> >>> Jacques >>> >>> From: "Vikas Mayur" <[hidden email]> >>>> >>>> On Aug 28, 2008, at 3:32 PM, [hidden email] wrote: >>>> >>>>> 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) >>>> >>>> >>>> I think we should stick to some guidelines on usage of groovy features especially semi-colon not mandatory, in OFBiz. This is >>>> just to make sure that code looks alike. >>>> My preference is to use semicolon. Thoughts ? >>>> >>>> - Vikas >>>> >>>> >>>>> >>>>> >>>>> 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" >>>>> >>>>> >>> >> > |
Administrator
|
Something I forgot to mention
http://docs.ofbiz.org/pages/viewpage.action?pageId=4472 Jacques From: "Jacques Le Roux" <[hidden email]> To: <[hidden email]> Sent: Saturday, August 30, 2008 1:36 AM Subject: Re: 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 > From: "Jacques Le Roux" <[hidden email]> >> From: "Vikas Mayur" <[hidden email]> >>> Yeah, it would be good to have consensus on usage of groovy features not just on this semi-colon issue but others - if any >>> (which >>> I am not able to think of). >>> >>> - Vikas >> >> This might help http://groovy.codehaus.org/Differences+from+Java >> For instance note the optional return in http://groovy.codehaus.org/Differences+from+Java#DifferencesfromJava-Thingstobeawareof >> This is interesting too http://groovy.codehaus.org/Runtime+vs+Compile+time%2C+Static+vs+Dynamic >> >> I also wondered if removing type when creating a variable was a good thing. It's obvious sometimes, somtimes not. But a rule for >> that would be boolean, so we would have to rewrite them all ... tedious... >> I had some other considerations, but, from the top of my head, the only one that really makes me hesitate was the semi-colon >> issue. Optional return maybe also but we don't use them much in script... >> >> Jacques > > I'm not sure anybody used it in OFBiz yet but there are also optional parenthesis > http://groovy.codehaus.org/Statements#Statements-Optionalparenthesis (another interesting page :o) > > Jacques > >>> >>> On Aug 28, 2008, at 4:38 PM, Jacques Le Roux wrote: >>> >>>> I'm divided. The 1st time I saw that in groovy scripts I checked and saw that Groovy allows that. >>>> My 1st reaction was, like you, to fix it. For me it was the same than not using {} for a single line in Java. It's like a >>>> bomb >>>> : sooner or later it may explode... >>>> But then I thought that there are other differences between Java and Goovy, why not allow this one ? >>>> As I outlined above it's a bit dangerous, even Groovy authors point it out ! >>>> Of course I will follow consensus... >>>> >>>> Jacques >>>> >>>> From: "Vikas Mayur" <[hidden email]> >>>>> >>>>> On Aug 28, 2008, at 3:32 PM, [hidden email] wrote: >>>>> >>>>>> 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) >>>>> >>>>> >>>>> I think we should stick to some guidelines on usage of groovy features especially semi-colon not mandatory, in OFBiz. This >>>>> is >>>>> just to make sure that code looks alike. >>>>> My preference is to use semicolon. Thoughts ? >>>>> >>>>> - Vikas >>>>> >>>>> >>>>>> >>>>>> >>>>>> 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" >>>>>> >>>>>> >>>> >>> >> > |
Free forum by Nabble | Edit this page |