[ 
https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jacques Le Roux updated OFBIZ-4580:
-----------------------------------

    Attachment: OFBIZ-4580-CategoryWorker-with-trail-export.patch

Hi Paul,

I think it's an interesting feature.

For now, just for the sake of the form (did not review complaty functional 
aspects yet) and in order of importance:

# +                ServiceUtil.isError(results);
+                ServiceUtil.isError(results);
are not supposed to be used like that. See comment there /** A little short-cut 
method to check to see if a service returned an error */
I guess you wanted to use rather 
ServiceUtil.returnSuccess();
return ServiceUtil.returnError(e.toString());
See new attached patch for more changes on this point (notably how to better 
log/return error in service, BTW doing this I found that the 
CommonDatabaseProblem label was missing an ${errMessage} parameter)
# duplicated Java doc with 2 tabs just before
# wrong formatting (tab related I guess)
+                        if (trailElements.contains(trailCategoryId)) {
+                            break;
+                        }else{
+                                trailElements.add(trailCategoryId);
+                        }
# (revision 3173): this might work but not always, notably if you have others 
changes in your working copy. To avoid this be sure to use a 
fresh-checkout/updated working copy of Apache OFBiz trunk (or release) when 
creating your patch, else committers might cross issues with your patches.
** create a patch from your custom working copy (like you did)
** apply it on a fresh-checkout/updated working copy of Apache OFBiz trunk. If 
it works contribute, else create a patch to contribute from there...

This said, thanks for your contribution, I will review later before 
committing... 
PS: Note that the right way to name a patch is to prefix it by the Jira issue. 
This is helpful for committers who have several patches pending, waiting to be 
committed
                
> Categories - calculated trails
> ------------------------------
>
>                 Key: OFBIZ-4580
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4580
>             Project: OFBiz
>          Issue Type: Improvement
>            Reporter: Paul Piper
>            Assignee: Jacques Le Roux
>            Priority: Minor
>         Attachments: CategoryWorker-with-trail-export.patch, 
> CategoryWorker.patch, OFBIZ-4580-CategoryWorker-with-trail-export.patch
>
>
> Hey folks,
> been a while since I contributed. I noticed that currently ofbiz misses a 
> simple function to generate a category trail. Generating a trail, however, is 
> often useful when generating breadcrums, facetted search results, and proper 
> category trees in general. Hence I created the following as a timesaver:
> {code:title=getCategoryTrail|borderStyle=solid}
> public static  List getCategoryTrail(String productCategoryId,DispatchContext 
> dctx){
>               GenericDelegator delegator = (GenericDelegator) 
> dctx.getDelegator();
>               List<String> trailElements = FastList.newInstance();
>         trailElements.add(productCategoryId);
>         String parentProductCategoryId = productCategoryId;
>         while (UtilValidate.isNotEmpty(parentProductCategoryId)) {
>             // find product category rollup
>             try {
>                 List<EntityCondition> rolllupConds = FastList.newInstance();
>                 
> rolllupConds.add(EntityCondition.makeCondition("productCategoryId", 
> parentProductCategoryId));
>                 rolllupConds.add(EntityUtil.getFilterByDateExpr());
>                 List<GenericValue> productCategoryRollups = 
> delegator.findList("ProductCategoryRollup", 
> EntityCondition.makeCondition(rolllupConds), null, 
> UtilMisc.toList("-fromDate"), null, true);
>                 if (UtilValidate.isNotEmpty(productCategoryRollups)) {
>                     // add only categories that belong to the top category to 
> trail
>                     for (GenericValue productCategoryRollup : 
> productCategoryRollups) {
>                         String trailCategoryId = 
> productCategoryRollup.getString("parentProductCategoryId");
>                         parentProductCategoryId = trailCategoryId;
>                         if (trailElements.contains(trailCategoryId)) {
>                             break;
>                         }else{
>                               trailElements.add(trailCategoryId);
>                         }
>                     }
>                 } else {
>                     parentProductCategoryId = null;
>                 }
>             } catch (GenericEntityException e) {
>                 Debug.logError(e, "Cannot generate trail from product 
> category", module);
>             }
>         }
>         Collections.reverse(trailElements);
>         return trailElements;
>       }
> {code}
> I suggest to add this to the CategoryWorker.java

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to