コード例 #1
0
  public static List<User> getThreadUsers(long userId, long mbThreadId)
      throws PortalException, SystemException {

    List<User> users = new ArrayList<User>();

    // Users who have contributed to the thread

    List<MBMessage> mbMessages =
        UserThreadServiceUtil.getThreadMessages(
            mbThreadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, false);

    for (MBMessage mbMessage : mbMessages) {
      if (userId == mbMessage.getUserId()) {
        continue;
      }

      User user = UserLocalServiceUtil.fetchUser(mbMessage.getUserId());

      if (user == null) {
        user = UserLocalServiceUtil.createUser(mbMessage.getUserId());

        user.setFirstName(mbMessage.getUserName());
        user.setStatus(WorkflowConstants.STATUS_INACTIVE);
      }

      if (!users.contains(user)) {
        users.add(user);
      }
    }

    // Users who can view the thread

    List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbThreadId);

    for (UserThread userThread : userThreads) {
      if (userId == userThread.getUserId()) {
        continue;
      }

      User user = UserLocalServiceUtil.fetchUser(userThread.getUserId());

      if (user == null) {
        user = UserLocalServiceUtil.createUser(userThread.getUserId());

        user.setFirstName(userThread.getUserName());
        user.setStatus(WorkflowConstants.STATUS_INACTIVE);
      }

      if (!users.contains(user)) {
        users.add(user);
      }
    }

    return users;
  }
コード例 #2
0
  protected long importMBMessage(
      MBMessage mbMessage, long threadId, long calendarBookingId, Map<Long, Long> mbMessageIds)
      throws PortalException, SystemException {

    Long messageId = mbMessageIds.get(mbMessage.getMessageId());

    if (messageId != null) {
      return messageId;
    }

    messageId = counterLocalService.increment();

    addMBMessage(
        PortalUUIDUtil.generate(),
        messageId,
        mbMessage.getGroupId(),
        mbMessage.getCompanyId(),
        mbMessage.getUserId(),
        mbMessage.getUserName(),
        mbMessage.getCreateDate(),
        mbMessage.getModifiedDate(),
        classNameLocalService.getClassNameId(CalendarBooking.class.getName()),
        calendarBookingId,
        mbMessage.getCategoryId(),
        threadId,
        mbMessage.getRootMessageId(),
        mbMessage.getParentMessageId(),
        mbMessage.getSubject(),
        mbMessage.getBody(),
        mbMessage.getFormat(),
        mbMessage.isAnonymous(),
        mbMessage.getPriority(),
        mbMessage.getAllowPingbacks(),
        mbMessage.isAnswer(),
        mbMessage.getStatus(),
        mbMessage.getStatusByUserId(),
        mbMessage.getStatusByUserName(),
        mbMessage.getStatusDate(),
        mbMessageIds);

    long mbDiscussionClassNameId =
        classNameLocalService.getClassNameId(MBDiscussion.class.getName());

    importRatings(
        mbDiscussionClassNameId, mbMessage.getMessageId(), mbDiscussionClassNameId, messageId);

    mbMessageIds.put(mbMessage.getMessageId(), messageId);

    return messageId;
  }
コード例 #3
0
  public static JSONObject toJSONObject(MBMessage model) {
    JSONObject jsonObj = new JSONObject();

    JSONUtil.put(jsonObj, "uuid", model.getUuid());
    JSONUtil.put(jsonObj, "messageId", model.getMessageId());
    JSONUtil.put(jsonObj, "companyId", model.getCompanyId());
    JSONUtil.put(jsonObj, "userId", model.getUserId());
    JSONUtil.put(jsonObj, "userName", model.getUserName());
    JSONUtil.put(jsonObj, "createDate", model.getCreateDate());
    JSONUtil.put(jsonObj, "modifiedDate", model.getModifiedDate());
    JSONUtil.put(jsonObj, "categoryId", model.getCategoryId());
    JSONUtil.put(jsonObj, "threadId", model.getThreadId());
    JSONUtil.put(jsonObj, "parentMessageId", model.getParentMessageId());
    JSONUtil.put(jsonObj, "subject", model.getSubject());
    JSONUtil.put(jsonObj, "body", model.getBody());
    JSONUtil.put(jsonObj, "attachments", model.getAttachments());
    JSONUtil.put(jsonObj, "anonymous", model.getAnonymous());

    return jsonObj;
  }
コード例 #4
0
  @Override
  public MBThread addThread(long categoryId, MBMessage message, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Thread

    Date now = new Date();

    long threadId = message.getThreadId();

    if (!message.isRoot() || (threadId <= 0)) {
      threadId = counterLocalService.increment();
    }

    MBThread thread = mbThreadPersistence.create(threadId);

    thread.setUuid(serviceContext.getUuid());
    thread.setGroupId(message.getGroupId());
    thread.setCompanyId(message.getCompanyId());
    thread.setUserId(message.getUserId());
    thread.setUserName(message.getUserName());
    thread.setCreateDate(serviceContext.getCreateDate(now));
    thread.setModifiedDate(serviceContext.getModifiedDate(now));
    thread.setCategoryId(categoryId);
    thread.setRootMessageId(message.getMessageId());
    thread.setRootMessageUserId(message.getUserId());

    if (message.isAnonymous()) {
      thread.setLastPostByUserId(0);
    } else {
      thread.setLastPostByUserId(message.getUserId());
    }

    thread.setLastPostDate(message.getCreateDate());

    if (message.getPriority() != MBThreadConstants.PRIORITY_NOT_GIVEN) {
      thread.setPriority(message.getPriority());
    }

    thread.setStatus(message.getStatus());
    thread.setStatusByUserId(message.getStatusByUserId());
    thread.setStatusByUserName(message.getStatusByUserName());
    thread.setStatusDate(message.getStatusDate());

    mbThreadPersistence.update(thread);

    // Asset

    if (categoryId >= 0) {
      assetEntryLocalService.updateEntry(
          message.getUserId(),
          message.getGroupId(),
          thread.getStatusDate(),
          thread.getLastPostDate(),
          MBThread.class.getName(),
          thread.getThreadId(),
          thread.getUuid(),
          0,
          new long[0],
          new String[0],
          false,
          null,
          null,
          null,
          null,
          String.valueOf(thread.getRootMessageId()),
          null,
          null,
          null,
          null,
          0,
          0,
          null,
          false);
    }

    return thread;
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, MBMessage message)
      throws Exception {

    long userId = portletDataContext.getUserId(message.getUserUuid());

    String userName = message.getUserName();

    Map<Long, Long> categoryIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBCategory.class);

    long parentCategoryId =
        MapUtil.getLong(categoryIds, message.getCategoryId(), message.getCategoryId());

    Map<Long, Long> threadIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBThread.class);

    long threadId = MapUtil.getLong(threadIds, message.getThreadId(), 0);

    Map<Long, Long> messageIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBMessage.class);

    long parentMessageId =
        MapUtil.getLong(messageIds, message.getParentMessageId(), message.getParentMessageId());

    Element element = portletDataContext.getImportDataStagedModelElement(message);

    List<ObjectValuePair<String, InputStream>> inputStreamOVPs =
        getAttachments(portletDataContext, element, message);

    try {
      ServiceContext serviceContext =
          portletDataContext.createServiceContext(message, MBPortletDataHandler.NAMESPACE);

      if (message.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
      }

      if ((parentCategoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
          && (parentCategoryId != MBCategoryConstants.DISCUSSION_CATEGORY_ID)
          && (parentCategoryId == message.getCategoryId())) {

        String categoryPath =
            ExportImportPathUtil.getModelPath(
                portletDataContext, MBCategory.class.getName(), parentCategoryId);

        MBCategory category = (MBCategory) portletDataContext.getZipEntryAsObject(categoryPath);

        StagedModelDataHandlerUtil.importStagedModel(portletDataContext, category);

        parentCategoryId =
            MapUtil.getLong(categoryIds, message.getCategoryId(), message.getCategoryId());
      }

      MBMessage importedMessage = null;

      if (portletDataContext.isDataStrategyMirror()) {
        MBMessage existingMessage =
            MBMessageUtil.fetchByUUID_G(message.getUuid(), portletDataContext.getScopeGroupId());

        if (existingMessage == null) {
          serviceContext.setUuid(message.getUuid());

          importedMessage =
              MBMessageLocalServiceUtil.addMessage(
                  userId,
                  userName,
                  portletDataContext.getScopeGroupId(),
                  parentCategoryId,
                  threadId,
                  parentMessageId,
                  message.getSubject(),
                  message.getBody(),
                  message.getFormat(),
                  inputStreamOVPs,
                  message.getAnonymous(),
                  message.getPriority(),
                  message.getAllowPingbacks(),
                  serviceContext);
        } else {
          importedMessage =
              MBMessageLocalServiceUtil.updateMessage(
                  userId,
                  existingMessage.getMessageId(),
                  message.getSubject(),
                  message.getBody(),
                  inputStreamOVPs,
                  new ArrayList<String>(),
                  message.getPriority(),
                  message.getAllowPingbacks(),
                  serviceContext);
        }
      } else {
        importedMessage =
            MBMessageLocalServiceUtil.addMessage(
                userId,
                userName,
                portletDataContext.getScopeGroupId(),
                parentCategoryId,
                threadId,
                parentMessageId,
                message.getSubject(),
                message.getBody(),
                message.getFormat(),
                inputStreamOVPs,
                message.getAnonymous(),
                message.getPriority(),
                message.getAllowPingbacks(),
                serviceContext);
      }

      importedMessage.setAnswer(message.getAnswer());

      if (importedMessage.isRoot()) {
        MBThreadLocalServiceUtil.updateQuestion(
            importedMessage.getThreadId(),
            GetterUtil.getBoolean(element.attributeValue("question")));
      }

      threadIds.put(message.getThreadId(), importedMessage.getThreadId());

      portletDataContext.importClassedModel(
          message, importedMessage, MBPortletDataHandler.NAMESPACE);
    } finally {
      for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {

        InputStream inputStream = inputStreamOVP.getValue();

        StreamUtil.cleanUp(inputStream);
      }
    }
  }
コード例 #6
0
  protected void mergeCategories(MBCategory fromCategory, long toCategoryId)
      throws PortalException, SystemException {

    Iterator itr =
        mbCategoryPersistence
            .findByG_P(fromCategory.getGroupId(), fromCategory.getCategoryId())
            .iterator();

    while (itr.hasNext()) {
      MBCategory category = (MBCategory) itr.next();

      mergeCategories(category, toCategoryId);
    }

    Iterator itr1 = mbThreadPersistence.findByCategoryId(fromCategory.getCategoryId()).iterator();

    while (itr1.hasNext()) {

      // Thread

      MBThread thread = (MBThread) itr1.next();

      thread.setCategoryId(toCategoryId);

      mbThreadPersistence.update(thread);

      Iterator itr2 = mbMessagePersistence.findByThreadId(thread.getThreadId()).iterator();

      while (itr2.hasNext()) {

        // Message

        MBMessage message = (MBMessage) itr2.next();

        message.setCategoryId(toCategoryId);

        mbMessagePersistence.update(message);

        // Lucene

        try {
          if (!fromCategory.isDiscussion()) {
            String[] tagsEntries =
                tagsEntryLocalService.getEntryNames(
                    MBMessage.class.getName(), message.getMessageId());

            Indexer.updateMessage(
                message.getCompanyId(),
                fromCategory.getGroupId(),
                message.getUserName(),
                toCategoryId,
                message.getThreadId(),
                message.getMessageId(),
                message.getSubject(),
                message.getBody(),
                tagsEntries);
          }
        } catch (IOException ioe) {
          _log.error("Indexing " + message.getMessageId(), ioe);
        }
      }
    }

    mbCategoryPersistence.remove(fromCategory.getCategoryId());
  }
コード例 #7
0
  public void reIndex(String[] ids) throws SystemException {
    if (LuceneUtil.INDEX_READ_ONLY) {
      return;
    }

    long companyId = GetterUtil.getLong(ids[0]);

    IndexWriter writer = null;

    try {
      writer = LuceneUtil.getWriter(companyId);

      Iterator itr1 = mbCategoryPersistence.findByCompanyId(companyId).iterator();

      while (itr1.hasNext()) {
        MBCategory category = (MBCategory) itr1.next();

        long categoryId = category.getCategoryId();

        Iterator itr2 = mbMessagePersistence.findByCategoryId(categoryId).iterator();

        while (itr2.hasNext()) {
          MBMessage message = (MBMessage) itr2.next();

          long groupId = category.getGroupId();
          String userName = message.getUserName();
          long threadId = message.getThreadId();
          long messageId = message.getMessageId();
          String title = message.getSubject();
          String content = message.getBody();

          String[] tagsEntries =
              tagsEntryLocalService.getEntryNames(MBMessage.class.getName(), messageId);

          try {
            Document doc =
                Indexer.getAddMessageDocument(
                    companyId,
                    groupId,
                    userName,
                    categoryId,
                    threadId,
                    messageId,
                    title,
                    content,
                    tagsEntries);

            writer.addDocument(doc);
          } catch (Exception e1) {
            _log.error("Reindexing " + messageId, e1);
          }
        }
      }
    } catch (SystemException se) {
      throw se;
    } catch (Exception e2) {
      throw new SystemException(e2);
    } finally {
      try {
        if (writer != null) {
          LuceneUtil.write(companyId);
        }
      } catch (Exception e) {
        _log.error(e);
      }
    }
  }
コード例 #8
0
  public void importComments(Class<?> clazz, long classPK, long newClassPK, long groupId)
      throws PortalException, SystemException {

    Map<Long, Long> messagePKs = new HashMap<Long, Long>();
    Map<Long, Long> threadPKs = new HashMap<Long, Long>();

    List<MBMessage> messages = _commentsMap.get(getPrimaryKeyString(clazz, classPK));

    if (messages == null) {
      return;
    }

    MBDiscussion discussion = null;

    try {
      discussion = MBDiscussionLocalServiceUtil.getDiscussion(clazz.getName(), newClassPK);
    } catch (NoSuchDiscussionException nsde) {
    }

    for (MBMessage message : messages) {
      long userId = getUserId(message.getUserUuid());
      long parentMessageId =
          MapUtil.getLong(messagePKs, message.getParentMessageId(), message.getParentMessageId());
      long threadId = MapUtil.getLong(threadPKs, message.getThreadId(), message.getThreadId());

      if ((message.getParentMessageId() == MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID)
          && (discussion != null)) {

        MBThread thread = MBThreadLocalServiceUtil.getThread(discussion.getThreadId());

        long rootMessageId = thread.getRootMessageId();

        messagePKs.put(message.getMessageId(), rootMessageId);
        threadPKs.put(message.getThreadId(), thread.getThreadId());
      } else {
        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setCreateDate(message.getCreateDate());
        serviceContext.setModifiedDate(message.getModifiedDate());
        serviceContext.setScopeGroupId(groupId);

        MBMessage importedMessage = null;

        if (_dataStrategy.equals(PortletDataHandlerKeys.DATA_STRATEGY_MIRROR)
            || _dataStrategy.equals(PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE)) {

          MBMessage existingMessage = MBMessageUtil.fetchByUUID_G(message.getUuid(), groupId);

          if (existingMessage == null) {
            serviceContext.setUuid(message.getUuid());

            importedMessage =
                MBMessageLocalServiceUtil.addDiscussionMessage(
                    userId,
                    message.getUserName(),
                    groupId,
                    clazz.getName(),
                    newClassPK,
                    threadId,
                    parentMessageId,
                    message.getSubject(),
                    message.getBody(),
                    serviceContext);
          } else {
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

            importedMessage =
                MBMessageLocalServiceUtil.updateDiscussionMessage(
                    userId,
                    existingMessage.getMessageId(),
                    clazz.getName(),
                    newClassPK,
                    message.getSubject(),
                    message.getBody(),
                    serviceContext);
          }
        } else {
          importedMessage =
              MBMessageLocalServiceUtil.addDiscussionMessage(
                  userId,
                  message.getUserName(),
                  groupId,
                  clazz.getName(),
                  newClassPK,
                  threadId,
                  parentMessageId,
                  message.getSubject(),
                  message.getBody(),
                  serviceContext);
        }

        messagePKs.put(message.getMessageId(), importedMessage.getMessageId());
        threadPKs.put(message.getThreadId(), importedMessage.getThreadId());
      }

      importRatingsEntries(
          MBDiscussion.class, message.getPrimaryKey(), messagePKs.get(message.getPrimaryKey()));
    }
  }
コード例 #9
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    MBMessage newMBMessage = _persistence.create(pk);

    newMBMessage.setUuid(RandomTestUtil.randomString());

    newMBMessage.setGroupId(RandomTestUtil.nextLong());

    newMBMessage.setCompanyId(RandomTestUtil.nextLong());

    newMBMessage.setUserId(RandomTestUtil.nextLong());

    newMBMessage.setUserName(RandomTestUtil.randomString());

    newMBMessage.setCreateDate(RandomTestUtil.nextDate());

    newMBMessage.setModifiedDate(RandomTestUtil.nextDate());

    newMBMessage.setClassNameId(RandomTestUtil.nextLong());

    newMBMessage.setClassPK(RandomTestUtil.nextLong());

    newMBMessage.setCategoryId(RandomTestUtil.nextLong());

    newMBMessage.setThreadId(RandomTestUtil.nextLong());

    newMBMessage.setRootMessageId(RandomTestUtil.nextLong());

    newMBMessage.setParentMessageId(RandomTestUtil.nextLong());

    newMBMessage.setSubject(RandomTestUtil.randomString());

    newMBMessage.setBody(RandomTestUtil.randomString());

    newMBMessage.setFormat(RandomTestUtil.randomString());

    newMBMessage.setAnonymous(RandomTestUtil.randomBoolean());

    newMBMessage.setPriority(RandomTestUtil.nextDouble());

    newMBMessage.setAllowPingbacks(RandomTestUtil.randomBoolean());

    newMBMessage.setAnswer(RandomTestUtil.randomBoolean());

    newMBMessage.setStatus(RandomTestUtil.nextInt());

    newMBMessage.setStatusByUserId(RandomTestUtil.nextLong());

    newMBMessage.setStatusByUserName(RandomTestUtil.randomString());

    newMBMessage.setStatusDate(RandomTestUtil.nextDate());

    _mbMessages.add(_persistence.update(newMBMessage));

    MBMessage existingMBMessage = _persistence.findByPrimaryKey(newMBMessage.getPrimaryKey());

    Assert.assertEquals(existingMBMessage.getUuid(), newMBMessage.getUuid());
    Assert.assertEquals(existingMBMessage.getMessageId(), newMBMessage.getMessageId());
    Assert.assertEquals(existingMBMessage.getGroupId(), newMBMessage.getGroupId());
    Assert.assertEquals(existingMBMessage.getCompanyId(), newMBMessage.getCompanyId());
    Assert.assertEquals(existingMBMessage.getUserId(), newMBMessage.getUserId());
    Assert.assertEquals(existingMBMessage.getUserName(), newMBMessage.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBMessage.getCreateDate()),
        Time.getShortTimestamp(newMBMessage.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBMessage.getModifiedDate()),
        Time.getShortTimestamp(newMBMessage.getModifiedDate()));
    Assert.assertEquals(existingMBMessage.getClassNameId(), newMBMessage.getClassNameId());
    Assert.assertEquals(existingMBMessage.getClassPK(), newMBMessage.getClassPK());
    Assert.assertEquals(existingMBMessage.getCategoryId(), newMBMessage.getCategoryId());
    Assert.assertEquals(existingMBMessage.getThreadId(), newMBMessage.getThreadId());
    Assert.assertEquals(existingMBMessage.getRootMessageId(), newMBMessage.getRootMessageId());
    Assert.assertEquals(existingMBMessage.getParentMessageId(), newMBMessage.getParentMessageId());
    Assert.assertEquals(existingMBMessage.getSubject(), newMBMessage.getSubject());
    Assert.assertEquals(existingMBMessage.getBody(), newMBMessage.getBody());
    Assert.assertEquals(existingMBMessage.getFormat(), newMBMessage.getFormat());
    Assert.assertEquals(existingMBMessage.getAnonymous(), newMBMessage.getAnonymous());
    AssertUtils.assertEquals(existingMBMessage.getPriority(), newMBMessage.getPriority());
    Assert.assertEquals(existingMBMessage.getAllowPingbacks(), newMBMessage.getAllowPingbacks());
    Assert.assertEquals(existingMBMessage.getAnswer(), newMBMessage.getAnswer());
    Assert.assertEquals(existingMBMessage.getStatus(), newMBMessage.getStatus());
    Assert.assertEquals(existingMBMessage.getStatusByUserId(), newMBMessage.getStatusByUserId());
    Assert.assertEquals(
        existingMBMessage.getStatusByUserName(), newMBMessage.getStatusByUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingMBMessage.getStatusDate()),
        Time.getShortTimestamp(newMBMessage.getStatusDate()));
  }