@Override
  public MBMessage addMessage(
      long parentMessageId,
      String subject,
      String body,
      String format,
      List<ObjectValuePair<String, InputStream>> inputStreamOVPs,
      boolean anonymous,
      double priority,
      boolean allowPingbacks,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    MBMessage parentMessage = mbMessagePersistence.findByPrimaryKey(parentMessageId);

    checkReplyToPermission(
        parentMessage.getGroupId(), parentMessage.getCategoryId(), parentMessageId);

    boolean preview = ParamUtil.getBoolean(serviceContext, "preview");

    int workFlowAction = serviceContext.getWorkflowAction();

    if ((workFlowAction == WorkflowConstants.STATUS_DRAFT)
        && !preview
        && !serviceContext.isSignedIn()) {

      MBMessagePermission.check(getPermissionChecker(), parentMessageId, ActionKeys.UPDATE);
    }

    if (lockLocalService.isLocked(MBThread.class.getName(), parentMessage.getThreadId())) {

      throw new LockedThreadException();
    }

    if (!MBCategoryPermission.contains(
        getPermissionChecker(),
        parentMessage.getGroupId(),
        parentMessage.getCategoryId(),
        ActionKeys.ADD_FILE)) {

      inputStreamOVPs = Collections.emptyList();
    }

    if (!MBCategoryPermission.contains(
        getPermissionChecker(),
        parentMessage.getGroupId(),
        parentMessage.getCategoryId(),
        ActionKeys.UPDATE_THREAD_PRIORITY)) {

      priority = MBThreadConstants.PRIORITY_NOT_GIVEN;
    }

    return mbMessageLocalService.addMessage(
        getGuestOrUserId(),
        null,
        parentMessage.getGroupId(),
        parentMessage.getCategoryId(),
        parentMessage.getThreadId(),
        parentMessageId,
        subject,
        body,
        format,
        inputStreamOVPs,
        anonymous,
        priority,
        allowPingbacks,
        serviceContext);
  }
  public void merge(ServiceContext serviceContext) {
    setAddGroupPermissions(serviceContext.isAddGroupPermissions());
    setAddGuestPermissions(serviceContext.isAddGuestPermissions());

    if (serviceContext.getAssetCategoryIds() != null) {
      setAssetCategoryIds(serviceContext.getAssetCategoryIds());
    }

    if (serviceContext.getAssetLinkEntryIds() != null) {
      setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds());
    }

    if (serviceContext.getAssetTagNames() != null) {
      setAssetTagNames(serviceContext.getAssetTagNames());
    }

    if (serviceContext.getAttributes() != null) {
      setAttributes(serviceContext.getAttributes());
    }

    if (Validator.isNotNull(serviceContext.getCommand())) {
      setCommand(serviceContext.getCommand());
    }

    if (serviceContext.getCompanyId() > 0) {
      setCompanyId(serviceContext.getCompanyId());
    }

    if (serviceContext.getCreateDate() != null) {
      setCreateDate(serviceContext.getCreateDate());
    }

    if (Validator.isNotNull(serviceContext.getCurrentURL())) {
      setCurrentURL(serviceContext.getCurrentURL());
    }

    if (serviceContext.getExpandoBridgeAttributes() != null) {
      setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes());
    }

    if (serviceContext.getGroupPermissions() != null) {
      setGroupPermissions(serviceContext.getGroupPermissions());
    }

    if (serviceContext.getGuestPermissions() != null) {
      setGuestPermissions(serviceContext.getGuestPermissions());
    }

    if (serviceContext.getHeaders() != null) {
      setHeaders(serviceContext.getHeaders());
    }

    setFailOnPortalException(serviceContext.isFailOnPortalException());
    setLanguageId(serviceContext.getLanguageId());

    if (Validator.isNotNull(serviceContext.getLayoutFullURL())) {
      setLayoutFullURL(serviceContext.getLayoutFullURL());
    }

    if (Validator.isNotNull(serviceContext.getLayoutURL())) {
      setLayoutURL(serviceContext.getLayoutURL());
    }

    if (serviceContext.getModifiedDate() != null) {
      setModifiedDate(serviceContext.getModifiedDate());
    }

    if (Validator.isNotNull(serviceContext.getPathMain())) {
      setPathMain(serviceContext.getPathMain());
    }

    if (serviceContext.getPlid() > 0) {
      setPlid(serviceContext.getPlid());
    }

    if (Validator.isNotNull(serviceContext.getPortalURL())) {
      setPortalURL(serviceContext.getPortalURL());
    }

    if (serviceContext.getPortletPreferencesIds() != null) {
      setPortletPreferencesIds(serviceContext.getPortletPreferencesIds());
    }

    if (Validator.isNotNull(serviceContext.getRemoteAddr())) {
      setRemoteAddr(serviceContext.getRemoteAddr());
    }

    if (Validator.isNotNull(serviceContext.getRemoteHost())) {
      setRemoteHost(serviceContext.getRemoteHost());
    }

    if (serviceContext.getScopeGroupId() > 0) {
      setScopeGroupId(serviceContext.getScopeGroupId());
    }

    setSignedIn(serviceContext.isSignedIn());

    if (Validator.isNotNull(serviceContext.getUserDisplayURL())) {
      setUserDisplayURL(serviceContext.getUserDisplayURL());
    }

    if (serviceContext.getUserId() > 0) {
      setUserId(serviceContext.getUserId());
    }

    if (Validator.isNotNull(serviceContext.getUuid())) {
      setUuid(serviceContext.getUuid());
    }

    if (serviceContext.getWorkflowAction() > 0) {
      setWorkflowAction(serviceContext.getWorkflowAction());
    }
  }