« Back to Portlets

Adding Social Activity Tracking to a Portlet

Introduction #

The following tutorial will go through the steps needed to social activity tracking to a portlet. Recorded social activities will appear on the Activities portlet.

The examples will use the wiki as an example.

Add Activity #

The first step is to add social activity. You'll probably do this in a add() or update() method.

SocialActivityLocalServiceUtil.addActivity(
	userId, groupId, className, classPK, type, extraData, receiverUserId);
  • The type parameter, identifies the type of activity it is. You are free to define this however you want. See WikiActivityKeys for an example.
  • The extraData parameter is a string that can contain any additional info you want
  • receiverUserId is the user who the activity is done to.

In the wiki portlet, it looks something like the following

SocialActivityLocalServiceUtil.addActivity(
	userId, groupId, WikiPage.class.getName(), page.getResourcePrimKey(),
	WikiActivityKeys.ADD_PAGE, StringPool.BLANK, 0);

Remove Activity #

SocialActivityLocalServiceUtil.deleteActivities(
	className, classPK);

In the wiki portlet, it looks something like the following

SocialActivityLocalServiceUtil.deleteActivities(
	WikiPage.class.getName(), page.getResourcePrimKey());

Activity Interpreter #

Next, create an activity interpreter that extends BaseSocialActivityInterpreter.

Your activity interpreter class needs a getClassName() method that returns an array of class names. This should include the className used in the call to addActivity().

You'll also need a doInterpret(SocialActivity, ThemeDisplay) method that returns a SocialActivityFeedEntry. Your code should parse the SocialActivity argument to create the SocialActivityFeedEntry. In particular, you'll need a link, a title, and a body.

You code will looking something like

protected SocialActivityFeedEntry doInterpret(
		SocialActivity activity, ThemeDisplay themeDisplay)
	throws Exception {

	// parse activity

	String link = ...
	String title = ...
	String body = ...

	return new SocialActivityFeedEntry(link, title, body);}}

== Add XML File ==
Finally add the following **liferay-portlet.xml** for your portlet

{{{
<social-activity-interpreter-class>ActivityInterpreterClass</social-activity-interpreter-class>

where ActivityInterpreterClass is your activity interpreter class

0 Attachments
12873 Views
Average (2 Votes)
Comments

Showing 2 Comments

Mahendra Mahakle
5/3/11 8:12 AM

please tell me How and When doInterpreter() method will call.

Nilesh Gundecha
5/4/11 8:05 AM

Hi Friends,

Very nice Wiki article. Just need clarification on -
How The ActivitiesPortlet (like MembersActivitiesPortlet / UserActivitiesPortlet / FriendsActivitiesPortlet) will know about my defined custom activity type?? Should not I configure/define about my activity type to it??

Please provide me some inputs on this??

Thanks and Regards,
Nilesh.