cancel
Showing results for 
Search instead for 
Did you mean: 

Repository.findNodeRef doesn't work for Company Home

kcepull
Champ in-the-making
Champ in-the-making
[ Alf v3.4.0(E) ]

Trying to follow the example Java-backed WebScript from the Professional Alfresco book published by Wrox (Chapter 11). I can't seem to get the Repository.findNodeRef function to work when searching for just "Company Home". Searching for a folder underneath Company Home (e.g. Data Dictionary) works, however.

This code sample highlights the issue:

—————————-
package org.example;

import java.util.HashMap;
import java.util.Map;

import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;

public class JavaDir extends DeclarativeWebScript {
   private Repository repository;
   
   public void setRepository(Repository repository) {
      this.repository = repository;
   }
   
   protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

      …

      // Test code:
      System.out.println("/Company Home ==> " + repository.findNodeRef("path", "workspace/SpacesStore/Company Home".split("/")));
      System.out.println("/Company Home/Data Dictionary ==> " + repository.findNodeRef("path", "workspace/SpacesStore/Company Home/Data Dictionary".split("/")));

      …


   }   
}
——————————————-

The output from the above is:

/Company Home ==> null
/Company Home/Data Dictionary ==> workspace://SpacesStore/0a9446f3-6cc0-4619-b31a-442c2ca183a7

When searching by path for just /Company Home, it returns null. Yet, searching for "/Company Home/Data Dictionary" works. Why is this? Am I doing something wrong? Is this a bug?

Thanks,
Karl
1 REPLY 1

dnallsopp
Champ in-the-making
Champ in-the-making
Repository provides a specific method for returning company home.

public org.alfresco.service.cmr.repository.NodeRef getCompanyHome()

Gets the Company Home

Returns:
    company home node ref

For a path query, this method delegates to:

   fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(path));

However, not sure why it doesn't return it anyway using findNodeRef(). Looking at the source, I think it does so as a special case… maybe it has been fixed since you posted?