/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This file is part of Liferay Social Office. Liferay Social Office is free * software: you can redistribute it and/or modify it under the terms of the GNU * Affero General Public License as published by the Free Software Foundation, * either version 3 of the License, or (at your option) any later version. * * Liferay Social Office is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License * for more details. * * You should have received a copy of the GNU General Public License along with * Liferay Social Office. If not, see http://www.gnu.org/licenses/agpl-3.0.html. */ package com.liferay.contacts.contactscenter.social; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.service.UserLocalServiceUtil; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.social.kernel.model.BaseSocialRequestInterpreter; import com.liferay.social.kernel.model.SocialRelationConstants; import com.liferay.social.kernel.model.SocialRequest; import com.liferay.social.kernel.model.SocialRequestFeedEntry; import com.liferay.social.kernel.service.SocialActivityLocalServiceUtil; import com.liferay.social.kernel.service.SocialRelationLocalServiceUtil; /** * @author Hai Yu */ public class ContactsCenterRequestInterpreter extends BaseSocialRequestInterpreter { @Override public String[] getClassNames() { return _CLASS_NAMES; } @Override protected SocialRequestFeedEntry doInterpret( SocialRequest request, ThemeDisplay themeDisplay) throws Exception { if (request.getType() != SocialRelationConstants.TYPE_BI_CONNECTION) { return new SocialRequestFeedEntry( StringPool.BLANK, StringPool.BLANK); } StringBundler sb = new StringBundler(8); sb.append("<a href=\""); sb.append(themeDisplay.getPortalURL()); sb.append(themeDisplay.getPathFriendlyURLPublic()); sb.append(StringPool.SLASH); User creatorUser = UserLocalServiceUtil.getUserById( request.getUserId()); sb.append(creatorUser.getScreenName()); sb.append("/profile\">"); sb.append(getUserName(request.getUserId(), themeDisplay)); sb.append("</a>"); String creatorUserNameURL = sb.toString(); String title = themeDisplay.translate( "request-social-networking-summary-add-connection", new Object[] {creatorUserNameURL}); return new SocialRequestFeedEntry(title, StringPool.BLANK); } @Override protected boolean doProcessConfirmation( SocialRequest request, ThemeDisplay themeDisplay) { try { SocialRelationLocalServiceUtil.addRelation( request.getUserId(), request.getReceiverUserId(), SocialRelationConstants.TYPE_BI_CONNECTION); SocialActivityLocalServiceUtil.addActivity( request.getUserId(), 0, User.class.getName(), request.getUserId(), SocialRelationConstants.TYPE_BI_CONNECTION, StringPool.BLANK, request.getReceiverUserId()); } catch (Exception e) { _log.error(e, e); } return true; } private static final String[] _CLASS_NAMES = new String[] {User.class.getName()}; private static Log _log = LogFactoryUtil.getLog( ContactsCenterRequestInterpreter.class); }