Book Image

Alfresco Developer Guide

Book Image

Alfresco Developer Guide

Overview of this book

Table of Contents (17 chapters)
Alfresco Developer Guide
Credits
About the Author
About the Reviewers
Preface
Index

Customizing Alfresco


Alfresco offers a significant amount of functionality out of the box, but most clients will customize it in some way. At a high level, the types of customizations typically done during an implementation can be divided into basic customizations and advanced customizations.

Basic Customization

Many Alfresco customizations can be done without writing a single line of code. Some may be done even by end users through the web client. Others might require editing a properties file or an XML file. These basic configuration and customization tasks are described in-depth in Alfresco Enterprise Content Management Implementation by Munwar Shariff, Packt Publishing. Let's look at them briefly here so that you can get an idea of what you don't have to code.

Dashlets

When users log in to Alfresco, the first thing that is usually displayed is the My Alfresco Dashboard. The dashboard is a user-configurable layout that contains dashlets. (If you are familiar with portals, think "portal page" and "portlet"). Users choose the layout of the dashboard (number of columns) as well as the specific dashlets they want displayed in each column.

There are a number of dashlets available out of the box, or you can develop your own and add them to the user-selectable list. Examples of out of the box dashlets include workflow-related dashlets such as My Tasks To Do and My Completed Tasks as well as content-related dashlets such as My Documents and My Spaces:

A dashlet is implemented as a JSP page. The JSP page can contain JSF components and make calls to JSF-managed beans. If FreeMarker is more your style, the JSP page can easily delegate its rendition to a FreeMarker template. Obviously, developing custom dashlets is probably not something you'd let your business users do; but it is still considered a basic customization.

Custom Views

Alfresco's web client uses a hierarchical folder metaphor for navigating the repository. Alfresco calls folders "spaces" because in Alfresco, folders can do more than just contain documents. They can also have metadata, rules, and permissions associated with them. I will use "folders" and "spaces" interchangeably throughout the book. The default behavior when a folder is opened is to display the contents of the folder. A common requirement is to display metadata or other information that's not available in the standard content list. One way to do this is to implement a custom view using FreeMarker templates. The custom view can then be applied to the folder by a business user to display it as needed, without changing the underlying folder list functionality.

There are several out of the box FreeMarker templates that can be used as custom views such as "My Documents" and "Recent Documents". Most likely, you'll want to create your own using one of the out of the box templates as an example.

Rules and Rule Actions

A rule is something that says, "When a piece of content is created, updated, or deleted, check these conditions. If these conditions are met, take these actions". Conditions may check whether a piece of content is a particular mime type, or a specific content type. They may also check whether a piece of content has a specific aspect applied, or whether the content's name property matches a particular pattern. Rules can be defined on any folder in the repository. Child folders can inherit rules from their parent.

Rule actions are repeatable operations that enable us to do things similar to those that can be done using JavaScript or Java. Out of the box actions include things such as check-in content, check-out content, move an item to another folder, specialize the type of the content, add an aspect to the content, transform content from one format to another, and so on.

Configuring folders to run rule actions is something non-technical users can do through the web client. In Chapter 4, you'll learn how to write your own custom rule actions using the Alfresco API.

Simple Workflow

Alfresco has two options for implementing workflow: simple workflow or advanced workflow. The good thing about simple workflows is that end users can configure them as needed without any technical skills or developer support.

Here's how it works. A web client user creates a rule to "add a simple workflow" to a document when it is placed in the folder. When a document has a simple workflow, it means it has a "forward step" and a "backward step". A user configuring the simple workflow decides whether to use one or both steps, and assigns appropriate names for steps such as "Approve" and "Reject". When the step is invoked, the content can be copied or moved to another folder. Users create serial processes by setting up multiple folders, each with rules to add the appropriately configured simple workflow to the incoming content. For example, there might be folders called "Draft"," In Review", and "Approved". The state of a document is determined by the folder in which it resides.

Simple workflows have obvious limitations:

  • Workflows are limited to serial processes. Content can only move forward or backward, one step at a time.

  • Content can only be in one process at a given time.

  • Content must change physical locations to reflect a change in state.

  • There is no opportunity for capturing (and acting on) process-related metadata.

  • Tasks can't be assigned to individuals or groups. (Of course, you could limit folders to specific individuals or groups through permissions, which would have a similar effect to a task assignment. But you wouldn't be able to easily pull a list of tasks for a specific user across all simple workflows).

  • Other than creating additional rules and rule actions for the folders used in a simple workflow, there is no way to add logic for decisions or other more complex constructs.

Advanced Customization

The basic configuration and customizations show that there is quite a lot of tweaking and tailoring that can happen before a developer gets involved. This is a good thing. It means a good chunk of the customization requirements can be dealt with quickly. In the case of simple workflows, they can be delegated to the end users altogether! Hopefully, this leaves more time for the more advanced (and more interesting) customizations required for a successful implementation.

Examples of Advanced Customizations

The advanced customizations are the customizations that are likely to require code. They are the focus of the book. To give you an idea of what's possible (and in an effort to provide an appetizer before the main meal is served), let's go over some of the areas of advanced customization.

Extend the Content Model

Alfresco's out of the box content model can be extended to define your own content types, content aspects, content metadata (properties), and relationships (associations). The out of the box model is very generic, and defines only a minimal subset of the metadata that will probably need to be captured with the content.

For example, SomeCo might want to capture different metadata for its Marketing documents than for its HR documents. Or maybe there is a set of metadata that doesn't belong to any one content type in particular, but should rather be grouped together in an aspect and attached to objects as needed. These and other content modeling concepts will be covered in Chapter 3.

Perform Automatic Operations on Content

There are several "hooks" or places where you can insert logic or take action to handle content automatically. These include rule actions, behaviors, content transformers, and metadata extractors. Rule actions have already been discussed. Behaviors are like actions but instead of being something that an end user can invoke on any piece of content, behaviors are tightly bound to their content type. Content transformers, as the name suggests, transform content from one format to another. Metadata extractors inspect content as it is added to the repository, and pull out data to store in the content object's properties. These tools for handling content automatically will all be covered in Chapter 4.

Customize the Web Client

Chapter 5 covers web client customization. Just about everything in the web client can be tweaked. Menu items can be rearranged or new menus and items can be created. If a JSP doesn't work quite the way it needs to, you can override it with your own custom version of the page. Don't like the out of the box date picker? Component renderers for out of the box data types can be overridden or completely new renderers for custom types can be created. If you need to guide users through a multi-step process, you can create custom dialogs and wizards.

In the current release, the web client is built with JSF. In the near future, Alfresco may be moving toward a lighter-weight framework based on web scripts. Regardless of what happens with the new and improved web client, the "classic" web client will be around for a while, so it is a good idea to know how to make it fit your requirements.

Create a RESTful API

Web scripts are one of the more exciting additions to the Alfresco architecture. The Next Generation Internet (NGI) or Web 2.0 (or 3.0 or whatever you want to call it) is built on RESTful services. The reason is that RESTful services are typically much easier to work with using scripting languages and AJAX toolkits than SOAP-based services, because they are invoked through plain old URLs. When a repository has a RESTful interface, it is much easier to incorporate as part of an NGI solution.

The web script framework, based on the Model-View-Control (MVC) pattern, allows you to build your own RESTful API to the repository. It will be covered in detail in Chapter 6, but the high-level summary is that URLs get mapped to a controller implemented as JavaScript or Java. The controller performs whatever logic is needed, then forwards the request to the view. The view is implemented as a FreeMarker template. The template could return anything from markup to XML to JSON. The framework is so powerful and flexible that Alfresco refactors several pieces of the web client to leverage web scripts. RESTful services via web scripts are well on their way to becoming the preferred way to integrate with the Alfresco repository.

Streamline Complex Business Processes with Advanced Workflows

Advanced workflows provide a way to automate complex business processes. Alfresco's advanced workflows are executed by the embedded JBoss jBPM engine, which is a very powerful and popular open source workflow engine.

Rather than basic workflows, which are end-user configurable and limited to serial processes, advanced workflows offer the power of parallel flows, the ability to add logic to the process via JavaScript and Java, and much more.

A handful of advanced workflows are available out of the box. These are most useful as starting points for your own custom advanced workflows. Exactly how it has to be done will be covered in Chapter 7.

Get Your Web sites under Control

Alfresco WCM uses the same web client user interface as everything else in Alfresco, so customization techniques covered in other chapters will apply here. Chapter 8 focuses on specific WCM implementation details such as creating web forms with XML Schema and presentation template development using XSLT and FreeMarker.

Integrate with Other Systems

Most of the coding and configuration discussed so far can be divided into two parts: (1) Customizations made to the core repository and (2) Customizations made to the web client. There is a third bucket to be considered, which is coding and configuration related to integrating Alfresco with other solutions. Maybe Alfresco needs to authenticate against an LDAP directory. Maybe a portal will get its content from Alfresco, or perhaps some other third-party application needs to share content with Alfresco. Chapter 9 discusses how to handle security and integration.