Search in sources :

Example 6 with TaskData

use of org.kie.api.task.model.TaskData in project jbpm by kiegroup.

the class MVELLifeCycleManager method evalCommand.

void evalCommand(final Operation operation, final List<OperationCommand> commands, final Task task, final User user, final OrganizationalEntity targetEntity, List<String> groupIds, OrganizationalEntity... entities) throws PermissionDeniedException {
    boolean statusMatched = false;
    final TaskData taskData = task.getTaskData();
    for (OperationCommand command : commands) {
        // first find out if we have a matching status
        if (command.getStatus() != null) {
            for (Status status : command.getStatus()) {
                if (task.getTaskData().getStatus() == status) {
                    statusMatched = true;
                    // next find out if the user can execute this doOperation
                    if (!isAllowed(command, task, user, groupIds)) {
                        String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId();
                        throw new PermissionDeniedException(errorMessage);
                    }
                    commands(command, task, user, targetEntity, entities);
                } else {
                    logger.debug("No match on status for task {} :status {}  != {}", task.getId(), task.getTaskData().getStatus(), status);
                }
            }
        }
        if (command.getPreviousStatus() != null) {
            for (Status status : command.getPreviousStatus()) {
                if (taskData.getPreviousStatus() == status) {
                    statusMatched = true;
                    // next find out if the user can execute this doOperation
                    if (!isAllowed(command, task, user, groupIds)) {
                        String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId();
                        throw new PermissionDeniedException(errorMessage);
                    }
                    commands(command, task, user, targetEntity, entities);
                } else {
                    logger.debug("No match on previous status for task {} :status {}  != {}", task.getId(), task.getTaskData().getStatus(), status);
                }
            }
        }
        if (!command.isGroupTargetEntityAllowed() && targetEntity instanceof Group) {
            String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to 'target entity cannot be group'";
            throw new PermissionDeniedException(errorMessage);
        }
    }
    if (!statusMatched) {
        String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to a no 'current status' match";
        throw new PermissionDeniedException(errorMessage);
    }
}
Also used : Status(org.kie.api.task.model.Status) Group(org.kie.api.task.model.Group) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) TaskData(org.kie.api.task.model.TaskData)

Aggregations

TaskData (org.kie.api.task.model.TaskData)6 Task (org.kie.api.task.model.Task)4 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)2 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)2 UserInfo (org.kie.internal.task.api.UserInfo)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 Notification (org.kie.internal.task.api.model.Notification)2 NotificationEvent (org.kie.internal.task.api.model.NotificationEvent)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RemoteEjbTest (org.jbpm.remote.ejb.test.RemoteEjbTest)1 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)1 AssignmentService (org.jbpm.services.task.assignment.AssignmentService)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 Test (org.junit.Test)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 Content (org.kie.api.task.model.Content)1 Group (org.kie.api.task.model.Group)1 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)1