
Using Liferay's Social Equity System
This document is not valid for Liferay 6.1. Please refer to this post. #
Defining the actions #
To define certain actions that will award points to an asset's information equity or a user's participation equity, a new section must be added to the xml descriptor where the resource actions are defined. This is usually called default.xml and resides in WEB-INF/resource-actions.
The new section should be inside a model-resource tag, which also means that the classname for assets affected by these actions would be the model name configured here.
The section should look like this:
<social-equity> <social-equity-mapping> <action-key>ADD_MESSAGE</action-key> <participation-value>20</participation-value> <participation-lifespan>30</participation-lifespan> </social-equity-mapping> <social-equity-mapping> <action-key>ADD_VOTE</action-key> <information-value>10</information-value> <information-lifespan>365</information-lifespan> <information-daily-limit>5</information-daily-limit> </social-equity-mapping> </social-equity>
In a social-equity-mapping tag both information and participation type values can be placed, but they would be evaluated as a separate setting.
The value is the amount of points that will be awarded to the appropriate equity, while lifespan is the number of days over which the rewarded points degrade to zero. Points for an action can be awarded to an asset or a user maximum "daily limit" times a day.
Methods to call #
To use the social equity service, portlets can call the following methods in SocialEquityLogLocalService:
- addEquityLogs
- deactivateEquityLogs
Calling the addEquityLogs method #
This method should be called when the user executes an action that is configured as a social equity action. The main signature of the method is
public void addEquityLogs(long userId, long assetEntryId, String actionId)
where userId is the acting user's id, assetEntryId is the asset's id the action targets and actionId is the string defined in the resource xml.
There is a convenience method that accepts a classname and a classPK instead of the asset's id:
public void addEquityLogs(long userId, String className, long classPK, String actionId)
Calling the deactivateEquityLogs method #
In case the points for an action should be revoked, the portlet should call one of the deactivateEquityLogs methods. The main signature is the same as for the addEquityLogs:
public void deactivateEquityLogs(long userId, long assetEntryId, String actionId)
and there is a convenience method that accepts className and classPK as well.
There is a third deactivateEquityLogs method that accepts only one parameter. This method is automatically called by the AssetEntryLocalService when an asset is deleted.
Built in actions #
There are a couple of actions are already wired to the social equity service that external portlets might want to use. AssetEntryLocalService calls the social equity service with the VIEW action whenever an asset is displayed. It also calls the service to clean up information equity values when an asset is deleted.
MessageEntryLocalService is also wired by the ADD_DISCUSSION action that is passed to the social equity service when a user adds a comment (discussion) to an asset.
RatingEntryLocalService class the social equity service with the ADD_VOTE action when a user votes on an asset.
To use these action, simply configure them in you portlet's resource actions xml under the appropriate model.