@Override public void afterTaskStartedEvent(TaskEvent event) { throw new TaskExecutionException("On purpose"); } });
public TaskException getException(String message) { if (this.exceptionClass != null) { try { return this.exceptionClass.getConstructor(new Class[]{String.class}).newInstance(new Object[]{message}); } catch (Exception e) { //do nothing } } return new CannotAddTaskException(message); }
@Override public Task execute(Context cntxt) { TaskContext context = (TaskContext) cntxt; Task task = context.getTaskQueryService().getTaskInstanceById(taskId); if (task == null) { throw new IllegalStateException("Unable to find task with id " + taskId); } if (!checkUserPermissions(userId, task, context)) { throw new PermissionDeniedException("User " + userId + " isn't allowed to see the task " + taskId); } return task; }
@Test public void testInvalidTask() { try { taskService.claim(-1, "Darth Vader"); } catch (PermissionDeniedException e) { if ("Task '-1' not found".equals(e.getMessage())) { return; } else { throw e; } } }
@Test public void testCreateTaskWithDisallowedCreationByRule() { // One potential owner, should go straight to state Reserved String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('peter')],businessAdministrators = [ new User('Administrator') ], }),"; str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], "; str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], "; str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })"; Task task = (Task) TaskFactory.evalTask(new StringReader(str)); try { taskService.addTask(task, new HashMap<String, Object>()); fail("Task should not be created due to rule violation"); } catch (CannotAddTaskException e) { assertTrue(e.getMessage().indexOf("peter does not work here any more") != -1); } }
@Override public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { Task task = taskService.getTaskByWorkItemId(workItem.getId()); if (task != null) { try { String adminUser = ADMIN_USER; List<OrganizationalEntity> businessAdmins = task.getPeopleAssignments().getBusinessAdministrators(); for (OrganizationalEntity admin : businessAdmins) { if (admin instanceof Group) { continue; } if (!admin.getId().equals(ADMIN_USER)) { adminUser = admin.getId(); break; } } logger.debug("Task {} is going to be exited by {} who is business admin", task.getId(), adminUser); taskService.exit(task.getId(), adminUser); } catch (PermissionDeniedException e) { logger.info(e.getMessage()); } } }
@Override public void afterTaskStartedEvent(TaskEvent event) { throw new TaskExecutionException("On purpose"); } };
throw new PermissionDeniedException("Can only assign task owner if status is Created!");
@Test public void testCreateTaskWithDisallowedCreationBasedOnContentByRule() { // One potential owner, should go straight to state Reserved String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),"; str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], "; str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], "; str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })"; Task task = (Task) TaskFactory.evalTask(new StringReader(str)); Map<String, Object> params = new HashMap<String, Object>(); params.put("manager", "John"); try { taskService.addTask(task, params); fail("Task should not be created due to rule violation"); } catch (CannotAddTaskException e) { assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1); } }
throw new CannotAddTaskException("There are no known Business Administrators, task cannot be created according to WS-HT specification");
@Override public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { RuntimeEngine runtime = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId())); Task task = runtime.getTaskService().getTaskByWorkItemId(workItem.getId()); if (task != null) { try { String adminUser = ADMIN_USER; List<OrganizationalEntity> businessAdmins = task.getPeopleAssignments().getBusinessAdministrators(); for (OrganizationalEntity admin : businessAdmins) { if (admin instanceof Group) { continue; } if (!admin.getId().equals(ADMIN_USER)) { adminUser = admin.getId(); break; } } logger.debug("Task {} is going to be exited by {} who is business admin", task.getId(), adminUser); runtime.getTaskService().exit(task.getId(), adminUser); } catch (PermissionDeniedException e) { logger.info(e.getMessage()); } } }
String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId(); throw new PermissionDeniedException(errorMessage); throw new PermissionDeniedException(errorMessage); throw new PermissionDeniedException(errorMessage); throw new PermissionDeniedException(errorMessage);
@Test public void testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData() { // One potential owner, should go straight to state Reserved String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),"; str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], "; str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], "; str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })"; Task task = (Task) TaskFactory.evalTask(new StringReader(str)); Map<String, Object> params = new HashMap<String, Object>(); params.put("manager", "John"); ContentData data = ContentMarshallerHelper.marshal(task, params, null); try { taskService.addTask(task, data); fail("Task should not be created due to rule violation"); } catch (CannotAddTaskException e) { assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1); } }
assertTrue(e.getMessage().indexOf("Mary is not allowed to complete task with approved false") != -1);
throw new PermissionDeniedException("Task '" + taskId + "' not found");
@Override public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { Task task = taskService.getTaskByWorkItemId(workItem.getId()); if (task != null) { try { String adminUser = ADMIN_USER; List<OrganizationalEntity> businessAdmins = task.getPeopleAssignments().getBusinessAdministrators(); for (OrganizationalEntity admin : businessAdmins) { if (admin instanceof Group) { continue; } if (!admin.getId().equals(ADMIN_USER)) { adminUser = admin.getId(); break; } } logger.debug("Task {} is going to be exited by {} who is business admin", task.getId(), adminUser); taskService.exit(task.getId(), adminUser); } catch (PermissionDeniedException e) { logger.info(e.getMessage()); } } }
throw new PermissionDeniedException(errorMessage); if (task.getPeopleAssignments().getPotentialOwners().stream().anyMatch(oe -> oe instanceof Group)) { throw new PermissionDeniedException("Task forward operation not allowed for task with group assignment");
@Override public void abortWorkItem(WorkItem workItem, WorkItemManager manager) { RuntimeEngine runtime = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId())); Task task = runtime.getTaskService().getTaskByWorkItemId(workItem.getId()); if (task != null) { try { String adminUser = ADMIN_USER; List<OrganizationalEntity> businessAdmins = task.getPeopleAssignments().getBusinessAdministrators(); for (OrganizationalEntity admin : businessAdmins) { if (admin instanceof Group) { continue; } if (!admin.getId().equals(ADMIN_USER)) { adminUser = admin.getId(); break; } } logger.debug("Task {} is going to be exited by {} who is business admin", task.getId(), adminUser); runtime.getTaskService().exit(task.getId(), adminUser); } catch (PermissionDeniedException e) { logger.info(e.getMessage()); } } }