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.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    }