
Adding Social Activity Tracking to a Portlet
Table of Contents [-]
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