Devoxx08 - Nuxeo Core, JCR 2, CMIS

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Devoxx08 - Nuxeo Core, JCR 2, CMIS - Presentation Transcript

    1. Using content repositories: Nuxeo Core, JCR 2, CMIS Florent Guillaume Head of R&D Nuxeo www.devoxx.com
    2. Overall presentation goal Learn how to use content repositories APIs to store and manipulate rich documents www.devoxx.com
    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. 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. What is a “rich” document? Depends on your definition of “rich” 5 www.devoxx.com
    6. What is a “rich” document? Depends on your definition of “rich” 5 www.devoxx.com
    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. What storage APIs? Filesystem Relational database JCR (JSR-170, JSR-283) Nuxeo Core CMIS 7 www.devoxx.com
    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. 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(\"UTF-8\")); } 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, \"UTF-8\"); MyDocument doc = new MyDocument(); doc.setId(id); doc.setTitle(title); return doc; } finally { in.close(); } } 9 www.devoxx.com
    11. Filesystem drawbacks Simplistic, no actual model Everything has to be done manually No search 10 www.devoxx.com
    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. Relational database JDBC Hibernate ...other ORMs JPA 12 www.devoxx.com
    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. 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. JDBC example Establish a connection, Write public void init() throws ClassNotFoundException { Class.forName(\"com.myvendor.TheDriverClass\"); } public Connection getConnection() throws SQLException { return DriverManager.getConnection(\"jdbc:myvendor:/my/database/info\", \"myLogin\", \"myPassword\"); } public void createDocument(Long id, String title) throws SQLException { PreparedStatement ps = null; Connection conn = getConnection(); try { ps = conn.prepareStatement(\"INSERT INTO MyDocuments (id, title) VALUES (?, ?)\"); ps.setLong(1, id); ps.setString(2, title); ps.execute(); } finally { if (ps != null) ps.close(); conn.close(); } } 15 www.devoxx.com
    17. JDBC example Read public MyDocument getDocument(Long id) throws SQLException { PreparedStatement ps = null; Connection conn = getConnection(); try { ps = conn.prepareStatement(\"SELECT title FROM MyDocuments WHERE id = ?\"); 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. JDBC drawbacks Still very much manual No document abstraction Reads from ResultSets have to know proper types 17 www.devoxx.com
    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. Hibernate example XML configuration <hibernate-mapping> <class name=\"example.MyDocument\" table=\"DOCUMENTS\"> <id name=\"id\" column=\"DOC_ID\"> <generator class=\"native\"/> </id> <property name=\"title\"/> </class> </hibernate-mapping> 19 www.devoxx.com
    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(\"FROM MyDocument WHERE id = :id\"); query.setParameter(\"id\", id); MyDocument doc = (MyDocument) query.uniqueResult(); session.getTransaction().commit(); session.close(); return doc; } } 20 www.devoxx.com
    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. JPA Model your documents as classes Define an object-relational mapping using annotations Use JPA to automate read/writes 22 www.devoxx.com
    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. 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(\"SELECT doc FROM MyDocument doc\"); return query.getResultList(); } } 24 www.devoxx.com
    26. JPA drawbacks Same as Hibernate Although annotations are very convenient 25 www.devoxx.com
    27. Beyond mere storage www.devoxx.com
    28. Beyond mere storage Standard document abstraction Security Locking Versioning Full text search Types and inheritance Folders? ordering? 27 www.devoxx.com
    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. JCR goals Java API Fine-grained, hierarchical storage model Be the “SQL” of hierarchical storage Lots of functionality 29 www.devoxx.com
    31. JCR features CRUD Hierarchy of nodes Simple properties, Lists, Binaries Queries Versioning, Locking, References, ... 30 www.devoxx.com
    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. 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. JCR – nodes and properties foo bar Property Type Node Type value child child 33 www.devoxx.com
    35. JCR – node hierarchy (root) foo bar gee Folder Folder Folder thing doc Docu Docu ment ment vignette File 34 www.devoxx.com
    36. JCR – properties types String JCR 2 Binary Decimal Date WeakReference Long URI Double Boolean Name Path Reference 35 www.devoxx.com
    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. 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. 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. 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(\"username\", \"password\".toCharArray()); session = repository.login(credentials); } public void close() { session.logout(); } 39 www.devoxx.com
    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(\"my:id\", id); doc.setProperty(\"my:title\", 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. JCR – API Query public List<Node> getDocuments() throws RepositoryException { QueryManager queryManager = session.getWorkspace().getQueryManager(); Query query = queryManager.createQuery( \"//element(*, my:document)\", Query.XPATH); query = queryManager.createQuery( \"SELECT * from my:document\", 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. 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. 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. 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. Nuxeo Core basics CRUD Hierarchy of document Complex properties Binaries Security Locking Versioning Publishing, Proxies 45 www.devoxx.com
    47. Nuxeo Core Define the model <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:nxs=\"http://www.nuxeo.org/ecm/schemas/mydocument\" targetNamespace=\"http://www.nuxeo.org/ecm/schemas/mydocument\"> <xs:include schemaLocation=\"core-types.xsd\"/> <xs:element name=\"id\" type=\"xs:integer\"/> <xs:element name=\"title\" type=\"xs:string\"/> <xs:element name=\"description\" type=\"xs:string\"/> <xs:element name=\"creator\" type=\"xs:string\"/> <xs:element name=\"date\" type=\"xs:date\"/> <xs:element name=\"vignette\" type=\"nxs:content\"/> <xs:element name=\"fullname\" type=\"nxs:fullname\"/> <xs:complexType name=\"fullname\"> <xs:sequence> <xs:element name=\"firstname\" type=\"xs:string\"/> <xs:element name=\"lastname\" type=\"xs:string\"/> </xs:sequence> </xs:complexType> </xs:schema> 46 www.devoxx.com
    48. Nuxeo Core Define the model <extension target=\"org.nuxeo.ecm.core.schema.TypeService\" point=\"schema\"> <schema name=\"mydocument\" src=\"schemas/mydocument.xsd\" prefix=\"mydoc\"/> </extension> <extension target=\"org.nuxeo.ecm.core.schema.TypeService\" point=\"doctype\"> <doctype name=\"MyDocument\" extends=\"Document\"> <schema name=\"common\"/> <schema name=\"mydocument\"/> <facet name=\"Versionable\"/> </doctype> </extension> 47 www.devoxx.com
    49. Nuxe Core – API Read/Write @Scope(ScopeType.STATELESS) @Name(\"myDocumentActions\") 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, \"MyDocument\"); doc.setProperty(\"mydocument\", \"id\", id); doc.setPropertyValue(\"mydoc:title\", title); doc.setPropertyValue(\"mydoc:fullname/firstname\", \"Florent\"); documentManager.createDocument(doc); documentManager.save(); } } 48 www.devoxx.com
    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. 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. CMIS basics CRUD Hierarchy folders, documents Simple properties, lists One binary Policies Versioning Relationships Queries 51 www.devoxx.com
    53. CMIS advanced Multi-filing Advanced queries Joins Full text ... maybe more to come 52 www.devoxx.com
    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. CMIS objects Folder Document Policy Relationship 54 www.devoxx.com
    56. CMIS folders Folder (root) Folder Folder Folder foo bar gee Folder Folder stuff blah 55 www.devoxx.com
    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. 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. CMIS policies Folder (root) Policy Folder Folder foo bar Policy Policy Doc Doc 001 123 58 www.devoxx.com
    60. CMIS policies uses ACLs Locks Retention & Hold Automatic transformations Repository hints etc. 59 www.devoxx.com
    61. CMIS queries 60 www.devoxx.com
    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. 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. CMIS Web Services bindings All the WSDL files are provided Check the spec ;-) 63 www.devoxx.com
    65. CMIS repository services getRepositories getRepositoryInfo getTypes getTypeDefinition 64 www.devoxx.com
    66. CMIS navigation services getDescendants getChildren getFolderParent getObjectParents getCheckedoutDocuments 65 www.devoxx.com
    67. CMIS object services createDocument createFolder createRelationship createPolicy getAllowableActions getProperties, updateProperties getContentStream, setContentStream, deleteContentStream moveObject, deleteObject, deleteTree 66 www.devoxx.com
    68. CMIS multi-filing services addObjectToFolder removeObjectFromFolder 67 www.devoxx.com
    69. CMIS discovery service query 68 www.devoxx.com
    70. CMIS relationships services getRelationships 69 www.devoxx.com
    71. CMIS policy services applyPolicy removePolicy getAppliedPolicies 70 www.devoxx.com
    72. CMIS versioning service checkOut cancelCheckOut checkIn getPropertiesOfLatestVersion getAllVersions deleteAllVersions 71 www.devoxx.com
    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. Jackrabbit tables 73 www.devoxx.com
    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. Visible SQL storage 75 www.devoxx.com
    77. Visible SQL storage 76 www.devoxx.com
    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. 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. Concluding statement Look for CMIS soon, and check out Nuxeo now! www.devoxx.com
    81. Q&A Questions? www.devoxx.com
    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

    + Open Source ECM NuxeoOpen Source ECM Nuxeo, 11 months ago

    custom

    1748 views, 2 favs, 1 embeds more stats

    Nuxeo Core, JCR 2, CMIS: learn how to use content r more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1748
      • 1721 on SlideShare
      • 27 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 47
    Most viewed embeds
    • 27 views on http://www.nuxeo.com

    more

    All embeds
    • 27 views on http://www.nuxeo.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories