Showing posts with label LifeRay. Show all posts
Showing posts with label LifeRay. Show all posts

Sunday, October 16, 2011

How to Implement a Simple Workflow


In this example I create two user acontent creator who will create content and a content publisher who willpublish the content.

sendrequest

backto creator for modification
ProcessDefinitions
Each workflow definitions isdefined by a single XML file.The XML file has several parts which define theworkflow. The key parts of the workflow definition are the asset, states,transitions, and tasks. The asset is whatever piece of content is being reviewedand approved in the workflow. States represent stages of the workflow; forexample: created, rejected, or approved. Transitions occur between states, andindicate what the next state should be. Tasks are steps in the workflow thatrequire user action.
Enhancing the portlet
This portlet is of coursevery basic and it could easily be enhanced in several
ways. Some suggestions:
_ Submit toa condor pool or Sun Grid Engine.
_ Let theuser choose which computational resource to submit to.
_ Add persistence by saving state to _le or database.

Liferay Workflow System

Liferay Portal is one of the leadingopen source portal frameworks.Liferay have the following features
                       Runson all major application servers and Servlet containers, databases, andoperating systems, and over 700 deployment combinations.
                       Usesthe latest in Java, J2EE, and Web 2.0 technologies.
                       Usesan open SOA framework.
                       JSR-168/JSR-286compliant.
                       Outof the box usability over 60 portlets.
                       AJAX-enableduser interface.
                       FullLDAP synchronization and secure Single Sign On (SSO) support.

Liferay portal includes adefault workflow engined called Kaleo. Kaleo workflow allows todefine any number of simple to complex business processes/workflows bydefining everything inside a single XML file.Liferay 6 also provide integrationmechanism with the JBPM workflow engine. The workflow is applied out-of-the-boxto the following Liferay entities:
1.     WikiPage
2.     WebContent
3.     DocumentLibrary Document
4.     BlogsEntry
5.     Comments
6.     MessageBoards Message

There are four portlets related to the workflow that allows theusers to manage this system.
                       My Submissions
                       My Workflow Tasks
                       Workflow Configuration
WorkflowPortlet.

What is a WorkFlow

A workflow can be defined as a business process in whichinformation can be passed from one participant to another for action accordingto a set of procedural rules. The workflow consist of a series of steps andeach steps contains tasks where the participant can perform different activiteslike review, approve, reject, or update an assignement.

Automated workflow is important insidean organization because it ensures maximum throughput and accuracy whendistributing work or tasks. It improves the control of a process with lessmanual intervention, eliminating misplaced work, reducing delays, and ensuringtasks are performed according to your company’s policies and procedures.Workflows automate the flow of employee tasks and activities, reducing the timethe process took to complete as well as potential errors caused by humaninteraction.

Recommended Tools For Liferay


The following instructions willhelp you get your development environment ready for working with the

source code. These instructionsare specific to setting up for deployment to Orion server and Tomcat 5.5

developing with Java JDK 1.5.Liferay Portal is compatible with Java 1.4 also and a wide array of

application servers andcontainers. You will need to adjust your development environment according to

your platform.

Before we can get started, thefollowing components must be installed on your machine.

3.1. JDK 1.5.0or JDK 1.4.2

1. Download and install JDK 1.5.0[http://java.sun.com/j2se/1.5.0/download.jsp]. JDK 1.4 is also

supported.

2. Set an environment variablecalled JAVA_HOME to point to your JDK directory.

3.2. Jikes 1.22or Jikes 1.21

Jikes is a Java compiler by IBMthat is much faster than the original one provided by the JDK.

1. Download and unzip Jikes 1.22[http://www-124.ibm.com/developerworks/oss/jikes]. If using JDK

1.4 you have to use Jikes 1.21instead.

2. Set an environment variablecalled JIKES_HOME to point to your Jikes directory.

3. Add JIKES_HOME\bintoyour PATH environment variable.

3.3. Ant 1.6.5

1. Download and unzip the latestversion of Ant [http://ant.apache.org/].

2. Set an environment variablecalled ANT_HOME to point to your Ant directory.

3. Add ANT_HOME\bin to your PATHenvironment variable.

3.4. Subversionor a Similar Version Control System

We recommend that you put allyour code and configuration files into a version control system.

Subversion is free and opensource and can be used through a set of commands, by installing a

subversion client such asSmartSVN [http://www.smartsvn.com/], TortoiseSVN [http://tortoisesvn.net/]

or through the integrationmechanisms provided by most IDEs.

Difference Between Portlet Development vs Servlet Development


Developing a Java Portlet issimilar to the process of developing a Servlet based web applications. The

main differences are:

• The portlet only produces afragment of the final HTML and not the full markup. The portal will join

the fragments of several portletsand will create the full page returned to the user.

• The class receiving therequests has to inherit from javax.portlet.Portlet instead of

javax.servlet.http.HttpServlet.

• A portlet request may involve atwo phase process:

1. On each request at most oneportlet will be able to perform an state-changing operation. This is

referred to as the Action phaseand is implemented through a method called processAction.

Not always an action phase isneeded. Requests that involved an action phase are invoked to an

URL known as an ActionURL, whilethose that only have a render phase are invoked through a

RenderURL.

2. Next is the render phase whereall other portlets related to the page that is going to be returned may

be called in any order to producethe HTML fragment to draw themselves. Portlet implement this

functionality through a methodcalled render.

• Existing web applicationdevelopment frameworks such as Struts, JSF, Webworks, etc can be used

through the use of Bridges. Otherexisting frameworks have been adapted to be usable directly

without the need of a bridge. Anexample is the Spring Portlet MVC framework.

A portlet container is a serverside software component that is capable of running portlets. A portal is a

web application that includes aportlet container and may offer additional services to the user. Liferay

Portal includes its own portletcontainer and offers lots of functionalities such as user and organization

administration, creation ofvirtual communities, having pages based on portlet layouts, graphical

selection of portlets anddrag&drop to place them, grouping pages into websites, several bundled

ready-to-use portlets, and much more.

How to Defining a new theme


Before digging into these folders, the next step is to registerthe theme in Liferay. Edit the file

liferay-look-and-feel.xmlpresent in the WEB-INF directory and add the followingXML

fragment:

<theme id="my-theme" name="My theme">

<root-path>/html/themes/my-theme</root-path>

<templates-path>/html/themes/my-theme/templates</templates-path>

<images-path>/html/themes/my-theme/images</images-path>

<template-extension >jsp</template-extension>

<settings>

<setting key="my-setting" value="example-value"/>

</settings>

<color-scheme id="gen-color" name="DarkBlue">

<![CDATA[

-- Content omitted for clarity --

]]>

</color-scheme>

</theme>

The root-path element must point to the root theme folder. Theelements templates-path

contains the path to the JSP templates, and images-path pointsto the subfolder that contains the

images for this theme. Note that you can choose any subdirectoryname you want or point to

subdirectories in other directories. However, it is recommendedthat you keep the default

convention unless you have a good reason to change it.

The template-extension element specifies the language in which thetemplates of the theme are

written. JSPs and velocity (specifying vm as the template extension) aresupported. Liferay

comes with examples of both. In this article we will assume JSPtemplates, but they are very

_

Page 5 of 11 Created by Jorge Ferrer

similar.

Finally the settings element and its inner setting sub elementsallow you to specify any number

of custom settings of the theme (note that this is optional). Thesesettings can be retrieved from

the templates of the theme by calling the getSetting() method ofthe current theme object. For

example using JSP scripting:

<% String value =themeDisplay.getTheme()getSetting(“my-setting”); %>

Each theme must also have at least one color-scheme which controlsthe colors of the theme.

The color scheme is defined using the color-scheme element in the liferay-look-and-feel.xml.

By specifying several color schemes, it is possible to have onesingle theme with more than one

combination of colors. An example of a combination of colors forthe previous theme would be:

<color-scheme id="gen-color" name="DarkBlue">

<![CDATA[

body-bg=#666666

layout-bg=#666666

layout-text=#FFFFFF

layout-tab-bg=#666666

layout-tab-text=#FFFFFF

layout-tab-selected-bg=#666666

layout-tab-selected-text=#FFFFFF

portlet-title-bg=#666666

portlet-title-text=#FFFFFF

portlet-menu-bg=#666666

portlet-menu-text=#FFFFFF

portlet-bg=#666666

portlet-font=#FFFFFF

portlet-font-dim=#FFFFFF

portlet-msg-status=#FFFFFF

portlet-msg-info=#FFFFFF

portlet-msg-error=#FFFFFF

portlet-msg-alert=#FFFFFF

portlet-msg-success=#FFFFFF

portlet-section-header=#FFFFFF

portlet-section-header-bg=#666666

portlet-section-subheader=#FFFFFF

portlet-section-subheader-bg=#666666

portlet-section-body=#FFFFFF

portlet-section-body-bg=#666666

portlet-section-body-hover=#000000

portlet-section-body-hover-bg=#F4F4F4

portlet-section-alternate=#FFFFFF

portlet-section-alternate-bg=#333333

portlet-section-alternate-hover=#000000

portlet-section-alternate-hover-bg=#F4F4F4

_

Page 6 of 11 Created by Jorge Ferrer

portlet-section-selected=#FFFFFF

portlet-section-selected-bg=#666666

portlet-section-selected-hover=#FFFFFF

portlet-section-selected-hover-bg=#666666

]]>

</color-scheme>

The values of these colors will be used by a file called css.jsp.

Liferay acknowledges that the format of a theme may need to changein the future and provides

a mechanism to prevent errors should that happen. You can specifyfor which versions of

Liferay your theme is designed for:

<look-and-feel>

<compatibility>

<version>3.5.0</version>

<version>3.5.1</version>

</compatibility>

...

After covering how to define a new theme we are ready to explaineach of its components in

moredetail.

What is portlet Content and Portlet Template

Portlet Content: theinternal area that shows the meatof the portal.
 Portlet Template:the external area and can be customized for each theme.

Liferay Interview Question and Answers

what can you do with a theme?
A theme can control the whole look and feelof the pages generated by Liferay. The portal-side

of the page can be completely customized.Even the appearance of the portlets that come with

Liferay can be customized using CSS, images, JavaScripts, and specialtemplates.

Saturday, October 15, 2011

How to install Liferay

First download the community version with tomcat server from the liferay website
or Click Here

Unzip the contents to a suitable location.

Open the bin directory



And click on the startup.bat file to start and shutdown.bat file to shutdown.




To change the server standard time.

Open the setenv.bat in an editor and change the –Duser.timezone

-Duser.timezone=Asia/Calcutta

Restart the Server .




For Database Settings

log into the MySql command line editor. 

mysql> create database `lportal` CHARACTER SET utf8 COLLATE utf8_general_ci;

 create a portal-ext.properties file in \liferay-portal-6.0.6 

Add the following Lines to connect to MySql Database. 

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

save and restart.

Check installation success in MySql 

mysql>use lportal ;
mysql>show tables ; A total of 185 rows indicating 185 tables must be shown.  

There is another way  to connect Tomcat to the database. Here is how it is done. Assuming that lportal schema is available in MySQL.

goto this path ${TOMCAT_HOME}\conf\Catalina\localhost
Open the root.xml and add the following lines in it.

<Context path="" crossContext="true">

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

while configuring your database do make sure the corresponding jar file of the database is present in the lib directory of tomcat. Liferay Bundled wit tomcat has mysql.jar in it by default in the lib/ext folder.
More Liferay 6.0.5 Properties.

Now ,some fine tuning must be done if you are going to start development in liferay , so that everything runs faster and smoother , without much of ui customization.

Here is what you've got to do.

Open setenv.bat again , and add the following lines to it

-Dexternal-properties=portal-developer.properties

Thats it, You are done and now you can start development on Liferay !!!

Liferay UI Tabs

Creating Tabs is a really Cool feature and Liferay has an inbuilt functionality to do so.
Here is how it can be done.
1) In your Project , first create the following files under the following path
/docroot/jsps by creating a new folder called jsps
view.jsp
sunday.jsp
monday.jsp
tuesday.jsp
admin.jsp

code for view.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<liferay-theme:defineObjects />
 
//A renderURL is created because we need to render a jsp page you need to use //renderURL we can also  pass parameters if required
 
<liferay-portlet:renderURL var="portletURL"/>
 
<%
//We must Specify a default value for tabs. In this example it is sunday. Else it //will throw an error.
String tabValue = ParamUtil.getString(request, "tab", "sunday");
String tabsURL = "/jsps/" + tabValue.trim() + ".jsp";
String tabNames="Sunday,Monday,Tuesday" ;
String tabVal="sunday,monday,tuesday" ;
if(permissionChecker.isCompanyAdmin(themeDisplay.getCompanyId())){
tabNames+=",Admin" ;
tabVal+=",admin" ;
}
%>
 
<liferay-ui:tabs
names="<%=tabNames%>"
tabsValues="<%=tabVal%>"
param="tab"
url="<%= portletURL %>"
/>
 
//this wud render the tab page
<c:import url="<%= tabsURL %>"></c:import>

Here is how it would Look Like


The Admin Page Will be Visible only if an Admin Logs in.



To Download the Project click here

Friday, October 14, 2011

Theme and layout in liferay

Create Theme and layout in one war.

1)Create a folder under plugins\themes\your-theme\docroot (e.g layout).
2)Add all the files Under your folder (e.g layout).
a.your_layout.tpl
b.your_layout.wap.tpl
c.your_layout.png
3)Add the files of your theme directly under the docroot/WEB-INF.
a.liferay-layout-templates.xml
4)Edit the file liferay-look-and-feel.xml present in the WEB-INF directory and add the following XML fragment.
<layout-templates>
<custom>
<layout-template id=" your_layout_Id" name=" your_layout_name">
<template-path>/layout/ your_layout.tpl</template-path>
<wap-template-path>/layout/your_layout.wap.tpl</wap-template-path>
<thumbnail-path>/layout/your_layout.png</thumbnail-path>
</layout-template>
</custom>
</layout-templates>
5)Then ant deploy from your theme level.

How to Add portlets in Liferay theme Level

For Adding portlet in theme level., If we add portlet in theme it will display once our theme as selected. Here we are taking sign_in portlet.

Step1: Create your own theme and add portal_normal.vm file under /docroot/_diff/templates/portal_normal.vm.

Step2: Paste this code in header tag:

#set ($globCounterOfThemeDynamicPortletId = 1000)
#set ($locPortletId = "58_INSTANCE_" + $globCounterOfThemeDynamicPortletId)
#set ($globCounterOfThemeDynamicPortletId = $globCounterOfThemeDynamicPortletId + 1)
$theme.runtime($locPortletId, "", $velocityPortletPreferences.toString())
(Note: change your portlet Id in this line here we are taking 58 for login portlet., See all Liferay default Portlet Click Here #set ($locPortletId = "58_INSTANCE_" + $globCounterOfThemeDynamicPortletId) )


Step3: Wirte Css for your portlet in Custom.css file under /docroot/_diff/css/custom.css.

Adding Google Translator in a Liferay portal

People always prefer their native language for their convence. To browse a website with a feature of tranlsation is what most of them would like. Liferay provides a feature where in we can have our portal in different languages. This is achieved using  Language-ext.properties file.

But there are few drawbacks in using the above.
The  drawbacks are :
1.This requires a customisation in all the Language_xx.properties file. (For eg. If we want 30 languages option then 30 Language_xx.properties files need to be customised).

2.Even after doing so the entire portal is not changed to the language selected,only the variables mentioned in the  Language_xx.properties file are changed and anything from database is not changed.

So here is the convenient solution of having your portal in different languages by integrating the Google's API in two simple steps

Step1:

Copy and paste the below snippet code in the "portal_normal.vm"
file
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.
translate.TranslateElement({
pageLanguage: 'en',
layout: google.
translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script>
<script src="//
translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Step 2:
We can further change the position of the translate tab. To change the display mode in Horizontal, change the layout to
  layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
For Bottom-right Position:    floatPosition: google.translate.TranslateElement.FloatPosition.BOTTOM_RIGHT
For Bottom-left Position:    floatPosition: google.translate.TranslateElement.FloatPosition.BOTTOM_LEFT

and so on..

To use the the Google's translator only in the selected sections of a website, we can use the below code

<script>
          function googleSectionalElementInit() {
new google.translate.SectionalElement({
sectionalNodeClassName: 'goog-trans-section',
controlNodeClassName: 'goog-trans-control',
background: '#99ff99'
}, 'google_sectional_element');
}
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleSectionalElementInit&ug=section&hl=auto"></script>

Add an element with a class name “goog-trans-section”  and a child element with class name “goog-trans-control”. On clicking the parent element, the contents within the child element will be translated.

Note: We can further customise the look and feel of the Google translator toolbar by strictly maintaining the Google trademark and logos.

The following are the merits and demerits of Liferay's translation and other translation APIs (eg. Google Translator)

Liferay's Translation

 Merits  1.Its looks professional
 2.Performance will not be affected.
 3.Translation of the content will be controlled by ourselves.

Demerits

 1.It will not translate Dynamic contents
 2.Static contents need to be mentioned in properties files manually
 3.The number of properties file increases as a number of language increases
 4.For CMS (i.e Web content and page navigations) we need to create articles in the                
respective languages seperately


Google and others Translation tools :

 Merits  1.No need of any properties file changes
 2.Dynamic content as well as static content will be translated in the respective languages
 3.For Web content and page navigations need not create articles in different languages
 4.Imlementation is easy.

De Merits
 1.Performance issue.
 2.The translation control is handled by third party
 3.We need to adhere to the terms & condition of the third party
 4.We don't have control over any issues that are caused by the third party applications .

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Wallpapers collections