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