AnsweredAssumed Answered

session.getObjectByPath() for sub dir

Question asked by narayana.giri on Aug 20, 2014
Latest reply on Aug 21, 2014 by narayana.giri
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.




Outcomes