cancel
Showing results for 
Search instead for 
Did you mean: 

session.getObjectByPath() for sub dir

narayana_giri
Champ in-the-making
Champ in-the-making
Hi,

Requirement is to upload attachment in the sub dir so using the below syntax:
AlfrescoFolder folder1 = (AlfrescoFolder) session.getObjectByPath("/dir1/dir2");

But getting the exception as below:
Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Object not found: /dir1/dir2/
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:430)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:552)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getObjectInternal(AbstractAtomPubService.java:776)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.getObjectByPath(ObjectServiceImpl.java:479)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.getObjectByPath(SessionImpl.java:430)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.getObjectByPath(SessionImpl.java:408)
   at com.fedbid.attach.services.CreateSession.main(CreateSession.java:62)

Tried other approaches as below:
AlfrescoFolder folder1 = (AlfrescoFolder) session.getObjectByPath("/dir1/dir2");
AlfrescoFolder folder1 = (AlfrescoFolder) session.getObjectByPath("/dir1/dir2/");
AlfrescoFolder folder1 = (AlfrescoFolder) session.getObjectByPath("/cm:dir1/cm:dir2");
AlfrescoFolder folder1 = (AlfrescoFolder) session.getObjectByPath("/cmis:dir1/cmis:dir2");

Folder folder1 = (Folder) session.getObjectByPath("/dir1/dir2");
Folder folder1 = (Folder) session.getObjectByPath("/dir1/dir2/");

Folder folder1 = (Folder) session.getObjectByPath("/cm:dir1/cm:dir2");
Folder folder1 = (Folder) session.getObjectByPath("/cmis:dir1/cmis:dir2");

Please let me know how to get the session.getObjectByPath() for sub dir.

The code to get the session:
String serverUrl ="http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom";
      String userName = "admin";
      String password = "admin";

      SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
      Map<String, String> params = new HashMap<String, String>();
      params.put(SessionParameter.USER, userName);
      params.put(SessionParameter.PASSWORD, password);
      params.put(SessionParameter.ATOMPUB_URL, serverUrl);
      params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      params.put(SessionParameter.OBJECT_FACTORY_CLASS,"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
      java.util.List<Repository> repos = sessionFactory.getRepositories(params);
      if (repos.isEmpty()) {
         throw new RuntimeException("Server has no repositories!");
      }
      Session session = repos.get(0).createSession();

      properties = new HashMap<String, Object>();
      properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
      properties.put(PropertyIds.NAME, "test4");
      properties.put(PropertyIds.CREATED_BY, "admin");
      properties.put("cm:title", "Title8");
      properties.put("cm:description", "description8");

Note: when i tried to use
Thanks.




6 REPLIES 6

kaynezhang
World-Class Innovator
World-Class Innovator
Just using
 session.getObjectByPath("/dir1/dir2");
  will be ok ,make sure /dir1 is under root folder.

Hi,

Thanks for the info.

dir1 is created under Company Home. Here is the directory structure:
Company Home > dir1> dir2.

But still unable to get session.getObjectByPath("/dir1/dir2") and the same exception is thrown.

Thanks.

kaynezhang
World-Class Innovator
World-Class Innovator
Please login to explorer as admin ,and open the admin console, and then click node browser.
Choose "workspace://SpacesStore" store,and browse to Company Home > dir1> dir2,Please check if both uri of dir1 and dir2 are
{http://www.alfresco.org/model/content/1.0}

Please see the attached file that has URI of both directories.

Both uri of directory1 and directory2 have same URI as {http://www.alfresco.org/model/content/1.0}

kaynezhang
World-Class Innovator
World-Class Innovator
Your object path is
/Directory1//Directory2
,not
/dir1/dir2
.
Please try
session.getObjectByPath("/Directory1/Directory2")

kaynezhang
World-Class Innovator
World-Class Innovator
Your object path is
/Directory1//Directory2
,not
/dir1/dir2
.
Please try
session.getObjectByPath("/Directory1/Directory2")
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.