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.bookmarks.social;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.portal.security.permission.PermissionChecker;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
021    import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
022    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
023    import com.liferay.portlet.social.model.SocialActivity;
024    import com.liferay.portlet.social.model.SocialActivityConstants;
025    
026    /**
027     * @author Juan Fern??ndez
028     * @author Zsolt Berentey
029     */
030    public class BookmarksEntryActivityInterpreter
031            extends BaseSocialActivityInterpreter {
032    
033            @Override
034            public String[] getClassNames() {
035                    return _CLASS_NAMES;
036            }
037    
038            @Override
039            protected String getPath(
040                    SocialActivity activity, ServiceContext serviceContext) {
041    
042                    return "/bookmarks/find_entry?entryId=" + activity.getClassPK();
043            }
044    
045            @Override
046            protected String getTitlePattern(
047                    String groupName, SocialActivity activity) {
048    
049                    int activityType = activity.getType();
050    
051                    if (activityType == BookmarksActivityKeys.ADD_ENTRY) {
052                            if (Validator.isNull(groupName)) {
053                                    return "activity-bookmarks-entry-add-entry";
054                            }
055                            else {
056                                    return "activity-bookmarks-entry-add-entry-in";
057                            }
058                    }
059                    else if (activityType == BookmarksActivityKeys.UPDATE_ENTRY) {
060                            if (Validator.isNull(groupName)) {
061                                    return "activity-bookmarks-entry-update-entry";
062                            }
063                            else {
064                                    return "activity-bookmarks-entry-update-entry-in";
065                            }
066                    }
067                    else if (activityType == SocialActivityConstants.TYPE_MOVE_TO_TRASH) {
068                            if (Validator.isNull(groupName)) {
069                                    return "activity-bookmarks-entry-move-to-trash";
070                            }
071                            else {
072                                    return "activity-bookmarks-entry-move-to-trash-in";
073                            }
074                    }
075                    else if (activityType ==
076                                            SocialActivityConstants.TYPE_RESTORE_FROM_TRASH) {
077    
078                            if (Validator.isNull(groupName)) {
079                                    return "activity-bookmarks-entry-restore-from-trash";
080                            }
081                            else {
082                                    return "activity-bookmarks-entry-restore-from-trash-in";
083                            }
084                    }
085    
086                    return null;
087            }
088    
089            @Override
090            protected boolean hasPermissions(
091                            PermissionChecker permissionChecker, SocialActivity activity,
092                            String actionId, ServiceContext serviceContext)
093                    throws Exception {
094    
095                    return BookmarksEntryPermission.contains(
096                            permissionChecker, activity.getClassPK(), actionId);
097            }
098    
099            private static final String[] _CLASS_NAMES =
100                    {BookmarksEntry.class.getName()};
101    
102    }