One of the greatest strengths of the eXo Platform is that it integrates a lot of features, such as content management and collaboration or social capabilities.

After the development of a JSF 2 / RichFaces portlet, and the integration of the Content Management capabilities of the eXo Platform, we will learn, in this third tutorial, how to leverage the eXo Platform social features in your own business portlets. To do so, we will start from the portlet created in the previous tutorial and post an activity in the user’s activity stream when he buys a product.

The source code of this tutorial is available here.

Adding eXo dependencies

The first step is to add the eXo dependencies that will be used in our portlet. Edit your pom.xml and add these lines:

Using the eXo Social API

Now let’s create a service that will use the eXo Social API to post an activity in the user’s activity stream. For this, we will create a new class with the following method:

This service retrieves the current user’s identity and then posts an activity for this identity with the given text.

We now use this service in our JSF view. The ‘Buy’ button of each product calls an action with the product’s data as parameter:

And this action, added in the ComicsStoreBean managed bean, uses our previously created service to post the activity:

You can now see the result in your activity stream after clicking on the Buy button of one of the products by going to the ‘intranet’ demo site (My Sites > intranet):

eXo Social offers you a lot of others possibilities, such as posting an activity in a space, posting different kinds of activity (for instance content activity, such as the one in the screenshot for the “iron-man-2.jpg” file), adding a comment to an activity, getting the relations of an user, getting the users of a space,…

Besides this Java API, the eXo social feature offers a REST API and the OpenSocial API.

In this tutorial, we learnt how to use the eXo Social API to post an activity from your own business portlet.

Don’t hesitate to take a look at the documentation to discover all the available APIs.

(original article from Thomas blog)

comments