cancel
Showing results for 
Search instead for 
Did you mean: 

How to select parent of a given type somwhere in hierarchy?

mmalczewski
Champ in-the-making
Champ in-the-making
Hello,

My type ce:festival extends cm:folder. Inside of this festival there can be many folders with subfolders. Somewhere in hierachy there is a node for which I need to select ce:festival it is under. I do not know how deep it is - users can create as many folders as they want.

For example, it could look like this:

+ COMPANYHOME
    + festival (of type ce:festival)
        + folder1
            + folder1_1
                + folder1_1_1
                    + folder1_1_1_1
                        - my_node

or like this:

+ COMPANYHOME
  + festival (of type ce:festival)
    + folder1
      - my_node

How to get to "festival" having my_node reference? My xpath experiments do not seem to work.

mm
3 REPLIES 3

jayjayecl
Confirmed Champ
Confirmed Champ
Hi,

I'll assume you have Java skills for developing in Alfresco, that you have the NodeRef of your node my_node, and that you have a QName for your custom ce:festival type

you just build a method like that (it is not working of course, but it may give you a few hints) :


public NodeRef getAssociatedFestival (NodeRef nodeRef) {
   // Test if this nodeRef is of type ce:festival
   if(nodeService.getType(NodeRef).equals(QName_festival))  {
        return nodeRef;
   } else {
   // get the parent node of nodeRef and run this very method on it
   ChildAssociationRef cAssocRef = nodeService.getPrimaryParent(nodeRef);
   NodeRef parentRef = cAssocRef.getParentRef();
   return getAssociatedFestival(parentRef);
   }
}

mmalczewski
Champ in-the-making
Champ in-the-making
Thanks for reply. I did not make myself clear at the beginning - I have already had this working this way, but I don't like this solution. I'd rather invoke single lucene query, I think xpath based. Any ideas how to build such query?

mm

rogier_oudshoor
Champ in-the-making
Champ in-the-making
There is no CHILDREN index in Lucene, so you cannot query a parent for containing a child. You probably can using the XPath set (that is, without using Lucene at all), which you can read about at http://wiki.alfresco.com/wiki/Search_Documentation#XPath_search_using_the_node_service