Home

session.getObjectByPath() for sub dir

You are here

7 posts / 0 new
Last post
session.getObjectByPath() for sub dir

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 params = new HashMap();
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 repos = sessionFactory.getRepositories(params);
if (repos.isEmpty()) {
throw new RuntimeException("Server has no repositories!");
}
Session session = repos.get(0).createSession();

properties = new HashMap();
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.

4.2.e
getObjectByPath

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

If this post was helpful, please click Yes on the Post Rating

session.getObjectByPath() for sub dir

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.

namespace

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}

If this post was helpful, please click Yes on the Post Rating

Please see the attached file

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}

object path

Your object path is /Directory1//Directory2 ,not /dir1/dir2.
Please try session.getObjectByPath("/Directory1/Directory2")

If this post was helpful, please click Yes on the Post Rating

object path

Your object path is /Directory1//Directory2 ,not /dir1/dir2.
Please try session.getObjectByPath("/Directory1/Directory2")

If this post was helpful, please click Yes on the Post Rating