001
014
015 package com.liferay.portlet.calendar.social;
016
017 import com.liferay.portal.kernel.util.HtmlUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.security.permission.ActionKeys;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portlet.calendar.model.CalEvent;
024 import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
025 import com.liferay.portlet.calendar.service.permission.CalEventPermission;
026 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
027 import com.liferay.portlet.social.model.SocialActivity;
028 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
029
030
034 public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
035
036 public String[] getClassNames() {
037 return _CLASS_NAMES;
038 }
039
040 protected SocialActivityFeedEntry doInterpret(
041 SocialActivity activity, ThemeDisplay themeDisplay)
042 throws Exception {
043
044 PermissionChecker permissionChecker =
045 themeDisplay.getPermissionChecker();
046
047 if (!CalEventPermission.contains(
048 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
049
050 return null;
051 }
052
053 String groupName = StringPool.BLANK;
054
055 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
056 groupName = getGroupName(activity.getGroupId(), themeDisplay);
057 }
058
059 String creatorUserName = getUserName(
060 activity.getUserId(), themeDisplay);
061
062 int activityType = activity.getType();
063
064
065
066 CalEvent event = CalEventLocalServiceUtil.getEvent(
067 activity.getClassPK());
068
069 String link =
070 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
071 "/calendar/find_event?redirect=" +
072 themeDisplay.getURLCurrent() + "&eventId=" +
073 activity.getClassPK();
074
075
076
077 String titlePattern = null;
078
079 if (activityType == CalendarActivityKeys.ADD_EVENT) {
080 titlePattern = "activity-calendar-add-event";
081 }
082 else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
083 titlePattern = "activity-calendar-update-event";
084 }
085
086 if (Validator.isNotNull(groupName)) {
087 titlePattern += "-in";
088 }
089
090 String eventTitle = wrapLink(
091 link, HtmlUtil.escape(cleanContent(event.getTitle())));
092
093 Object[] titleArguments = new Object[] {
094 groupName, creatorUserName, eventTitle
095 };
096
097 String title = themeDisplay.translate(titlePattern, titleArguments);
098
099
100
101 String body = StringPool.BLANK;
102
103 return new SocialActivityFeedEntry(link, title, body);
104 }
105
106 private static final String[] _CLASS_NAMES = new String[] {
107 CalEvent.class.getName()
108 };
109
110 }