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