001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.util.HttpUtil;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.security.permission.ActionKeys;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
026    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
027    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
028    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
029    import com.liferay.portlet.social.model.SocialActivity;
030    import com.liferay.portlet.social.model.SocialActivityFeedEntry;
031    
032    /**
033     * @author Ryan Park
034     */
035    public class DLActivityInterpreter extends BaseSocialActivityInterpreter {
036    
037            public String[] getClassNames() {
038                    return _CLASS_NAMES;
039            }
040    
041            @Override
042            protected SocialActivityFeedEntry doInterpret(
043                            SocialActivity activity, ThemeDisplay themeDisplay)
044                    throws Exception {
045    
046                    PermissionChecker permissionChecker =
047                            themeDisplay.getPermissionChecker();
048    
049                    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
050                            activity.getClassPK());
051    
052                    if (!DLFileEntryPermission.contains(
053                                    permissionChecker, fileEntry.getFileEntryId(),
054                                    ActionKeys.VIEW)) {
055    
056                            return null;
057                    }
058    
059                    String groupName = StringPool.BLANK;
060    
061                    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
062                            groupName = getGroupName(activity.getGroupId(), themeDisplay);
063                    }
064    
065                    String creatorUserName = getUserName(
066                            activity.getUserId(), themeDisplay);
067    
068                    int activityType = activity.getType();
069    
070                    // Link
071    
072                    String link =
073                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
074                                    "/document_library/get_file?groupId=" +
075                                            fileEntry.getRepositoryId() + "&folderId=" +
076                                                    fileEntry.getFolderId() + "&title=" +
077                                                            HttpUtil.encodeURL(fileEntry.getTitle());
078    
079                    // Title
080    
081                    String titlePattern = null;
082    
083                    if (activityType == DLActivityKeys.ADD_FILE_ENTRY) {
084                            titlePattern = "activity-document-library-add-file";
085                    }
086                    else if (activityType == DLActivityKeys.UPDATE_FILE_ENTRY) {
087                            titlePattern = "activity-document-library-update-file";
088                    }
089    
090                    if (Validator.isNotNull(groupName)) {
091                            titlePattern += "-in";
092                    }
093    
094                    String fileTitle = getValue(
095                            activity.getExtraData(), "title", fileEntry.getTitle());
096    
097                    Object[] titleArguments = new Object[] {
098                            groupName, creatorUserName, wrapLink(link, fileTitle)
099                    };
100    
101                    String title = themeDisplay.translate(titlePattern, titleArguments);
102    
103                    // Body
104    
105                    StringBundler sb = new StringBundler(3);
106    
107                    String fileEntryLink =
108                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
109                                    "/document_library/find_file_entry?fileEntryId=" +
110                                            fileEntry.getFileEntryId();
111    
112                    sb.append(wrapLink(fileEntryLink, "view-document", themeDisplay));
113                    sb.append(StringPool.SPACE);
114    
115                    String folderLink =
116                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
117                                    "/document_library/find_folder?groupId=" +
118                                            fileEntry.getRepositoryId() + "&folderId=" +
119                                                    fileEntry.getFolderId();
120    
121                    sb.append(wrapLink(folderLink, "go-to-folder", themeDisplay));
122    
123                    String body = sb.toString();
124    
125                    return new SocialActivityFeedEntry(link, title, body);
126            }
127    
128            private static final String[] _CLASS_NAMES = new String[] {
129                    DLFileEntry.class.getName()
130            };
131    
132    }