public void addComments(Class<?> clazz, long classPK) throws SystemException { long classNameId = PortalUtil.getClassNameId(clazz); MBDiscussion discussion = MBDiscussionUtil.fetchByC_C(classNameId, classPK); if (discussion == null) { return; } List<MBMessage> messages = MBMessageLocalServiceUtil.getThreadMessages( discussion.getThreadId(), WorkflowConstants.STATUS_APPROVED); if (messages.size() == 0) { return; } for (MBMessage message : messages) { message.setUserUuid(message.getUserUuid()); addRatingsEntries(MBDiscussion.class, message.getPrimaryKey()); } _commentsMap.put(getPrimaryKeyString(clazz, classPK), messages); }
protected void importMBDiscussion(CalEvent calEvent, long calendarBookingId) throws PortalException, SystemException { MBDiscussion mbDiscussion = mbDiscussionPersistence.fetchByC_C( classNameLocalService.getClassNameId(CalEvent.class), calEvent.getEventId()); if (mbDiscussion == null) { return; } long threadId = importMBThread(mbDiscussion.getThreadId(), calendarBookingId); addMBDiscussion( PortalUUIDUtil.generate(), counterLocalService.increment(), mbDiscussion.getGroupId(), mbDiscussion.getCompanyId(), mbDiscussion.getUserId(), mbDiscussion.getUserName(), mbDiscussion.getCreateDate(), mbDiscussion.getModifiedDate(), classNameLocalService.getClassNameId(CalendarBooking.class.getName()), calendarBookingId, threadId); }
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())); } }
protected void addMBDiscussion( String uuid, long discussionId, long groupId, long companyId, long userId, String userName, Date createDate, Date modifiedDate, long classNameId, long classPK, long threadId) throws SystemException { MBDiscussion mbDiscussion = mbDiscussionPersistence.create(discussionId); mbDiscussion.setUuid(uuid); mbDiscussion.setGroupId(groupId); mbDiscussion.setCompanyId(companyId); mbDiscussion.setUserId(userId); mbDiscussion.setUserName(userName); mbDiscussion.setCreateDate(createDate); mbDiscussion.setModifiedDate(modifiedDate); mbDiscussion.setClassNameId(classNameId); mbDiscussion.setClassPK(classPK); mbDiscussion.setThreadId(threadId); mbDiscussionPersistence.update(mbDiscussion); }