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