cancel
Showing results for 
Search instead for 
Did you mean: 

Get the parent of a category?

wiggum
Champ in-the-making
Champ in-the-making
Hi all,

I have a content rule that is linking documents that go in different spaces with ProductIDs, ProductCodes, etc. that I have defined as categories. 

I'm writing a custom action where I'd like to use the values of these, but I need more of a key/value relationship.  E.g. ProductID=101

But I can't seem to figure out how to properly get the category applied to the document and it's parent.

Any suggestions are welcome.

Thanks!
1 REPLY 1

wiggum
Champ in-the-making
Champ in-the-making
For reference, I figured it out:


                 // we know for now that the general classifiable aspect only will be
                // applied so we can retrive the categories property direclty
                Collection<NodeRef> categories = (Collection<NodeRef>)this.nodeService.getProperty(
                      actionedUponNodeRef, ContentModel.PROP_CATEGORIES);
               
                if (categories == null || categories.size() == 0)
                {
                   writeLog("No Categories applied");
                }
                else
                {
                  writeLog("Categories found!  Size: " + categories.size() + "");
                   for (NodeRef ref : categories)
                   {
                      if (this.nodeService.exists(ref))
                      {
                         category = Repository.getNameForNode(this.nodeService, ref);
                         writeLog("category: " + category);
                        
                         parentCategory = Repository.getNameForNode(this.nodeService, this.nodeService.getPrimaryParent(ref).getParentRef());
                         writeLog("parent: " + parentCategory);
               }
            }
         }