1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.calendar.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.calendar.model.CalEvent;
31  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
32  import com.liferay.portlet.calendar.service.permission.CalEventPermission;
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="CalendarActivityInterpreter.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   * @author Ryan Park
42   *
43   */
44  public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
45  
46      public String[] getClassNames() {
47          return _CLASS_NAMES;
48      }
49  
50      protected SocialActivityFeedEntry doInterpret(
51              SocialActivity activity, ThemeDisplay themeDisplay)
52          throws Exception {
53  
54          PermissionChecker permissionChecker =
55              themeDisplay.getPermissionChecker();
56  
57          if (!CalEventPermission.contains(
58                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
59  
60              return null;
61          }
62  
63          String groupName = StringPool.BLANK;
64  
65          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
66              groupName = getGroupName(activity.getGroupId(), themeDisplay);
67          }
68  
69          String creatorUserName = getUserName(
70              activity.getUserId(), themeDisplay);
71  
72          int activityType = activity.getType();
73  
74          // Link
75  
76          CalEvent event = CalEventLocalServiceUtil.getEvent(
77              activity.getClassPK());
78  
79          String link =
80              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
81                  "/calendar/find_event?eventId=" + activity.getClassPK();
82  
83          // Title
84  
85          String titlePattern = null;
86  
87          if (activityType == CalendarActivityKeys.ADD_EVENT) {
88              titlePattern = "activity-calendar-add-event";
89          }
90          else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
91              titlePattern = "activity-calendar-update-event";
92          }
93  
94          if (Validator.isNotNull(groupName)) {
95              titlePattern += "-in";
96          }
97  
98          String eventTitle = wrapLink(link, cleanContent(event.getTitle()));
99  
100         Object[] titleArguments = new Object[] {
101             groupName, creatorUserName, eventTitle
102         };
103 
104         String title = themeDisplay.translate(titlePattern, titleArguments);
105 
106         // Body
107 
108         String body = StringPool.BLANK;
109 
110         return new SocialActivityFeedEntry(link, title, body);
111     }
112 
113     private static final String[] _CLASS_NAMES = new String[] {
114         CalEvent.class.getName()
115     };
116 
117 }