plat-16 using enterprise content in grails

26
Using Enterprise Content in Grails Robin Bramley, Ixxus

Upload: alfresco-software

Post on 08-May-2015

1.673 views

Category:

Technology


2 download

DESCRIPTION

Grails is revolutionizing web development in many corporate Java environments. However, leveraging managed content isn’t straight forward with the myriad of incompatible ECM systems prevalent in businesses. The Content Management Interoperability Services (CMIS) standard allows for products or applications to be built independently of the underlying content repository. CMIS and Grails is a powerful combination for handling document management activities and displaying web content assets within custom web applications. This session will explore: How to integrate a CMIS repository with Grails applications, Apache Chemistry OpenCMIS vs. roll your own, Authentication models, Practical considerations, Alfresco extensions to CMIS and OpenCMIS. The concepts will be presented before diving into a hands-on session with Grails.

TRANSCRIPT

Page 1: PLAT-16 Using Enterprise Content in Grails

Using Enterprise Content in Grails!

Robin Bramley, Ixxus!

Page 2: PLAT-16 Using Enterprise Content in Grails

Agenda!

•  Who I am!•  Setting the scene!•  Grails!•  CMIS!

•  Sample application styles!•  Document Management!•  Managed web content!

•  CMIS clients!•  Roll your own!•  OpenCMIS!

•  Practicalities!•  Alfresco extensions to CMIS!•  Performance!

•  Grails OpenCMIS Plugin!•  Alternatives!

Page 3: PLAT-16 Using Enterprise Content in Grails

My Background!

•  Senior Architect @ Ixxus!•  The UK Platinum partner!

•  Worked at consultancies for 13 years!•  Developing solutions with Alfresco since 0.6!•  First UK Alfresco Gold partner!

•  Around the edges I also write!•  GroovyMag author – inc. 4 hands-on Grails articles!•  DZone Most Valuable Blogger!

•  Re-published my series on Grails & Hudson / Jenkins!•  Open source contributions!

•  OpenID support for Acegi / Spring Security!•  Codenarc support for Hudson / Jenkins CI Violations plugin!

•  Presented at the London GGUG!

Page 4: PLAT-16 Using Enterprise Content in Grails

Grails!

•  Full-stack web framework!•  Embedded Tomcat & database!•  Allows for rapid development!

•  > grails create-application test •  > cd test •  > grails run-app

•  Scaffolding from domain classes!•  Convention over configuration!•  Builds on the shoulders of Giants!

•  Groovy!•  Spring Framework!•  Spring MVC!•  Hibernate!

•  Rich plugin ecosystem!•  Backed by SpringSource!

Page 5: PLAT-16 Using Enterprise Content in Grails

CMIS!

Content Management Interoperability Services standard!• Open standard published by OASIS!

•  Version 1.0 – 1st May 2010!•  Alfresco 3.3 was first CMIS 1.0 compliant product launched!

• ̒SQL for contentʼ!•  Query language!•  Virtual tables!

•  Folder!•  Document!•  Relationship!•  Policy!

• Bindings (ʻJDBC/ODBC equivalentʼ)!•  REST / AtomPub!•  SOAP Web Services!•  Browser binding in CMIS 1.1!

Page 6: PLAT-16 Using Enterprise Content in Grails

Documents & Folders!

Document •  Has a set of metadata

properties !•  Columns!•  Custom extensions!

•  May have a content stream (e.g. an actual file)!

•  May have renditions!

Folder •  Has a set of metadata

properties!•  Can have zero or more

children!•  Documents or Folders!

Page 7: PLAT-16 Using Enterprise Content in Grails

CMIS Repository Information !

Service Document •  3.x CMIS AtomPub binding: /alfresco/service/cmis •  4.x CMIS AtomPub binding: /alfresco/cmisatom

<cmisra:repositoryInfo> <cmis:repositoryId>ea9c2b9e-2892-4370-8791-4b0049f917f3</cmis:repositoryId> <cmis:repositoryName>Main Repository</cmis:repositoryName> <cmis:repositoryDescription>Main Repository</cmis:repositoryDescription> <cmis:vendorName>Alfresco</cmis:vendorName> <cmis:productName>Alfresco Repository (Community)</cmis:productName> <cmis:productVersion>4.0.0 (a 3755)</cmis:productVersion> <cmis:rootFolderId>workspace://SpacesStore/784b5b19-61ee-4963-a367-db6164ed43af</cmis:rootFolderId>

Page 8: PLAT-16 Using Enterprise Content in Grails

CMIS Query Syntax!SQL like •  Subset of SQL-92 with some extensions !

•  SELECT * FROM cmis:document •  SELECT * FROM cmis:folder

WHERE IN_FOLDER(‘folder-id’) •  SELECT * FROM cmis:document

WHERE IN_TREE(‘folder-id’) •  SELECT cmis:objectId, cmis:name, cmis:contentStreamLength

FROM cmis:DOCUMENT WHERE contains(‘fox’) OR cmis:name like ‘%fox%’

•  The complete BNF grammar is included in the specification at http://docs.oasis-open.org/cmis/CMIS/v1.0/os/cmis-spec-v1.0.html#_Toc243905422 !

Page 9: PLAT-16 Using Enterprise Content in Grails

CMIS Query Submission!•  Queries are submitted by POSTing application/cmisquery+xml

•  Accepted response format e.g. application/atom+xml;type=feed

<cmis:query xmlns:cmis=’http://docs.oasis-open.org/ns/cmis/core/200908/’>

<cmis:statement>SELECT * FROM cmis:document</cmis:statement>

<cmis:searchAllVersions>false</cmis:searchAllVersions>

<cmis:includeAllowableActions>false<cmis:includeAllowableActions>

<cmis:includeRelationships>none</cmis:includeRelationships>

<cmis:renditionFilter>*</cmis:renditionFilter>

<cmis:maxItems>-1</cmis:maxItems>

<cmis:pageSize>-1</cmis:pageSize>

<cmis:skipCount>0</cmis:skipCount>

</cmis:query>

Page 10: PLAT-16 Using Enterprise Content in Grails

Atom response!

Page 11: PLAT-16 Using Enterprise Content in Grails

Atom response – feed metadata!

<author><name>System</name></author> <generator version="4.0.0">Alfresco</generator> <icon>http://localhost:8080/alfresco/images/logo/AlfrescoLogo16.ico</icon> <id>urn:uuid:784b5b19-61ee-4963-a367-db6164ed43af-children</id> <title>Company Home Children</title> <updated>2011-11-01T18:54:14.541Z</updated> <opensearch:totalResults>5</opensearch:totalResults> <opensearch:startIndex>0</opensearch:startIndex> <opensearch:itemsPerPage>-1</opensearch:itemsPerPage> <cmisra:numItems>5</cmisra:numItems>

Page 12: PLAT-16 Using Enterprise Content in Grails

Atom response – entry!

<author><name>admin</name></author> <content src="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/140c55fc-c8ca-4491-96ee-3c9d72214238/content"/><id>urn:uuid:140c55fc-c8ca-4491-96ee-3c9d72214238</id> <published>2011-11-01T18:54:14.529Z</published> <summary></summary> <title>Projects</title> <updated>2011-11-01T18:54:38.831Z</updated> <app:edited>2011-11-01T18:54:38.831Z</app:edited> <alf:icon>http://localhost:8080/alfresco/images/icons/space-icon-star-16.gif</alf:icon> <cmisra:object> <cmis:properties> <cmis:propertyId propertyDefinitionId="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Object Types Ids" queryName="cmis:allowedChildObjectTypeIds"/> <cmis:propertyId propertyDefinitionId="cmis:objectTypeId" displayName="Object Type Id" queryName="cmis:objectTypeId"><cmis:value>cmis:folder</cmis:value></cmis:propertyId> <cmis:propertyString propertyDefinitionId="cmis:path" displayName="Path" queryName="cmis:path"><cmis:value>/Projects</cmis:value></cmis:propertyString> <cmis:propertyString propertyDefinitionId="cmis:name" displayName="Name" queryName="cmis:name"><cmis:value>Projects</cmis:value></cmis:propertyString> <cmis:propertyDateTime propertyDefinitionId="cmis:creationDate" displayName="Creation Date" queryName="cmis:creationDate"><cmis:value>2011-11-01T18:54:14.529Z</cmis:value></cmis:propertyDateTime> <cmis:propertyString propertyDefinitionId="cmis:lastModifiedBy" displayName="Last Modified By" queryName="cmis:lastModifiedBy"><cmis:value>admin</cmis:value></cmis:propertyString> <cmis:propertyString propertyDefinitionId="cmis:createdBy" displayName="Created by" queryName="cmis:createdBy"><cmis:value>admin</cmis:value></cmis:propertyString> <cmis:propertyId propertyDefinitionId="cmis:objectId" displayName="Object Id" queryName="cmis:objectId"><cmis:value>workspace://SpacesStore/140c55fc-c8ca-4491-96ee-3c9d72214238</cmis:value></cmis:propertyId> <cmis:propertyDateTime propertyDefinitionId="cmis:lastModificationDate" displayName="Last Modified Date" queryName="cmis:lastModificationDate"><cmis:value>2011-11-01T18:54:38.831Z</cmis:value></cmis:propertyDateTime> <cmis:propertyId propertyDefinitionId="cmis:parentId" displayName="Parent Id" queryName="cmis:parentId"><cmis:value>workspace://SpacesStore/784b5b19-61ee-4963-a367-db6164ed43af</cmis:value></cmis:propertyId> </cmis:properties> </cmisra:object> <cmisra:pathSegment>Projects</cmisra:pathSegment>

Page 13: PLAT-16 Using Enterprise Content in Grails

Links!Folder Tree Navigation

•  Can be achieved through queries!•  Specifying attributes means you can pull back less data!•  Can also apply criteria!

•  Atom entries also feature links including:!•  children (immediate)!

•  <link rel=”down” href=”http://cmis.alfresco. com:80/service/cmis/s/workspace:SpacesStore/ i/2dfb66de-9cb5-4e60-a786-5ea2ad8740d6/children” type=”application/atom+xml;type=feed”/> !

Page 14: PLAT-16 Using Enterprise Content in Grails

Links!Folder Tree Navigation

•  Atom entries links also including:!•  descendants (note type is cmistree)

•  <link rel=”down” href=”http://cmis.alfresco. com:80/service/cmis/s/workspace:SpacesStore/ i/2dfb66de-9cb5-4e60-a786-5ea2ad8740d6/descendants” type=”application/cmistree+xml”/> !

•  tree •  <link rel=”http://docs.oasis-open.org/ns/cmis/ link/200908/

foldertree” href=”http://cmis.alfresco. com:80/service/cmis/s/workspace:SpacesStore/ i/2dfb66de-9cb5-4e60-a786-5ea2ad8740d6/tree” type=”application/atom+xml;type=feed”/> !

•  Can apply depth control to these two!

Page 15: PLAT-16 Using Enterprise Content in Grails

Enough Theory?!

Page 16: PLAT-16 Using Enterprise Content in Grails

Application styles: Document Management!Simple repository client

•  First phase provided browse-search-retrieve!•  Intended for mobile usage (as featured in Alfresco 3 Business

Solutions by Martin Bergljung of Ixxus)!•  Uses an in-house roll your own Grails CMIS plugin!•  Authenticates users against Alfresco!

Page 17: PLAT-16 Using Enterprise Content in Grails

Application styles: Document Management!Simple repository client

Page 18: PLAT-16 Using Enterprise Content in Grails

Application styles: Web Content!

Blurb-style WCM •  Featured in!

•  Code requested by NASA !•  Taglib to embed identified

content!•  Backed by a service!

•  Uses OpenCMIS!•  Application level

credentials!

Page 19: PLAT-16 Using Enterprise Content in Grails

Application styles: Web Content!Associated documents

•  Web applications commonly have a need for associated documents!

•  E.g. case studies!•  This can be achieved by linking a

record to an Alfresco node reference!•  To zero to many documents!•  Or a folder!

•  An application built for one customer featured a folder picker for the admins!

•  Built as a taglib using AJAX with jQuery and jQuery UI components:!

•  dialog!•  treeview + treeview.async!

Page 20: PLAT-16 Using Enterprise Content in Grails

CMIS clients!

Roll your own •  Easy with

•  Commons HttpClient!•  XmlSlurper / GPath!•  MarkupBuilder!

•  Can add caching in Grails using Spring Modules Caching!

•  Flexible!•  Can easily get alf:icon etc.!

•  Arguably higher maintenance!

•  Minimal changes from 3.1.1/3.2 3.3/3.4 and then to 4.0!

OpenCMIS •  Java CMIS client and server

libraries!•  Part of!

•  Graduated from incubator in February!

•  Currently at version 0.5!•  Provides session-level

caching!•  Used by Alfresco!•  Doesnʼt support Alfresco

CMIS extensions*!

Page 21: PLAT-16 Using Enterprise Content in Grails

Practicalities: Alfresco CMIS extensions!

Aspects •  Alfresco uses the CMIS extension mechanism to allow for usage of

Aspects!•  E.g.!

<alf:aspects> <alf:appliedAspects>P:cm:titled</alf:appliedAspects>

<alf:properties>

<cmis:propertyString propertyDefinitionId="cm:description" displayName="Description" queryName="cm:description">

<cmis:value></cmis:value></cmis:propertyString> <cmis:propertyString propertyDefinitionId="cm:title" displayName="Title" queryName="cm:title">

<cmis:value></cmis:value></cmis:propertyString> </alf:properties>

</alf:aspects>

•  There is also an Alfresco OpenCMIS Extension!•  http://code.google.com/a/apache-extras.org/p/alfresco-opencmis-extension/ !•  Custom aspect-aware ObjectFactory implementation!•  0.2 POM depends on OpenCMIS Client Impl 0.3!

Page 22: PLAT-16 Using Enterprise Content in Grails

Practicalities: Performance!Tips

•  Filter!•  Donʼt ask for more data than you need!

•  Specify columns on queries (the wildcard is lazy)!•  Use the OperationContext filter!

•  Cache!•  Donʼt repeat yourself requests!

•  Use OpenCMIS session-level caching!•  Use Spring Modules application level caching if appropriate!•  Consider reverse proxy caches such as Varnish!

•  Compress!•  Donʼt waste bandwidth!

•  Compress the XML data types if the clients can handle it(see http://wiki.alfresco.com/wiki/CMIS#Compression) !

Page 23: PLAT-16 Using Enterprise Content in Grails

Time to crack open the code!

Page 24: PLAT-16 Using Enterprise Content in Grails

Grails OpenCMIS Plugin!•  What happened to it?!•  I jokingly blame Marc Palmer and his advice to plugin authors…!

•  Distilled guidance: “Make it work, make it simple, make it magic”!•  Though he didnʼt want people to not put a 0.1 out there!

•  But in reality the sponsoring project got delayed!•  So what magic is being considered for the road map?!•  Content-centric DSL !

•  Primarily around OpenCMIS API!•  GORM domain mapWith / mapping magic!

•  Could join the data mapping project as datastore-cmis!•  static mapWith = “cmis” •  Dynamic finders / criteria could use CMIS QL!•  But need to work out how feasible associative documents are!

•  E.g. only persist certain properties to CMISbyte[] document static mapping = { document mapWith:’cmis’ }

•  Plus taglibs, service, implementing the Alfresco extensions as a child plugin etc.!

Page 25: PLAT-16 Using Enterprise Content in Grails

Alternative Plugins!

Other possible solutions

•  Plugins that use the RivetLogic APIs!• http://www.grails.org/plugin/alfresco!

•  Last release 0.4 for Grails 1.1.1 in Feb 2010!•  Bundles old Alfresco core/repository jars and CMA 1.11!

• https://github.com/fix/grails-alfresco-plugin - uses Remote Access API rivet !

• RivetLogicʼs Crafter rivet for Grails!•  June 2010!

•  GORM JCR datastore!• Had dependencies on Jackrabbit!

Page 26: PLAT-16 Using Enterprise Content in Grails

Twitter: @rbramleyGitHub: https://github.com/rbramley

Blog: http://leanjavaengineering.com/ Web: http://www.ixxus.com !