1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.messageboards.social;
16  
17  import com.liferay.portal.kernel.util.HtmlUtil;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portlet.messageboards.model.MBMessage;
24  import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
25  import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
26  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
27  import com.liferay.portlet.social.model.SocialActivity;
28  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
29  
30  /**
31   * <a href="MBActivityInterpreter.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Ryan Park
35   */
36  public class MBActivityInterpreter extends BaseSocialActivityInterpreter {
37  
38      public String[] getClassNames() {
39          return _CLASS_NAMES;
40      }
41  
42      protected SocialActivityFeedEntry doInterpret(
43              SocialActivity activity, ThemeDisplay themeDisplay)
44          throws Exception {
45  
46          PermissionChecker permissionChecker =
47              themeDisplay.getPermissionChecker();
48  
49          if (!MBMessagePermission.contains(
50                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
51  
52              return null;
53          }
54  
55          String groupName = StringPool.BLANK;
56  
57          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
58              groupName = getGroupName(activity.getGroupId(), themeDisplay);
59          }
60  
61          String creatorUserName = getUserName(
62              activity.getUserId(), themeDisplay);
63          String receiverUserName = getUserName(
64              activity.getReceiverUserId(), themeDisplay);
65  
66          int activityType = activity.getType();
67  
68          // Link
69  
70          MBMessage message = MBMessageLocalServiceUtil.getMessage(
71              activity.getClassPK());
72  
73          String link =
74              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
75                  "/message_boards/find_message?messageId=" +
76                      message.getMessageId();
77  
78          // Title
79  
80          String titlePattern = null;
81  
82          if (activityType == MBActivityKeys.ADD_MESSAGE) {
83              titlePattern = "activity-message-boards-add-message";
84          }
85          else if (activityType == MBActivityKeys.REPLY_MESSAGE) {
86              titlePattern = "activity-message-boards-reply-message";
87          }
88  
89          if (Validator.isNotNull(groupName)) {
90              titlePattern += "-in";
91          }
92  
93          String messageSubject = wrapLink(
94              link, HtmlUtil.escape(cleanContent(message.getSubject())));
95  
96          Object[] titleArguments = new Object[] {
97              groupName, creatorUserName, receiverUserName, messageSubject
98          };
99  
100         String title = themeDisplay.translate(titlePattern, titleArguments);
101 
102         // Body
103 
104         String categoryLink =
105             themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
106                 "/message_boards/find_category?categoryId=" +
107                     message.getCategoryId();
108 
109         String body = wrapLink(categoryLink, "go-to-category", themeDisplay);
110 
111         return new SocialActivityFeedEntry(link, title, body);
112     }
113 
114     private static final String[] _CLASS_NAMES = new String[] {
115         MBMessage.class.getName()
116     };
117 
118 }