Example #1
0
  public static com.liferay.portlet.messageboards.model.MBMessageSoap addMessage(
      long groupId,
      long categoryId,
      java.lang.String subject,
      java.lang.String body,
      java.lang.String format,
      java.util.List<
              com.liferay.portal.kernel.util.ObjectValuePair<java.lang.String, java.io.InputStream>>
          inputStreamOVPs,
      boolean anonymous,
      double priority,
      boolean allowPingbacks,
      com.liferay.portal.service.ServiceContext serviceContext)
      throws RemoteException {
    try {
      com.liferay.portlet.messageboards.model.MBMessage returnValue =
          MBMessageServiceUtil.addMessage(
              groupId,
              categoryId,
              subject,
              body,
              format,
              inputStreamOVPs,
              anonymous,
              priority,
              allowPingbacks,
              serviceContext);

      return com.liferay.portlet.messageboards.model.MBMessageSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public void deliver(String from, String recipient, Message message)
      throws MessageListenerException {

    try {
      StopWatch stopWatch = null;

      if (_log.isDebugEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();

        _log.debug("Deliver message from " + from + " to " + recipient);
      }

      String messageId = getMessageId(recipient, message);

      Company company = getCompany(messageId);

      if (_log.isDebugEnabled()) {
        _log.debug("Message id " + messageId);
      }

      long groupId = 0;
      long categoryId = getCategoryId(messageId);

      try {
        MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId);

        groupId = category.getGroupId();
      } catch (NoSuchCategoryException nsce) {
        groupId = categoryId;
        categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Group id " + groupId);
        _log.debug("Category id " + categoryId);
      }

      User user = UserLocalServiceUtil.getUserByEmailAddress(company.getCompanyId(), from);

      long parentMessageId = getParentMessageId(recipient, message);

      if (_log.isDebugEnabled()) {
        _log.debug("Parent message id " + parentMessageId);
      }

      MBMessage parentMessage = null;

      try {
        if (parentMessageId > 0) {
          parentMessage = MBMessageLocalServiceUtil.getMessage(parentMessageId);
        }
      } catch (NoSuchMessageException nsme) {

        // If the parent message does not exist we ignore it and post
        // the message as a new thread.

      }

      if (_log.isDebugEnabled()) {
        _log.debug("Parent message " + parentMessage);
      }

      String subject = MBUtil.getSubjectWithoutMessageId(message);

      MBMailMessage collector = new MBMailMessage();

      MBUtil.collectPartContent(message, collector);

      PermissionCheckerUtil.setThreadValues(user);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setLayoutFullURL(
          PortalUtil.getLayoutFullURL(groupId, PortletKeys.MESSAGE_BOARDS));
      serviceContext.setScopeGroupId(groupId);

      if (parentMessage == null) {
        MBMessageServiceUtil.addMessage(
            groupId,
            categoryId,
            subject,
            collector.getBody(),
            MBMessageConstants.DEFAULT_FORMAT,
            collector.getFiles(),
            false,
            0.0,
            true,
            serviceContext);
      } else {
        MBMessageServiceUtil.addMessage(
            groupId,
            categoryId,
            parentMessage.getThreadId(),
            parentMessage.getMessageId(),
            subject,
            collector.getBody(),
            MBMessageConstants.DEFAULT_FORMAT,
            collector.getFiles(),
            false,
            0.0,
            true,
            serviceContext);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Delivering message takes " + stopWatch.getTime() + " ms");
      }
    } catch (PrincipalException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug("Prevented unauthorized post from " + from);
      }

      throw new MessageListenerException(pe);
    } catch (Exception e) {
      _log.error(e, e);

      throw new MessageListenerException(e);
    } finally {
      PermissionCheckerUtil.setThreadValues(null);
    }
  }