Social Activities in Liferay(5.2.x)


World of Liferay portlets (Friends Activity, Recent Activity) give you feed of activities about your friends and overall.Here I am explaining how Blogs portlet generates feed for these portlets.

You can follow same steps to implement it, to display your portlet in feeds.

1) Define the Activity Interpreter class in liferay-portlet.xml

In this case it’s BlogsActivityInterpreter.java

<portlet>
<portlet-name>33</portlet-name>
<icon>/html/icons/blogs.png</icon>
<struts-path>blogs</struts-path>
...............
<social-activity-interpreter-class>com.liferay.portlet.blogs.social.BlogsActivityInterpreter</social-activity-interpreter-class>
….
</portlet>

2) Define an Activity Keys class, which tells the type of activity.

In case blog portlet it’s BlogsActivityKeys.java.There are two types of keys are defined:

public static final int ADD_COMMENT = 1;
public static final int ADD_ENTRY = 2;

3) Save the data in the SocailActivity Table , which you want to display as feed.

In case of blog portlet there are 3 places.

  • Add new Blog Entry.
socialActivityLocalService.addActivity(userId, groupId, BlogsEntry.class.getName(), entryId,BlogsActivityKeys.ADD_ENTRY, StringPool.BLANK, 0);
  • Update a existing Blog Entry.
socialActivityLocalService.addActivity(userId, entry.getGroupId(), BlogsEntry.class.getName(), entryId,BlogsActivityKeys.ADD_ENTRY, StringPool.BLANK, 0);
  • Delete a Blog Entry.
socialActivityLocalService.deleteActivities(BlogsEntry.class.getName(), entry.getEntryId());
  • Implement interpreting logic in Interpreter Class .

In case of blog portlet it’s BlogsActivityInterpreter.java.You need to implement doInterpret() Method defined in base class

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

There are three variables which decide the Feed Entry.

  • Link – Anchor link which will take you to original Entry (If you want to do that)
  • Title – Title of the Feed. [ Ex: UserX added a new blog entry , UserX added a new event etc. ]
  • Body – Body of the feed entry

Let’s see how it’s done in Blog portlet

  • Link – It’s the finder link for Blog Entry (/c/blogs/find_entry?entryId=100)
  • Title – (User added a new blog entry ) .Text is defined in language.properties , Ex: “activity-blogs-add-entry” .You can change the text .
  • Body – It’s the title(embedded with link) and preview of the entry .
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s