Friday, December 31, 2010

Velocity Templating and its application in liferay

Velocity is my favorite template language which enables me to get the static pages up in no time with rich content(thanks to the document and image library).
I would like to share some of its fantastic capabilities.
Web content in Liferay is controlled by template scrip file,Velocity can be used for simple transformations in web content/journal portlets which detrmines how the content will be displayed on the page.Velocity can also be utlilized for making custom changes in vm files of Liferay themes.
GUI requirements determine the degree of customization required in VM templates. I have observed cases where a lot of coding effort can be reduced if velocity is used in optimally.

In liferay portal services can also be used with help of velocity in Liferay themes(VM templates)or templates of Articles (web content portlet).
Lifeay provides service locator to use the services with velocity.
TO enable access of services in liferay make following changes in portal-ext.properties
# Input a comma delimited list of variables which are restricted from the
# context in Velocity based Journal templates.
#
journal.template.velocity.restricted.variables=serviceLocator
remove serviceLocator in property it will now look as
journal.template.velocity.restricted.variables=


example --- (a complete example is available in my earlier post named quick tips)
#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($roleLocalService = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))

----------------------------------------------------------
Objects that can be used OOB in VM files
$user, $company, $layout, and $themeDisplay
example ---> $user.getFirstName()

themeDisplay,company,user,realUser,layout,layouts,plid,layoutTypePortlet,scopeGroupId,permissionChecker,locale,timeZone,theme,colorScheme,portletDisplay,

other variable you can from VelocityVariables.java class from source code
com.liferay.portal.velocity.VelocityVariables

Check null -- #if ($validator.isNotNull($variable))

Example
Now if you have a page which displays news article for a person with his name and a custom welcome message you can get his name in through web content portlet , template along with his name which can be dropped at top of page so no need to write a java portlet just use velocity
< b > Welcome to news page< /b >
$user.getFirstName()
< tags> news begins

Velocity references
Official documentation
Advanced concepts
Quick Learning
My Favourite reference link

Tuesday, October 26, 2010

Hardware Requirements and few examples of possible combinations

There have been many post in Liferay forum around Hardware Requirements
I will share few successful implementation I am aware of and minimum requirements for server and developer sandboxes.
I will update this post every time I come across new config so watch out this space for newer Hardware configs :)

The best resources for server sizing and hardware requirements are Liferay whitepaper, choose the one which is relevant to your version
LPEE 6.2 Deployment Checklist
Liferay Portal 6.2 Performance Whitepaper
https://www.liferay.com/documentation/additional-resources/whitepapers

There can be unlimited combination so please leave your requirements and I will try to device optimal hardware requirements for you as per my learning's :D

General thumb rule before finalizing the architecture and server sizing / hardware configuration is

1. Gather requirements for
a. Total number of users
b. Concurrent users  & maximum logged in users expected at one time
c. Operation expected WCM scenario, Content reading, content access, transaction / login, search etc
d. High availability required
e. Clustering required (Need to request for a cluster key)

Based on the inputs you can reach a rough sizing estimate using the performance whitepaper

make sure when you are taking vCPU into consideration use 2 vCPU = 1 physical core.

Again hardware will also depend on the application being built on top of Liferay so if its a page with login and WCM etc it will handle smaller number of user than plain text age and you need to prorate and adjust the users based on the application and OOB components used from Liferay.

Make sure in a HA architecture the nodes / cluster node are in same network / DC

Liferay portal 6.2

 Production Box
RAM --Min : 16 GB , Good to have 32 - 64 GB RAM
Processor - Min 4 CPU (I1 quad core processor) , Good to have 8 CPU ( 2 quad core processor)
example - 2 X Intel core 2 Quad X5677 3.46GHz, 12MB L2 cache

Liferay portal 6.1 and below :
Developer Box
Minimal -- 1 GB RAM , processor with clocks more than 2.X Ghz for example celeron processor will suffice if you provide 2 GB RAM and Processor 2.6GHz
if you are working with LR portal 5.1X below you can use processor with lower clock.

In scenarios where developers have a complete sandbox setup on their local machine my recommendation is at least 2 GB RAM is used with dual core CPU @2.50GHz
(MySQL , eclipse , LR portal , Apache webserver +3rd party integration component

----------
For Testing /UAT / Staging environment
The number of nodes will depend on the load / traffic expected however its good to have Minimum of 2 portal nodes 2 authentication server nodes and a hot standby of DB

Minimal --
Liferay portal 1.5 GB RAM , dual core CPU @2.50GHz or more (per node)
------------
Production Environment
Some possible combination

1>
OS: Redhat Linux
Sever : Dell Power edge
CPU :1 quad core @2.5Ghz or 2 Dual core with no less clock
Ram :4GB

2>
Sever : Dell Power edge or Sunfire in case of Solaris
2X 2.0Ghz
quad core
8GB
Linux
--------------------------
For DB and third party servers

Sever : Dell Power edge or Sunfire in case of Solaris
4X1.6GHz
8Gb
Solaris

Monday, October 25, 2010

Liferay Installation Checklist

I wanted to share a checklist to follow after Liferay installation to minimize portal start up failures

1>Check your JAVA_HOME variable .It`s good to use JRE available in JDK bundle
Check for compatibility of JRE required for portal version being used

2>Check LIFERAY_HOME variable This folder is one folder higher than the location of the application server itself

3>Check database connection setting & verify database JDBC driver .jar

4>Check consistency of Liferay portal bundle and dependency jars .
corrupt or incompletely downloaded jars create issues hard to investigate

4b>Check consistency of The portal-ext.properties File verify changes made as per your environment

5>Check for folder permissions (mostly this issue come in Linux/UNIX or other open source OS)

Troubleshooting
a>If server does not start check for setenv.bat
{tomcat-home}/bin/setenv.bat and point JRE_HOME to folder where you installed Java. You setenv.bat haas following entries :
set "JRE_HOME=C:\Program Files\Java\jre6"
set "JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF8 -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"

b>Check for database availability
c> Cheksum jar /portal library

Thursday, October 21, 2010

Database connection settings

I have seen numerous post around database connection not working or portal server not starting properly due to the database connections not working properly.Many post including mine are available on Liferay forum for resolving the issue however I thought of making a checklist here for database connection settings.

Developer need to keep in mind that settings have been changing for every version in lower version till 5.1X DB setting were done in Root.xml , 5.2.X onwards all the setting entries are made in portal-ext.properties file
lets discuss the different version setting first.

Version 6.X and 5.2X have same config
put JDBC setting in portal-ext.properties
location : \\webapps\ROOT\WEB-INF\classes
< 6.X or 5.X>

copy your JDBC settings from portal.properties ---> ## JDBC section
get file from the downloaded source or tomcat setup or directly from SVN
SVN location : http://svn.liferay.com/repos/public/portal/trunk/portal-impl/src/portal.properties

username is : guest and password is : leave the password field blank

e.g.
# MySQL
#
#jdbc.default.driverClassName=com.mysql.jdbc.Driver
#jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
#jdbc.default.username=
#jdbc.default.password=

Liferay 5.1.X and lower versions

Make JDBC changes in Root.xml
ROOT.xml can be found in tomcat\conf\Catalina\localhost\ROOT.xml

e.g. Sample setting get exact setting from portal.properties file
MySQL

Resource
name="jdbc/LiferayPool"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8"
username=""
password=""
maxActive="20"


Set properties for schema
## Schema
##

#
# Set this to true to automatically create tables and populate with default
# data if the database is empty.
#
schema.run.enabled=true

#
# Set this to to true to populate with the minimal amount of data. Set this
# to false to populate with a larger amount of sample data.
#
schema.run.minimal=true


Checklist:
1> Make sure you have copied your database driver support
e.g. for oracle copy ojdbc14.jar to \\lib\ext

2> Test your DB availability and creation of schema
Schema name should match the schema name mentioned in jdbc.default.url

3>Check that you have correct version of driver support jar and is compatible with your your installation I have seen number of user facing problem due to incompatible version.

4> Check for proper character set settings for your database

Detailed Learning resource official documentation

Thursday, September 9, 2010

Links to official standards

Adding links for most common standards which need to be referred while development
1. CLick on link below for email standards
Email Standards
Example : Sample 1

2. W3C's easy-to-use markup validation service, based on SGML and XML parsers.
http://validator.w3.org/

3. JSR-000286 Portlet Specification 2.0
Final release
JSR 168 final specifications

4. Scripting
ecma-international standards

5. Code Conventions for the Java Programming Language
Conventions

Tuesday, September 7, 2010

Quick Workaround & Temporary fixes

Theme > Change in portlet.vm for requirement to remove portlet title showing text "web content diplay"

Summary : #if( $portlet_title =='Web Content Display')
#else
$theme.iconPortlet() $portlet_title
#end

2>
Change is custom.css to acomdate tab space for 'BiggerNameTab' tab in navigation

Summary:
#navigation ul li.parent-nav-item {
text-align:center;
width:109px;

Wednesday, September 1, 2010

Enable user creation with duplicate email id

To enable user creation with duplicate email -id

If you don't have ant ext environment and still want to add this functionality leave me a note and I will send you steps for creating a separate jar and configurations to make your custom code work for your custom application.

For extension environment -- Write a new class in ext-environment

public class AbhishekUserLocalServiceImpl extends UserLocalServiceImpl
Now override two validate methods and make following changes

1. For method with signature
protected void validate(long userId, String screenName, String emailAddress, String firstName, String lastName, String smsSn)

remove ----> throw new DuplicateUserEmailAddressException();

from
if (userPersistence.fetchByC_EA(
user.getCompanyId(), emailAddress) != null) {

throw new DuplicateUserEmailAddressException();
}


2.
For method with signature

protected void validate(long companyId, long userId, boolean autoPassword, String password1,String password2, boolean autoScreenName, String screenName, String emailAddress, String firstName, String lastName, long[] organizationIds)

remove --->throw new DuplicateUserEmailAddressException();

from

if (Validator.isNotNull(emailAddress)) {
User user = userPersistence.fetchByC_EA(companyId, emailAddress);

if (user != null) {
throw new DuplicateUserEmailAddressException();
}
}

Monday, August 30, 2010

Change existing context 'ROOT' with your chosen context

I have come across many instance in which developers want to change the existing context 'ROOT'

Steps mentioned below is one easy way of doing it , however I have tried this on versions prior to 6.X . I will update post once I do it successfully on ver 6.X

1. Download tomcat bundle

Using the tomcat bundles saves you from making unwanted changes ,if you start fresh portal installation over tomcat and then try to change the 'ROOT' context , you will have to change many files .

2. Change the name of the existing context ROOT

liferay-portal-5.2.3\tomcat-5.5.27\webapps\ROOT
to
liferay-portal-5.2.3\tomcat-5.5.27\webapps\MyChosenContext

MyChosenContext is the context name you want to use

2b . Change the name of config file
\liferay-portal-5.2.3\tomcat-5.5.27\conf\Catalina\localhost\ROOT.xml
to
\liferay-portal-5.2.3\tomcat-5.5.27\conf\Catalina\localhost\MyChosenContext.xml

3. create a new file named portal-ext.properties which will override portal.properties

location -- liferay-portal-5.2.3\tomcat-5.5.27\webapps\ROOT\WEB-INF\classes\portal-ext.properties

3b. Change portal.ctx property or add in case of new installation
portal.ctx=/MyChosenContext

Snipet of property to be added to portal-ext.properties

## Portal Context
##
#
# Set this property if you deploy the portal to another path besides root.
#
portal.ctx=/

Monday, July 19, 2010

Quick Tips

Tips
For using Liferay services in Web Content portlet Previously known as journal content portlet , we use LR services in templates
e.g. #set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))

However at first attempt we encounter null which happens when we forget to update the property in portal-ext.properties.
Use of LR services are restricted by default in templates.
Following property has list of restricted variables
so change property from journal.template.velocity.restricted.variables=serviceLocator
journal.template.velocity.restricted.variables=
Once serviceLocator is available we can invoke the services to achieve desired results.
===================================================
Get httpRequest within the portlet
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(actionReq);

===================================================
CMS Template VM code for finding user and roles

This code has been used by developers time and again I have used some different methods than existing approach to make it simpler.

#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($roleLocalService = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
#set ($user_id = $request.getAttribute("USER_ID"))
#set ($user = $userLocalService.getUserById($user_id))
#set ($role = $roleLocalService.getRole($user.getCompanyId(),"sponsor"))
#set ($hasUserRole = $roleLocalService.hasUserRole($user.getUserId(),$role.getRoleId()))

======================================================

Tuesday, June 22, 2010

Using newly launched Liferay IDE 1.0

IDE is awesome , it rocks .I was able to configure the IDE by following the instructions on IDE release wiki Installation Guide, its easy to configure and if you have the resource downloaded you will be able to start developing portlets in no time.
Follow the getting started tutorial Getting started
Watch demos if you need some help around creating portlets rely on demo videos Portlet development video demo

Feature like auto deployment ,hot sync are very helpful changes are reflected as soon as a change is made in the code , gone are the days when you needed to redeploy manually .GUI based wizard options are available for selecting portlet mode and Liferay portlet mode, choose category for portlets choose file location resource location etc. Truly wonderful.
I haven't encountered any bug yet , I will update the post once I use more features and encounter bugs.

Wednesday, June 16, 2010

Liferay IDE 1.0.0 Released

For all Liferay enthusiast First version of IDE has been release based on Eclipse Galileo SR2.
Click here to get IDE

I will use it today and post some of the capabilities and reviews

Monday, May 24, 2010

Liferay IDE 1.0

I have seen the video demos and the IDE rocks, it has all the features a developer would love to see in first version

The IDE has not been released yet. Once the next release candidate LR portal(6.0RC2) is released, then IDE will be rolled out as it will support version 6.0RC2 onwards

In my next post I will detail the features once IDE is available for general use.

I also plan for a post with detailed usage of OOB(out of the box) portlets and their configuration.

Tuesday, April 27, 2010

Liferay 5.2.3 and solr integration

I thought of writing this blog while I was trying to implement search indexing in clustered environment for liferay 5.2.3. I faced couple of problems and for resolution I had to read on way too many articles and blog to reach out to final implementation, so I though it would be nice to have everything in one place
Solr provides search indexing option for clustered Liferay environment.

version:
solr-web-5.2.0.1.war --solr plugin
Solr 1.4 --- Solr server

Follow the steps provided

1. Installing Solr

1. Solr is a standalone search engine thus it will be installed separately from liferay create a directory named solr which will be called as SOLR_HOME going forward.
2. Copy the content in solr folder from the downloaded solr installation bundle from http://lucene.apache.org/solr
3. Create an environment variable SOLR_HOME which points to the solr installation directory.
4. Once you have created the environment variable, you then can use it in your application server's start up configuration as a parameter to your JVM. This is configured differently per application server, but again, if you are using Tomcat, you would edit catalina.sh or catalina.bat and append the following to the $JAVA_OPTS variable:

-Dsolr.solr.home=$SOLR_HOME

5. Edit solrconfig.xml available at \solr\conf

${solr.data.dir:C:\TomcatA\webapps\example\solr\data}

change directory path for unix , I have given a windows path
This data folder will contain all the index files (try not to delete these index files manually if you don't get proper result after first run, reindex again)

Provide the path to a newly created directory which you want to hold the indexing data, after indexing files will be generated in this folder.


2. Deploy solr war
1. Copy solr.war to deploy folder of liferay from resource packet or download it directly from http://lucene.apache.org/solr


3. Installing the Solr Plug-in

Download plugin link

1. Update the solr-spring.xml file available at \WEB-INF\classes\META-INF

Change server URL e.g. http://{domain}:8181/solr/


2. Copy the update archive file in deploy folder of liferay

2b(IMP). Extract the file schema.xml from the plug-in. This xml file describes how the fields will be indexed to the Solr index and it should be located in the docroot/WEB-INF/conf folder. Copy this file to $SOLR_HOME/conf


3. Go to the Admin Portlet in Liferay 5.1 or Control panel in higher versions. Click the Server tab and then click the Execute button next to Reindex all search indexes. It may take a while, but Liferay will begin sending indexing requests to Solr for execution. When the process is complete, Solr will have a complete search index of your site, and will be running independently of all of your Liferay nodes.

References:

Solr > http://lucene.apache.org/solr

Liferay: Liferay.com

Tip: To check if Solr server is working perfectly hit the following URL after restart
To check if indexing is working fine check the data folder in Solr server new
index files must have formed there.

http://{domain}/{port}/solr/admin

Change Log: Changes have been made in LuceneUtil class for making it compatible to search users in control panel. If you have older version you need to delete a line and add a snippet and repackage you portalutil jar, check out the below mentioned link for changes.

For overcoming the issue in user search in control panel