How to Customize Your Platform Activity Stream Content
Overview
The Activity Stream (AS) is the most recognizable social feature of eXo Platform. AS gives you updates of the activities of your connections and spaces. It is also the place to share your work, your stuff or even just your mood.
By using the event listener mechanism, AS automatically publishes activities like user profile updates, document updates, relationship updates and space updates.
In some cases, you might want to remove such default activities from AS or implement customized actions based on dedicated activities. In this tutorial, you will see how to remove the activities for space leaving and space joining by overriding the SpaceActivityPublisher listener.
How a listener works
Listeners are registered with the main services. Every time the main service is running and fires a registered event, listeners will be called.
<component> <key>org.exoplatform.social.core.space.spi.SpaceService</key> <type>org.exoplatform.social.core.space.impl.SpaceServiceImpl</type> ……………… <component-plugin> <name>SpaceActivityPublisher</name> <set-method>addSpaceListener</set-method> <type>org.exoplatform.social.core.application.SpaceActivityPublisher</type> </component-plugin> ……………… </component>
The above configuration can be found in social-extension.war:
SpaceActivityPublisher implements the SpaceLifeCycleListener interface and it is registered with SpaceService as a listener. It listens to most space-related activities, such as when a space is created, a space is removed, space settings change or someone leaves or joins a space, and it publishes them as social activities on AS.
If you would like to remove all space-related activities from AS, just simply comment out the component plugin config of SpaceActivityPublisher. This will disable the SpaceActivityPublisher listener. If you want to remove just the activities for when someone leaves or joins a space, as seeing such activities can sometimes be annoying, then you have to override SpaceActivityPublisher with your own implementation. To do so, you need to create an extension project, which can override the default components or default configuration of eXo Platform. Please find details for how to create an extension project here.
Override a listener
We will create a sub-class of SpaceActivityPublisher called CustomSpaceActivityPublisher in our extension project. In this class, we inherit all the methods of SpaceActivityPublisher, and only override the joined(SpaceLifeCycleEvent event) and left(SpaceLifeCycleEvent event) methods so that no action is taken for the events when a member joins or leaves.
public class CustomSpaceActivityPublisher extends SpaceActivityPublisher { public CustomSpaceActivityPublisher(InitParams params, ActivityManager activityManager, IdentityManager identityManager) { super(params, activityManager, identityManager); // TODO Auto-generated constructor stub } /** * {@inheritDoc} */ @Override public void joined(SpaceLifeCycleEvent event) { //Do nothing } /** * {@inheritDoc} */ @Override public void left(SpaceLifeCycleEvent event) { //Do nothing } }
Override a configuration
As mentioned above, the configuration needed to register SpaceActivityPublisher listener with SpaceService is in social-extension.war:
We copy this configuration file into our extension project and update the configuration as follows:
<component-plugin> <name>SpaceActivityPublisher</name> <set-method>addSpaceListener</set-method> <type>org.exoplatform.customization.listener.CustomSpaceActivityPublisher</type> </component-plugin>
This registers our new sub-class as the listener for SpaceService. Remember that to override the existing core-configuration.xml of social-extension.war, we have to put our configuration file in the same path as the original one.
* Important note: We cannot just add the above listener registration to the existing core-configuration.xml. We have to override the existing core-configuration.xml with the new one in our extension project. This is to avoid a registration conflict.
Launching customization
Now you are ready to deploy your extension project. The source code of a sample extension project can be found here. After you have built this extension project using Maven, simply copy the .war files to and copy the .jar files to then start your Tomcat instance.
Going further
Customization can do more than removing unwanted activities from AS. You can override any method of the existing listener for the expected behavior. Besides SpaceActivityPublisher, there are a number of overridable components supported by eXo Platform.
You can download the Sample extension project.
Join the eXo tribe by registering for the community and access tutorials, support, and downloads!
Make the most out of eXo Platform 4
Register to the next webinar and get a complete overview of what you can do with eXo Platform 4. Reserve your seat now!