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