Retrieving Objects

CMIS 1.0 CMIS 1.1

Getting the Root Folder

All repositories have to provide a root folder. It’s the entry point for browsing the repository content. The root folder might be completely empty and useless for repositories that only support unfiled objects.

OpenCMIS (Java)

Folder rootFolder = session.getRootFolder();

PortCMIS (C#)

IFolder rootFolder = Session.GetRootFolder();

Getting Objects by ID

All objects in a repository must have a unique object ID and can be retrieved by this ID. If the user has no permissions to see the object, an objectNotFound exception is thrown.

Use an Operation Context to define which details of the object should be returned.

OpenCMIS (Java)

CmisObject cmisObject = session.getObject(id);

if (cmisObject instanceof Document) {
    Document document = (Document) cmisObject;
} else if (cmisObject instanceof Folder) {
    Folder folder = (Folder) cmisDocument;
} else {
    ...
}

PortCMIS (C#)

ICmisObject cmisObject = Session.GetObject(id);

if (cmisObject is IDocument) {
    IDocument document = cmisObject as IDocument;
} else if (cmisObject is IFolder) {
    IFolder folder = cmisDocument as IFolder;
} else {
    ...
}

Getting Objects by Path

A filed object has one or more paths and can be retrieved by this path. If the user has no permissions to see the object, an objectNotFound exception is thrown.

Most repositories use the cmis:name property of the folders and the object to assemble the path. But it is possible that the path segments don’t match the names.

Use an Operation Context to define which details of the object should be returned.

OpenCMIS (Java)

String path = "/User Homes/customer1/document.odt";
CmisObject cmisObject = session.getObjectByPath(path);

// get the object ID
String id = cmisObject.getId();

// we know it is a filable object, we just retrieved it by path
FileableCmisObject fileableCmisObject = (FileableCmisObject) cmisObject;

// get all paths, there must be at least one
List<String> paths = fileableCmisObject.getPaths();

// get all parent folders, there must be at least one
List<Folder> parents = fileableCmisObject.getParents();

PortCMIS (C#)

string path = "/User Homes/customer1/document.odt";
ICmisObject cmisObject = Session.GetObjectByPath(path);

// get the object ID
string id = cmisObject.Id;

// we know it is a filable object, we just retrieved it by path
IFileableCmisObject fileableCmisObject = cmisObject as IFileableCmisObject;

// get all paths, there must be at least one
IList<string> paths = fileableCmisObject.Paths;

// get all parent folders, there must be at least one
IList<IFolder> parents = fileableCmisObject.Parents;

Getting Folder Children

The page about lists explains how paging works.

Use an Operation Context to define which details of the objects should be returned.

OpenCMIS (Java)

Folder folder = ...

for (CmisObject child: folder.getChildren()) {
    System.out.println(child.getName());
}

PortCMIS (C#)

IFolder folder = ...

foreach (ICmisObject child in folder.GetChildren()) {
    Console.WriteLine(child.Name);
}

Understanding the Object Cache

By default, OpenCMIS and PortCMIS cache objects. That is, the object returned by getObject() or getObjectbyPath() can be stale. There are multiple ways to deal with that.

Refresh the object data that is returned from getObject()

OpenCMIS (Java)

CmisObject cmisObject = session.getObject(id);
cmisObject.refresh(); // contacts the repository and refreshes the object
cmisObject.refreshIfOld(60 * 1000); // ... or refreshes the object only if the data is older than a minute

PortCMIS (C#)

ICmisObject cmisObject = Session.GetObject(id);
cmisObject.Refresh(); // contacts the repository and refreshes the object
cmisObject.RefreshIfOld(60 * 1000); // ... or refreshes the object only if the data is older than a minute

Turn off the session cache completely

OpenCMIS (Java)

session.getDefaultContext().setCacheEnabled(false);

PortCMIS (C#)

Session.DefaultContext.CacheEnabled = false;

Turn off caching for this getObject() call

See also the page about the Operation Context.

OpenCMIS (Java)

OperationContext oc = session.createOperationContext();
oc.setCacheEnabled(false);

CmisObject cmisObject = session.getObject(id, oc);

PortCMIS (C#)

IOperationContext oc = Session.CreateOperationContext();
oc.CacheEnabled = false;

ICmisObject cmisObject = Session.GetObject(id, oc);

Clear the session cache

This is not recommended!

OpenCMIS (Java)

session.clear();

PortCMIS (C#)

Session.Clear();