Wednesday

Tweet My World Portlet

Hello everyone

The joy of creating something is something which cannot be expressed.
The idea of this portlet struck to me because Julio. When I created Google Chartlet, Julio posted the same to Twitter. I thought why not create something which could automate this. The result is Tweet My World Portlet

Features
  • Sets Twitter Status as soon as some new content is added in the available assets
  • Twitter Credentials configurable via control panel
  • Supports Wikis, Blogs and Software Catalog right now
  • Creates small url using Bit.ly internally
  • Set twitter credentials individually for organization, community or per user. For example, you can configure twitter credential for your organization and also you can do the same for your Community. So if there is a blog post in your community public page, twitter status get set for that particular Twitter account, similary if you have configured it for your organization, status would be set for the twitter account that you have configured for organization
How To Use?
  • Usage is pretty simple. Go to the Control Panel.
  • Click Tweet My World under content section.
  • Set your Twitter Credentials.
  • Select the assets for which you want to set the status when content is added.
Example
  • For guest community select Blogs from Tweet My World section. Make sure your twitter credentials are correct.
  • Place a public blog in one of the pages of your Guest community.
  • Add a blog post. 
  • Login to the twitter account you have configured. The  status must appear there.
  • Thats it. You are done.
Note: You wont get any error if you don't fill any of the above or details are partially filled, apart from the fact that, if you do so, the status won't be set.

Improvements
  • Right now the status that is set is in English. I wish i could apply some I18N there.
  • More assets can be identified and added.
  • Right now status is only set when someone has added a blog post or wiki page. It could be modified further if someone edits blog post or for other actions.
Links
SourceForge
Community Download page
JTwitter Page
Bit.ly api
Forum

ScreenShots



Have a nice day!!

------Update------

Gustavo Fernandez has found a problem  with my portlet behind proxy and solution for it. Please check this entry
http://www.zylk.net/web/guest/web-2-0/blog/-/blogs/using-jtweet-portlet-behind-a-proxy-for-twittering-liferay-contents
Thanks Gustavo.

Friday

Google Chartlet - Yipeee!!!! My First Portlet for community

I am very glad to announce that I have created a portlet to display Google Charts. I have named it as Google Chartlet in sourceforge.

I feel so good about it as
  • Its my first portlet that i am creating for community. Glad to give back something to community
  • First time I am using sourceforge.
This portlet is made using charts4j.

This portlet has very limited functionality as of now.

What it has?


User Charts

  • Shows total users, organizations and communities in the system (2D and 3D pie charts)
  • Show number of users in the organization (2D and 3D Pie chart)
  • Number of users registered with system for current year(Bar chart)
Asset Chart
  • Shows distribution of assets in system(2D and 3D pie charts)
Sample Charts
  • These are basically the same charts that are listed in charts4j project page. They are static charts, but show the power of Google charts and Charts4j api.
How to Configure?
  • This portlet basically is an instanceable portlet. So you can create multiple instances of portlet on same page.
  • Configuring is pretty much simple. You will see Configure button as soon as you add the portlet.
  • Clicking on that you are provided with two step process of selecting the type of report and type of chart.
  • Once you have done that you will be shown the chart.
  • You can click on settings if you have configure permission, where you can set the report title, width and height of report.
What next?
  • I want ideas to create new report types.
  • Right now the color of the report is predefined too. It would be nice if that is configurable as well.
  • Your comments to improve are very much welcome.
Download Link

Screenshots


Wednesday

Allow user to delete his own comments for any commentable asset

The Problem

In the assets where user can comment like blog, journal article and the rest, users should have Delete Discussion Permission for that particular asset to delete comment.

You can test this by commenting on a blog entry. Now give that user Delete Discussion permission for Blog.

Now the problem is, if he is given Delete Discussion permission, he is able to delete any users comment.

What I wanted was like user should be able to delete his own comments.

Solution - Hook to the rescue
  • Commenting comes from liferay:ui discussion. So I created a jsp hook for the same.
  • In the jsp hook, recreate this folder structure html/taglib/ui/discussion/page.jsp under your jsps or whatever folder you have configured for the jsp hook
  • We have to modify page.jsp, so edit the same.Find the below line.
    There are two occurances for the same.

  • <c:if test=\"<%= MBDiscussionPermission.contains(permissionChecker, company.getCompanyId(), scopeGroupId, className, classPK, userId, ActionKeys.DELETE_DISCUSSION)
  • Basically this is the condition that allows user to delete a comment.
  • Now here we want to add an additional condition that if the logged in user has created the comment he should be able to delete the comment.
  • So replace the above line with following for both the occurances of above line.

  • <c:if test=\"<%= MBDiscussionPermission.contains(permissionChecker, company.getCompanyId(), scopeGroupId, className, classPK, userId, ActionKeys.DELETE_DISCUSSION) || (themeDisplay.getUserId() == message.getUserId()) %>\">
  • Deploy the hook.Thats it. Now the user should be able to delete his own comments not anyone else's.

Thursday

Implementing SSL in Liferay with Apache Web Server

CheckLists & Pre-requisites

Configuring Apache Web Server with Liferay - http

Apache WebServer Changes

  • Make sure Apache Web server is running. Open your favorite browser and type http://localhost

  • You should be able to see a page which displays "It works"

  • Go to your Apache installation directory and open httpd.conf file under conf directory

  • Uncomment the following lines

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

LoadModule proxy_connect_module modules/mod_proxy_connect.so

LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

LoadModule proxy_http_module modules/mod_proxy_http.so

  • At the very end of the file append the following

ProxyRequests On

ProxyPass / http://localhost:8080/

ProxyPassReverse / http://localhost:8080/

  • Restart Apache Web server

Liferay Changes

  • Open you portal-ext.properties in Liferay

  • Add the following lines

web.server.http.port=80

web.server.https.port=443

  • Restart Liferay.

  • Open your browser and type http://localhost.

  • You should be able to see your liferay homepage.

  • You have configured Liferay to use with Apache web server


Creating Self-signed SSL certificate

Pre-requisites

  • Open the OpenSSL toolkit that you have installed

Generating Private Key

  • The first step is to create your RSA Private Key.

  • This key is a 1024 bit RSA key which is encrypted using Triple-DES and stored in a PEM format so that it is readable as ASCII text.

  • On the toolkit command prompt type the following

genrsa -des3 -out server.key 1024

  • It will create server.key

Generate a CSR(Certificate Signing Request)

  • Once the private key is generated a Certificate Signing Request can be generated.

  • The CSR is then used in one of two ways. Ideally, the CSR will be sent to a Certificate Authority, such as Thawte or Verisign who will verify the identity of the requestor and issue a signed certificate.

  • The second option is to self-sign the CSR, which we will do.

  • During the generation of the CSR, you will be prompted for several pieces of information.

  • The command to generate the CSR is as follows

req -new -key server.key -out server.csr

Remove Passphrase from key

  • Make another copy of server.key and name it as server.key.org

  • Type the following in ssl toolkit command prompt

rsa -in server.key.org -out server.key

Generate a self-signed certificate

  • At this point you will need to generate a self-signed certificate because you either don't plan on having your certificate signed by a CA, or you wish to test your new SSL implementation while the CA is signing your certificate.

  • This temporary certificate will generate an error in the client browser to the effect that the signing certificate authority is unknown and not trusted.

  • To generate a temporary certificate which is good for 365 days, issue the following command

x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

  • You should have server.key, server.csr and server.crt generated at this step


Configuring Apache Web Server with Liferay - https

  • Copy server.key, server.csr and server.crt generated to conf directory of Apache.

  • Open httpd.conf in Apache and uncomment the following lines to enable mod_ssl and configuration file for https

LoadModule ssl_module modules/mod_ssl.so

Include conf/extra/httpd-ssl.conf

  • Restart your Apache web server

  • Open your browser and type https://localhost

  • You should be able to see your liferay main page in https

Configuring login and create account page for https

  • Open your portal-ext.properties and add the following property

company.security.auth.requires.https=true

  • Restart your tomcat

  • Open your browser and type http://localhost

  • Click on sign in or create account page. This should change the protocol to https

  • Enter your credentials and Login to the application. The protocol should change back to http when user is logged in.

Disabling https with apache web server

  • Comment out or remove the following properties in portal-ext.properties

web.server.http.port=80

web.server.https.port=443

company.security.auth.requires.https=true

  • Restart the tomcat.

  • This would make Tomcat run alone without apache. You have to access application using http://localhost:8080

Monday

Merging Layouts together

One of the common requirements that I have encountered is to Merge Layouts. Like people want on login all their community Layouts are shown along with the guest Layouts.
Or they want user layouts + org layouts together.

In this tutorial i would show how this can be achieved.

First Thought
  • How does all my Layouts get displayed as tabs in navigation?
  • How does it by default show the Home page as selected or the first tab as selected?
I found on debugging that above mentioned logic is written in ServicePreAction class. Here all the layouts that are to be displayed on a page as tabs are stored in themeDisplay along with one selected layout.

Where did I modify

I had to modify VelocityVariables in extension to merge my Layouts. Here you have a method named insertVariables where themeDisplay is inserted. Now the catch is
to manipulate on this themeDisplay object and set its Layouts and default layouts as we require.
This i had done using Extension environment.

  • In extension environment make a java file at the same package structure and name as of VelocityVariables
  • Find its insertVariables method
  • Find this line if (themeDisplay != null) {
  • Below that add your custom code to set its Layout. Like add this line below that
layouts = getLayouts(themeDisplay)
  • Now create a method that does the merging logic as under. Assuming that by default when user logs in he sees his Guest community pages and the requirement is to show users public pages along with that
private static List getLayouts(ThemeDisplay themeDisplay){
List layouts = themeDisplay.getLayouts;
return layouts;
}
  • The above piece of code will do nothing but what is happening already like showing the current layouts. Now we have to write our code in between the two lines such that the returning list of Layouts has our user layouts as well. So first we need user layouts. This can be achieved with following snippet
Group userGroup = themeDisplay.getUser().getGroup();
List userLayouts = LayoutLocalServiceUtil.getLayouts(userGroup.getGroupId(), false,LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
  • This will retrieve all the user layouts. Make sure this happens when user is logged in otherwise it may give exception since there is no user to retrieve their layouts. This can be achieved by wrapping the above snippet in a if condition which checks themeDisplay.isSignedIn().
  • The next step is pretty simple. You have to merge both layouts and return the same.
  • Hope that helps some. This may not be the ideal solution, if you have better solution please do share.

Checking Liferay 6 - Whats New Part I (Navigation)

Hi everyone
  • Today i thought why not check Liferay 6. So i went and downloaded Liferay 6 Tomcat bundle from sourceforge.

  • Created portal-ext.properties in ROOT/WEB-INF/classes

  • Added the following properties in it to connect to Mysql

jdbc.default.driverClassName=com.mysql.jdbc.Driver

jdbc.default.url=jdbc:mysql://localhost/lportal6? useUnicode=true&characterEncoding=UTF8&useFastDateParsing=false

jdbc.default.username=root

jdbc.default.password=root

  • Ran startup.bat in bin folder and it came up with the below page

Cool!!!

  • Logged in with test@liferay.com and password test

Wow first glimpse of Liferay 6!!!

So what do we have new here. I will check the general navigation today that is provided by default classic theme.

NAVIGATION

  • Single dock has been replaced with multiple dropdowns

  • My places previously in dock is replaced with Go To in top right. It takes you to by default

  • My Public Pages -- Your public pages

My Private Pages -- Your private pages

liferay.com -- Guest Public pages

  • Toggle Edit Controls finds a new separate home at top instead of a single dock
  • There is a new dropdown at top right named Manage which has following options

  • Page -- This is our old Manage Pages

  • Page Layout -- Same as Layout Template

  • SiteMap -- I found it same as Manage Page but by default taken to the second Tab named Children

  • Settings -- Settings is same as page settings available in Liferay 5.2.3 where in you can specify logo, virtual host, activate staging,etc

  • Control Panel -- Old Control panel


  • An Add drop with following options

  1. Page -- Same as Add Page

  2. Applications -- This lists commonly used portlets that can be directly add with option More which brings add application portlet

  • There is a small pin option that is to extreme right. I couldnt figure out what it pinned. At first I thought it would pin Navigation menu but navigation menu was by default pinned. After some clicks found out that it pinned the top most navigation menu, that is ones having option Add,Manage and Go To. Pretty cool!!!

Questions

  • I see two strips as below. On basic Navigation and the second one i am not sure, is it a navigation or Bread crumb portlet. How do i remove that?

Issues I found

  • I was getting Manage Pages temporarily not available occasionally with server log showing .NoSuchGroupException: No Group exists with the primary key 0. This happend sometimes when i clicked on children or look and feel.


  • I had liferay 5.2.3 instance logged in one tab of browser and liferay 6 in another tab IE 8. It kept me logging out from both if i tried to perform any action. Finally i had to switch to chrome for 5.2.3 instance and Liferay 6 in IE 8. Some problem with session i guess

BottomLine

I loved the new navigation that the default theme of Liferay has provided. It's very very interesting. Hard work by Liferay team really shows here. Kudos to them.

What next

I will check new portlets available in Liferay 6 next time.

PS

  • If you find anything new and interesting with Liferay 6 Navigation please mention it in a comment here.

  • By the time i finished posting this blog entry Liferay 6.0.1 was released. You can get if from sourceforge
  • Please pardon the mistakes and shabbiness of this blog entry

Tuesday

The First Step -- Installing Liferay Bundle

So here I go. My first step is to Install Liferay Bundle. I will use Liferay-Tomcat Bundle latest community edition that is Liferay 5.2.3

What You Need

Liferay Tomcat Bundle - Download it here
Java - Download it here
Steps

  • Install JDK
  • Right Click My Computer and click on Properties. Click on Advanced Tab and click on Environment Variables Button. You will see System Variables there. Click "New" under it. Set Variable Name = JAVA_HOME and Variable Value = path till jdk like C:\Program Files\Java\jdk1.6.0_18
  • In System Variables Section you will see a variable named Path. Select that and click on Edit. Add this at the start %JAVA_HOME%\bin;
  • Go to command prompt and type java or javac. It should show a list of command options to go with particular java or javac.
  • Installing Tomcat bundle is very easy one. Just unzip the bundle that you have downloaded. Go to the path C:\liferay\bundles\liferay-portal-5.2.3\tomcat-6.0.18\bin and double click startup.bat.
  • Server should start up as shown in the screen below and it will automatically open your default browser with liferay homepage.
Hurray!!!