1
19
20 package com.liferay.portlet.calendar.social;
21
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portal.model.Group;
25 import com.liferay.portal.service.GroupLocalServiceUtil;
26 import com.liferay.portal.theme.ThemeDisplay;
27 import com.liferay.portlet.calendar.model.CalEvent;
28 import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
29 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
30 import com.liferay.portlet.social.model.SocialActivity;
31 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
32
33
39 public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
40
41 public String[] getClassNames() {
42 return _CLASS_NAMES;
43 }
44
45 protected SocialActivityFeedEntry doInterpret(
46 SocialActivity activity, ThemeDisplay themeDisplay)
47 throws Exception {
48
49 String creatorUserName = getUserName(
50 activity.getUserId(), themeDisplay);
51
52 int activityType = activity.getType();
53
54
56 CalEvent event = CalEventLocalServiceUtil.getEvent(
57 activity.getClassPK());
58
59 String link =
60 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
61 "/calendar/find_event?eventId=" + activity.getClassPK();
62
63
65 String groupName = StringPool.BLANK;
66
67 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
68 Group group = GroupLocalServiceUtil.getGroup(activity.getGroupId());
69
70 groupName = group.getDescriptiveName();
71 }
72
73 String titlePattern = null;
74 Object[] titleArguments = null;
75
76 if (activityType == CalendarActivityKeys.ADD_EVENT) {
77 titlePattern = "activity-calendar-add-event";
78
79 if (Validator.isNotNull(groupName)) {
80 titlePattern += "-in";
81 }
82
83 titleArguments = new Object[] {creatorUserName, groupName};
84 }
85 else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
86 titlePattern = "activity-calendar-update-event";
87
88 if (Validator.isNotNull(groupName)) {
89 titlePattern += "-in";
90 }
91
92 titleArguments = new Object[] {creatorUserName, groupName};
93 }
94
95 String title = themeDisplay.translate(titlePattern, titleArguments);
96
97
99 StringBuilder sb = new StringBuilder();
100
101 sb.append("<a href=\"");
102 sb.append(link);
103 sb.append("\">");
104 sb.append(cleanContent(event.getTitle()));
105 sb.append("</a><br />");
106 sb.append(cleanContent(event.getDescription()));
107
108 String body = sb.toString();
109
110 return new SocialActivityFeedEntry(link, title, body);
111 }
112
113 private static final String[] _CLASS_NAMES = new String[] {
114 CalEvent.class.getName()
115 };
116
117 }