Search in sources :

Example 1 with CommentEntity

use of org.activiti.engine.impl.persistence.entity.CommentEntity in project Activiti by Activiti.

the class AddCommentCmd method execute.

public Comment execute(CommandContext commandContext) {
    // Validate task
    if (taskId != null) {
        TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId);
        if (task == null) {
            throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class);
        }
        if (task.isSuspended()) {
            throw new ActivitiException(getSuspendedTaskException());
        }
    }
    if (processInstanceId != null) {
        ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
        if (execution == null) {
            throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class);
        }
        if (execution.isSuspended()) {
            throw new ActivitiException(getSuspendedExceptionMessage());
        }
    }
    String userId = Authentication.getAuthenticatedUserId();
    CommentEntity comment = new CommentEntity();
    comment.setUserId(userId);
    comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
    comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
    comment.setTaskId(taskId);
    comment.setProcessInstanceId(processInstanceId);
    comment.setAction(Event.ACTION_ADD_COMMENT);
    String eventMessage = message.replaceAll("\\s+", " ");
    if (eventMessage.length() > 163) {
        eventMessage = eventMessage.substring(0, 160) + "...";
    }
    comment.setMessage(eventMessage);
    comment.setFullMessage(message);
    commandContext.getCommentEntityManager().insert(comment);
    return comment;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity)

Example 2 with CommentEntity

use of org.activiti.engine.impl.persistence.entity.CommentEntity in project Activiti by Activiti.

the class DefaultHistoryManager method createIdentityLinkComment.

/* (non-Javadoc)
   * @see org.activiti.engine.impl.history.HistoryManagerInterface#createIdentityLinkComment(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, boolean)
   */
@Override
public void createIdentityLinkComment(String taskId, String userId, String groupId, String type, boolean create, boolean forceNullUserId) {
    if (isHistoryEnabled()) {
        String authenticatedUserId = Authentication.getAuthenticatedUserId();
        CommentEntity comment = new CommentEntity();
        comment.setUserId(authenticatedUserId);
        comment.setType(CommentEntity.TYPE_EVENT);
        comment.setTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
        comment.setTaskId(taskId);
        if (userId != null || forceNullUserId) {
            if (create) {
                comment.setAction(Event.ACTION_ADD_USER_LINK);
            } else {
                comment.setAction(Event.ACTION_DELETE_USER_LINK);
            }
            comment.setMessage(new String[] { userId, type });
        } else {
            if (create) {
                comment.setAction(Event.ACTION_ADD_GROUP_LINK);
            } else {
                comment.setAction(Event.ACTION_DELETE_GROUP_LINK);
            }
            comment.setMessage(new String[] { groupId, type });
        }
        getSession(CommentEntityManager.class).insert(comment);
    }
}
Also used : CommentEntityManager(org.activiti.engine.impl.persistence.entity.CommentEntityManager) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity)

Example 3 with CommentEntity

use of org.activiti.engine.impl.persistence.entity.CommentEntity in project Activiti by Activiti.

the class DefaultHistoryManager method createProcessInstanceIdentityLinkComment.

@Override
public void createProcessInstanceIdentityLinkComment(String processInstanceId, String userId, String groupId, String type, boolean create, boolean forceNullUserId) {
    if (isHistoryEnabled()) {
        String authenticatedUserId = Authentication.getAuthenticatedUserId();
        CommentEntity comment = new CommentEntity();
        comment.setUserId(authenticatedUserId);
        comment.setType(CommentEntity.TYPE_EVENT);
        comment.setTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
        comment.setProcessInstanceId(processInstanceId);
        if (userId != null || forceNullUserId) {
            if (create) {
                comment.setAction(Event.ACTION_ADD_USER_LINK);
            } else {
                comment.setAction(Event.ACTION_DELETE_USER_LINK);
            }
            comment.setMessage(new String[] { userId, type });
        } else {
            if (create) {
                comment.setAction(Event.ACTION_ADD_GROUP_LINK);
            } else {
                comment.setAction(Event.ACTION_DELETE_GROUP_LINK);
            }
            comment.setMessage(new String[] { groupId, type });
        }
        getSession(CommentEntityManager.class).insert(comment);
    }
}
Also used : CommentEntityManager(org.activiti.engine.impl.persistence.entity.CommentEntityManager) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity)

Example 4 with CommentEntity

use of org.activiti.engine.impl.persistence.entity.CommentEntity in project Activiti by Activiti.

the class DefaultHistoryManager method createAttachmentComment.

/* (non-Javadoc)
   * @see org.activiti.engine.impl.history.HistoryManagerInterface#createAttachmentComment(java.lang.String, java.lang.String, java.lang.String, boolean)
   */
@Override
public void createAttachmentComment(String taskId, String processInstanceId, String attachmentName, boolean create) {
    if (isHistoryEnabled()) {
        String userId = Authentication.getAuthenticatedUserId();
        CommentEntity comment = new CommentEntity();
        comment.setUserId(userId);
        comment.setType(CommentEntity.TYPE_EVENT);
        comment.setTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
        comment.setTaskId(taskId);
        comment.setProcessInstanceId(processInstanceId);
        if (create) {
            comment.setAction(Event.ACTION_ADD_ATTACHMENT);
        } else {
            comment.setAction(Event.ACTION_DELETE_ATTACHMENT);
        }
        comment.setMessage(attachmentName);
        getSession(CommentEntityManager.class).insert(comment);
    }
}
Also used : CommentEntityManager(org.activiti.engine.impl.persistence.entity.CommentEntityManager) CommentEntity(org.activiti.engine.impl.persistence.entity.CommentEntity)

Aggregations

CommentEntity (org.activiti.engine.impl.persistence.entity.CommentEntity)4 CommentEntityManager (org.activiti.engine.impl.persistence.entity.CommentEntityManager)3 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)1