cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Alfresco Path from UUID

dsnkostic
Champ in-the-making
Champ in-the-making
I have question about getting Path of alfresco from UUID. Here is an use-case:
I have UUID of user_home (using WebServiceFactory.getAdministrationService().getUser("username") I have UUID like: "workspace://SpacesStore/93170542-12bf-46c6-858f-2400f265cf42").
From user_home I want to go to some sub-folder, so I need Path of user_home ("/app:company_home/cm:myappusers/cm:username"), to concat next sub folder (like: "/cm:subfolder1/cmSmiley Tongueroducts").
When I have Path I can upload, modify, browse or something else with it.
I can't hardcode path or UUID for sub-folder, since every user in application has its own folder. However structure inside every userhome is the same.

Thanks in advance.
4 REPLIES 4

dsnkostic
Champ in-the-making
Champ in-the-making
I forgot to add, that I need to do this from our JAVA client application (through SOAP webservices). There is possibility for writing our webscript for that (using NodeService I guess), but I want to see if is there way to avoid using them.

dsnkostic
Champ in-the-making
Champ in-the-making
OK, I figured it out in case someone have similar problem.

You need to expose RepositoryServiceSoapBindingStub through WebServiceFactory.getRepositoryService().
Then you need to extract UUID from NodeRef String. Example: From "workspace://SpacesStore/93170542-12bf-46c6-858f-2400f265cf42" you need "93170542-12bf-46c6-858f-2400f265cf42". You can use String.Split("/") for this.
Next create Reference object and fill it with StoreRed and UUID. StoreRef is that leftover from NodeRef string ("workspace://SpacesStore") and can be created using
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
Finally call RepositoryServiceSoapBindingStub get method and pass Predicate object to it. Predicate is used for defining search criteria for you alfresco using Lucene or some other Query. Interestingly you can pass only array of nodereferences and omit Query object (with null). Repository service will then fill array of nodereferences with missing data based on data available in structure (in this case StoreRef and UUID).
Here is sample of last step:
      Reference node = new Reference();
      node.setStore(storeRef);
      node.setUuid(nodeUUID);

      Node [] nodes = null;
      try
      {
         nodes = repositoryService.get(new Predicate(new Reference[]{node}, storeRef, null ));
      }
      catch (RepositoryFault e)
      {
         e.printStackTrace();
      }
      catch (RemoteException e)
      {
         e.printStackTrace();
      }
      return nodes[0].getReference().getPath();

Hope this will helps…

gyro_gearless
Champ in-the-making
Champ in-the-making
Not sure if i missed a step here, but i'd guess that you anyway get the path to the cmSmiley Tongueerson node (which is suposed to exist under /s:system/sSmiley Tongueeople/), not the home folder itself  :?  To lookup the real home folder, you would have to evaluate the cm:homeFolder property of that user object.

This can perhaps be done on the client, but i'd prefer to write a webscript for such purposes, as these are more reusable and more entertaining to write than to fiddle with that Predicate stuff (just my opinion)….

Cheers
Gyro

dsnkostic
Champ in-the-making
Champ in-the-making
Yes I am getting home folder correctly.
Here is the code:

      try {
         AuthenticationDetails aDetails = AuthenticationUtils.getAuthenticationDetails();
         UserDetails ud = WebServiceFactory.getAdministrationService().getUser(aDetails.getUserName());
         //ud.get
         for (NamedValue item : ud.getProperties()) {
            if (item.getName().equals("{http://www.alfresco.org/model/content/1.0}homeFolder"))
               return item.getValue();
         }
      } catch (AdministrationFault e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

As for webscripts, we wanted to first use everything that Alfresco supports out-of-the box and add additional webscripts for some advanced functions. My guess was that finding UUID from Path and vice-versa was already implemented since it is one of the basic functionality.

Cheers