Your SlideShare is downloading. ×
0
OpenCMIS Introduction<br />2<br />FlorianMüller<br />Software Architect, Alfresco<br />twitter: @florian_mueller<br />
OpenCMIS<br />3<br />OpenCMIS is a sub-project of<br />Apache Chemistry is an umbrella project for CMIS implementations<br...
OpenCMIS goals<br />4<br />OpenCMIS hides the bindings and provides binding agnostic APIs and SPIs<br />OpenCMIS adds a lo...
Current state<br />5<br />OpenCMIS has contributors from Alfresco, Open Text, SAP and Nuxeo<br />OpenCMIS 0.1.0 has been r...
OpenCMIS Architecture<br />6<br />Server, client, common and test modules<br />
OpenCMIS Server<br />7<br />One Servlet per binding that map the requests to an SPI<br />Repository vendors have to implem...
OpenCMIS client<br />8<br />Client API<br />OO API<br />Easy to use<br />Build-in caching<br />Client Binding API<br />Low...
Let’s start<br />9<br />Download it! http://incubator.apache.org/chemistry/opencmis.html<br />Use Maven!<br />Build the la...
Connect to a repository – Variant 1<br />10<br />Map<String, String> parameter = new HashMap<String, String>();<br />param...
Connect to a repository – Variant 2<br />11<br />Map<String, String> parameter = new HashMap<String, String>();<br />param...
Walking around<br />12<br />RepositoryInfori = session.getRepositoryInfo();<br />String id = ri.getId();<br />String name ...
Walking around<br />13<br />ObjectId id = session.createObjectId(“1234567890”):<br />CmisObject object = session.getObject...
Caching<br />14<br />Repository Info<br />Retrieved and cached during session creation<br />Will not be updated during the...
Caching<br />15<br />CMIS Objects<br />Object caching is turned on by default<br />LRU cache with 1000 objects<br />getObj...
Caching<br />16<br />Turn caching offsession.getDefaultContext().setCacheEnabled(false); <br />Turn caching off for one re...
CMIS Workbench<br />17<br />A tool for CMIS developers<br />
Demos<br />18<br />Children and parents<br />Paging<br />Properties<br />Content<br />Query<br />Create, update and delete...
Navigation<br />19<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons....
Paging<br />20<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data...
Upcoming SlideShare
Loading in...5
×

OpenCMIS Part 1

3,904

Published on

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.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,904
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
143
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "OpenCMIS Part 1"

  1. 1. OpenCMIS Introduction<br />2<br />FlorianMüller<br />Software Architect, Alfresco<br />twitter: @florian_mueller<br />
  2. 2. OpenCMIS<br />3<br />OpenCMIS is a sub-project of<br />Apache Chemistry is an umbrella project for CMIS implementations<br />Java<br />Python<br />PHP<br />Server and client implementation of the CMIS specification<br />
  3. 3. OpenCMIS goals<br />4<br />OpenCMIS hides the bindings and provides binding agnostic APIs and SPIs<br />OpenCMIS adds a lot of convenience<br />Developers should focus on the domain model!<br />
  4. 4. Current state<br />5<br />OpenCMIS has contributors from Alfresco, Open Text, SAP and Nuxeo<br />OpenCMIS 0.1.0 has been released in September<br />The code is pretty mature and stable and has been tested against all major ECM vendors<br />The some areas of client API will be refactored and simplified within the next month<br />OpenCMIS is an active Open Source project<br />
  5. 5. OpenCMIS Architecture<br />6<br />Server, client, common and test modules<br />
  6. 6. OpenCMIS Server<br />7<br />One Servlet per binding that map the requests to an SPI<br />Repository vendors have to implement two interfaces<br />Not our focus today…<br />… for CMIS connector developers<br />SOAP<br />AtomPub<br />CMIS Service Factory<br />CMIS Service<br />CMIS Service<br />CMIS Service<br />
  7. 7. OpenCMIS client<br />8<br />Client API<br />OO API<br />Easy to use<br />Build-in caching<br />Client Binding API<br />Low-level<br />Very close to the CMIS specification<br />More control, less comfort<br />… for CMIS application developers<br />
  8. 8. Let’s start<br />9<br />Download it! http://incubator.apache.org/chemistry/opencmis.html<br />Use Maven!<br />Build the latest and greatest! http://incubator.apache.org/chemistry/opencmis-how-to-build.html<br />Get hold of the OpenCMIS Jars<br /><dependency><br /> <groupId>org.apache.chemistry.opencmis</groupId><br /> <artifactId>chemistry-opencmis-client-impl</artifactId><br /> <version>0.1.0-incubating</version><br /></dependency><br />
  9. 9. Connect to a repository – Variant 1<br />10<br />Map<String, String> parameter = new HashMap<String, String>();<br />parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());<br />parameter.put(SessionParameter.ATOMPUB_URL, "http://cmis.alfresco.com/service/cmis");<br />parameter.put(SessionParameter.REPOSITORY_ID, "84ccfe80-b325-4d79-ab4d-080a4bdd045b");<br />parameter.put(SessionParameter.USER, "admin");<br />parameter.put(SessionParameter.PASSWORD, "admin");<br />SessionFactory factory = SessionFactoryImpl.newInstance();<br />Session session = factory.createSession(parameter);<br />CMIS is stateless!<br />OpenCMIS introduces a <br />session concept to support caching.<br />
  10. 10. Connect to a repository – Variant 2<br />11<br />Map<String, String> parameter = new HashMap<String, String>();<br />parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());<br />parameter.put(SessionParameter.ATOMPUB_URL, "http://cmis.alfresco.com/service/cmis");<br />parameter.put(SessionParameter.REPOSITORY_ID, "84ccfe80-b325-4d79-ab4d-080a4bdd045b");<br />parameter.put(SessionParameter.USER, "admin");<br />parameter.put(SessionParameter.PASSWORD, "admin");<br />SessionFactory factory = SessionFactoryImpl.newInstance();<br />List<Repository> repositories = factory.getRepositories(parameter);<br />Session session = repositories.get(0).createSession();<br />Alfresco only exposes one repository!<br />This is the simplest way <br />to create a session.<br />
  11. 11. Walking around<br />12<br />RepositoryInfori = session.getRepositoryInfo();<br />String id = ri.getId();<br />String name = ri.getName();<br />Folder rootFolder = session.getRootFolder();<br />String rootFolderId = rootFolder.getId();<br />for(CmisObject object: rootFolder.getChildren()) {<br /> String name = object.getName();<br />if(objectinstanceof Document) {<br /> Document doc = (Document) object;<br /> long size = doc.getContentStreamLength(); <br /> }<br />}<br />
  12. 12. Walking around<br />13<br />ObjectId id = session.createObjectId(“1234567890”):<br />CmisObject object = session.getObject(id);<br />// CmisObject object = session.getObjectByPath(“/my/path/doc”);<br />String creator = object.getCreatedBy();<br />Property<?> myProp = object.getProperty(“my:prop”);<br />String propId = myProp.getId();<br />String displayName = myProp.getDefinition().getDisplayName();<br />String queryName = myProp.getDefinition().getQueryName();<br />PropertyTypedatatype = myProp.getType();<br />Object value = myProp.getFirstValue();<br />
  13. 13. Caching<br />14<br />Repository Info<br />Retrieved and cached during session creation<br />Will not be updated during the lifetime of a session<br />Type Definitions<br />Cached whenever a type definition is retrieved –explicitly or implicitly<br />Will not be updated during the lifetime of a session<br />(OpenCMIS can be forced to forget Repository Infos and Type Definitions. That is similar to creating a new session.)<br />What is cached and when?<br />
  14. 14. Caching<br />15<br />CMIS Objects<br />Object caching is turned on by default<br />LRU cache with 1000 objects<br />getObject() might return stale objectsif an old copy is found in the cache<br />Refresh objects manually<br />CmisObject object = session.getObject(id); object.refresh(); object.refreshIfOld(60 * 1000); <br />What is cached and when?<br />
  15. 15. Caching<br />16<br />Turn caching offsession.getDefaultContext().setCacheEnabled(false); <br />Turn caching off for one requestOperationContextoc = session.createOperationContext(); oc.setCacheEnabled(false);CmisObject object = session.getObject(id, oc); <br />Control the cache!<br />
  16. 16. CMIS Workbench<br />17<br />A tool for CMIS developers<br />
  17. 17. Demos<br />18<br />Children and parents<br />Paging<br />Properties<br />Content<br />Query<br />Create, update and delete folders<br />Create, update and delete documents<br />Code samples<br />
  18. 18. Navigation<br />19<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data.*;<br />import org.apache.chemistry.opencmis.commons.enums.*;<br />import org.apache.chemistry.opencmis.client.api.*;<br />// get root folder<br />Folder root = session.getRootFolder();<br />String rootFolderName = root.getName();<br />println "Root folder: ${rootFolderName}n"<br />// print root folder children<br />for(CmisObject object: root.getChildren()) {<br /> String name = object.getName();<br /> String typeId = object.getType().getId();<br /> String path = object.getPaths().get(0);<br />println "${name} t${typeId} t(${path})"<br /> // get parents<br /> /*<br />for(CmisObject parent: object.getParents()) {<br /> String parentName = parent.getName();<br />println " Parent: ${parentName}"<br /> }<br /> */<br />}<br />
  19. 19. Paging<br />20<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data.*;<br />import org.apache.chemistry.opencmis.commons.enums.*;<br />import org.apache.chemistry.opencmis.client.api.*;<br />Folder root = session.getRootFolder();<br />printList( root.getChildren() )<br />//printList( root.getChildren().getPage(3) )<br />//printList( root.getChildren().skipTo(2) )<br />//printList( root.getChildren().skipTo(2).getPage(3) )<br />void printList(ItemIterable<CmisObject> list) {<br />list.each { println "${it.name} t${it.type.id}" }<br /> long numItems = list.getTotalNumItems();<br />booleanhasMore = list.getHasMoreItems();<br />println "--------------------------------------"<br />println "Total number: ${numItems}"<br />println "Has more: ${hasMore}" <br />println "--------------------------------------"<br />}<br />
  20. 20. Properties<br />21<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data.*;<br />import org.apache.chemistry.opencmis.commons.enums.*;<br />import org.apache.chemistry.opencmis.client.api.*;<br />CmisObject object = session.getObjectByPath("/User Homes/florian/Test Folder/MyText");<br />for(Property<?> property: object.getProperties()) {<br /> String propId = property.getId();<br /> String displayName = property.getDefinition().getDisplayName();<br /> String queryName = property.getDefinition().getQueryName();<br />PropertyTypedatatype = property.getType();<br /> Object value = property.getFirstValue();<br />println "${displayName}: ${value}"<br />println " Data type: ${datatype}"<br />println " Id: ${propId}"<br />println " Query name: ${queryName}"<br />println ""<br />}<br />
  21. 21. Content<br />22<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data.*;<br />import org.apache.chemistry.opencmis.commons.enums.*;<br />import org.apache.chemistry.opencmis.client.api.*;<br />CmisObject object = session.getObjectByPath("/User Homes/florian/Test Folder/MyText");<br />if(!(objectinstanceof Document)) {<br /> throw new Exception("Not a document!");<br />}<br />Document doc = (Document) object;<br />ContentStream content = doc.getContentStream();<br />if(content == null) {<br /> throw new Exception("Document has no content!");<br />}<br />String filename = content.getFileName();<br />String mimeType = content.getMimeType();<br />long length = content.getLength();<br />InputStream stream = content.getStream();<br />println "File: ${filename}"<br />println "MIME Type: ${mimeType}"<br />println "Size: ${length} bytes"<br />println "Has stream: " + (stream != null)<br />
  22. 22. Query<br />23<br />import org.apache.chemistry.opencmis.commons.*<br />import org.apache.chemistry.opencmis.commons.data.*<br />import org.apache.chemistry.opencmis.commons.enums.*<br />import org.apache.chemistry.opencmis.client.api.*<br />String cql = "SELECT cmis:objectId, cmis:name, cmis:contentStreamLength FROM cmis:document";<br />ItemIterable<QueryResult> results = session.query(cql, false);<br />//ItemIterable<QueryResult> results = session.query(cql, false).getPage(10);<br />//ItemIterable<QueryResult> results = session.query(cql, false).skipTo(10).getPage(10);<br />for(QueryResult hit: results) { <br />for(PropertyData<?> property: hit.getProperties()) {<br /> String queryName = property.getQueryName();<br /> Object value = property.getFirstValue();<br />println "${queryName}: ${value}" <br /> }<br />println "--------------------------------------"<br />}<br />
  23. 23. Folders<br />24<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data.*;<br />import org.apache.chemistry.opencmis.commons.enums.*;<br />import org.apache.chemistry.opencmis.client.api.*;<br />Folder root = session.getRootFolder();<br />// create a new folder<br />Map<String, Object> properties = new HashMap<String, Object>();<br />properties.put("cmis:objectTypeId", "cmis:folder");<br />properties.put("cmis:name", "a new folder");<br />Folder newFolder = root.createFolder(properties);<br />printProperties(newFolder);<br />// update properties<br />Map<String, Object> updateproperties = new HashMap<String, Object>();<br />updateproperties.put("cmis:name", "renamed folder");<br />newFolder.updateProperties(updateproperties);<br />newFolder.refresh();<br />printProperties(newFolder);<br />// delete folder<br />newFolder.deleteTree(true, UnfileObject.DELETE, true);<br />
  24. 24. Documents<br />25<br />import org.apache.chemistry.opencmis.commons.*;<br />import org.apache.chemistry.opencmis.commons.data.*;<br />import org.apache.chemistry.opencmis.commons.enums.*;<br />import org.apache.chemistry.opencmis.commons.impl.dataobjects.*;<br />import org.apache.chemistry.opencmis.client.api.*;<br />Folder root = session.getRootFolder();<br />// create a new document<br />String name = "myNewDocument.txt";<br />Map<String, Object> properties = new HashMap<String, Object>();<br />properties.put("cmis:objectTypeId", "cmis:document");<br />properties.put("cmis:name", name);<br />byte[] content = "Hello World!".getBytes();<br />InputStream stream = new ByteArrayInputStream(content);<br />ContentStreamcontentStream = new ContentStreamImpl(name, content.length, "text/plain", stream);<br />Document newDoc = root.createDocument(properties, contentStream, VersioningState.MAJOR);<br />printProperties(newDoc);<br />// delete document<br />newDoc.delete(true);<br />void printProperties(CmisObject object) {<br />object.properties.each { println "${it.id}: ${it.firstValue}" }<br />println "--------------------------------------"<br />}<br />
  25. 25. CMIS Extensions<br />26<br />CMIS specifies extension points<br />Arbitrary data can be attached to CMIS structures<br />Clients and servers either understand the extension or ignore them<br />Alfresco sends aspect data as CMIS extension<br />Alfresco will accept aspect data through CMIS extensions<br />There will be an Alfresco addition to OpenCMISthat handles aspects <br />How to get and set of aspect properties?<br />
  26. 26. Learn More<br />27<br />wiki.alfresco.com<br />forums.alfresco.com<br />twitter: @AlfrescoECM<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×