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