cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with getChildByName

dwighth
Champ on-the-rise
Champ on-the-rise
Hi.
I always get a null from NodeService.getChildByName() and FileFolderService.resolveNamePath().  Since FileFolderService.resolveNamePath() uses NodeService.getChildByName(), I suspect the problem is with the latter.

I'm trying to get Company Home as my test, but to no avail. I've tried every combination of qualified association type name and child name that I can think of, but none of them works. The following is the combination that I think is the correct one:


nodeService.getChildByName(root, ContentModel.ASSOC_CONTAINS, "app:company_home");

I'm working with 2.1 and the JCR methods seem to work for me, so I have a work around, but I'd rather be using the FileFolderService methods.

Any ideas?

Thanks in advance;
Dwight
15 REPLIES 15

derek
Star Contributor
Star Contributor
Hi,

There are other methods to match the association QName, which is app:company_home.  You need to look for the actual name, which will be Company Home.  The FileFolderService completely hides the use of associations and works only with the display names as stored in property cm:name.

Regards

dwighth
Champ on-the-rise
Champ on-the-rise
Hi.
Thanks for the response.

The use of common name by the FileFolder methods is what I had understood from the javaDocs as well. However, that doesn't seem to get around my problem. When I try the following calls


fileFolderService.listFolders(root);
fileFolderService.search(root, "Company Home", false);

I get a List containing the Company Home node. That's what I'd expect. However, when I call


fileFolderService.searchSimple(root, "Company Home");

I get null.

When I do


List<String> nodePath = new ArrayList<String>();
nodePath.add("Company Home");
fileFolderService.resolveNamePath(root, nodePath);

I get a FileNotFound exception. I've tried it with a preceding slash and get the same result.

Any insight that you can give me is appreciated.

Thanks;
Dwight

derek
Star Contributor
Star Contributor
Hi,
FileFolderService originally threw out any operations that weren't performed against the cm:content-cm:folder model.  That constraint was relaxed a little over time.  It remains, however, a model-specific service.

Company Home is the top-level cm:folder in the hierarchy.  You're expected to know what its NodeRef is.  The root node is not a cm:folder and FileFolderService should really have nothing to do with it.  The type of association between the root node and the Company Home node is not the type that FileFolderService serves.

That being said, the search code should also return no results in order to be consistent - but it's a minor issue.
Think of Company Home as being the root of the file-folder hierarchy.  You need it before you can use FileFolderService.  To get it, make a quick call to the NodeService
QName qname = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "company_home");
List<ChildAssociationRef> assocRefs = nodeService.getChildAssocs(rootNodeRef, ContentModel.ASSOC_CHILDREN, qname);
From that point on, you're in the hierarchy with the model that the FileFolderService uses.

Regards

derek
Star Contributor
Star Contributor
Another thing: If you're concerned about having to know the company home association QName out of the blue, it is available as an injectable property spaces.company_home.childname.  This is how our services get hold of it.

dwighth
Champ on-the-rise
Champ on-the-rise
Hi.
Great - thanks, that explains it.

Appreciate the time & effort…

Regards;
Dwight

derek
Star Contributor
Star Contributor
You're welcome.  Good luck.

kdejaeger
Champ in-the-making
Champ in-the-making
Hello,

I wrote some code using the filefolderservice and stumbled upon a similar problem.
You can see the code sniplet in this post http://forums.alfresco.com/en/viewtopic.php?f=4&t=12891 .

The arguments given to the function resolveNamePath are easy:
* first argument : the noderef pointing to "Company Home"
* second argument : an arraylist ; for example [User Homes, username, subfolder]

Apparently the code works as admin but not as a regular user.
As a regular user the method resolveNamePath throws a filenotfoundexception.

Help would be appreciated.

derek
Star Contributor
Star Contributor
Do regular users have access to all elements of the path?

kdejaeger
Champ in-the-making
Champ in-the-making
I found my stupid mistake.

For example user koen has home folder "Company Home/User Homes/koen".
And when using the resolveNamePath method (companyhome_noderef, list [User Homes, koen]), I got the error.

The rootnode is resolved like this:

User user = AuthenticationHelper.getUser(request, response);
NodeRef personRef = user.getPerson();
NodeRef homeRef = nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);

So since I was testing as root, I allways got the "Company Home" noderef as homefolder.
But as user koen, I get "Company Home/User Homes/koen"

However I didn't manage to get the "Company Home" noderef with the code you mentioned earlier.
Can you add another code sniplet that gets the actual "Company Home" noderef from the ChildAssociationRef you mentioned earlier?

Right now I am using an xpath query "cm:name" equals "Company Home" to get this noderef.