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.JournalFolderLocalServiceUtil;
022    import com.liferay.portlet.journal.service.permission.JournalFolderPermission;
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    import com.liferay.portlet.trash.util.TrashUtil;
027    
028    /**
029     * @author Zsolt Berentey
030     */
031    public class JournalFolderActivityInterpreter
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                    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(
044                            activity.getClassPK());
045    
046                    if (folder.isInTrash()) {
047                            return TrashUtil.getOriginalTitle(folder.getName());
048                    }
049    
050                    return folder.getName();
051            }
052    
053            @Override
054            protected String getPath(
055                    SocialActivity activity, ServiceContext serviceContext) {
056    
057                    return "/journal/find_folder?folderId=" + activity.getClassPK();
058            }
059    
060            @Override
061            protected String getTitlePattern(
062                    String groupName, SocialActivity activity) {
063    
064                    int activityType = activity.getType();
065    
066                    if (activityType == SocialActivityConstants.TYPE_MOVE_TO_TRASH) {
067                            if (Validator.isNull(groupName)) {
068                                    return "activity-journal-folder-move-to-trash";
069                            }
070                            else {
071                                    return "activity-journal-folder-move-to-trash-in";
072                            }
073                    }
074                    else if (activityType ==
075                                            SocialActivityConstants.TYPE_RESTORE_FROM_TRASH) {
076    
077                            if (Validator.isNull(groupName)) {
078                                    return "activity-journal-folder-restore-from-trash";
079                            }
080                            else {
081                                    return "activity-journal-folder-restore-from-trash-in";
082                            }
083                    }
084    
085                    return null;
086            }
087    
088            @Override
089            protected boolean hasPermissions(
090                            PermissionChecker permissionChecker, SocialActivity activity,
091                            String actionId, ServiceContext serviceContext)
092                    throws Exception {
093    
094                    return JournalFolderPermission.contains(
095                            permissionChecker, activity.getGroupId(), activity.getClassPK(),
096                            actionId);
097            }
098    
099            private static final String[] _CLASS_NAMES =
100                    {JournalFolder.class.getName()};
101    
102    }