1
19
20 package com.liferay.portlet.blogs.social;
21
22 import com.liferay.portal.kernel.json.JSONFactoryUtil;
23 import com.liferay.portal.kernel.json.JSONObject;
24 import com.liferay.portal.kernel.util.StringPool;
25 import com.liferay.portal.kernel.util.Validator;
26 import com.liferay.portal.model.Group;
27 import com.liferay.portal.service.GroupLocalServiceUtil;
28 import com.liferay.portal.theme.ThemeDisplay;
29 import com.liferay.portlet.blogs.model.BlogsEntry;
30 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
31 import com.liferay.portlet.messageboards.NoSuchMessageException;
32 import com.liferay.portlet.messageboards.model.MBMessage;
33 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
34 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
35 import com.liferay.portlet.social.model.SocialActivity;
36 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
37 import com.liferay.portlet.social.service.SocialActivityLocalServiceUtil;
38
39
45 public class BlogsActivityInterpreter extends BaseSocialActivityInterpreter {
46
47 public String[] getClassNames() {
48 return _CLASS_NAMES;
49 }
50
51 protected SocialActivityFeedEntry doInterpret(
52 SocialActivity activity, ThemeDisplay themeDisplay)
53 throws Exception {
54
55 String creatorUserName = getUserName(
56 activity.getUserId(), themeDisplay);
57 String receiverUserName = getUserName(
58 activity.getReceiverUserId(), themeDisplay);
59
60 int activityType = activity.getType();
61
62 JSONObject extraData = null;
63
64 if (Validator.isNotNull(activity.getExtraData())) {
65 extraData = JSONFactoryUtil.createJSONObject(
66 activity.getExtraData());
67 }
68
69
71 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
72 activity.getClassPK());
73
74 String link =
75 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
76 "/blogs/find_entry?entryId=" + activity.getClassPK();
77
78
80 String groupName = StringPool.BLANK;
81
82 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
83 Group group = GroupLocalServiceUtil.getGroup(activity.getGroupId());
84
85 groupName = group.getDescriptiveName();
86 }
87
88 String titlePattern = null;
89 Object[] titleArguments = null;
90
91 if (activityType == BlogsActivityKeys.ADD_COMMENT) {
92 titlePattern = "activity-blogs-add-comment";
93
94 if (Validator.isNotNull(groupName)) {
95 titlePattern += "-in";
96 }
97
98 titleArguments = new Object[] {
99 creatorUserName, receiverUserName, groupName
100 };
101 }
102 else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
103 titlePattern = "activity-blogs-add-entry";
104
105 if (Validator.isNotNull(groupName)) {
106 titlePattern += "-in";
107 }
108
109 titleArguments = new Object[] {creatorUserName, groupName};
110 }
111
112 String title = themeDisplay.translate(titlePattern, titleArguments);
113
114
116 StringBuilder sb = new StringBuilder();
117
118 sb.append("<a href=\"");
119 sb.append(link);
120 sb.append("\">");
121
122 if (activityType == BlogsActivityKeys.ADD_COMMENT) {
123 long messageId = extraData.getInt("messageId");
124
125 try {
126 MBMessage message = MBMessageLocalServiceUtil.getMessage(
127 messageId);
128
129 sb.append(cleanContent(message.getBody()));
130 }
131 catch (NoSuchMessageException nsme) {
132 SocialActivityLocalServiceUtil.deleteActivity(
133 activity.getActivityId());
134
135 return null;
136 }
137 }
138 else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
139 sb.append(entry.getTitle());
140 }
141
142 sb.append("</a><br />");
143
144 if (activityType == BlogsActivityKeys.ADD_ENTRY) {
145 sb.append(cleanContent(entry.getContent()));
146 }
147
148 String body = sb.toString();
149
150 return new SocialActivityFeedEntry(link, title, body);
151 }
152
153 private static final String[] _CLASS_NAMES = new String[] {
154 BlogsEntry.class.getName()
155 };
156
157 }