Events

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

Advertisement

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.

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Adding+Social+Activity+Tracking+to+a+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);
grpDynaQuery.setProjection(ProjectionFactoryUtil.property("groupId"));

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

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

//Get the userid
DynamicQuery usrDynaQuery = DynamicQueryFactoryUtil.forClass(UserImpl.class);
usrDynaQuery.setProjection(ProjectionFactoryUtil.property("userId"));

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

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

 SocialActivityLocalServiceUtil.deleteActivity(activityId); 



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! 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