留言板

social activity for webcontent

Daniel Aschauer,修改在11 年前。

social activity for webcontent

New Member 发布: 1 加入日期: 12-11-6 最近的帖子
Hi there!
I want to enable social activity for web content, thus I created a hook for the JournalArticleLocalService class overriding the updateStatus message where I added code that calls addActivity.

As i want to assign contribution points to the user that created content i added a new activity definition to liferay-social.xml

<activity>
<model-name>com.liferay.portlet.journal.model.JournalArticle</model-name>
<activity-type>${at.cyberhouse.portlet.journal.service.SocialJournalArticleLocalServiceImpl.ADD_ENTRY}</activity-type>
<language-key>ADD_ENTRY</language-key>
<log-activity>true</log-activity>
<contribution-limit enabled="false" />
<participation-value>50</participation-value>
<participation-limit period="lifetime">1</participation-limit>
<counter>
<name>user.article</name>
<owner-type>actor</owner-type>
</counter>
</activity>


But something seems to be wrong in my definition, as when I enter the social activity configuration a get two entrys for
social.activity.com.liferay.portlet.journal.model.JournalArticle.ADD_ENTRY
and lot of other entrys in Blog, WIKI,.. are missing. There are no exceptions in the logs.
When I activate the points the activity is then logged but no points are assigned.

What could be wrong with the definition?
What is the best way to modify the liferay-social.xml, should this be done with a serperate ext-plugin (I edit the original file on the server)?

Thanks for any hints!
Daniel Aschauer,修改在11 年前。

RE: social activity for webcontent

Junior Member 帖子: 39 加入日期: 12-10-22 最近的帖子
Ok, I can reply to myself now.
To add the new definition they have to be configured in a separate liferay-social.xml within a hook plugin. Then everything works fine.
Sergio San José,修改在10 年前。

RE: social activity for webcontent

New Member 帖子: 2 加入日期: 12-6-13 最近的帖子
Hi Daniel.

Did you register an Activity Interpreter for the Journal Article? If so, where did you do it? I'm having problems doing this in the liferay-portlet-ext.xml (over <portlet-name>15</portlet-name>).

Thanks!
Sergio San José,修改在10 年前。

RE: social activity for webcontent

New Member 帖子: 2 加入日期: 12-6-13 最近的帖子
Replying to myself, I've resolved this issue by creating the interpreter class in a separate Java Project, exporting it as a jar file, and adding it to the web server library.

Then I've created liferay-portlet-ext.xml adding it directly in ..webapps\ROOT\WEB-INF (it can also be done via ext plugin) overriding portlet 56 by adding <social-activity-interpreter-class> element.
Daniel Aschauer,修改在10 年前。

RE: social activity for webcontent

Junior Member 帖子: 39 加入日期: 12-10-22 最近的帖子
Hello Sergio!

I am not familiar with your approach, but you can add a social activity interpreter class simply by adding a class that extends BaseSocialActivityInterpreter to your hook project:

public class SocialActivityInterpreterHook extends BaseSocialActivityInterpreter {
	
private static final String[]_CLASS_NAMES = new String[] {
		JournalArticle.class.getName()
		};

	public String[] getClassNames() {
		return _CLASS_NAMES;
	}


This way you don't have to use a ext plugin. Note that the class then takes over ALL activity interpretations for the classes defined and returned by getClassNames().
I hope this helps you!
thumbnail
Andrew Jardine,修改在7 年前。

RE: social activity for webcontent

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hey Guys,

I'm doing something along these lines and I can only find references on how to do it by registering an *ActivityInterpreter in the liferay-portlet.xml. My question is, if I create a class (as described right above this post) that is a, for example, LayoutActivityInterpreter class, and I have it along with a liferay-social.xml definition in a hook like so --

<!--?xml version="1.0"?-->


<liferay-social>
    <activity>
        <model-name>com.liferay.portal.model.Layout</model-name>
        <activity-type>${com.liferay.portlet.social.model.SocialActivityConstants.TYPE_ADD_COMMENT}</activity-type>
        <language-key>ADD_COMMENT</language-key>
        <log-activity>true</log-activity>&gt;
        <processor-class>com.otpp.sip.liferay.social.interpreter.LayoutActivityInterpreter</processor-class>
        <contribution-value>2</contribution-value>
        <participation-value>2</participation-value>
        <participation-limit period="day">10</participation-limit>
        <counter>
            <name>user.page-comments</name>
            <owner-type>actor</owner-type>
        </counter>
    </activity>
    <activity>
        <model-name>com.liferay.portal.model.Layout</model-name>
        <activity-type>${com.liferay.portlet.social.model.SocialActivityConstants.TYPE_ADD_VOTE}</activity-type>
        <language-key>ADD_VOTE</language-key>
        <log-activity>true</log-activity>
        <processor-class>com.otpp.sip.liferay.social.interpreter.LayoutActivityInterpreter</processor-class>
        <contribution-value>1</contribution-value>
        <participation-value>1</participation-value>
        <participation-limit period="day">10</participation-limit>
        <counter>
            <name>user.page-votes</name>
            <owner-type>actor</owner-type>
        </counter>
    </activity>
</liferay-social>


how the heck to I register the ActivityInterpreter? I don't see anything in the SocialHotDeploy class that seems to do it -- just a reference to reading that XML and putting the "activity" objects into a map with the servlet context for a key.

-- so while it's great to see how you can register activity listeners for a custom portlet, how can we register them for existing Liferay models? Is that possible?
thumbnail
Andrew Jardine,修改在6 年前。

RE: social activity for webcontent

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Searching for a way to solve another problem, I came across my own post -- thought I might answer in case someone else comes along. It turns out that what I was doing, in my hook, was fine. I have actually done it for several "portal" entities and can see the Social Activity configurations in the site configuration section. The rules/points I set there are applied, provided the entry in the SocialActivity table matches.

THe challenge now though is that the out of the box JournalArticleActivityInterpreter does not support the activity type that I provided in the configuration (ie. ADD_COMMENT). When it tried to render the FeedEntry, it tries to lookup the language bundle key to use for the title and comes up with a blank. That blank is interpreted as a null and the entry is skipped.

So for the moment I am on a hunt for a way, other than what has been mentioned here, to provide a custom JournalArticleActivityInterpreter so that I can add additional activity ids to it. I'll post the answer here if I find another way (other than what is here) to do it.
thumbnail
Andrew Jardine,修改在6 年前。

RE: social activity for webcontent

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Jut an update to note that I did manage to get it working, for an existing entity in Liferay without the liferay-portlet-ext.xml and without the need for an EXT plugin. I found the solution, as usual, in Liferay's code itself. If you have a look at the so-hook project you will see that there is a portlet.properties file with a couple of keys. One is a list of portlets, the other is a repeated key with a filter -- where the filter references a portlet from the first property and the value is the *ActivityInterpreter class.

In my case I am trying to show activities for Comments that people leave on a JournalArticle. Digging into the code I found that the JournalArticleActivityInterpreter class supported several activityId's, but not the one for ADD_COMMENT. This resulted in an empty field for the title which causes the activity to be skipped when outputting the values in the activities portlet. So I needed to add my own custom activity interpreter which overrode the default one. To do this, I borrowed some code from the so-hook project.

1. Create a startup action

2. In the startup action read the portlet.properties using the PortletProps -- or use the PropsUtil as i did and put the settings in the portal-ext. This is a little easier to manage. For me, it looks like this --

social.activity.interpreter.portlet.ids=56,107


3. Use the same model, a key with the list of portlet ids that you are providing interpreters for, and then a KVP for each portlet specifying the listener. Again, for me it looks like this --

social.activity.interpreter[56]=com.xxx.liferay.social.XXXJournalArticleActivityInterpreter
social.activity.interpreter[107]=com.xxx.liferay.social.XXXLayoutActivityInterpreter


NOTE: that in my case these are full on overriding anything that LR does OOTB -- but in my case that is fine.

4. For the startup action body I just used the same approach that LR did

public void run(String[] ids) throws ActionException
    {
        try
        {
            doRun();
        }
        catch ( Exception e )
        {
            throw new ActionException(e);
        }
    }

    protected void doRun() throws Exception
    {
        initSocialActivityInterpreters();
    }

    protected void initSocialActivityInterpreters()
    {
        List<socialactivityinterpreter> activityInterpreters = SocialActivityInterpreterLocalServiceUtil.getActivityInterpreters("SO");

        String[] portletIds = PortletProps.getArray("social.activity.interpreter.portlet.ids");

        for ( String portletId : portletIds )
        {
            Filter filter = new Filter(portletId);

            //PortletPropsKeys.SOCIAL_ACTIVITY_INTERPRETER
            String activityInterpreterClassName = PortletProps.get("social.activity.interpreter", filter);

            try
            {
                SocialActivityInterpreter activityInterpreter = (SocialActivityInterpreter) InstanceFactory.newInstance(activityInterpreterClassName);

                activityInterpreter = new SocialActivityInterpreterImpl(portletId, activityInterpreter);

                if ( activityInterpreters != null )
                {
                    for ( SocialActivityInterpreter curActivityInterpreter : activityInterpreters )
                    {
                        if ( ArrayUtil.containsAll(activityInterpreter.getClassNames(), curActivityInterpreter.getClassNames()) )
                        {
                            SocialActivityInterpreterLocalServiceUtil.deleteActivityInterpreter(curActivityInterpreter);
                            break;
                        }
                    }
                }

                SocialActivityInterpreterLocalServiceUtil.addActivityInterpreter(activityInterpreter);
            }
            catch ( Exception e )
            {
                if ( _log.isWarnEnabled() )
                {
                    _log.warn("Unable to add social activity interpreter " + activityInterpreterClassName);
                }
            }
        }
    }</socialactivityinterpreter>


5. For each of the interpreters I added I used the Liferay interpreters as my example and then altered them accordingly.

Deployed my code, and magique -- all my activities that were previously not showing (journal article comments and page comments) started showing up in the feed.