001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.calendar.social;
016    
017    import com.liferay.portal.kernel.util.HtmlUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.calendar.model.CalEvent;
024    import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
025    import com.liferay.portlet.calendar.service.permission.CalEventPermission;
026    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
027    import com.liferay.portlet.social.model.SocialActivity;
028    import com.liferay.portlet.social.model.SocialActivityFeedEntry;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Ryan Park
033     */
034    public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
035    
036            public String[] getClassNames() {
037                    return _CLASS_NAMES;
038            }
039    
040            @Override
041            protected SocialActivityFeedEntry doInterpret(
042                            SocialActivity activity, ThemeDisplay themeDisplay)
043                    throws Exception {
044    
045                    PermissionChecker permissionChecker =
046                            themeDisplay.getPermissionChecker();
047    
048                    if (!CalEventPermission.contains(
049                                    permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
050    
051                            return null;
052                    }
053    
054                    String groupName = StringPool.BLANK;
055    
056                    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
057                            groupName = getGroupName(activity.getGroupId(), themeDisplay);
058                    }
059    
060                    String creatorUserName = getUserName(
061                            activity.getUserId(), themeDisplay);
062    
063                    int activityType = activity.getType();
064    
065                    // Link
066    
067                    CalEvent event = CalEventLocalServiceUtil.getEvent(
068                            activity.getClassPK());
069    
070                    String link =
071                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
072                                    "/calendar/find_event?redirect=" +
073                                            HtmlUtil.escapeURL(themeDisplay.getURLCurrent()) +
074                                                    "&eventId=" + activity.getClassPK();
075    
076                    // Title
077    
078                    String titlePattern = null;
079    
080                    if (activityType == CalendarActivityKeys.ADD_EVENT) {
081                            titlePattern = "activity-calendar-add-event";
082                    }
083                    else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
084                            titlePattern = "activity-calendar-update-event";
085                    }
086    
087                    if (Validator.isNotNull(groupName)) {
088                            titlePattern += "-in";
089                    }
090    
091                    String eventTitle = wrapLink(
092                            link, HtmlUtil.escape(cleanContent(event.getTitle())));
093    
094                    Object[] titleArguments = new Object[] {
095                            groupName, creatorUserName, eventTitle
096                    };
097    
098                    String title = themeDisplay.translate(titlePattern, titleArguments);
099    
100                    // Body
101    
102                    String body = StringPool.BLANK;
103    
104                    return new SocialActivityFeedEntry(link, title, body);
105            }
106    
107            private static final String[] _CLASS_NAMES = new String[] {
108                    CalEvent.class.getName()
109            };
110    
111    }