论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Daniel Aschauer
social activity for webcontent
2013年3月7日 上午6:01
答复

Daniel Aschauer

等级: New Member

帖子: 1

加入日期: 2012年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
RE: social activity for webcontent
2013年3月8日 上午3:29
答复

Daniel Aschauer

等级: Junior Member

帖子: 39

加入日期: 2012年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é
RE: social activity for webcontent
2013年9月17日 上午4:51
答复

Sergio San José

等级: New Member

帖子: 2

加入日期: 2012年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é
RE: social activity for webcontent
2013年9月17日 上午9:47
答复

Sergio San José

等级: New Member

帖子: 2

加入日期: 2012年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
RE: social activity for webcontent
2013年9月19日 上午1:15
答复

Daniel Aschauer

等级: Junior Member

帖子: 39

加入日期: 2012年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:

 1public class SocialActivityInterpreterHook extends BaseSocialActivityInterpreter {
 2   
 3private static final String[]_CLASS_NAMES = new String[] {
 4        JournalArticle.class.getName()
 5        };
 6
 7    public String[] getClassNames() {
 8        return _CLASS_NAMES;
 9    }


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!
Andrew Jardine
RE: social activity for webcontent
2016年11月21日 上午11:12
答复

Andrew Jardine

Community Moderator

等级: Liferay Legend

帖子: 1242

加入日期: 2010年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 --

 1<?xml version="1.0"?>
 2<!DOCTYPE liferay-social PUBLIC "-//Liferay//DTD Social 6.2.0//EN"
 3        "http://www.liferay.com/dtd/liferay-social_6_2_0.dtd">
 4
 5<liferay-social>
 6    <activity>
 7        <model-name>com.liferay.portal.model.Layout</model-name>
 8        <activity-type>${com.liferay.portlet.social.model.SocialActivityConstants.TYPE_ADD_COMMENT}</activity-type>
 9        <language-key>ADD_COMMENT</language-key>
10        <log-activity>true</log-activity>>
11        <processor-class>com.otpp.sip.liferay.social.interpreter.LayoutActivityInterpreter</processor-class>
12        <contribution-value>2</contribution-value>
13        <participation-value>2</participation-value>
14        <participation-limit period="day">10</participation-limit>
15        <counter>
16            <name>user.page-comments</name>
17            <owner-type>actor</owner-type>
18        </counter>
19    </activity>
20    <activity>
21        <model-name>com.liferay.portal.model.Layout</model-name>
22        <activity-type>${com.liferay.portlet.social.model.SocialActivityConstants.TYPE_ADD_VOTE}</activity-type>
23        <language-key>ADD_VOTE</language-key>
24        <log-activity>true</log-activity>
25        <processor-class>com.otpp.sip.liferay.social.interpreter.LayoutActivityInterpreter</processor-class>
26        <contribution-value>1</contribution-value>
27        <participation-value>1</participation-value>
28        <participation-limit period="day">10</participation-limit>
29        <counter>
30            <name>user.page-votes</name>
31            <owner-type>actor</owner-type>
32        </counter>
33    </activity>
34</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?
Andrew Jardine
RE: social activity for webcontent
2017年4月5日 下午12:53
答复

Andrew Jardine

Community Moderator

等级: Liferay Legend

帖子: 1242

加入日期: 2010年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.
Andrew Jardine
RE: social activity for webcontent
2017年4月5日 下午7:07
答复

Andrew Jardine

Community Moderator

等级: Liferay Legend

帖子: 1242

加入日期: 2010年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 --

1social.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 --

1social.activity.interpreter[56]=com.xxx.liferay.social.XXXJournalArticleActivityInterpreter
2social.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

 1public void run(String[] ids) throws ActionException
 2    {
 3        try
 4        {
 5            doRun();
 6        }
 7        catch ( Exception e )
 8        {
 9            throw new ActionException(e);
10        }
11    }
12
13    protected void doRun() throws Exception
14    {
15        initSocialActivityInterpreters();
16    }
17
18    protected void initSocialActivityInterpreters()
19    {
20        List<SocialActivityInterpreter> activityInterpreters = SocialActivityInterpreterLocalServiceUtil.getActivityInterpreters("SO");
21
22        String[] portletIds = PortletProps.getArray("social.activity.interpreter.portlet.ids");
23
24        for ( String portletId : portletIds )
25        {
26            Filter filter = new Filter(portletId);
27
28            //PortletPropsKeys.SOCIAL_ACTIVITY_INTERPRETER
29            String activityInterpreterClassName = PortletProps.get("social.activity.interpreter", filter);
30
31            try
32            {
33                SocialActivityInterpreter activityInterpreter = (SocialActivityInterpreter) InstanceFactory.newInstance(activityInterpreterClassName);
34
35                activityInterpreter = new SocialActivityInterpreterImpl(portletId, activityInterpreter);
36
37                if ( activityInterpreters != null )
38                {
39                    for ( SocialActivityInterpreter curActivityInterpreter : activityInterpreters )
40                    {
41                        if ( ArrayUtil.containsAll(activityInterpreter.getClassNames(), curActivityInterpreter.getClassNames()) )
42                        {
43                            SocialActivityInterpreterLocalServiceUtil.deleteActivityInterpreter(curActivityInterpreter);
44                            break;
45                        }
46                    }
47                }
48
49                SocialActivityInterpreterLocalServiceUtil.addActivityInterpreter(activityInterpreter);
50            }
51            catch ( Exception e )
52            {
53                if ( _log.isWarnEnabled() )
54                {
55                    _log.warn("Unable to add social activity interpreter " + activityInterpreterClassName);
56                }
57            }
58        }
59    }


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.