Difference between revisions of "GCube Portlets Deploying on Liferay"
(Created page with 'GCube Portlets Deploying on Liferay') |
|||
(30 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | [[Category:TO BE REMOVED]] | |
+ | |||
+ | == Gcube Portlets to Liferay == | ||
+ | |||
+ | Porting and deploying the existing gCube portlets to Liferay portal is an easy task. The deployment of a portlet to Liferay requires an existing installation of the Liferay portal bundled with the Apache Tomcat server (For more information on how to install and configure Liferay portal visit: [[https://gcube.wiki.gcube-system.org/gcube/index.php?title=New_D4Science_Portal_Installation&action=edit&redlink=1 D4Science Portal Installation]] ).<br> | ||
+ | The required changes are focused on the configuration files that Liferay requires and on the way the logged in user's information are retrieved. After setting up these information then the portlet can be compiled and deployed on liferay. | ||
+ | |||
+ | == Create a new Liferay Portlet == | ||
+ | |||
+ | * Go to <b>$LIFERAY_HOME/liferay-plugins-sdk/</b> directory | ||
+ | * If the <b>create.sh</b> script file (located in the current directory) is not executable, change its permissions | ||
+ | * Execute <b>./create.sh</b> "<b>portlet-id</b>" "<b>portlet-name</b>" | ||
+ | * A new directory with name <b>portlet-name</b>-portlet is created at the <b>$LIFERAY_HOME/liferay-plugins-sdk/portlets</b> directory | ||
+ | <br> | ||
+ | |||
+ | == Liferay portlet hierarchical organization == | ||
+ | The hierarchical organization of a liferay portlet is the following: | ||
+ | * <b>portlet-name-portlet</b> | ||
+ | ** docroot | ||
+ | *** css | ||
+ | *** js | ||
+ | *** WEB-INF | ||
+ | **** classes | ||
+ | **** lib | ||
+ | **** src | ||
+ | **** tld | ||
+ | **** liferay-display.xml | ||
+ | **** liferay-plugin-package.properties | ||
+ | **** liferay-portlet.xml | ||
+ | **** portlet.xml | ||
+ | **** web.xml | ||
+ | *** icon.png | ||
+ | *** view.jsp | ||
+ | ** build.xml | ||
+ | |||
+ | The source code of the portlet should be copied inside the <b>src</b> directory. | ||
+ | |||
+ | == Modify the configuration files == | ||
+ | * <b>liferay-portlet.xml</b> | ||
+ | The elements that should be placed in that file must follow the exact order | ||
+ | <portlet> | ||
+ | <portlet-name>”portletName”</portlet-name> | ||
+ | <icon>/icon.png</icon> <b>//optional</b> | ||
+ | <layout-cacheable>false</layout-cacheable> <b>//for loading the new portlet</b> | ||
+ | <instanceable>false</instanceable> <b>//to use one portlet instance for the D4S portal</b> | ||
+ | <ajaxable>false</ajaxable> <b>//it is need for the correct rendering of the GWT portlet</b> | ||
+ | <header-portlet-css>/css/test.css</header-portlet-css> | ||
+ | </portlet> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | * <b>liferay-display.xml</b> | ||
+ | The element 'category' is recommended to use the name "gCube Applications" | ||
+ | |||
+ | <display> | ||
+ | <category name="<b>gCube Applications</b>"> | ||
+ | <portlet id="'portlet-id'" /> | ||
+ | </category> | ||
+ | </display> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | * <b>portlet.xml</b> | ||
+ | |||
+ | <portlet-class><b>add you portlet class here</b></portlet-class> | ||
+ | ... | ||
+ | <security-role-ref> | ||
+ | <role-name>administrator</role-name> | ||
+ | </security-role-ref> | ||
+ | ... | ||
+ | |||
+ | The root directory is considered the docroot directory | ||
+ | |||
+ | * <b>web.xml</b> | ||
+ | |||
+ | The web.xml of the existing portlets can be used at the liferay portlet. Remove any references to gridshere servlet mappings. | ||
+ | |||
+ | == How to get the logged in user's information == | ||
+ | The users that are logged in to the portal have certain information registered that can be retrieved using the Liferay's API. | ||
+ | |||
+ | <source lang="java5"> | ||
+ | long userid = Long.parseLong(request.getRemoteUser()); | ||
+ | |||
+ | User user = null; | ||
+ | try { | ||
+ | user = UserLocalServiceUtil.getUser(userid); | ||
+ | } catch (PortalException e) { | ||
+ | } catch (SystemException e) { | ||
+ | |||
+ | String username = user.getScreenName(); //Gets the username | ||
+ | String fullName = user.getFullName(); //Gets the fullname | ||
+ | String email = user.getEmailAddress(); //Gets the email address | ||
+ | </source> | ||
+ | |||
+ | The needed imports are: | ||
+ | |||
+ | <source lang="java5"> | ||
+ | import com.liferay.portal.model.User; | ||
+ | |||
+ | import com.liferay.portal.service.UserLocalServiceUtil; | ||
+ | |||
+ | import com.liferay.portal.service.UserService; | ||
+ | |||
+ | import com.liferay.portal.service.UserServiceUtil; | ||
+ | |||
+ | import com.liferay.portal.PortalException; | ||
+ | import com.liferay.portal.SystemException; | ||
+ | </source> | ||
+ | |||
+ | The jars that are needed can be found at $CATALINA_HOME/common/lib/ext and are the following: | ||
+ | * portal-kernel.jar | ||
+ | * portal-service.jar | ||
+ | |||
+ | == Compiling & Deploying a portlet to Liferay == | ||
+ | |||
+ | In order to compile your portlet go to portlet's directory and execute: <b>ant compile</b> <br> | ||
+ | If the compilation succeeded you can deploy the portlet to Liferay by executing: <b>ant deploy</b> <br> | ||
+ | |||
+ | Liferay supports hot deployment for portlets so if the deploy is successful then no restart is needed. |
Latest revision as of 18:13, 6 July 2016
Contents
Gcube Portlets to Liferay
Porting and deploying the existing gCube portlets to Liferay portal is an easy task. The deployment of a portlet to Liferay requires an existing installation of the Liferay portal bundled with the Apache Tomcat server (For more information on how to install and configure Liferay portal visit: [D4Science Portal Installation] ).
The required changes are focused on the configuration files that Liferay requires and on the way the logged in user's information are retrieved. After setting up these information then the portlet can be compiled and deployed on liferay.
Create a new Liferay Portlet
- Go to $LIFERAY_HOME/liferay-plugins-sdk/ directory
- If the create.sh script file (located in the current directory) is not executable, change its permissions
- Execute ./create.sh "portlet-id" "portlet-name"
- A new directory with name portlet-name-portlet is created at the $LIFERAY_HOME/liferay-plugins-sdk/portlets directory
Liferay portlet hierarchical organization
The hierarchical organization of a liferay portlet is the following:
- portlet-name-portlet
- docroot
- css
- js
- WEB-INF
- classes
- lib
- src
- tld
- liferay-display.xml
- liferay-plugin-package.properties
- liferay-portlet.xml
- portlet.xml
- web.xml
- icon.png
- view.jsp
- build.xml
- docroot
The source code of the portlet should be copied inside the src directory.
Modify the configuration files
- liferay-portlet.xml
The elements that should be placed in that file must follow the exact order
<portlet> <portlet-name>”portletName”</portlet-name> <icon>/icon.png</icon> //optional <layout-cacheable>false</layout-cacheable> //for loading the new portlet <instanceable>false</instanceable> //to use one portlet instance for the D4S portal <ajaxable>false</ajaxable> //it is need for the correct rendering of the GWT portlet <header-portlet-css>/css/test.css</header-portlet-css> </portlet>
- liferay-display.xml
The element 'category' is recommended to use the name "gCube Applications"
<display> <category name="gCube Applications"> <portlet id="'portlet-id'" /> </category> </display>
- portlet.xml
<portlet-class>add you portlet class here</portlet-class> ... <security-role-ref> <role-name>administrator</role-name> </security-role-ref> ...
The root directory is considered the docroot directory
- web.xml
The web.xml of the existing portlets can be used at the liferay portlet. Remove any references to gridshere servlet mappings.
How to get the logged in user's information
The users that are logged in to the portal have certain information registered that can be retrieved using the Liferay's API.
long userid = Long.parseLong(request.getRemoteUser()); User user = null; try { user = UserLocalServiceUtil.getUser(userid); } catch (PortalException e) { } catch (SystemException e) { String username = user.getScreenName(); //Gets the username String fullName = user.getFullName(); //Gets the fullname String email = user.getEmailAddress(); //Gets the email address
The needed imports are:
import com.liferay.portal.model.User; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserService; import com.liferay.portal.service.UserServiceUtil; import com.liferay.portal.PortalException; import com.liferay.portal.SystemException;
The jars that are needed can be found at $CATALINA_HOME/common/lib/ext and are the following:
- portal-kernel.jar
- portal-service.jar
Compiling & Deploying a portlet to Liferay
In order to compile your portlet go to portlet's directory and execute: ant compile
If the compilation succeeded you can deploy the portlet to Liferay by executing: ant deploy
Liferay supports hot deployment for portlets so if the deploy is successful then no restart is needed.