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

Preface

Alfresco is the leading open source platform for Enterprise Content Management. The progress the Alfresco Engineering team has made since that first production release in June of 2005 has simply been amazing. The platform is well on its way to fulfilling its vision of becoming a viable alternative to those from legacy vendors who simply cannot keep up with the pace of innovation inherent in a solution assembled from open source components.

This book takes you through the process of customizing and extending the Alfresco platform. It uses a fictitious professional services company called "SomeCo" as an example. SomeCo has decided to roll out Alfresco across the enterprise. Your job is to take advantage of Alfresco's extension mechanism, workflow engine, and various APIs to meet the requirements from SomeCo's various departments.

Although many customizations can be made by editing XML and properties files, this book is focused on developers. That might mean writing Java code against the foundation API to implement an action or a behavior, maybe creating some server-side JavaScript to use as the controller of a RESTful web script, or perhaps implementing custom business logic in an advanced workflow. The point is that all but the most basic implementations of any ECM platform require code to be written. The goal of this book is to help you identify patterns, techniques, and specific steps that you can use to become productive on the platform more quickly.

By the end of this book, you will have stepped through every aspect of the Alfresco platform. You will have performed the same types of customizations and extensions found in typical Alfresco implementations. Most importantly, when someone comes to you and asks, "How would you do this in Alfresco?", you'll have at least one answer and maybe even some source code to go with it.

What This Book Covers

Chapter 1 is for people new to the Alfresco platform. It walks you through the capabilities of Alfresco and gives some examples of the types of solutions that can be built on the platform. You'll also learn what tools and skills are required to implement Alfresco-based solutions.

Chapter 2 is about getting your development environment set up. Like preparing for a home improvement project, this is the trip to the hardware store to get the tools and supplies you'll need to get the job done. Throughout the book, you will be building and deploying changes. So just as in any software development project, it pays to get that process working up front. You'll also learn about the debugging tools that are available to you. The chapter includes a short and simple customization example to test out your setup.

Chapter 3 starts where all Alfresco projects should begin: defining the content model. You'll learn how to define the content model as well as how to expose the model to the Alfresco web client. Once you've got it in place, you'll write some Java code that utilizes the Web Services API to test out the model. This will also be your first taste of the JavaScript API. The exercises set up the initial content model for SomeCo.

Chapter 4 begins to show you the power of the repository by exposing you to some of the mechanisms or hooks that can be used to perform "hands off" operations on content. You'll learn about actions, behaviors, transformers, and metadata extractors. The exercises include implementing a rule action for SomeCo's Human Resources department to help manage HR policies, writing a custom behavior to calculate user ratings, and writing a custom metadata extractor to make Microsoft Project files indexable by the Lucene search engine.

Chapter 5 takes you through web client customizations. First, it establishes whether or not you should be customizing the web client at all. Once that's out of the way, you learn how to add new menu items, how to create your own custom component renderers, and how to define new dialogs and wizards. Examples in this chapter include writing a new "Execute Script" UI Action to make it easier to run server-side JavaScript, creating a "Stoplight" component to graphically show project status, and creating a multi-step wizard SomeCo's HR department can use to set up job interviews.

Chapter 6 focuses on the web script framework. Web scripts are an important part of the platform because they allow you to expose the repository through a RESTful API. They are also core to the Surf framework that is in the 3.0 release. The exercises in this chapter are about creating a set of URLs that can be called from the frontend web site to retrieve and persist user ratings of objects in the repository.

Chapter 7 is about advanced workflows. You'll learn how the embedded JBoss jBPM workflow engine works and how to define your own workflows, including how to implement your own business logic. The chapter includes a comparison between the capabilities of Alfresco's simple workflow and advanced workflow so that you can decide which one is appropriate for your needs. By the end of the chapter, you will have built a workflow that SomeCo will use to review and approve Whitepapers for external publication. The process includes an asynchronous step, which leverages the web script knowledge you gained in the previous chapter.

Chapter 8 takes you through the key developer-related aspects of Alfresco's Web Content Management functionality. The chapter is not an exhaustive WCM how-to. Rather, the chapter starts with a simple web form and then quickly moves to using the API to work with WCM assets. You'll also leverage advanced workflow and web script techniques you learned in previous chapters to work with WCM sites and assets. You'll create a "no approval" workflow that SomeCo will use for Job Postings and web scripts developers can use to deploy web sites to test servers and to commit changes to staging.

Chapter 9 covers a variety of security-related topics. You'll learn how to define your own custom roles, and how to create users and groups with the API. Although not strictly developer-centric, you'll also learn how to configure Alfresco to authenticate and synchronize with an LDAP directory and how to implement Single Sign-On (SSO) between Alfresco and other web resources.

A set of Appendices is included at the end of the book. There you'll find reference information such as the JavaScript API, a set of diagrams showing the out-of-the-box content model, and a list of the out-of-the-box public spring beans.

Appendix C is available for download from the book's page on Packtpub.com. You can visit http://www.packtpub.com/files/3117_AppendixC.pdf to directly download it. It includes a section on packaging and deploying AMPs, and an overview of the new Surf framework.

What You Need for This Book

To work through the examples in this book, you will need:

  • Alfresco. Either Enterprise or Labs will work. The examples have been tested on 2.2 Enterprise and 3.0 Labs. Chapter 2 provides further details on obtaining Alfresco.

  • Alfresco SDK.

  • Apache Ant.

  • Apache Tomcat.

  • Eclipse, although other IDEs (or even a text editor) will work.

There are other tools or libraries that you will need for certain exercises, which will be mentioned as necessary.

Who This Book is For

This book will be most useful to developers who are writing code to customize Alfresco for their organization or who are creating custom applications that sit on top of Alfresco.

This book is for Java developers, and you will get most from the book if you already work with Java, but you need not have prior experience on Alfresco. Although Alfresco makes heavy use of open source frameworks such as Spring, Hibernate, JavaServer Faces, and Lucene, no prior experience using these is assumed or necessary.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The question mark in the user value placeholder declares the argument as optional."

A block of code will be set as follows:

{"rating" : 
   {
      "average" : "1.923",
      "count" : "13",
   }
        }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

    enableLookups="false" disableUploadTimeout="true"
    acceptCount="100" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    keystoreFile="/root/.keystore"
    keystorePass="changeit"

Any command-line input and output is written as follows:

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="scwf:publishWhitepaper">

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "Click the Browse Website link in the Staging Sandbox ."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code for the Book

Visit http://www.packtpub.com/files/code/3117_Code.zip to directly download the example code.

Note

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide the location address or website name immediately so we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it.