001
014
015 package com.liferay.portlet.blogs.social;
016
017 import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.kernel.workflow.WorkflowConstants;
021 import com.liferay.portal.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portlet.blogs.model.BlogsEntry;
025 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
026 import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
027 import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
028 import com.liferay.portlet.social.model.SocialActivity;
029 import com.liferay.portlet.social.model.SocialActivityConstants;
030 import com.liferay.portlet.social.model.SocialActivityFeedEntry;
031
032 import java.text.Format;
033
034
038 public class BlogsActivityInterpreter extends BaseSocialActivityInterpreter {
039
040 @Override
041 public String[] getClassNames() {
042 return _CLASS_NAMES;
043 }
044
045 @Override
046 protected SocialActivityFeedEntry doInterpret(
047 SocialActivity activity, ThemeDisplay themeDisplay)
048 throws Exception {
049
050 PermissionChecker permissionChecker =
051 themeDisplay.getPermissionChecker();
052
053 if (!BlogsEntryPermission.contains(
054 permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
055
056 return null;
057 }
058
059 String groupName = StringPool.BLANK;
060
061 if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
062 groupName = getGroupName(activity.getGroupId(), themeDisplay);
063 }
064
065 String creatorUserName = getUserName(
066 activity.getUserId(), themeDisplay);
067 String receiverUserName = getUserName(
068 activity.getReceiverUserId(), themeDisplay);
069
070 int activityType = activity.getType();
071
072
073
074 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
075 activity.getClassPK());
076
077 String link =
078 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
079 "/blogs/find_entry?entryId=" + activity.getClassPK();
080
081
082
083 String entryTitle = getValue(
084 activity.getExtraData(), "title", entry.getTitle());
085
086 String displayTitle = wrapLink(link, entryTitle);
087 String displayDate = StringPool.BLANK;
088
089 String titlePattern = null;
090
091 if ((activityType == BlogsActivityKeys.ADD_COMMENT) ||
092 (activityType == SocialActivityConstants.TYPE_ADD_COMMENT)) {
093
094 if (Validator.isNull(groupName)) {
095 titlePattern = "activity-blogs-add-comment";
096 }
097 else {
098 titlePattern = "activity-blogs-add-comment-in";
099 }
100 }
101 else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
102 if (entry.getStatus() == WorkflowConstants.STATUS_SCHEDULED) {
103 if (Validator.isNull(groupName)) {
104 titlePattern = "activity-blogs-scheduled-entry";
105 }
106 else {
107 titlePattern = "activity-blogs-scheduled-entry-in";
108 }
109
110 Format dateFormatDate =
111 FastDateFormatFactoryUtil.getSimpleDateFormat(
112 "MMMM d", themeDisplay.getLocale(),
113 themeDisplay.getTimeZone());
114
115 displayDate = dateFormatDate.format(entry.getDisplayDate());
116
117 displayTitle = entryTitle;
118 }
119 else {
120 if (Validator.isNull(groupName)) {
121 titlePattern = "activity-blogs-add-entry";
122 }
123 else {
124 titlePattern = "activity-blogs-add-entry-in";
125 }
126 }
127 }
128 else if (activityType == BlogsActivityKeys.UPDATE_ENTRY) {
129 if (Validator.isNull(groupName)) {
130 titlePattern = "activity-blogs-update-entry";
131 }
132 else {
133 titlePattern = "activity-blogs-update-entry-in";
134 }
135 }
136
137 Object[] titleArguments = new Object[] {
138 groupName, creatorUserName, receiverUserName, displayTitle,
139 displayDate
140 };
141
142 String title = themeDisplay.translate(titlePattern, titleArguments);
143
144
145
146 String body = StringPool.BLANK;
147
148 return new SocialActivityFeedEntry(link, title, body);
149 }
150
151 private static final String[] _CLASS_NAMES = new String[] {
152 BlogsEntry.class.getName()
153 };
154
155 }