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.documentlibrary.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.documentlibrary.model.DLFolder;
021    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
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 DLFolderActivityInterpreter extends BaseSocialActivityInterpreter {
030    
031            @Override
032            public String[] getClassNames() {
033                    return _CLASS_NAMES;
034            }
035    
036            @Override
037            protected String getPath(
038                    SocialActivity activity, ServiceContext serviceContext) {
039    
040                    return "/document_library/find_folder?folderId=" +
041                            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-document-library-folder-move-to-trash";
053                            }
054                            else {
055                                    return "activity-document-library-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-document-library-folder-restore-from-trash";
063                            }
064                            else {
065                                    return
066                                            "activity-document-library-folder-restore-from-trash-" +
067                                                    "in";
068                            }
069                    }
070    
071                    return null;
072            }
073    
074            @Override
075            protected boolean hasPermissions(
076                            PermissionChecker permissionChecker, SocialActivity activity,
077                            String actionId, ServiceContext serviceContext)
078                    throws Exception {
079    
080                    return DLFolderPermission.contains(
081                            permissionChecker, activity.getGroupId(), activity.getClassPK(),
082                            actionId);
083            }
084    
085            private static final String[] _CLASS_NAMES = {DLFolder.class.getName()};
086    
087    }