Search in sources :

Example 31 with PermissionDeniedException

use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.

the class HTWorkItemHandlerBaseTest method testTaskGroupActors.

@Test
public void testTaskGroupActors() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("NodeName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("GroupId", "Crusaders");
    workItem.setProcessInstanceId(10);
    getHandler().executeWorkItem(workItem, manager);
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Luke Cage", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    assertEquals("TaskName", taskSummary.getName());
    assertEquals(10, taskSummary.getPriority().intValue());
    assertEquals("Comment", taskSummary.getDescription());
    assertEquals(Status.Ready, taskSummary.getStatus());
    PermissionDeniedException denied = null;
    try {
        taskService.claim(taskSummary.getId(), "nocrusadaer");
    } catch (PermissionDeniedException e) {
        denied = e;
    }
    assertNotNull("Should get permissed denied exception", denied);
    // Check if the parent task is InProgress
    Task task = taskService.getTaskById(taskSummary.getId());
    assertEquals(Status.Ready, task.getTaskData().getStatus());
}
Also used : Task(org.kie.api.task.model.Task) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) TaskSummary(org.kie.api.task.model.TaskSummary) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 32 with PermissionDeniedException

use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.

the class HTWorkItemHandlerBaseTest method testTaskExitNonAdministrator.

@Test
public void testTaskExitNonAdministrator() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("NodeName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    workItem.setProcessInstanceId(10);
    getHandler().executeWorkItem(workItem, manager);
    Task task = taskService.getTaskByWorkItemId(workItem.getId());
    try {
        taskService.exit(task.getId(), "Darth Vader");
        fail("Should not allow to exit task for non administrators");
    } catch (PermissionDeniedException e) {
    }
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    assertEquals("TaskName", taskSummary.getName());
    assertEquals(10, taskSummary.getPriority().intValue());
    assertEquals("Comment", taskSummary.getDescription());
    assertEquals(Status.Reserved, taskSummary.getStatus());
    assertEquals("Darth Vader", taskSummary.getActualOwner().getId());
}
Also used : Task(org.kie.api.task.model.Task) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) TaskSummary(org.kie.api.task.model.TaskSummary) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 33 with PermissionDeniedException

use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.

the class LocalHTWorkItemHandler method executeWorkItem.

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    RuntimeEngine runtime = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId()));
    KieSession ksessionById = runtime.getKieSession();
    Task task = createTaskBasedOnWorkItemParams(ksessionById, workItem);
    // ContentData content = createTaskContentBasedOnWorkItemParams(ksessionById, workItem);
    Map<String, Object> content = createTaskDataBasedOnWorkItemParams(ksessionById, workItem);
    try {
        long taskId = ((InternalTaskService) runtime.getTaskService()).addTask(task, content);
        if (isAutoClaim(ksessionById, workItem, task)) {
            try {
                runtime.getTaskService().claim(taskId, (String) workItem.getParameter("SwimlaneActorId"));
            } catch (PermissionDeniedException e) {
                logger.warn("User {} is not allowed to auto claim task due to permission violation", workItem.getParameter("SwimlaneActorId"));
            }
        }
    } catch (Exception e) {
        if (action.equals(OnErrorAction.ABORT)) {
            manager.abortWorkItem(workItem.getId());
        } else if (action.equals(OnErrorAction.RETHROW)) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        } else if (action.equals(OnErrorAction.LOG)) {
            StringBuilder logMsg = new StringBuilder();
            logMsg.append(new Date()).append(": Error when creating task on task server for work item id ").append(workItem.getId());
            logMsg.append(". Error reported by task server: ").append(e.getMessage());
            logger.error(logMsg.toString(), e);
            // rethrow to cancel processing if the exception is not recoverable
            if (!(e instanceof TaskException) || ((e instanceof TaskException) && !((TaskException) e).isRecoverable())) {
                if (e instanceof RuntimeException) {
                    throw (RuntimeException) e;
                } else {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) InternalTaskService(org.kie.internal.task.api.InternalTaskService) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskException(org.kie.internal.task.exception.TaskException) Date(java.util.Date) TaskException(org.kie.internal.task.exception.TaskException) KieSession(org.kie.api.runtime.KieSession) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException)

Example 34 with PermissionDeniedException

use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.

the class LifeCycleBaseTest method testResumeFromReservedWithIncorrectUser.

@Test
public void testResumeFromReservedWithIncorrectUser() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
    str += "name = 'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    // Check is Reserved
    taskService.claim(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.Reserved, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    // Check not changed
    PermissionDeniedException denied = null;
    try {
        taskService.suspend(taskId, "Bobba Fet");
    } catch (PermissionDeniedException e) {
        denied = e;
    }
    assertNotNull("Should get permissed denied exception", denied);
    Task task2 = taskService.getTaskById(taskId);
    assertEquals(Status.Reserved, task2.getTaskData().getStatus());
    assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) StringReader(java.io.StringReader) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Test(org.junit.Test)

Example 35 with PermissionDeniedException

use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.

the class LifeCycleBaseTest method testClaimConflictAndRetry.

@Test
public void testClaimConflictAndRetry() {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('salaboy'), new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
    str += "name = 'This is my task name' })";
    // Create a local instance of the TaskService
    // Deploy the Task Definition to the Task Component
    taskService.addTask(TaskFactory.evalTask(new StringReader(str)), new HashMap<String, Object>());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> salaboyTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    // We know that there is just one task available so we get the first one
    Long salaboyTaskId = salaboyTasks.get(0).getId();
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task salaboyTask = taskService.getTaskById(salaboyTaskId);
    assertEquals(Status.Ready, salaboyTask.getTaskData().getStatus());
    // Because the Task contains a direct assignment we can query it for its Potential Owner
    // Notice that we obtain a list of TaskSummary (a lightweight representation of a task)
    List<TaskSummary> bobbaTasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
    // We know that there is just one task available so we get the first one
    Long bobbaTaskId = bobbaTasks.get(0).getId();
    assertEquals(bobbaTaskId, salaboyTaskId);
    // In order to check the task status we need to get the real task
    // The task is in a Reserved status because it already have a well-defined Potential Owner
    Task bobbaTask = taskService.getTaskById(bobbaTaskId);
    assertEquals(Status.Ready, bobbaTask.getTaskData().getStatus());
    taskService.claim(bobbaTask.getId(), "Bobba Fet");
    try {
        taskService.claim(salaboyTask.getId(), "salaboy");
    } catch (PermissionDeniedException ex) {
        // The Task is gone.. salaboy needs to retry
        assertNotNull(ex);
    }
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Test(org.junit.Test)

Aggregations

PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)48 Task (org.kie.api.task.model.Task)30 InternalTask (org.kie.internal.task.api.model.InternalTask)18 Test (org.junit.Test)17 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)17 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)16 InternalTaskService (org.kie.internal.task.api.InternalTaskService)16 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 UserTaskService (org.jbpm.services.api.UserTaskService)15 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)15 TaskService (org.kie.api.task.TaskService)15 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)15 StringReader (java.io.StringReader)14 TaskContext (org.jbpm.services.task.commands.TaskContext)9 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)6 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)5 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)5 Content (org.kie.api.task.model.Content)4