Reader small image

You're reading from  Alfresco One 5.x Developer???s Guide - Second Edition

Product typeBook
Published inFeb 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781787128163
Edition2nd Edition
Languages
Concepts
Right arrow
Authors (2):
Benjamin Chevallereau
Benjamin Chevallereau
author image
Benjamin Chevallereau

Benjamin Chevallereau is a French software architect, based in London, who has been working on Alfresco projects for the last 8 years and Ephesoft projects for the last 3 years. He implemented solutions for small companies and global organizations in different domains such as transport, finance, and government. He has worked for different Alfresco-recognized partners in France, the UK, and USA, including Armedia LLC, Zaizi, Michelin / Wipro, and BlueXML. He is also one of the committers and PMC members of the Apache CMIS Chemistry project.
Read more about Benjamin Chevallereau

Jeff Potts
Jeff Potts
author image
Jeff Potts

Jeff Potts is the founder of Metaversant Group, Inc., a consulting firm focused on content management, search, and workflow. Jeff brings over 20 years of Enterprise Content Management implementation experience to organizations of all sizes including the Fortune 500. Throughout his consulting career he has worked on a number of projects for clients across the media and entertainment, airline, consumer packaged goods, and retail sectors. Jeff began working with and blogging about Alfresco in November of 2005. In 2006 and 2007, he published a series of Alfresco tutorials and published them on his blog, ecmarchitect.com. That work, together with other Community activity in Alfresco's forum, Wiki site, and JIRA earned him Alfresco's 2007 Community Contributor of the Year Award. In the past, Mr. Potts has worked for Alfresco Software, Inc. as Chief Community Officer, Optaros as Senior Practice Director, and Hitachi Consulting as Vice President where he ran the ECM practice.
Read more about Jeff Potts

View More author details
Right arrow

Chapter 4. Handling Content Automatically with Actions, Behaviors, Transformers, and Extractors

Alfresco provides several types of hooks that can be used to perform interesting operations on content. Whether an operation is triggered by an end user, as is the case with Actions (sometimes called "Rule Actions"), or is handled automatically with Behaviors, Transformers, or Extractors. This chapter is about leveraging what is already available out of the box and, more importantly, how to develop your own when what is available doesn't meet your needs.

By the end of this chapter, you will know how to:

  • Create your own actions using Java

  • Bind Java- and JavaScript-based behavior to types and aspects

  • Configure and extend metadata extractors

  • Write custom content transformers

Encapsulating content operations in actions


As you might suspect, a repository action is a piece of code that can be executed against a piece of content. Actions are discrete units of work. Then, you have Share action representing an action that you can do in Alfresco Share. Some of the out-of-the-box Share actions are Edit Online, Upload New Version, Edit Properties, Move to..., Copy to..., Start Workflow, or Delete Document.

Most of the out-of-the-box Share actions are not linked directly to a repository action, most of them are linked to the Alfresco repository via webscripts. In this chapter, we will focus only on repository actions, and rules that can be configured in the UI and allow you to execute repository actions based on some criteria. Share actions will be covered in Chapter 5, Customizing Alfresco Share.

In the last chapter, SomeCo created some metadata related to publishing Whitepapers on the Web. The sc:webable aspect included a flag to identify whether or not a piece of content...

Binding logic to custom types with behaviors


So far, you've seen how to write code that works with custom content types, properties, aspects, and associations. But the code wasn't tightly coupled to the objects on which it operated. With an action, the business logic is triggered by something-an item in the user interface, a schedule, or a workflow-rather than being bound to the content type or aspect.

As you know, a repository action is a piece of code that can be performed against a node. You don't have one good way of implementing your project. Some argue that the best place to develop your business logic is within repository actions. It's a good approach because it means that you can trigger your action using a rule, via a webscript, or via a Javascript code. I'll go a bit further and I'd say that a repository action should never contain business logic. All the business logic should be encapsulated in a Java service that is called by a repository action, or a webscript. It allows to share...

Extracting metadata from files


Many authoring tools provide a mechanism for capturing metadata within the authoring tool user interface. If certain pieces of metadata are already stored as part of the file, why force content contributors to re-key the metadata when they add the content to the repository? Alfresco can use metadata extractors to inspect the file, extract the metadata, and save the metadata in the node's properties.

A metadata extractor is a Java class configured as a Spring bean that either gets called when content is created in the repository, or when the extractor is invoked by a rule action. Alfresco knows which extractor to use for a given piece of content because metadata extractors declare the MIME types they support.

Metadata extractors have a default mapping that identifies which pieces of file metadata should be stored in which node properties. The property mapping can be overridden by pointing to a custom mapping in the Spring bean configuration.

Customizing metadata...

Transforming content from one format to another


A content transformer is used to transform content from one format to another. Content transformers are implemented as a Java class configured as a Spring bean. Alfresco finds the appropriate transformer based on source and target MIME type. There are two important use cases for transformers. The first is when an end user triggers a transformation, usually through an action. The most well-known out of the box example is converting Microsoft Office documents to PDF. Other out of the box transformers include:

  • HTML-to-text

  • Microsoft Excel-to-CSV

  • Microsoft Word-to-text

  • PDF-to-text

  • Images-to-Images

See the Appendix for further details on the out of the box transformers.

The second key transformer use case involves the Solr full-text search engine. Solr indexes content when it is added to the repository. But the Alfresco Tracker code embedded in Solr only understands plain text. The Solr process sends queries every 15 seconds by default to Alfresco to get...

Summary


This chapter covered four different ways in which you can automatically process content as it is created, read, updated, and deleted. Specifically, you learned how to:

  • Write custom actions both with and without action parameters, as well as how to invoke actions from JavaScript

  • Bind logic to custom types using behaviors, including the logic that has a deal with the fact that it may have to wait until an existing transaction completes

  • Extract metadata from binary files to reduce the amount of re-keying content contributors have to do when adding content to the repository

  • Transform content from one format to another to facilitate full-text searching, or to simply provide a way for users to generate additional output formats from the same piece of content

When planning your own Alfresco implementations and Alfresco-based solutions, it is important to keep these hooks in mind. This is because the more code that can be moved into these areas, the more flexible and end-user configurable your...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Alfresco One 5.x Developer???s Guide - Second Edition
Published in: Feb 2017Publisher: PacktISBN-13: 9781787128163
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Benjamin Chevallereau

Benjamin Chevallereau is a French software architect, based in London, who has been working on Alfresco projects for the last 8 years and Ephesoft projects for the last 3 years. He implemented solutions for small companies and global organizations in different domains such as transport, finance, and government. He has worked for different Alfresco-recognized partners in France, the UK, and USA, including Armedia LLC, Zaizi, Michelin / Wipro, and BlueXML. He is also one of the committers and PMC members of the Apache CMIS Chemistry project.
Read more about Benjamin Chevallereau

author image
Jeff Potts

Jeff Potts is the founder of Metaversant Group, Inc., a consulting firm focused on content management, search, and workflow. Jeff brings over 20 years of Enterprise Content Management implementation experience to organizations of all sizes including the Fortune 500. Throughout his consulting career he has worked on a number of projects for clients across the media and entertainment, airline, consumer packaged goods, and retail sectors. Jeff began working with and blogging about Alfresco in November of 2005. In 2006 and 2007, he published a series of Alfresco tutorials and published them on his blog, ecmarchitect.com. That work, together with other Community activity in Alfresco's forum, Wiki site, and JIRA earned him Alfresco's 2007 Community Contributor of the Year Award. In the past, Mr. Potts has worked for Alfresco Software, Inc. as Chief Community Officer, Optaros as Senior Practice Director, and Hitachi Consulting as Vice President where he ran the ECM practice.
Read more about Jeff Potts