You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

!!! Work In Progress !!!

RepositoryService and Repository

Because CMIS allows several repositories to live in the same server, the information about the remote server and how to talk to it is encapsulated in a RepositoryService. The RepositoryManager is the global registry of RepositoryServices, and from a RepositoryService you can get to several Repositories.

Your code can either instantiate a protocol-specific version of the Repository interface:

Instantiating an AtomPub repository service
RepositoryService repositoryService = new APPRepositoryService(url, null);
Getting to a repository directly
Repository repository = repositoryService.getRepository("myrepo");

Or rely on it being already registered and look up the repository by name:

Registering a repository service
RepositoryManager.getInstance().registerService(repositoryService);
Looking up a repository by name
Repository repository = RepositoryManager.getInstance().getRepository("myrepo");

High-level, object-oriented API: Connection, Folder, Document

From a Repository you can get a new Connection, get the root folder, get the first of its children and change its description:

Object-oriented API
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(Repository.PARAM_USERNAME, "username");
params.put(Repository.PARAM_PASSWORD, "password");

Connection conn = repository.getConnection(params);
try {
    Folder root = conn.getRootFolder();
    List<CMISObject> children = root.getChildren();
    for (CMISObject child : children) {
        System.out.println(child.getName());
    }
    Document doc = (Document) children.get(0);
    doc.setValue("description", "First child");
    doc.save();
} finally {
    conn.close();
}

Low-level SPI: SPI, ObjectEntry

Here you access the DTO for the object itself. This example does the same thing as above:

Object-oriented API
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(Repository.PARAM_USERNAME, "username");
params.put(Repository.PARAM_PASSWORD, "password");

SPI spi = repository.getSPI(params);
try {
    ObjectId rootId = repository.getInfo().getRootFolderId();
    ListPage<ObjectEntry> page = spi.getChildren(rootId, null, null, null);
    for (ObjectEntry entry : page) {
        System.out.println(entry.getValue(Property.NAME));
    }
    ObjectId docId = page.get(0); // ObjectEntry implements ObjectId
    Map<String, Serializable> props = new HashMap<String, Serializable>();
    props.put("description", "First child");
    spi.updateProperties(docId, null, props);    
} finally {
    spi.close();
}

  • No labels