Adding Social Equity services on custom assets through plugins

Social Equity is a cool new feature in Liferay 6 or above version. Refer to Zsolt's blogs post Social Equity in Liferay.

Social Equity can be used to measure the contribution and participation of a user and the information value of an asset. The activities that award equities include, but not limited: adding contributions, rating, commenting, viewing content, searching and tagging.

Currently there are three portlets (Wiki, Blogs and Message Boards) that use the social equity service. The activities and their default values are configured in the /resource-actions/wiki.xml, blogs.xml, messageboards.xml.

Logically the Social Equity framework is assets agnostic. It operates on assets directly and uses action keys defined in resource-actions xml. Thus service calls need to be added to the respective services like Journal, Knowledge Base, etc.

As shown in following screenshot, Currently there are three portlets (Wiki, Blogs and Message Boards) that use the social equity service. The activities and their default values are configured in the /resource-actions/wiki.xml, blogs.xml, messageboards.xml.

For Wiki, configured activities are ADD_PAGE, VIEW, and ADD_DISCUSSION; for Blogs configured activities are ADD_ENTRY, VIEW, and ADD_DISCUSSION; and for Message Boards, configured activities are ADD_MESSAGE, ADD_VOTE, REPLY_MESSAGE, and VIEW. How do you add social equity services on custom assets like Knowledge base articles in plugins?

How to make it?

Abstracted from the book: Liferay User Interface Developement.

Supposed that configured activity is VIEW in Knowledge Base plugin, how do you make it? Loosely speaking, adding social equity capabilities in plugins should be simple in following steps.

First, you can configure the activities and their default values in the resource actions xml, that is, $PLUGIN_SDK_HOME/knowledge-base-portlet/docroot/WEB-INF/src/resource-actions/default.xml. You can simply add following lines before the line </model-resource> of the model com.liferay.knowledgebase.model.Article.

<social-equity>
 <social-equity-mapping>
    <action-key>VIEW</action-key>
    <information-value>1</information-value>
    <information-lifespan>365</information-lifespan>
    <participation-value>1</participation-value>
    <participation-lifespan>365</participation-lifespan>
 </social-equity-mapping>
</social-equity>

Then you should add social equity as references in $PLUGIN_SDK_HOME/knowledge-base-portlet/docroot/WEB-INF/service.xml as follows.

<reference package-path="com.liferay.portlet.social" entity="SocialEquityLog" />

It is time for you to re-build services by using ANT target build-service. That’s it. From now on, you would be able to see that Knowledge base Article is available under Control Panel | Social Equity | Settings, as shown in above screenshot.

What’s happening?

In fact, the portal has specified following social equity related properties by default in portal.properties. Of course, you would be able to override these properties in portal-ext.properties.

social.equity.equity.log.check.interval=1440   
social.equity.equity.log.enabled=true

As shown in above code, social equity feature is enabled by default and can be turned off by setting the social.equity.equity.log.enabled property to false. The property social.equity.equity.log.check.interval sets the interval like 1140 minutes on which the CheckEquityLogMessageListener will run. The value is set in one minute increments.

Where do you find sample code?

You can download sample code from 

knowledge-base-portlet-6.0.6.1.war

and deploy it.

Note that the WAR was generated based on the portal 6.0.10 (revision 63177 ).

Summary

As you can see, you would be able to add Social Equity services on any custom assets generated by Service-Builder in plugins. The asset Knowledge Base articles is one of them (custom assets).Try it now, you would be able to make Knowledge Base and / or your own portlet as one of Social Equity contributing portlets.

Last but not least, I'd like to send a ton of thanks to Zsolt Berentey, Brian Chan, Samuel Kong, and John Wayne Jiang,  who did a great job to make Social Equity a reality in Liferay portal 6.

Blogs
Hey Jonas,

very interesting Article, but i can't download the war file - no permissions :-(

Greets
Markus
Hi Markus, thanks.

Forgot giving VIEW permission to Guest user. :-)

The View permission has been assigned to Guest user. You should be able to download the WAR file now.

Please let me know if you have any questions,

Blessings,

Jonas
Hi Jonas,

Very nice article indeed. It might also be worth mentioning that there are some generic actions such as VIEW that are wired into the asset service and so simply configuring a VIEW action on an asset does the trick. The asset service service will call social equity with the VIEW action on the asset and if such an action is configured for that particular model resource and of course social equity is enabled on that model resource, voila, you'll get your points without adding any code.

For other actions however, you need to call the social equity service manually from your services.

By the way, deleting an asset from the system works automatically too, so it will clean up all information and contribution equities related to that asset...

Cheers,
Zsolt
Thanks for the article!
I had one question:
If you don't use service-builder, how do you make the relations made by <reference package-path="com.liferay.portlet.social" entity="SocialEquityLog" /> manually?
We really want to combine this amazing feature with our asset, the only problem is, it is not made by Service-builder and at the moment we don't have time to do everything from the beginning with service-builder. Are there any solutions?
Hi Puj,

You can use SocialEquityLogLocalServiceUtil to access the service. The service-reference is just a shortcut using Spring IoC to inject the service bean into your service code, so that you always have the "shortest" route to the service.
So If I have understood it correctly then I will not be able to use it beyond Blog, Message Board, Wiki & my custom entity as of now. And if I want to use this for my OOB entity such as Web-content etc. then I can not do it because it requires to re-generate services. right?