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.calendar.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.calendar.model.CalEvent;
28  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
29  import com.liferay.portlet.calendar.service.permission.CalEventPermission;
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="CalendarActivityInterpreter.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 CalendarActivityInterpreter 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 (!CalEventPermission.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  
69          int activityType = activity.getType();
70  
71          // Link
72  
73          CalEvent event = CalEventLocalServiceUtil.getEvent(
74              activity.getClassPK());
75  
76          String link =
77              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
78                  "/calendar/find_event?eventId=" + activity.getClassPK();
79  
80          // Title
81  
82          String titlePattern = null;
83  
84          if (activityType == CalendarActivityKeys.ADD_EVENT) {
85              titlePattern = "activity-calendar-add-event";
86          }
87          else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
88              titlePattern = "activity-calendar-update-event";
89          }
90  
91          if (Validator.isNotNull(groupName)) {
92              titlePattern += "-in";
93          }
94  
95          String eventTitle = wrapLink(link, cleanContent(event.getTitle()));
96  
97          Object[] titleArguments = new Object[] {
98              groupName, creatorUserName, eventTitle
99          };
100 
101         String title = themeDisplay.translate(titlePattern, titleArguments);
102 
103         // Body
104 
105         String body = StringPool.BLANK;
106 
107         return new SocialActivityFeedEntry(link, title, body);
108     }
109 
110     private static final String[] _CLASS_NAMES = new String[] {
111         CalEvent.class.getName()
112     };
113 
114 }