001    /**
002     * Copyright (c) 2000-2013 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.StringBundler;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.ServiceContext;
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    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Ryan Park
032     */
033    public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
034    
035            public String[] getClassNames() {
036                    return _CLASS_NAMES;
037            }
038    
039            @Override
040            protected String getEntryTitle(
041                            SocialActivity activity, ServiceContext serviceContext)
042                    throws Exception {
043    
044                    CalEvent event = CalEventLocalServiceUtil.getEvent(
045                            activity.getClassPK());
046    
047                    return getJSONValue(activity.getExtraData(), "title", event.getTitle());
048            }
049    
050            @Override
051            protected String getPath(
052                    SocialActivity activity, ServiceContext serviceContext) {
053    
054                    StringBundler sb = new StringBundler(4);
055    
056                    sb.append("/calendar/find_event?redirect=");
057                    sb.append(HtmlUtil.escapeURL(serviceContext.getCurrentURL()));
058                    sb.append("&eventId=");
059                    sb.append(activity.getClassPK());
060    
061                    return sb.toString();
062            }
063    
064            @Override
065            protected String getTitlePattern(
066                    String groupName, SocialActivity activity) {
067    
068                    int activityType = activity.getType();
069    
070                    if (activityType == CalendarActivityKeys.ADD_EVENT) {
071                            if (Validator.isNull(groupName)) {
072                                    return "activity-calendar-event-add-event";
073                            }
074                            else {
075                                    return "activity-calendar-event-add-event-in";
076                            }
077                    }
078                    else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
079                            if (Validator.isNull(groupName)) {
080                                    return "activity-calendar-event-update-event";
081                            }
082                            else {
083                                    return "activity-calendar-event-update-event-in";
084                            }
085                    }
086    
087                    return StringPool.BLANK;
088            }
089    
090            @Override
091            protected boolean hasPermissions(
092                            PermissionChecker permissionChecker, SocialActivity activity,
093                            String actionId, ServiceContext serviceContext)
094                    throws Exception {
095    
096                    return CalEventPermission.contains(
097                            permissionChecker, activity.getClassPK(), actionId);
098            }
099    
100            private static final String[] _CLASS_NAMES = {CalEvent.class.getName()};
101    
102    }