This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. 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