001    /**
002     * Copyright (c) 2000-2013 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.bookmarks.social;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
023    import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
024    import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
025    import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
026    import com.liferay.portlet.social.model.SocialActivity;
027    import com.liferay.portlet.social.model.SocialActivityFeedEntry;
028    
029    /**
030     * @author Juan Fern??ndez
031     */
032    public class BookmarksActivityInterpreter
033            extends BaseSocialActivityInterpreter {
034    
035            @Override
036            public String[] getClassNames() {
037                    return _CLASS_NAMES;
038            }
039    
040            @Override
041            protected SocialActivityFeedEntry doInterpret(
042                            SocialActivity activity, ThemeDisplay themeDisplay)
043                    throws Exception {
044    
045                    PermissionChecker permissionChecker =
046                            themeDisplay.getPermissionChecker();
047    
048                    if (!BookmarksEntryPermission.contains(
049                                    permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
050    
051                            return null;
052                    }
053    
054                    String groupName = StringPool.BLANK;
055    
056                    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
057                            groupName = getGroupName(activity.getGroupId(), themeDisplay);
058                    }
059    
060                    String creatorUserName = getUserName(
061                            activity.getUserId(), themeDisplay);
062                    String receiverUserName = getUserName(
063                            activity.getReceiverUserId(), themeDisplay);
064    
065                    int activityType = activity.getType();
066    
067                    // Link
068    
069                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(
070                            activity.getClassPK());
071    
072                    String link =
073                            themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
074                                    "/bookmarks/find_entry?entryId=" + activity.getClassPK();
075    
076                    // Title
077    
078                    String titlePattern = null;
079    
080                    if (activityType == BookmarksActivityKeys.ADD_ENTRY) {
081                            titlePattern = "activity-bookmarks-add-entry";
082                    }
083                    else if (activityType == BookmarksActivityKeys.UPDATE_ENTRY) {
084                            titlePattern = "activity-bookmarks-update-entry";
085                    }
086    
087                    if (Validator.isNotNull(groupName)) {
088                            titlePattern += "-in";
089                    }
090    
091                    String entryTitle = getValue(
092                            activity.getExtraData(), "title", entry.getName());
093    
094                    Object[] titleArguments = new Object[] {
095                            groupName, creatorUserName, receiverUserName,
096                            wrapLink(link, entryTitle)
097                    };
098    
099                    String title = themeDisplay.translate(titlePattern, titleArguments);
100    
101                    // Body
102    
103                    String body = StringPool.BLANK;
104    
105                    return new SocialActivityFeedEntry(link, title, body);
106            }
107    
108            private static final String[] _CLASS_NAMES = new String[] {
109                    BookmarksEntry.class.getName()
110            };
111    
112    }