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