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 @Override
037 public String[] getClassNames() {
038 return _CLASS_NAMES;
039 }
040
041 @Override
042 protected SocialActivityFeedEntry doInterpret(
043 SocialActivity activity, ThemeDisplay themeDisplay)
044 throws Exception {
045
046 PermissionChecker permissionChecker =
047 themeDisplay.getPermissionChecker();
048
049 if (!CalEventPermission.contains(
050 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
051
052 return null;
053 }
054
055 String groupName = StringPool.BLANK;
056
057 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
058 groupName = getGroupName(activity.getGroupId(), themeDisplay);
059 }
060
061 String creatorUserName = getUserName(
062 activity.getUserId(), themeDisplay);
063
064 int activityType = activity.getType();
065
066
067
068 CalEvent event = CalEventLocalServiceUtil.getEvent(
069 activity.getClassPK());
070
071 String link =
072 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
073 "/calendar/find_event?redirect=" +
074 HtmlUtil.escapeURL(themeDisplay.getURLCurrent()) +
075 "&eventId=" + activity.getClassPK();
076
077
078
079 String titlePattern = null;
080
081 if (activityType == CalendarActivityKeys.ADD_EVENT) {
082 titlePattern = "activity-calendar-add-event";
083 }
084 else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
085 titlePattern = "activity-calendar-update-event";
086 }
087
088 if (Validator.isNotNull(groupName)) {
089 titlePattern += "-in";
090 }
091
092 String eventTitle = getValue(
093 activity.getExtraData(), "title", event.getTitle());
094
095 Object[] titleArguments = new Object[] {
096 groupName, creatorUserName, wrapLink(link, eventTitle)
097 };
098
099 String title = themeDisplay.translate(titlePattern, titleArguments);
100
101
102
103 String body = StringPool.BLANK;
104
105 return new SocialActivityFeedEntry(link, title, body);
106 }
107
108 private static final String[] _CLASS_NAMES = new String[] {
109 CalEvent.class.getName()
110 };
111
112 }