svn commit: r664687 - in /ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions: category/ config/ lookup/

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

svn commit: r664687 - in /ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions: category/ config/ lookup/

lektran
Author: lektran
Date: Mon Jun  9 04:58:34 2008
New Revision: 664687

URL: http://svn.apache.org/viewvc?rev=664687&view=rev
Log:
A few minor improvements to Marco's groovy conversions

Modified:
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/CreateProductInCategoryCheckExisting.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategory.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/FindProductConfigItems.groovy
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/lookup/LookupVariantProduct.groovy

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/CreateProductInCategoryCheckExisting.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/CreateProductInCategoryCheckExisting.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/CreateProductInCategoryCheckExisting.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/CreateProductInCategoryCheckExisting.groovy Mon Jun  9 04:58:34 2008
@@ -26,33 +26,29 @@
 visitId = VisitHandler.getVisitId(session);
 
 featureIdByType = ParametricSearch.makeFeatureIdByTypeMap(request);
-featureIdSet = new HashSet();
-if (featureIdByType != null) {
+featureIdSet = [] as Set;
+if (featureIdByType) {
     featureIdSet.addAll(featureIdByType.values());
 }
 
 productIds = ProductSearch.parametricKeywordSearch(featureIdSet, null, delegator, productCategoryId, true, visitId, true, true, false);
 
 // get the product for each ID
-productIdIter = productIds.iterator();
 products = new ArrayList(productIds.size());
-while (productIdIter.hasNext()) {
-    productId = productIdIter.next();
+productIds.each { productId ->
     product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
     products.add(product);
 }
 
 productFeatureAndTypeDatas = new ArrayList(featureIdByType.size());
-featureIdByTypeIter = featureIdByType.entrySet().iterator();
-while (featureIdByTypeIter.hasNext()) {
-    featureIdByTypeEntry = featureIdByTypeIter.next();
-    productFeatureType = delegator.findByPrimaryKeyCache("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", featureIdByTypeEntry.getKey()));
-    productFeature = delegator.findByPrimaryKeyCache("ProductFeature", UtilMisc.toMap("productFeatureId", featureIdByTypeEntry.getValue()));
-    productFeatureAndTypeData = new HashMap();
-    productFeatureAndTypeData.put("productFeatureType", productFeatureType);
-    productFeatureAndTypeData.put("productFeature", productFeature);
+featureIdByType.each { featureIdByTypeEntry ->
+    productFeatureType = delegator.findByPrimaryKeyCache("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", featureIdByTypeEntry.key));
+    productFeature = delegator.findByPrimaryKeyCache("ProductFeature", UtilMisc.toMap("productFeatureId", featureIdByTypeEntry.value));
+    productFeatureAndTypeData = [:];
+    productFeatureAndTypeData.productFeatureType = productFeatureType;
+    productFeatureAndTypeData.productFeature = productFeature;
     productFeatureAndTypeDatas.add(productFeatureAndTypeData);
 }
 
-context.put("productFeatureAndTypeDatas", productFeatureAndTypeDatas);
-context.put("products", products);
+context.productFeatureAndTypeDatas = productFeatureAndTypeDatas;
+context.products = products;

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategory.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategory.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategory.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategory.groovy Mon Jun  9 04:58:34 2008
@@ -20,31 +20,29 @@
 import org.ofbiz.base.util.*
 import org.ofbiz.base.util.string.*
 
-productCategoryType = null;
 if (productCategory) {
-    productCategoryType = productCategory.getRelatedOne("ProductCategoryType");
-    context.productCategoryType = productCategoryType;
+    context.productCategoryType = productCategory.getRelatedOne("ProductCategoryType");
 }
 
 primaryParentCategory = null;
 primParentCatIdParam = request.getParameter("primaryParentCategoryId");
 if(productCategory) {
     primaryParentCategory = productCategory.getRelatedOne("PrimaryParentProductCategory");
-} else if (primParentCatIdParam && primParentCatIdParam.length() > 0) {
+} else if (primParentCatIdParam) {
     primaryParentCategory = delegator.findOne("ProductCategory", [productCategoryId : primParentCatIdParam], false);
 }
 context.primaryParentCategory = primaryParentCategory;
 
 
 // make the image file formats
-String imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format");
-String imageServerPath = UtilProperties.getPropertyValue("catalog", "image.server.path");
-String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
+imageFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format");
+imageServerPath = UtilProperties.getPropertyValue("catalog", "image.server.path");
+imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");
 context.imageFilenameFormat = imageFilenameFormat;
 context.imageServerPath = imageServerPath;
 context.imageUrlPrefix = imageUrlPrefix;
 
-FlexibleStringExpander filenameExpander = new FlexibleStringExpander(imageFilenameFormat);
+filenameExpander = new FlexibleStringExpander(imageFilenameFormat);
 context.imageNameCategory = imageUrlPrefix + "/" + filenameExpander.expandString([location : "categories", type : "category", id : productCategoryId]);
 context.imageNameLinkOne  = imageUrlPrefix + "/" + filenameExpander.expandString([location : "categories", type : "linkOne", id : productCategoryId]);
 context.imageNameLinkTwo  = imageUrlPrefix + "/" + filenameExpander.expandString([location : "categories", type : "linkTwo", id : productCategoryId]);
@@ -52,9 +50,9 @@
 
 // UPLOADING STUFF
 
-Object forLock = new Object();
-String contentType = null;
-String fileType = request.getParameter("upload_file_type");
+forLock = new Object();
+contentType = null;
+fileType = request.getParameter("upload_file_type");
 if (fileType) {
     context.fileType = fileType;
 
@@ -72,18 +70,18 @@
         contentType = "--" + contentType;
     }
 
-    String defaultFileName = filenameToUse + "_temp";
-    HttpRequestFileUpload uploadObject = new HttpRequestFileUpload();
+    defaultFileName = filenameToUse + "_temp";
+    uploadObject = new HttpRequestFileUpload();
     uploadObject.setOverrideFilename(defaultFileName);
     uploadObject.setSavePath(imageServerPath + "/" + filePathPrefix);
     uploadObject.doUpload(request);
 
-    String clientFileName = uploadObject.getFilename();
+    clientFileName = uploadObject.getFilename();
     if (clientFileName) {
         context.clientFileName = clientFileName;
     }
 
-    if (clientFileName && clientFileName.length() > 0) {
+    if (clientFileName) {
         if (clientFileName.lastIndexOf(".") > 0 && clientFileName.lastIndexOf(".") < clientFileName.length()) {
             filenameToUse += clientFileName.substring(clientFileName.lastIndexOf("."));
         } else {
@@ -93,12 +91,12 @@
         context.clientFileName = clientFileName;
         context.filenameToUse = filenameToUse;
 
-        String characterEncoding = request.getCharacterEncoding();
-        String imageUrl = imageUrlPrefix + "/" + filePathPrefix + java.net.URLEncoder.encode(filenameToUse, characterEncoding);
+        characterEncoding = request.getCharacterEncoding();
+        imageUrl = imageUrlPrefix + "/" + filePathPrefix + java.net.URLEncoder.encode(filenameToUse, characterEncoding);
 
         try {
-            File file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName);
-            File file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse);
+            file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName);
+            file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse);
             try {
                 file1.delete();
             } catch(Exception e) {
@@ -109,7 +107,7 @@
             e.printStackTrace();
         }
 
-        if (imageUrl && imageUrl.length() > 0) {
+        if (imageUrl) {
             context.imageUrl = imageUrl;
             productCategory.set(fileType + "ImageUrl", imageUrl);
             productCategory.store();

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContent.groovy Mon Jun  9 04:58:34 2008
@@ -30,8 +30,8 @@
 context.imageServerPath = imageServerPath;
 context.imageUrlPrefix = imageUrlPrefix;
 
-FlexibleStringExpander filenameExpander = new FlexibleStringExpander(imageFilenameFormat);
-context.imageNameSmall = imageUrlPrefix + "/" + filenameExpander.expandString(['size' : 'small', configItemId : configItemId]);
+filenameExpander = new FlexibleStringExpander(imageFilenameFormat);
+context.imageNameSmall = imageUrlPrefix + "/" + filenameExpander.expandString([size : 'small', configItemId : configItemId]);
 
 // Start ProdConfItemContent stuff
 productContent = null;
@@ -41,22 +41,20 @@
 context.productContent = productContent;
 
 productContentDatas = [];
-Iterator productContentIter = productContent.iterator();
-while (productContentIter) {
-    GenericValue productContent = (GenericValue) productContentIter.next();
-    GenericValue content = productContent.getRelatedOne("Content");
+productContent.each { productContent ->
+    content = productContent.getRelatedOne("Content");
     productContentDatas.add([productContent : productContent, content : content]);
 }
 
-HtmlFormWrapper updateProductContentWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "UpdateProductConfigItemContentAssoc", request, response);
+updateProductContentWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "UpdateProductConfigItemContentAssoc", request, response);
 context.updateProductContentWrapper = updateProductContentWrapper;
 updateProductContentWrapper.putInContext("productContentDatas", productContentDatas);
 
-HtmlFormWrapper prepareAddProductContentWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "PrepareAddProductConfigItemContentAssoc", request, response);
+prepareAddProductContentWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "PrepareAddProductConfigItemContentAssoc", request, response);
 context.prepareAddProductContentWrapper = prepareAddProductContentWrapper;
 prepareAddProductContentWrapper.putInContext("configItem", configItem);
 
-HtmlFormWrapper addProductContentWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "AddProductConfigItemContentAssoc", request, response);
+addProductContentWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "AddProductConfigItemContentAssoc", request, response);
 context.addProductContentWrapper = addProductContentWrapper;
 addProductContentWrapper.putInContext("configItem", configItem);
 
@@ -70,16 +68,16 @@
 if (!configItem) {
     tryEntity = false;
 }
-if ("true".equalsIgnoreCase((String)request.getParameter("tryEntity"))) {
+if ("true".equalsIgnoreCase(request.getParameter("tryEntity"))) {
     tryEntity = true;
 }
 context.tryEntity = tryEntity;
 
 // UPLOADING STUFF
 
-Object forLock = new Object();
-String contentType = null;
-String fileType = request.getParameter("upload_file_type");
+forLock = new Object();
+contentType = null;
+fileType = request.getParameter("upload_file_type");
 if (fileType) {
     context.fileType = fileType;
 
@@ -99,7 +97,7 @@
     }
         
     defaultFileName = filenameToUse + "_temp";
-    HttpRequestFileUpload uploadObject = new HttpRequestFileUpload();
+    uploadObject = new HttpRequestFileUpload();
     uploadObject.setOverrideFilename(defaultFileName);
     uploadObject.setSavePath(imageServerPath + "/" + filePathPrefix);
     uploadObject.doUpload(request);
@@ -107,9 +105,6 @@
     clientFileName = uploadObject.getFilename();
     if (clientFileName) {
         context.clientFileName = clientFileName;
-    }
-    
-    if (clientFileName && clientFileName.length() > 0) {
         if (clientFileName.lastIndexOf(".") > 0 && clientFileName.lastIndexOf(".") < clientFileName.length()) {
             filenameToUse += clientFileName.substring(clientFileName.lastIndexOf("."));
         } else {
@@ -123,8 +118,8 @@
         imageUrl = imageUrlPrefix + "/" + filePathPrefix + java.net.URLEncoder.encode(filenameToUse, characterEncoding);
         
         try {
-            File file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName);
-            File file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse);
+            file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName);
+            file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse);
             try {
                 file1.delete();
             } catch(Exception e) {
@@ -135,7 +130,7 @@
             e.printStackTrace();
         }
         
-        if (imageUrl && imageUrl.length() > 0) {
+        if (imageUrl) {
             context.imageUrl = imageUrl;
             configItem.set("imageUrl", imageUrl);
             configItem.store();

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigItemContentContent.groovy Mon Jun  9 04:58:34 2008
@@ -22,21 +22,12 @@
 import org.ofbiz.base.util.*;
 import org.ofbiz.widget.html.*;
 
-contentId = request.getParameter("contentId");
-if ("".equals(contentId)) {
-    contentId = null;
-}
+contentId = request.getParameter("contentId") ?: null;
 
 confItemContentTypeId = request.getParameter("confItemContentTypeId");
-fromDate = request.getParameter("fromDate");
-if ("".equals(fromDate)) {
-    fromDate = null;
-}
+fromDate = request.getParameter("fromDate") ?: null;
 
-description = request.getParameter("description");
-if ("".equals(description)) {
-    description = null;
-}
+description = request.getParameter("description") ?: null;
 
 productContent = delegator.findOne("ProdConfItemContent", [contentId : contentId, configItemId : configItemId, confItemContentTypeId : confItemContentTypeId, fromDate : fromDate], false);
 if (!productContent) {
@@ -64,8 +55,6 @@
     }
 }
 
-HtmlFormWrapper updateProductContentWrapper = null;
-
 //Assume it is a generic simple text content
 textData = [:];
 if (contentId && content) {

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/EditProductConfigOptions.groovy Mon Jun  9 04:58:34 2008
@@ -19,7 +19,7 @@
 
 import org.ofbiz.widget.html.*
 
-HtmlFormWrapper createConfigOptionWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "CreateConfigOption", request, response);
+createConfigOptionWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "CreateConfigOption", request, response);
 createConfigOptionWrapper.putInContext("configItemId", configItemId);
 createConfigOptionWrapper.putInContext("configOption", configOption);
 
@@ -27,7 +27,7 @@
 
 
 if (configOption) {
-    HtmlFormWrapper createConfigProductWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "CreateProductConfigProduct", request, response);
+    createConfigProductWrapper = new HtmlFormWrapper("component://product/webapp/catalog/config/ConfigForms.xml", "CreateProductConfigProduct", request, response);
     createConfigProductWrapper.putInContext("productConfigProduct", configProduct);
     createConfigProductWrapper.putInContext("configOptionId", configOptionId);
     createConfigProductWrapper.putInContext("configItemId", configItemId);

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/FindProductConfigItems.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/FindProductConfigItems.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/FindProductConfigItems.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/config/FindProductConfigItems.groovy Mon Jun  9 04:58:34 2008
@@ -23,14 +23,14 @@
 // set the page parameters
 viewIndex = 0;
 try {
-    viewIndex = Integer.valueOf((String) parameters.get("VIEW_INDEX")).intValue();
+    viewIndex = parameters.VIEW_INDEX as int;
 } catch (Exception e) {
     viewIndex = 0;
 }
 
 viewSize = 20;
 try {
-    viewSize = Integer.valueOf((String) parameters.get("VIEW_SIZE")).intValue();
+    viewSize = parameters.VIEW_SIZE as int;
 } catch (Exception e) {
     viewSize = 20;
 }

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/lookup/LookupVariantProduct.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/lookup/LookupVariantProduct.groovy?rev=664687&r1=664686&r2=664687&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/lookup/LookupVariantProduct.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/lookup/LookupVariantProduct.groovy Mon Jun  9 04:58:34 2008
@@ -25,23 +25,22 @@
 product = delegator.findOne("Product", [productId : productId], false);
 
 result = dispatcher.runSync("getProductFeaturesByType", [productId : productId, productFeatureApplTypeId : "SELECTABLE_FEATURE"]);
-featureTypes = result.get("productFeatureTypes");
-featuresByTypes = result.get("productFeaturesByType");
+featureTypes = result.productFeatureTypes;
+featuresByTypes = result.productFeaturesByType;
 searchFeatures = [];
 selectedFeatureTypeValues = [];
 if (featureTypes) {
-    for (int i = 0; i < featureTypes.size(); i++) {
-        featureType = featureTypes.get(i);
-        featuresByType = featuresByTypes.get(featureType);
+    featureTypes.each { featureType ->
+        featuresByType = featuresByTypes[featureType];
         featureTypeAndValues = [featureType : featureType, features : featuresByType];
         searchFeatures.add(featureTypeAndValues);
         //
         selectedFeatureTypeValue = request.getParameter(featureType);
-        if (selectedFeatureTypeValue && selectedFeatureTypeValue.length() > 0) {
+        if (selectedFeatureTypeValue) {
             featureTypeAndValues.selectedFeatureId = selectedFeatureTypeValue;
             selectedFeatureTypeValues.add(selectedFeatureTypeValue);
             feature = delegator.findOne("ProductFeature", [productFeatureId : selectedFeatureTypeValue]);
-            productVariantId += (feature.getString("idCode") != null? feature.getString("idCode"): "");
+            productVariantId += feature.getString("idCode") ?: "";
             productFeatureIds += "|" + selectedFeatureTypeValue;
         }
     }
@@ -50,7 +49,7 @@
 variants = [];
 //if (selectedFeatureTypeValues) {
     result = dispatcher.runSync("getAllExistingVariants", [productId : productId, productFeatureAppls : selectedFeatureTypeValues]);
-    variants = result.get("variantProductIds");
+    variants = result.variantProductIds;
 //}
 
 // Quick Add Variant
@@ -66,9 +65,7 @@
 
 // also need the variant products themselves
 variantProducts = [];
-iter = variants.iterator();
-while (iter) {
-    variantId = iter.next();
+variants.each { variantId ->
     variantProducts.add(delegator.findOne("Product", [productId : variantId], true));
 }
 context.variantProducts = variantProducts;