Integrating Portofino with Alfresco
![]() on May 29, 2009 In this tutorial, I'll explain how to integrate Portofino with other systems in an enterprise environment. Portofino has several integration features: Listeners, Custom workflow Actions, Custom operations. In this tutorial we'll see:
Alfresco (http://www.alfresco.com) is an Enterprise content manager (ECM), a tool used to capture, manage, store, and deliver content and documents related to an organization and it's processes. Before we startBefore we start, I suggest that you read:
You also need:
A “Job Application” demoWe'll make a simple example: a “Job Application” to store candidates with their personal data and curricula. The demo application will have a simple workflow to manage its state: "submitted" when it is inserted and still needs to be evaluated; after an evaluation it can be “accepted” or "rejected". We also want that:
Let's start to model the app. I used this portofino-custom.properties to connect to a derby db.
portofino-custom.properties
Now connect to your instance (http://127.0.0.1:8080/portofino) and create a class “job_application”, with the following attributes:
Until now we have used the basic features of Portofino, but we still need the mail notification and the integration with Alfresco which cannot be obtained without coding. Let's consider first the email notification. For this purpose we can use a listener. Sending an email notification through a Portofino listenerIn Portofino a listener allows you to intercept (create, update, delete) operations on objects, in a similar way to triggers in relational databases. To create our listener:
“create pre script” for job_application String surname = obj.getTextAttribute("surname");
String email = obj.getTextAttribute("email"); String server = "smtp.example.com";
com.manydesigns.portofino.base.email.EMailTask em = new com.manydesigns.portofino.base.email.EMailTask(config.getConfigContainer());
String body = "Dear "+surname+", \n we've received your cv.\nHugs and kisses"; String subject = "We receveid your job application"; em.addEmail(new java.util.Date(), "sender@example.com", email, body, subject); Inside the script, the following variables are pre-set by Portofino: obj (the object for which the listener is executed) and cls (the class to which the listener is bound). We can read the values of the object
trough the getter
obj.getTypeAttribute(String AttributeName), where Type
can be Text, Integer, Boolean, Decimal, ... and the AttributeName
is the name of the attribute, e.g.:
obj.getTextAttribute("surname"); The remaining code is the standard way to send an email through Portofino API. Remember to customize the sender. Storing documents in Alfresco through a Portofino workflow actionNext step, we want to save the blob in Portofino into Content
repository managed by Alfresco. Here, I won't deepen Alfresco's architecture and configuration (see the wiki at http://www.alfresco.org
or Jeff Potts' blog http://ecmarchitect.com/
). I have simply created a space called “CV” where I'm going to store the PDFs during the workflow transition from “submitted” to "accepted". To create a workflow action we need to create a maven overlay project to include the original portofino war and jars, the alfresco client libraries and our custom classes. Follow the tutorial to create a maven overlay. Then we need some modifications in the
pom.xml. First of all we add a new dependency
“portofino-jar” to the pom.xml of the previous tutorial, because in this project our classes will use the Portofino API. <dependency> <groupId>com.manydesigns</groupId> <artifactId>portofino-jar</artifactId> <version>2.0.16</version> <type>jar</type> <scope>compile</scope> </dependency> ... Then we add all the jars needed by Alfresco Web Service Client (see the pom.xml in the References section). I found them in the JBoss repository. The only one that is missing is “alfresco-web-service-client” (download it from Alfresco http://wiki.alfresco.com/wiki/Download_Alfresco_Community_Network), I manually installed it with the following maven command. mvn install:install-file -DgroupId=alfresco \ Now open your favorite Java IDE and create a Custom Action
(StoreCV.java), with which you can launch your java code every time a workflow transition is triggered. A custom Action must implement
com.manydesigns.portofino.base.workflow.WfActionAPI and its method
“run” - void run(MDObject obj, MDWfTransition wft, “run” is executed when object "obj" changes its state through transition "wft". A collection of strings ("errors") is passed to accumulate any error messages. The comments are in the code. package com.manydesigns.demo; You need to create a resource (alfresco/webserviceclient.properties) to tell to our application where Alfresco is listening for connections. This file has only the following row.
repository.location=http://127.0.0.1:8080/alfresco/api
Now run:
mvn package
At the end you have your war file under the "target" directory. Deploy it under your running apache tomcat. Now we'll tell Portofino about our custom action. Open your browser and go to your application:
Now test your application, go downstairs and create a "job application" with a cv in pdf attached. You'll receive an email after the creation of a job application. Move the workflow forward by clicking on "approve": this will store the CV in Alfresco. Connect to Alfresco and look at the "CV" space" to see the uploaded CV. ConclusionsIn a complex enterprise environment, Portofino can be viewed as one of the components. Using Portofino's API you can integrate it with complementary system (e.g. an ECM), while maintaing its ease of use and high levels of productivity.Resources[1] – complete source code
|



