Package com.liferay.socialnetworking.friends.social

Source Code of com.liferay.socialnetworking.friends.social.FriendsRequestInterpreter

/**
* Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library 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 Lesser General Public License for more
* details.
*/

package com.liferay.socialnetworking.friends.social;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.social.model.BaseSocialRequestInterpreter;
import com.liferay.portlet.social.model.SocialRelationConstants;
import com.liferay.portlet.social.model.SocialRequest;
import com.liferay.portlet.social.model.SocialRequestFeedEntry;
import com.liferay.portlet.social.service.SocialActivityLocalServiceUtil;
import com.liferay.portlet.social.service.SocialRelationLocalServiceUtil;

/**
* @author Brian Wing Shun Chan
*/
public class FriendsRequestInterpreter extends BaseSocialRequestInterpreter {

  public String[] getClassNames() {
    return _CLASS_NAMES;
  }

  protected SocialRequestFeedEntry doInterpret(
      SocialRequest request, ThemeDisplay themeDisplay)
    throws Exception {

    String creatorUserName = getUserName(
      request.getUserId(), themeDisplay);

    User creatorUser = UserLocalServiceUtil.getUserById(
      request.getUserId());

    int requestType = request.getType();

    // Title

    String title = StringPool.BLANK;

    if (requestType == FriendsRequestKeys.ADD_FRIEND) {
      StringBuilder sb = new StringBuilder();

      sb.append("<a href=\"");
      sb.append(themeDisplay.getPortalURL());
      sb.append(themeDisplay.getPathFriendlyURLPublic());
      sb.append(StringPool.SLASH);
      sb.append(creatorUser.getScreenName());
      sb.append("/profile\">");
      sb.append(creatorUserName);
      sb.append("</a>");

      String creatorUserNameURL = sb.toString();

      title = themeDisplay.translate(
        "request-social-networking-summary-add-friend",
        new Object[] {creatorUserNameURL});
    }

    // Body

    String body = StringPool.BLANK;

    return new SocialRequestFeedEntry(title, body);
  }

  protected boolean doProcessConfirmation(
    SocialRequest request, ThemeDisplay themeDisplay) {

    try {
      SocialRelationLocalServiceUtil.addRelation(
        request.getUserId(), request.getReceiverUserId(),
        SocialRelationConstants.TYPE_BI_FRIEND);

      SocialActivityLocalServiceUtil.addActivity(
        request.getUserId(), 0, User.class.getName(),
        request.getUserId(), FriendsActivityKeys.ADD_FRIEND,
        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(
    FriendsRequestInterpreter.class);

}
TOP

Related Classes of com.liferay.socialnetworking.friends.social.FriendsRequestInterpreter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.