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