You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Paul Piper (Created) (JIRA)" <ji...@apache.org> on 2011/11/20 00:29:51 UTC

[jira] [Created] (OFBIZ-4580) Categories - calculated trails

Categories - calculated trails
------------------------------

                 Key: OFBIZ-4580
                 URL: https://issues.apache.org/jira/browse/OFBIZ-4580
             Project: OFBiz
          Issue Type: Improvement
            Reporter: Paul Piper
            Priority: Minor


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

        

Re: [jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by Jacques Le Roux <ja...@les7arts.com>.
Kiran,

I think Paul is not monitoring the dev ML. 
Your comment should be better in the Jira issue (from where it will be relayed to Paul, creator of the issue). 
This anyway is by and large true, to keep history, and ease comments flow

Thanks

Jacques

From: <ki...@objectedge.com>
> Hello Paul,
> 
> I agree that having such function to generate the trail would be useful. 
> But this is an expensive operation (not sure if it would hit the cache) as 
> it recursively lookups the parent category by doing query. A comment 
> should be added to make it clear to user.
> 
> When possible, you should set category_id and pcategory. These are used to 
> update the trail (see setTrail). setTrail can be called from anywhere as 
> below:
> 
> curCategoryId = parameters.category_id ?: parameters.CATEGORY_ID ?: "";
> CategoryWorker.setTrail(request, curCategoryId);
> 
> Cheers,
> Kiran

Re: [jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by ki...@objectedge.com.
Hello Paul,

I agree that having such function to generate the trail would be useful. 
But this is an expensive operation (not sure if it would hit the cache) as 
it recursively lookups the parent category by doing query. A comment 
should be added to make it clear to user.

When possible, you should set category_id and pcategory. These are used to 
update the trail (see setTrail). setTrail can be called from anywhere as 
below:

curCategoryId = parameters.category_id ?: parameters.CATEGORY_ID ?: "";
CategoryWorker.setTrail(request, curCategoryId);

Cheers,
Kiran

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Erwan de FERRIERES (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13154475#comment-13154475 ] 

Erwan de FERRIERES commented on OFBIZ-4580:
-------------------------------------------

Hi Paul,
thanks for the function. But in order to commit it to OFBiz, you need to attach your code to the Jira issue, and accept the license.
Could you also add an use case ?

Cheers,
                
> Categories - calculated trails
> ------------------------------
>
>                 Key: OFBIZ-4580
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4580
>             Project: OFBiz
>          Issue Type: Improvement
>            Reporter: Paul Piper
>            Priority: Minor
>
> 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

        

[jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by "Paul Piper (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Piper updated OFBIZ-4580:
------------------------------

    Attachment: getCategoryTrail-patch.patch

Added a little service descriptor to go along with the function and fixed the patch
                
> 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, getCategoryTrail-patch.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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13237834#comment-13237834 ] 

Jacques Le Roux commented on OFBIZ-4580:
----------------------------------------

Kiran,

As Paul explained and I commented at http://svn.apache.org/viewvc?rev=1304454&view=rev
{quote}
This service/mathod are not meant to be run on every request. Its best use is to generate the trail every so often and store somewhere (a lucene/solr tree, entities, cache or so). 
{quote}

So it does not need to be optmised it seems. Else you could provice a patch...

                
> 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
>             Fix For: SVN trunk
>
>         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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Kiran Gawde (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13236720#comment-13236720 ] 

Kiran Gawde commented on OFBIZ-4580:
------------------------------------

Friends, my concern was that the solution was using findList for each productCategoryId. And that would hit the database(?).
My suggestion was to use existing setTrail/getTrail method from CategoryWorker.
                
> 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
>             Fix For: SVN trunk
>
>         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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13236386#comment-13236386 ] 

Jacques Le Roux commented on OFBIZ-4580:
----------------------------------------

Hi Kiran,

Could you elaborate on when/where to set category_id and pcategory?
                
> 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

        

[jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Updated) (JIRA)" <ji...@apache.org>.
     [ 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

        

[jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by "Paul Piper (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Piper updated OFBIZ-4580:
------------------------------

    Attachment: CategoryWorker.patch

This should be an example inclusion of how to wrap it in a service... maybe we should consider doing both - adding the function first, before wrapping it in a service.

Either way, this works fine but needs to be tested.
                
> 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
>
>
> 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

        

[jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by "Paul Piper (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Piper updated OFBIZ-4580:
------------------------------

    Attachment: CategoryWorker-with-trail-export.patch

Attached you will find the patch for direct inclusion. It has been a while since i did this, so my best guess is that we should add a proper and simple service to wrap it around this function. 

Either way, a usecase is as follows:

On any ecommerce system you may be required to export the way you need to access a specific categoryId taken from its root. This is useful for exporting a tree for data migration to another system, to create an easy way to print breadcrumbs, or to later (in combination with modern search engines) create a proper facceted index. The function attached provides the basic means for that.
                
> Categories - calculated trails
> ------------------------------
>
>                 Key: OFBIZ-4580
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4580
>             Project: OFBiz
>          Issue Type: Improvement
>            Reporter: Paul Piper
>            Priority: Minor
>         Attachments: 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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13195769#comment-13195769 ] 

Jacques Le Roux commented on OFBIZ-4580:
----------------------------------------

BTW, here are comments from Kiran on dev ML

{quote}
Hello Paul,

I agree that having such function to generate the trail would be useful. 
But this is an expensive operation (not sure if it would hit the cache) as 
it recursively lookups the parent category by doing query. A comment 
should be added to make it clear to user.

When possible, you should set category_id and pcategory. These are used to 
update the trail (see setTrail). setTrail can be called from anywhere as 
below:

curCategoryId = parameters.category_id ?: parameters.CATEGORY_ID ?: "";
CategoryWorker.setTrail(request, curCategoryId);

Cheers,
Kiran
{quote}


                
> 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

        

[jira] [Resolved] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux resolved OFBIZ-4580.
------------------------------------

       Resolution: Fixed
    Fix Version/s: SVN trunk

Thanks Paul,

I committed your patch in trunk at r1304205. I wait Kiran's anwser before closing
                
> 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
>             Fix For: SVN trunk
>
>         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

        

[jira] [Assigned] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux reassigned OFBIZ-4580:
--------------------------------------

    Assignee: Jacques Le Roux
    
> 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
>
>
> 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

        

[jira] [Updated] (OFBIZ-4580) Categories - calculated trails

Posted by "Paul Piper (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Piper updated OFBIZ-4580:
------------------------------

    Attachment:     (was: getCategoryTrail-patch.patch)
    
> 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
>
>
> 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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Kiran Gawde (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13237901#comment-13237901 ] 

Kiran Gawde commented on OFBIZ-4580:
------------------------------------

Please go ahead and close the issue.
                
> 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
>             Fix For: SVN trunk
>
>         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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13236478#comment-13236478 ] 

Jacques Le Roux commented on OFBIZ-4580:
----------------------------------------

Thanks Paul I will add your comment in the method and service. We still want to wait for Kiran's answer, right?
                
> 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
>             Fix For: SVN trunk
>
>         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

        

[jira] [Closed] (OFBIZ-4580) Categories - calculated trails

Posted by "Jacques Le Roux (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux closed OFBIZ-4580.
----------------------------------


Thanks Kiran
                
> 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
>             Fix For: SVN trunk
>
>         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

        

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

Posted by "Paul Piper (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13236456#comment-13236456 ] 

Paul Piper commented on OFBIZ-4580:
-----------------------------------

Just to clarify: The attached feature is not meant to be run on every request, its best use is to generate the trail every so often and store somewhere (a lucene/solr tree, entities, cache or so). 
                
> 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
>             Fix For: SVN trunk
>
>         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