Tuesday, September 22, 2009

Liferay and Alfresco VS. Liferay or Alfresco

Long since Liferay and Alfresco stormed into Open Source Industry, business owners and developers are working on integrating or using these two frameworks and generating some business solutions using these.

At a time, the focus of these two softwares were (still are?) entirely different. For example,

Liferay is by heart a portal solution with a very strong & active community behind it and an impressive clientele to prove its credentials. By far it is in today's days, arguably, the most popular open source portal solution, specially in Java technology.

Alfresco is an Enterprise Content Management Software which also has an equally powerful & vigorous community supporting it and an imposing set of patrons using the software. This is again, the most admired ECMS solution available in today's open source market.

Liferay has been wonderful in handling portal problems in the industry and its scalability have been the main driver that helped itself to be adopted in a variety of business verticals. However, as since its primary focus has been a portal solution, the document and content management capabilities of this framework does not make it very much enterprise ready, and not at all extensible, specially if we compare it with proper document and content management systems. However, the collaboration features of Liferay are definitely quite powerful.

On the other hand, Alfresco has been fantastic as an Enterprise Document and Content Management solution. The framework's architecture, functionality and extensibility makes it really the best choice for an enterprise business. Having features like customizable workflow, templated UI, user-defined data-types, powerful rules engine etc makes this one of the best ECMS solution. Conversely, since it is not intended to be a collaboration solution, these features are not very well provided, at least not suitable for business users.


Integrated Solution


In this scenario, these two technologies seems to be very much complementary to each other - Liferay providing the portal environment while Alfresco sits at the lower level of the stack supplying the content management services.

Alfresco Web Script is a very great framework which makes this solution even more feasible and extensible. Web Scripts can be used as a pltaform of SOA architecture based solution as well as these can be used as standard JSR portlets deployed in Liferay. Both these technologies support Single Sign On with standard LDAP providers.


New Offerings


However, now both these solutions have now come up with new products in order to capture the market with focus and to provide a ready-made solution to the business. Quite excitingly, both these prodcuts seems to be targeting the same market segment - Collaborative Document Management System.

Liferay has launched Liferay Social Office http://www.liferay.com/web/guest/products/social_office, offers features such as Wikis, Blogs, Document Libraries, Calendar, Sites, Message Boards, Activities etc - http://www.liferay.com/web/guest/products/social_office/features.

On the other hand, Alfresco has also launched Alfresco Share http://www.alfresco.com/products/collaboration, offering almost similar features like Document Library, Sites, Wikis, Blogs, Activities, SharePoint protocol support etc.

Although the behavior and presentation of these two systems are different, features and functionalities offered by these are very much similar.


Big Question


Now the big question is, where these two systems are leading into? As the document management, record management features are not main focus of Liferay, similarly the collaboration features are not the most important offerings of Alfresco.

It will be quite interesting to see in next few months or years how these systems grow and place themselves as complementary or competitive solutions.

Wednesday, July 29, 2009

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets - Part 4

Deploying the Web Scripts as Liferay Portlets

Well, we now are able to create and build web scripts both by Java and by JavaScript.
Now, we want our web scripts to be displayed in Liferay portal as portlets.

For that, we need to update the following xml files in order to register the alfresco web scripts in Liferay portlet list. These files are in C:\mystackroot\webapps\alfresco\WEB-INF folder.

For deploying the Alfresco web scripts in Liferay, you need to add the information of the web script (as portlet) in 4 XML files, restart your server, and Whoa - you are done.


web.xml

  • Register the Web Script as a servlet.
<servlet>
<servlet-name>myfirstscript</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-class</param-name>
<param-value>org.alfresco.web.scripts.portlet.WebScriptPortlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
  • Register the Servlet mapping.
<servlet-mapping>
<servlet-name>myfirstscript</servlet-name>
<url-pattern>/myfirstscript/*</url-pattern>
</servlet-mapping>
  • In this way, register all the web scripts as servlets to be deployed as Liferay portlets.



portlet.xml

Register the web scripts as portlets
<portlet>
<description>myfirstscript</description>
<portlet-name>myfirstscript</portlet-name>
<portlet-class>org.alfresco.web.scripts.portlet.WebScriptPortlet</portlet-class>
<init-param>
<name>authenticator</name>
<value>webscripts.authenticator.jsr168.webclient</value>
</init-param>
<init-param>
<name>scriptUrl</name>
<value>/alfresco/168s/infoaxon/repository/ myfirstscript</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<portlet-info>
<title>My First Web Script</title>
<short-title>My First Web Script</short-title>
</portlet-info>
</portlet>



Few points to be noted here:
  1. portlet-name should match the web script name
  2. scriptURL should be like /alfresco/168s/<<web-script-url-as-defined-description-xml>>
In this way, register all the web scripts to be deployed as Liferay portlets.


liferay-portlet.xml

Define the web scripts as portlets
<portlet>
<portlet-name>myfirstscript</portlet-name>
<use-default-template>true</use-default-template>
<restore-current-view>true</restore-current-view>
</portlet>
  • The portlet-name must be same as defined in portlet.xml file.
  • In this way, define all the web scripts to be deployed as Liferay portlets.



liferay-display.xml

Describe how the portlets will be displayed in Liferay portlet list
<portlet id="myfirstscript"></portlet>

The portlet id should match the portlet-name defined earlier.
You can define your own category in which you would like see your portlets in Liferay.
<display>
<category name="My Custom Portlets">
<portlet id="myfirstscript"></portlet>
<portlet id="helloworld"></portlet>
</category>
</display>

In this way, define all the web scripts to be deployed as Liferay portlets.


Congrats, All Done!!!
  • Restart your server.
  • Navigate to Liferay and login as a user with suitable permissions to add a portlet is a page.
  • Open the Add Application popup in liferay. You should see My Custom Portlets category in the list and the portlets you have just registered under it.
  • Drag your portlet in the page and enjoy!

Tuesday, April 14, 2009

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets - Part 3

Creating a Web Script using Java

Step 1: Create the Source Code Folder Hierarchy
  • Decide the package structure and URL of your web scripts.
  • For example, if we create web script in package com.infoaxon.repository
  • In this case, our folder structure would be <<root>>\com\infoaxon\repository. The Java source files will start from this folder.
  • Our all Java source files would be in the repository folder or in any of the subfolders, as per the package design suggests.
  • We will later on create a jar of all these classes.
  • One jar should ideally represent one module in Alfresco, hence if we plan to create a number of alfresco modules, we should design our packages accordingly.
  • One alfresco module can have any number of web scripts, and any number of different packages. So technically speaking, there is no need to create a number of modules for different packages; however, still creating separate modules might be a clean design approach.

Step 2: Create the main Java Class
We will now write the main Java class which will be responsible for generating the web script. This class must be inherited from org.alfresco.web.scripts.DeclarativeWebScript class and must implement executeImpl method.

Here is a sample class code

package com.infoaxon.repository;

import java.util.HashMap;
import java.util.Map;
import java.net.InetAddress;

import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptStatus;
import org.apache.log4j.Logger;

public class myfirstscript extends org.alfresco.web.scripts.DeclarativeWebScript {

Logger logger = Logger.getLogger(myfirstscript.class);

@Override
protected Map executeImpl(WebScriptRequest req, WebScriptStatus status) {
Map model = new HashMap();
String txt = "";
try {
txt = "Hello, Well Done!!! You seems to be got it, this is coming from Java!!!";
} catch (Exception e) {}

model.put("servertext", txt);
return model;
}
}


This class will simply return a hashtable with only one key named servertext. The web script Freemarker template than would take this variable, and would display.

Now to compile this one (assuming the file name is myfirstscript.java):
javac -cp C:\mystackroot\webapps\alfresco\WEB-INF\lib\alfresco-repository.jar;C:\mystackroot\webapps\alfresco\WEB-INF\lib\alfresco-web-client.jar;C:\mystackroot\webapps\alfresco\WEB-INF\lib\log4j.jar myfirstscript.java

This would create myfirstscript.class


Step 3: Package the Class
Now we will package the class, i.e. create jar of this.
For that, go to the root folder (mind that, we are in <<root>>\com\infoaxon\repository folder, and we have create our class and Java files there only). To create the jar:
jar -cvf <<jar-name>> <<root-package-name>>

For example in our case, jar -cvf myfirstscript.jar com
This should create the jar file with root namespace (package) as com.


Step 4: Deploy the Jar
As you know, to define a web script, we need to have:
  1. A description xml file, in our case the name would be myfirstscript.get.desc.xml
  2. An FTL file generating HTML code, in our case the name would be myfirstscript.get.html.ftl
  3. Optionally, a JS file, in our case the name would be myfirstscript.get.js
These files need to be created in C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder hierarchy.
  1. Create subfolder hierarchy com\infoaxon\repository under C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder.
  2. Under the repository folder, create the following three files:


myfirstscript.get.desc.xml
<webscript>
<shortname>My First Java based Web Script</shortname>
<description> My First Java based Web Script</description>
<url>/infoaxon/repository/myfirstscript</url>
<authentication>none</authentication>
</webscript>


myfirstscript.get.html.ftl
<html>
<body>
<p>${servertext}</p>
<p>${jstext}</p>
</body>
</html>


myfirstscript.get.js
model.jstext = "Hello, what do you think, this is coming from JavaScript!!!";


Step 6: Define a Alfresco Module that binds and deploys the Web Script
Now we need to create an alfresco module that binds the web script.

Alfresco modules are defined and deployed in C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\module folder. We need to register our web script as module in this folder only, so that next time when the server boots, it reads this module and deploys in Alfresco.
  • Create a folder here with name as you think properly represents your module. In our example, we create the folder named myfirstscriptmodule. Note: there is no restriction in module name; in other words, there is no binding in web script name, package name and module name. So you are free to use anything as your module name.
  • Under the myfirstscriptmodule folder, we need to create at least two files (by these names only):
module.properties:
This file renders the details of the module. A typical module.properties file looks like:

#Mon Jul 21 18:34:18 IST 2008
module.version=1.0
module.description=My First Web Script
module.id=myfirstscript
module.repo.version.max=999
module.title=My First Web Script
module.repo.version.min=2.1
module.installState=INSTALLED
module.installDate=2008-07-21T18\:33\:45.875+05\:30


module-context.xml:
This file registers the web script implementation Java class files as beans.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
<bean id="webscript.com.infoaxon.repository.myfirstscript.get" class="com.infoaxon.repository.myfirstscript" parent="webscript">
</bean>
</beans>


There are a few important things to be noted in this file:
  1. The bean id naming convention is strict:
  2. It must start with keyword webscript, thus Alfresco comes to know that this bean is a web script implementation bean
  3. The further name parts should match the web script package and web script name
  4. The class name should exactly match with the name of the web script along with its package
  5. The parent should always be webscript, since the implementation class is a web script.

Step 7: Start Server: Test your Web Script
That’s it, is everything goes fine, you have just created your first Java based custom web script.
  • Start tomcat server
  • In your favourite browser, navigate to http://localhost:8080/alfresco/service/index. Find your web script and test whether it is working.

In the next installment of this tutorial, we will discuss about how we can deploy the web script as a JSR-168 portlet in Liferay.

Happy Scripting!!!

Friday, January 9, 2009

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets - Part 2

Creating a Web Script using JavaScript API

Step 1: Define the Web Script
As you know, to define a web script, we need to have:
  1. A description xml file, in our case the name would be helloworld.get.desc.xml
  2. An FTL file generating HTML code, in our case the name would be helloworld.get.html.ftl
  3. A JS file, in our case the name would be helloworld.get.js. Note that, this JS is technically not mandatory; however, in practical situation you cannot live without this, because this is only place where you write the business logic of your web script, and return some data.
These files need to be created in C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder hierarchy.
  • Create subfolder hierarchy com\infoaxon\repository under C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder.
  • Note that, maintaining this folder hierarchy is not mandatory; this is just because of good practice to group your web scripts. Technically as per alfresco, it will pick up all items which are defined as web scripts under the templates\webscripts\ folder.
  • Under the repository folder, create the following three files:


helloworld.get.desc.xml
<webscript>
<shortname>helloworld</shortname>
<description>helloworld</description>
<url>/infoaxon/helloworld</url>
</webscript>

helloworld.get.html.ftl
<html>
<body>
<p>Wow, this is quite ${jstext}, rather.</p>
</body>
</html>

helloworld.get.js
model.jstext = "Simple";

Step 2: Start Server, Test your Web Script
That’s it, that’s really it, you have just created your first JavaScript based custom web script.
  • Start tomcat server
  • In your favourite browser, navigate to http://localhost:8080/alfresco/service/index. Find your web script and test whether it is working, but just clicking on it.
  • Since, you have created a HTTP GET Web Script, you can invoke and test the service by typing URL in your browser http://localhost:8080/alfresco/service/infoaxon/helloworld. Note that, this is the URL which you have defined in your configuration XML file.
In the next installment of this tutorial, we will discuss about how we can create a simple helloworld web script using java.