IBM Webcast - Mobility in the Cloud

Optimize Your Mobile Workforce with Social Collaboration in the Cloud

A Free Template from Joomlashack

A Free Template from Joomlashack


Custom Activities Portlet PDF Print E-mail
Written by Administrator   
Wednesday, 30 December 2009 18:45

This article will you an insight into how to use the Liferay Social Activity api for developing a custom activities portlet.

The article available on liferay wiki is good enough to understand how to add Social Activity tracking in portlet.

I would like to dwell into details on how you can develop a custom portlet which would list the activities created while creating Calendar events, blogs, Wikis etc in Liferay.

The important thing to be noted is that every social activity created in Liferay is associated with a classname which is registered in CLASSNAME_ table. This classname is registered with the name specified in the Social Activity Interpreter implementation class or specified in the SocialActivity api while creating the activity. Lets look at how to create, retrieve and delete an activity.

 Creating an Activity 

 SocialActivityLocalServiceUtil.addActivity(long userId,long groupId, java.util.Date createDate,
java.lang.String className, long classPK, int type,
java.lang.String extraData, long receiverUserId) 

 If you are creating this activity outside of portal environment, then you need to know the login user and community name to get the liferay database userid and groupid. 

 //Get the groupid
DynamicQuery grpDynaQuery = DynamicQueryFactoryUtil.forClass(GroupImpl.class);

Criterion criterion = RestrictionsFactoryUtil.eq("name", communityName);

List<?> groupIdList = SocialActivityLocalServiceUtil.dynamicQuery(grpDynaQuery);
groupId = ((Long)groupIdList.get(0)).longValue();

//Get the userid
DynamicQuery usrDynaQuery = DynamicQueryFactoryUtil.forClass(UserImpl.class);

Criterion usrCriterion = RestrictionsFactoryUtil.eq("screenName", actCreateUser);

List<?> usrIdList = SocialActivityLocalServiceUtil.dynamicQuery(usrDynaQuery);
userId = ((Long)usrIdList.get(0)).longValue();

The classname can be any String "com.skzine.activity.model.SkZineActivity". This classname will be registered in the CLASSNAME_ table in the liferay database.

 Retrieving an Activity

 List<SocialActivity> socialActivityList = SocialActivityLocalServiceUtil.getGroupActivities(groupId, 0, actCount);

For retrieving the SocialActivity details, invoke the interpreter of each activity.

SocialActivityFeedEntry socialFeedEntry = SocialActivityInterpreterLocalServiceUtil.interpret(socialActivity, themeDisplay);

For getting the activity icon, get the portlet id from socialFeedEntry object and use the below method.

Portlet portlet = PortletLocalServiceUtil.getPortletById(finAct.getPortletId()); 
portlet.getContextPath() + portlet.getIcon()

 Deleting an Activity


Add this page to your favorite Social Bookmarking websites
Reddit!! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! TwitThis Joomla Free PHP
Last Updated on Wednesday, 30 December 2009 23:23
Joomla 1.5 Templates by Joomlashack