1
22
23 package com.liferay.portlet.messageboards.social;
24
25 import com.liferay.portal.kernel.util.StringMaker;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portal.model.User;
29 import com.liferay.portal.service.UserLocalServiceUtil;
30 import com.liferay.portal.theme.ThemeDisplay;
31 import com.liferay.portlet.messageboards.model.MBMessage;
32 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
33 import com.liferay.portlet.social.model.SocialActivity;
34 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
35 import com.liferay.portlet.social.model.SocialActivityInterpreter;
36
37 import org.apache.commons.logging.Log;
38 import org.apache.commons.logging.LogFactory;
39
40
46 public class MBActivityInterpreter implements SocialActivityInterpreter {
47
48 public String[] getClassNames() {
49 return _CLASS_NAMES;
50 }
51
52 public SocialActivityFeedEntry interpret(
53 SocialActivity activity, ThemeDisplay themeDisplay) {
54
55 try {
56 return doInterpret(activity, themeDisplay);
57 }
58 catch (Exception e) {
59 if (_log.isWarnEnabled()) {
60 _log.warn(e);
61 }
62 }
63
64 return null;
65 }
66
67 protected SocialActivityFeedEntry doInterpret(
68 SocialActivity activity, ThemeDisplay themeDisplay)
69 throws Exception {
70
71 User creatorUser = UserLocalServiceUtil.getUserById(
72 activity.getUserId());
73
74 String creatorUserName = creatorUser.getFullName();
75 String creatorUserDisplayURL = creatorUser.getDisplayURL(
76 themeDisplay.getURLPortal());
77
78 creatorUserName = "<a href=\"" + creatorUserDisplayURL + "\">" + creatorUserName + "</a>";
79
80 String type = activity.getType();
81
82 String receiverUserName = activity.getReceiverUserName();
83
84 if (activity.getReceiverUserId() > 0) {
85 User receiverUser = UserLocalServiceUtil.getUserById(
86 activity.getReceiverUserId());
87
88 receiverUserName = receiverUser.getFullName();
89 }
90
91
93 String title = StringPool.BLANK;
94
95 if (type.equals(MBActivityKeys.ADD)) {
96 title = themeDisplay.translate(
97 "activity-message-boards-add", creatorUserName);
98 }
99 else if (type.equals(MBActivityKeys.REPLY)) {
100 title = themeDisplay.translate(
101 "activity-message-boards-reply",
102 new Object[] {creatorUserName, receiverUserName});
103 }
104
105
107 MBMessage message = MBMessageLocalServiceUtil.getMessage(
108 activity.getClassPK());
109
110 StringMaker sm = new StringMaker();
111
112 sm.append("<b>");
113 sm.append(message.getSubject());
114 sm.append("</b><br />");
115 sm.append(StringUtil.shorten(message.getBody(), 200));
116
117 String body = sm.toString();
118
119 return new SocialActivityFeedEntry(title, body);
120 }
121
122 private static final String[] _CLASS_NAMES = new String[] {
123 MBMessage.class.getName()
124 };
125
126 private static Log _log = LogFactory.getLog(MBActivityInterpreter.class);
127
128 }