opencmis part 1
DESCRIPTION
OpenCMIS, an Apache Chemistry sub-project, is an open source library which provides a simple Java API for accessing any CMIS compliant content repository. Think of it as the JDBC of content repositories. In this session, you'll learn about the architecture of OpenCMIS and walkthrough many code samples showing how easy it is to build CMIS-based applications.TRANSCRIPT
1
OpenCMIS Introduction
Florian MüllerSoftware Architect, Alfresco
twitter: @florian_mueller
2
OpenCMIS
• OpenCMIS is a sub-project of
• Apache Chemistry is an umbrella project for CMIS implementations
• Java• Python• PHP
Server and client implementation of the CMIS specification
3
OpenCMIS goals
• OpenCMIS hides the bindings and provides binding agnostic APIs and SPIs
• OpenCMIS adds a lot of convenience
Developers should focus on the domain model!
4
Current state
• OpenCMIS has contributors from Alfresco, Open Text, SAP and Nuxeo
• OpenCMIS 0.1.0 has been released in September
• The code is pretty mature and stable and has been tested against all major ECM vendors
• The some areas of client API will be refactored and simplified within the next month
OpenCMIS is an active Open Source project
5
OpenCMIS Architecture
Server, client, common and test modules
6
OpenCMIS Server
• One Servlet per binding that map the requests to an SPI
• Repository vendors have to implement two interfaces
Not our focus today…
… for CMIS connector developers
SOAP AtomPub
CMIS Service Factory
CMIS ServiceCMIS Service
CMIS Service
7
OpenCMIS client
• Client API• OO API• Easy to use• Build-in caching
• Client Binding API• Low-level• Very close to the CMIS specification• More control, less comfort
… for CMIS application developers
8
Let’s start
• Download it! http://incubator.apache.org/chemistry/opencmis.html
• Use Maven!
• Build the latest and greatest! http://incubator.apache.org/chemistry/opencmis-how-to-build.html
Get hold of the OpenCMIS Jars
<dependency> <groupId>org.apache.chemistry.opencmis</groupId> <artifactId>chemistry-opencmis-client-impl</artifactId> <version>0.1.0-incubating</version></dependency>
9
Connect to a repository – Variant 1
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());parameter.put(SessionParameter.ATOMPUB_URL, "http://cmis.alfresco.com/service/cmis");parameter.put(SessionParameter.REPOSITORY_ID, "84ccfe80-b325-4d79-ab4d-080a4bdd045b");
parameter.put(SessionParameter.USER, "admin");parameter.put(SessionParameter.PASSWORD, "admin");
SessionFactory factory = SessionFactoryImpl.newInstance();Session session = factory.createSession(parameter);
CMIS is stateless!
OpenCMIS introduces a session concept to support caching.
10
Connect to a repository – Variant 2
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());parameter.put(SessionParameter.ATOMPUB_URL, "http://cmis.alfresco.com/service/cmis");parameter.put(SessionParameter.REPOSITORY_ID, "84ccfe80-b325-4d79-ab4d-080a4bdd045b");
parameter.put(SessionParameter.USER, "admin");parameter.put(SessionParameter.PASSWORD, "admin");
SessionFactory factory = SessionFactoryImpl.newInstance();List<Repository> repositories = factory.getRepositories(parameter);Session session = repositories.get(0).createSession();
Alfresco only exposes one repository!
This is the simplest way to create a session.
11
Walking around
RepositoryInfo ri = session.getRepositoryInfo();String id = ri.getId();String name = ri.getName();
Folder rootFolder = session.getRootFolder();String rootFolderId = rootFolder.getId();
for(CmisObject object: rootFolder.getChildren()) { String name = object.getName();
if(object instanceof Document) { Document doc = (Document) object; long size = doc.getContentStreamLength(); }}
12
Walking around
ObjectId id = session.createObjectId(“1234567890”):CmisObject object = session.getObject(id);// CmisObject object = session.getObjectByPath(“/my/path/doc”);
String creator = object.getCreatedBy();
Property<?> myProp = object.getProperty(“my:prop”);
String propId = myProp.getId();String displayName = myProp.getDefinition().getDisplayName();String queryName = myProp.getDefinition().getQueryName();PropertyType datatype = myProp.getType();Object value = myProp.getFirstValue();
13
Caching
• Repository Info• Retrieved and cached during session creation• Will not be updated during the lifetime of a session
• Type Definitions• Cached whenever a type definition is retrieved –
explicitly or implicitly• Will not be updated during the lifetime of a session
(OpenCMIS can be forced to forget Repository Infos and Type Definitions. That is similar to creating a new session.)
What is cached and when?
14
Caching
• CMIS Objects• Object caching is turned on by default• LRU cache with 1000 objects• getObject() might return stale objects
if an old copy is found in the cache
• Refresh objects manually
CmisObject object = session.getObject(id);object.refresh(); object.refreshIfOld(60 * 1000);
What is cached and when?
15
Caching
• Turn caching off
session.getDefaultContext().setCacheEnabled(false);
• Turn caching off for one request
OperationContext oc = session.createOperationContext(); oc.setCacheEnabled(false);
CmisObject object = session.getObject(id, oc);
Control the cache!
16
CMIS Workbench
A tool for CMIS developers
17
Demos
• Children and parents• Paging• Properties• Content• Query• Create, update and delete folders• Create, update and delete documents
Code samples
25
CMIS Extensions
• CMIS specifies extension points• Arbitrary data can be attached to CMIS structures• Clients and servers either understand the extension or
ignore them
• Alfresco sends aspect data as CMIS extension• Alfresco will accept aspect data through CMIS extensions
• There will be an Alfresco addition to OpenCMIS that handles aspects
How to get and set of aspect properties?
26
Learn Morewiki.alfresco.comforums.alfresco.comtwitter: @AlfrescoECM