public boolean accept(String from, String recipient, Message message) {
    try {
      String messageId = getMessageId(recipient, message);

      if ((messageId == null)
          || (!messageId.startsWith(MBUtil.MESSAGE_POP_PORTLET_PREFIX, getOffset()))) {

        return false;
      }

      Company company = getCompany(messageId);
      long categoryId = getCategoryId(messageId);

      MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId);

      if (category.getCompanyId() != company.getCompanyId()) {
        return false;
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Check to see if user " + from + " exists");
      }

      UserLocalServiceUtil.getUserByEmailAddress(company.getCompanyId(), from);

      return true;
    } catch (Exception e) {
      if (_log.isErrorEnabled()) {
        _log.error("Unable to process message: " + message, e);
      }

      return false;
    }
  }
Ejemplo n.º 2
0
  public static void addPortletBreadcrumbEntries(
      long categoryId, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    if ((categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
        || (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

      return;
    }

    MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId);

    addPortletBreadcrumbEntries(category, request, renderResponse);
  }
Ejemplo n.º 3
0
  public static List<Object> getEntries(Hits hits) {
    List<Object> entries = new ArrayList<Object>();

    for (Document document : hits.getDocs()) {
      long categoryId = GetterUtil.getLong(document.get(Field.CATEGORY_ID));

      try {
        MBCategoryLocalServiceUtil.getCategory(categoryId);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Message boards search index is stale and contains " + "category " + categoryId);
        }

        continue;
      }

      long threadId = GetterUtil.getLong(document.get("threadId"));

      try {
        MBThreadLocalServiceUtil.getThread(threadId);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn("Message boards search index is stale and contains " + "thread " + threadId);
        }

        continue;
      }

      String entryClassName = document.get(Field.ENTRY_CLASS_NAME);
      long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      Object obj = null;

      try {
        if (entryClassName.equals(DLFileEntry.class.getName())) {
          long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));

          MBMessageLocalServiceUtil.getMessage(classPK);

          obj = DLFileEntryLocalServiceUtil.getDLFileEntry(entryClassPK);
        } else if (entryClassName.equals(MBMessage.class.getName())) {
          obj = MBMessageLocalServiceUtil.getMessage(entryClassPK);
        }

        entries.add(obj);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Message boards search index is stale and contains "
                  + "entry {className="
                  + entryClassName
                  + ", "
                  + "classPK="
                  + entryClassPK
                  + "}");
        }

        continue;
      }
    }

    return entries;
  }
 @Override
 public MBCategory getCategory() throws PortalException, SystemException {
   return MBCategoryLocalServiceUtil.getCategory(getCategoryId());
 }
  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);
    }
  }