Devoxx08 - Nuxeo Core, JCR 2, CMIS

2,580 views
2,419 views

Published on

Nuxeo Core, JCR 2, CMIS: learn how to use content repositories APIs
 to store and manipulate rich documents.

Published in: Technology, Education
1 Comment
4 Likes
Statistics
Notes
  • Strange, cannot download.
    Press download button, and it just refresh to the same page!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,580
On SlideShare
0
From Embeds
0
Number of Embeds
41
Actions
Shares
0
Downloads
97
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Devoxx08 - Nuxeo Core, JCR 2, CMIS

  1. 1. Using content repositories: Nuxeo Core, JCR 2, CMIS Florent Guillaume Head of R&D Nuxeo www.devoxx.com
  2. 2. Overall presentation goal Learn how to use content repositories APIs to store and manipulate rich documents www.devoxx.com
  3. 3. Speaker’s qualifications Florent Guillaume is Head of R&D at Nuxeo, a leading vendor of Open Source ECM platforms Florent Guillaume is a member of international normalization technical committees: JSR-283, Oasis CMIS Florent Guillaume architected and wrote an ECM system (Nuxeo CPS) and is a lead architect on another (Nuxeo EP) Florent Guillaume wrote a low-level storage engine for Nuxeo Core 3 www.devoxx.com
  4. 4. What is a document? Store information Attached file (binary stream) Metadata Retrieve information Search Security Be visible and editable Out of scope for a repository 4 www.devoxx.com
  5. 5. What is a “rich” document? Depends on your definition of “rich” 5 www.devoxx.com
  6. 6. What is a “rich” document? Depends on your definition of “rich” 5 www.devoxx.com
  7. 7. What is a “rich” document? Depends on your definition of “rich” Associated binary streams Multiple attached files Vignettes Renditions Complex metadata Lists of records Sub-records (XML-like) 6 www.devoxx.com
  8. 8. What storage APIs? Filesystem Relational database JCR (JSR-170, JSR-283) Nuxeo Core CMIS 7 www.devoxx.com
  9. 9. Filesystem Decide where to store files Decide how to uniquely identify files Use java.io.FileOutputStream for binaries Decide how to serialize metadata All by hand java.io.ObjectOutputStream, Serializable etc. 8 www.devoxx.com
  10. 10. Filesystem example Read/write public void createDocument(Long id, String title) throws IOException { File file = new File(ROOT_DIR, id.toString()); OutputStream out = new FileOutputStream(file); try { out.write(title.getBytes(quot;UTF-8quot;)); } finally { out.close(); } } public MyDocument getDocument(Long id) throws IOException { File file = new File(ROOT_DIR, id.toString()); InputStream in = new FileInputStream(file); try { byte[] bytes = new byte[100]; int n = in.read(bytes); String title = new String(bytes, quot;UTF-8quot;); MyDocument doc = new MyDocument(); doc.setId(id); doc.setTitle(title); return doc; } finally { in.close(); } } 9 www.devoxx.com
  11. 11. Filesystem drawbacks Simplistic, no actual model Everything has to be done manually No search 10 www.devoxx.com
  12. 12. Filesystem using JAXB Map Java objects to/from XML representations Define a schema (model) Marshall/Unmarshall using JAXB APIs 11 www.devoxx.com
  13. 13. Relational database JDBC Hibernate ...other ORMs JPA 12 www.devoxx.com
  14. 14. JDBC Define a SQL model for your data Tables, Columns, Data types Decide where to store BLOBs Column or filesystem Emit SQL statements to do all read/write operations 13 www.devoxx.com
  15. 15. JDBC example Class defining the model class MyDocument { private Long id; private String title; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } 14 www.devoxx.com
  16. 16. JDBC example Establish a connection, Write public void init() throws ClassNotFoundException { Class.forName(quot;com.myvendor.TheDriverClassquot;); } public Connection getConnection() throws SQLException { return DriverManager.getConnection(quot;jdbc:myvendor:/my/database/infoquot;, quot;myLoginquot;, quot;myPasswordquot;); } public void createDocument(Long id, String title) throws SQLException { PreparedStatement ps = null; Connection conn = getConnection(); try { ps = conn.prepareStatement(quot;INSERT INTO MyDocuments (id, title) VALUES (?, ?)quot;); ps.setLong(1, id); ps.setString(2, title); ps.execute(); } finally { if (ps != null) ps.close(); conn.close(); } } 15 www.devoxx.com
  17. 17. JDBC example Read public MyDocument getDocument(Long id) throws SQLException { PreparedStatement ps = null; Connection conn = getConnection(); try { ps = conn.prepareStatement(quot;SELECT title FROM MyDocuments WHERE id = ?quot;); ps.setLong(1, id); ResultSet rs = ps.executeQuery(); if (!rs.next()) { return null; } String title = rs.getString(1); MyDocument doc = new MyDocument(); doc.setId(id); doc.setTitle(title); return doc; } finally { if (ps != null) ps.close(); conn.close(); } } 16 www.devoxx.com
  18. 18. JDBC drawbacks Still very much manual No document abstraction Reads from ResultSets have to know proper types 17 www.devoxx.com
  19. 19. Hibernate Model your documents as classes Define an object-relational mapping in XML Use Hibernate to automate read/writes 18 www.devoxx.com
  20. 20. Hibernate example XML configuration <hibernate-mapping> <class name=quot;example.MyDocumentquot; table=quot;DOCUMENTSquot;> <id name=quot;idquot; column=quot;DOC_IDquot;> <generator class=quot;nativequot;/> </id> <property name=quot;titlequot;/> </class> </hibernate-mapping> 19 www.devoxx.com
  21. 21. Hibernate example Read/write class DocumentManager { public void createDocument(Long id, String title) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); MyDocument doc = new MyDocument(); doc.setId(id); doc.setTitle(title); session.save(doc); session.getTransaction().commit(); session.close(); } public MyDocument getDocument(Long id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Query query = session.createQuery(quot;FROM MyDocument WHERE id = :idquot;); query.setParameter(quot;idquot;, id); MyDocument doc = (MyDocument) query.uniqueResult(); session.getTransaction().commit(); session.close(); return doc; } } 20 www.devoxx.com
  22. 22. Hibernate drawbacks Document classes have to be defined by hand No standard, just application-defined classes Object-relational mapping too flexible Too much choice can be a curse Binaries are still a problem (no streaming) Hibernate’s “binary” is a byte[] → Memory hog Blob support inconsistent 21 www.devoxx.com
  23. 23. JPA Model your documents as classes Define an object-relational mapping using annotations Use JPA to automate read/writes 22 www.devoxx.com
  24. 24. JPA example Class defining the model and the mapping @Entity class MyDocument { private Long id; private String title; @Id public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } www.devoxx.com 23
  25. 25. JPA example Read/write @Stateless class DocumentManagerBean { @PersistenceContext EntityManager em; public void createDocument(Long id, String title) { MyDocument doc = new MyDocument(); doc.setId(id); doc.setTitle(title); em.persist(doc); } public MyDocument getDocument(Long id) { return em.find(MyDocument.class, id); } public List<MyDocument> listDocuments() { Query query = em.createQuery(quot;SELECT doc FROM MyDocument docquot;); return query.getResultList(); } } 24 www.devoxx.com
  26. 26. JPA drawbacks Same as Hibernate Although annotations are very convenient 25 www.devoxx.com
  27. 27. Beyond mere storage www.devoxx.com
  28. 28. Beyond mere storage Standard document abstraction Security Locking Versioning Full text search Types and inheritance Folders? ordering? 27 www.devoxx.com
  29. 29. JCR Content Repository API for Java™ Technology JSR-170, released in June 2005 Initiated by Day Software Also BEA, Documentum, FileNet, IBM, Oracle, Vignette and others Apache Jackrabbit is the RI 28 www.devoxx.com
  30. 30. JCR goals Java API Fine-grained, hierarchical storage model Be the “SQL” of hierarchical storage Lots of functionality 29 www.devoxx.com
  31. 31. JCR features CRUD Hierarchy of nodes Simple properties, Lists, Binaries Queries Versioning, Locking, References, ... 30 www.devoxx.com
  32. 32. JCR 2 JSR-283 First public review July 2007 Final release expected early 2009 Nuxeo is a contributor to the specification 31 www.devoxx.com
  33. 33. JCR 2 features Fix JSR-170 inconsistencies Several compliance levels New property types Improved features Versioning, Access control, Observation Retention & Hold Shareable nodes Java query API 32 www.devoxx.com
  34. 34. JCR – nodes and properties foo bar Property Type Node Type value child child 33 www.devoxx.com
  35. 35. JCR – node hierarchy (root) foo bar gee Folder Folder Folder thing doc Docu Docu ment ment vignette File 34 www.devoxx.com
  36. 36. JCR – properties types String JCR 2 Binary Decimal Date WeakReference Long URI Double Boolean Name Path Reference 35 www.devoxx.com
  37. 37. JCR – hierarchy with properties (root) foo bar gee Folder Folder Folder thing doc Docu Docu ment ment title description date creator vignette String String Date String File my doc ... 2008-12-11 florent filename data String Binary img.png <binary> 36 www.devoxx.com
  38. 38. JCR – node hierarchy (root) foo bar gee Folder Folder Folder thing doc Document title: my doc Document description: ... date: 2008-12-11 creator: florent vignette File filename: img.png date: <binary> 37 www.devoxx.com
  39. 39. JCR – types Define the model <my='http://my.example.com/ns'> [my:document] - my:id (long) mandatory - my:title - my:description - my:creator - my:date (date) + my:vignette (nt:resource) 38 www.devoxx.com
  40. 40. JCR – API Establish a connection public Repository repository; public javax.jcr.Session session; public void init() throws IOException { repository = new TransientRepository(); } public void open() throws LoginException, RepositoryException { Credentials credentials = new SimpleCredentials(quot;usernamequot;, quot;passwordquot;.toCharArray()); session = repository.login(credentials); } public void close() { session.logout(); } 39 www.devoxx.com
  41. 41. JCR – API Read/write public void createDocument(Long id, String title) throws RepositoryException { Node root = session.getRootNode(); Node doc = root.addNode(id.toString()); doc.setProperty(quot;my:idquot;, id); doc.setProperty(quot;my:titlequot;, title); session.save(); } public Node getDocument(Long id) throws RepositoryException { Node root = session.getRootNode(); Node doc = root.getNode(id.toString()); return doc; } 40 www.devoxx.com
  42. 42. JCR – API Query public List<Node> getDocuments() throws RepositoryException { QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery( quot;//element(*, my:document)quot;, Query.XPATH); query = queryManager.createQuery( quot;SELECT * from my:documentquot;, Query.SQL); List<Node> documents = new LinkedList<Node>(); NodeIterator it = query.execute().getNodes(); while (it.hasNext()) { documents.add(it.nextNode()); } return documents; } 41 www.devoxx.com
  43. 43. Nuxeo Founded in 2000 Sustained growth for 8 years Pioneering Open Source ECM software vendor International organization, customers, partners, community 40+ employees Business oriented Open Source 42 www.devoxx.com
  44. 44. Nuxeo ECM 3+ years of work Focus on the platform Document Core Nuxeo EP, Nuxeo WebEngine, Nuxeo RCP Components everywhere (OSGi) Large feature set Big deployments 43 www.devoxx.com
  45. 45. Nuxeo Core High-level document-oriented Java API Complex document abstraction Independent of actual storage backend EJB remoting REST bindings (JAX-RS) SOAP bindings (JAX-WS) 44 www.devoxx.com
  46. 46. Nuxeo Core basics CRUD Hierarchy of document Complex properties Binaries Security Locking Versioning Publishing, Proxies 45 www.devoxx.com
  47. 47. Nuxeo Core Define the model <xs:schema xmlns:xs=quot;http://www.w3.org/2001/XMLSchemaquot; xmlns:nxs=quot;http://www.nuxeo.org/ecm/schemas/mydocumentquot; targetNamespace=quot;http://www.nuxeo.org/ecm/schemas/mydocumentquot;> <xs:include schemaLocation=quot;core-types.xsdquot;/> <xs:element name=quot;idquot; type=quot;xs:integerquot;/> <xs:element name=quot;titlequot; type=quot;xs:stringquot;/> <xs:element name=quot;descriptionquot; type=quot;xs:stringquot;/> <xs:element name=quot;creatorquot; type=quot;xs:stringquot;/> <xs:element name=quot;datequot; type=quot;xs:datequot;/> <xs:element name=quot;vignettequot; type=quot;nxs:contentquot;/> <xs:element name=quot;fullnamequot; type=quot;nxs:fullnamequot;/> <xs:complexType name=quot;fullnamequot;> <xs:sequence> <xs:element name=quot;firstnamequot; type=quot;xs:stringquot;/> <xs:element name=quot;lastnamequot; type=quot;xs:stringquot;/> </xs:sequence> </xs:complexType> </xs:schema> 46 www.devoxx.com
  48. 48. Nuxeo Core Define the model <extension target=quot;org.nuxeo.ecm.core.schema.TypeServicequot; point=quot;schemaquot;> <schema name=quot;mydocumentquot; src=quot;schemas/mydocument.xsdquot; prefix=quot;mydocquot;/> </extension> <extension target=quot;org.nuxeo.ecm.core.schema.TypeServicequot; point=quot;doctypequot;> <doctype name=quot;MyDocumentquot; extends=quot;Documentquot;> <schema name=quot;commonquot;/> <schema name=quot;mydocumentquot;/> <facet name=quot;Versionablequot;/> </doctype> </extension> 47 www.devoxx.com
  49. 49. Nuxe Core – API Read/Write @Scope(ScopeType.STATELESS) @Name(quot;myDocumentActionsquot;) public class DocumentActionsBean { @In(create = true) protected transient NavigationContext navigationContext; @In(create = true) protected transient CoreSession documentManager; public void createDocument(Long id, String title) throws ClientException { DocumentModel current = navigationContext.getCurrentDocument(); DocumentModel doc = documentManager.createDocumentModel( current.getPathAsString(), null, quot;MyDocumentquot;); doc.setProperty(quot;mydocumentquot;, quot;idquot;, id); doc.setPropertyValue(quot;mydoc:titlequot;, title); doc.setPropertyValue(quot;mydoc:fullname/firstnamequot;, quot;Florentquot;); documentManager.createDocument(doc); documentManager.save(); } } 48 www.devoxx.com
  50. 50. CMIS Draft v 0.5 published in September 2008 by EMC, IBM, Microsoft Alfresco, Open Text, Oracle, SAP also on board from the start Oasis TC formed in November 2008 Adullact, Booz Allen Hamilton, Day, Ektron, Exalead, Fidelity, Flatirons, Magnolia, Mitre, Nuxeo, Saperion, Sun, Vamosa, Vignette (as of 2008-12-01) CMIS 1.0 expected mid-2009 49 www.devoxx.com
  51. 51. CMIS goals Simple document model Independent of protocol SOAP, REST (AtomPub) bindings Not tied to a programming language Platform, vendor independent Basic set of ECM functions “Greatest common denominator” 50 www.devoxx.com
  52. 52. CMIS basics CRUD Hierarchy folders, documents Simple properties, lists One binary Policies Versioning Relationships Queries 51 www.devoxx.com
  53. 53. CMIS advanced Multi-filing Advanced queries Joins Full text ... maybe more to come 52 www.devoxx.com
  54. 54. CMIS basic properties ObjectId Name (doc, folder) Uri version-related props (doc) ObjectTypeId ParentId (folder) CreatedBy AllowedChildObjectTypeIds (folder) CreationDate SourceId (rel) LastModifiedBy TargetId (rel) LastModificationDate PolicyName (policy) ChangeToken PolicyText (policy) 53 www.devoxx.com
  55. 55. CMIS objects Folder Document Policy Relationship 54 www.devoxx.com
  56. 56. CMIS folders Folder (root) Folder Folder Folder foo bar gee Folder Folder stuff blah 55 www.devoxx.com
  57. 57. CMIS documents Folder (root) Folder Folder Folder foo bar gee Doc Folder Folder 001 stuff blah Doc Doc Doc 123 456 789 56 www.devoxx.com
  58. 58. CMIS relationships Folder (root) Folder Folder foo bar Doc Folder Folder 001 stuff blah 333 Doc Doc 555 123 456 57 www.devoxx.com
  59. 59. CMIS policies Folder (root) Policy Folder Folder foo bar Policy Policy Doc Doc 001 123 58 www.devoxx.com
  60. 60. CMIS policies uses ACLs Locks Retention & Hold Automatic transformations Repository hints etc. 59 www.devoxx.com
  61. 61. CMIS queries 60 www.devoxx.com
  62. 62. CMIS query example Standard SQL-92 Extensions for multi-valued properties Extensions for hierarchical searches Extensions for fulltext search SELECT OBJECT_ID, SCORE() AS SC, DESTINATION, DEPARTURE_DATES FROM TRAVEL_BROCHURE WHERE IN_TREE( , ‘ID00093854763’) AND CONTAINS( , 'PARADISE ISLAND CRUISE') AND '2010-01-01' < ANY DEPARTURE_DATES AND CONTINENT <> 'ANTARCTICA' ORDER BY SC DESC 61 www.devoxx.com
  63. 63. CMIS AtomPub bindings Additional headers for behavior control MIME types Service application/atomsvc+xml Feed application/atom+xml;type=feed Entry application/atom+xml;type=entry Query application/cmisquery+xml AllowableActions application/cmisallowableactions+xml 62 www.devoxx.com
  64. 64. CMIS Web Services bindings All the WSDL files are provided Check the spec ;-) 63 www.devoxx.com
  65. 65. CMIS repository services getRepositories getRepositoryInfo getTypes getTypeDefinition 64 www.devoxx.com
  66. 66. CMIS navigation services getDescendants getChildren getFolderParent getObjectParents getCheckedoutDocuments 65 www.devoxx.com
  67. 67. CMIS object services createDocument createFolder createRelationship createPolicy getAllowableActions getProperties, updateProperties getContentStream, setContentStream, deleteContentStream moveObject, deleteObject, deleteTree 66 www.devoxx.com
  68. 68. CMIS multi-filing services addObjectToFolder removeObjectFromFolder 67 www.devoxx.com
  69. 69. CMIS discovery service query 68 www.devoxx.com
  70. 70. CMIS relationships services getRelationships 69 www.devoxx.com
  71. 71. CMIS policy services applyPolicy removePolicy getAppliedPolicies 70 www.devoxx.com
  72. 72. CMIS versioning service checkOut cancelCheckOut checkIn getPropertiesOfLatestVersion getAllVersions deleteAllVersions 71 www.devoxx.com
  73. 73. Mapping documents to JCR Document → Node Schema → Mixin type Simple & Array properties → Properties Complex type → Sub-node Lists of complex types → Ordered sub-nodes 72 www.devoxx.com
  74. 74. Jackrabbit tables 73 www.devoxx.com
  75. 75. Mapping documents to SQL Parent-child relationships → Dedicated “hierarchy” table Schema → Table Simple property → Column Array property → “Collection” table Complex type → Sub-document Lists of complex types → Ordered sub-documents 74 www.devoxx.com
  76. 76. Visible SQL storage 75 www.devoxx.com
  77. 77. Visible SQL storage 76 www.devoxx.com
  78. 78. Nuxeo Core 2 and CMIS Next-generation storage based on CMIS model No “impedance mismatch” in models Nuxeo extensions if needed Leverage the Visible SQL Storage backend Distributed and clusterable Faster remote access and caching True clusters Facilitate cloud-based backends 77 www.devoxx.com
  79. 79. Summary Many storage choices Define your model, choose the right API JCR is very capable CMIS is coming fast Nuxeo gives the best of both 78 www.devoxx.com
  80. 80. Concluding statement Look for CMIS soon, and check out Nuxeo now! www.devoxx.com
  81. 81. Q&A Questions? www.devoxx.com
  82. 82. Thank you for your attention! http://www.nuxeo.com http://doc.nuxeo.org http://jcp.org/en/jsr/detail?id=170 http://jcp.org/en/jsr/detail?id=283 http://jackrabbit.apache.org/ http://www.oasis-open.org/committees/cmis/ www.devoxx.com

×