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.repository.model.FileEntry;
018    import com.liferay.portal.kernel.repository.model.Folder;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portlet.documentlibrary.model.DLFolder;
025    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
026    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
027    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
028    import com.liferay.portlet.social.model.SocialActivity;
029    import com.liferay.portlet.social.model.SocialActivityConstants;
030    import com.liferay.portlet.trash.util.TrashUtil;
031    
032    /**
033     * @author Zsolt Berentey
034     */
035    public class DLFolderActivityInterpreter extends BaseSocialActivityInterpreter {
036    
037            public String[] getClassNames() {
038                    return _CLASS_NAMES;
039            }
040    
041            @Override
042            protected String getEntryTitle(
043                            SocialActivity activity, ServiceContext serviceContext)
044                    throws Exception {
045    
046                    Folder folder = DLAppLocalServiceUtil.getFolder(activity.getClassPK());
047    
048                    if (folder.getModel() instanceof DLFolder) {
049                            DLFolder dlFolder = (DLFolder)folder.getModel();
050    
051                            if (dlFolder.isInTrash()) {
052                                    return TrashUtil.getOriginalTitle(folder.getName());
053                            }
054                    }
055    
056                    return folder.getName();
057            }
058    
059            protected String getFolderLink(
060                    FileEntry fileEntry, ThemeDisplay themeDisplay) {
061    
062                    StringBundler sb = new StringBundler(6);
063    
064                    sb.append(themeDisplay.getPortalURL());
065                    sb.append(themeDisplay.getPathMain());
066                    sb.append("/document_library/find_folder?groupId=");
067                    sb.append(fileEntry.getRepositoryId());
068                    sb.append("&folderId=");
069                    sb.append(fileEntry.getFolderId());
070    
071                    return sb.toString();
072            }
073    
074            @Override
075            protected String getPath(
076                    SocialActivity activity, ServiceContext serviceContext) {
077    
078                    return "/document_library/find_folder?folderId=" +
079                            activity.getClassPK();
080            }
081    
082            @Override
083            protected String getTitlePattern(
084                    String groupName, SocialActivity activity) {
085    
086                    int activityType = activity.getType();
087    
088                    if (activityType == SocialActivityConstants.TYPE_MOVE_TO_TRASH) {
089                            if (Validator.isNull(groupName)) {
090                                    return "activity-document-library-folder-move-to-trash";
091                            }
092                            else {
093                                    return "activity-document-library-folder-move-to-trash-in";
094                            }
095                    }
096                    else if (activityType ==
097                                            SocialActivityConstants.TYPE_RESTORE_FROM_TRASH) {
098    
099                            if (Validator.isNull(groupName)) {
100                                    return "activity-document-library-folder-restore-from-trash";
101                            }
102                            else {
103                                    return
104                                            "activity-document-library-folder-restore-from-trash-" +
105                                                    "in";
106                            }
107                    }
108    
109                    return null;
110            }
111    
112            @Override
113            protected boolean hasPermissions(
114                            PermissionChecker permissionChecker, SocialActivity activity,
115                            String actionId, ServiceContext serviceContext)
116                    throws Exception {
117    
118                    return DLFolderPermission.contains(
119                            permissionChecker, activity.getGroupId(), activity.getClassPK(),
120                            actionId);
121            }
122    
123            private static final String[] _CLASS_NAMES = {DLFolder.class.getName()};
124    
125    }