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());
}
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());
}
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);
}
}
}
}
}
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());
}
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);
}
}
Aggregations