UserTaskAdminServiceImpl implements UserTaskAdminService { @Override public void addPotentialOwners(long taskId, boolean removeExisting, OrganizationalEntity... orgEntities) throws TaskNotFoundException { addPotentialOwners(null, taskId, removeExisting, orgEntities); } UserTaskAdminServiceImpl(); void setUserTaskService(UserTaskService userTaskService); void setRuntimeDataService(RuntimeDataService runtimeDataService); void setIdentityProvider(IdentityProvider identityProvider); void setCommandService(TransactionalCommandService commandService); @Override void addPotentialOwners(long taskId, boolean removeExisting, OrganizationalEntity... orgEntities); @Override void addPotentialOwners(String deploymentId, long taskId, boolean removeExisting, OrganizationalEntity... orgEntities); @Override void addExcludedOwners(long taskId, boolean removeExisting, OrganizationalEntity... orgEntities); @Override void addExcludedOwners(String deploymentId, long taskId, boolean removeExisting, OrganizationalEntity... orgEntities); @Override void addBusinessAdmins(long taskId, boolean removeExisting, OrganizationalEntity... orgEntities); @Override void addBusinessAdmins(String deploymentId, long taskId, boolean removeExisting, OrganizationalEntity... orgEntities); @Override void removePotentialOwners(long taskId, OrganizationalEntity... orgEntities); @Override void removePotentialOwners(String deploymentId, long taskId, OrganizationalEntity... orgEntities); @Override void removeExcludedOwners(long taskId, OrganizationalEntity... orgEntities); @Override void removeExcludedOwners(String deploymentId, long taskId, OrganizationalEntity... orgEntities); @Override void removeBusinessAdmins(long taskId, OrganizationalEntity... orgEntities); @Override void removeBusinessAdmins(String deploymentId, long taskId, OrganizationalEntity... orgEntities); @Override void addTaskInput(long taskId, String name, Object value); @Override void addTaskInput(String deploymentId, long taskId, String name, Object value); @Override void addTaskInputs(long taskId, Map<String, Object> data); @Override void addTaskInputs(String deploymentId, long taskId, Map<String, Object> data); @Override void removeTaskInputs(long taskId, String... name); @Override void removeTaskInputs(String deploymentId, long taskId, String... name); @Override void removeTaskOutputs(long taskId, String... name); @Override void removeTaskOutputs(String deploymentId, long taskId, String... name); @Override Long reassignWhenNotStarted(long taskId, String timeExpression, OrganizationalEntity... orgEntities); @Override Long reassignWhenNotStarted(String deploymentId, long taskId, String timeExpression, OrganizationalEntity... orgEntities); @Override Long reassignWhenNotCompleted(long taskId, String timeExpression, OrganizationalEntity... orgEntities); @Override Long reassignWhenNotCompleted(String deploymentId, long taskId, String timeExpression, OrganizationalEntity... orgEntities); @Override Long notifyWhenNotStarted(long taskId, String timeExpression, Notification notification); @Override Long notifyWhenNotStarted(String deploymentId, long taskId, String timeExpression, Notification notification); @Override Long notifyWhenNotCompleted(long taskId, String timeExpression, Notification notification); @Override Long notifyWhenNotCompleted(String deploymentId, long taskId, String timeExpression, Notification notification); @Override Collection<TaskReassignment> getTaskReassignments(long taskId, boolean activeOnly); @Override Collection<TaskReassignment> getTaskReassignments(String deploymentId, long taskId, boolean activeOnly); @Override Collection<TaskNotification> getTaskNotifications(long taskId, boolean activeOnly); @Override Collection<TaskNotification> getTaskNotifications(String deploymentId, long taskId, boolean activeOnly); @Override void cancelNotification(long taskId, long notificationId); @Override void cancelNotification(String deploymentId, long taskId, long notificationId); @Override void cancelReassignment(long taskId, long reassignmentId); @Override void cancelReassignment(String deploymentId, long taskId, long reassignmentId); @Override EmailNotification buildEmailNotification(String subjectStr, List<OrganizationalEntity> recipients, String bodyStr, String fromStr, String replyToStr); @Override List<ExecutionError> getErrors(boolean includeAcknowledged, QueryContext queryContext); @Override List<ExecutionError> getErrorsByTaskId(long taskId, boolean includeAcknowledged, QueryContext queryContext); @Override List<ExecutionError> getErrorsByTaskName(String taskName, boolean includeAcknowledged, QueryContext queryContext); @Override List<ExecutionError> getErrorsByTaskName(String processId, String taskName, boolean includeAcknowledged, QueryContext queryContext); @Override List<ExecutionError> getErrorsByTaskName(String deploymentId, String processId, String taskName, boolean includeAcknowledged, QueryContext queryContext); @Override void acknowledgeError(String... errorId); @Override ExecutionError getError(String errorId); static final int POT_OWNER; static final int EXCL_OWNER; static final int ADMIN; }
@Test public void testAddPotentialOwnersNotBusinessAdmin() { identityProvider.setName("notAdmin"); processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); Assertions.assertThat(processInstanceId).isNotNull(); List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); TaskSummary task = tasks.get(0); userTaskService.release(task.getId(), "salaboy"); Assertions.assertThatThrownBy( () -> userTaskAdminService.addPotentialOwners(task.getId(), false, factory.newUser("john"))) .hasMessageContaining("User notAdmin is not business admin of task 1"); }
@Test public void testAddPotentialOwnersToNonExistentTask() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); Assertions.assertThat(processInstanceId).isNotNull(); List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); TaskSummary task = tasks.get(0); userTaskService.release(task.getId(), "salaboy"); Assertions.assertThatThrownBy( () -> userTaskAdminService.addPotentialOwners(15456, false, factory.newUser("john"))) .hasMessageContaining("Task with id 15456 was not found"); }
@Test public void testAddPotentialOwners() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); Assertions.assertThat(processInstanceId).isNotNull(); List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); TaskSummary task = tasks.get(0); userTaskService.release(task.getId(), "salaboy"); userTaskAdminService.addPotentialOwners(task.getId(), false, factory.newUser("john")); List<TaskEvent> events = runtimeDataService.getTaskEvents(task.getId(), new QueryFilter()); Assertions.assertThat(events).hasSize(4); TaskEvent updatedEvent = events.get(3); Assertions.assertThat(updatedEvent.getMessage()).isEqualTo("Potential owners [john] have been added"); tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); userTaskAdminService.addPotentialOwners(task.getId(), true, factory.newUser("john")); tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter()); Assertions.assertThat(tasks).hasSize(0); tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); }
@Test public void testAddPotentialOwnersWrongDeploymentId() { processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument"); Assertions.assertThat(processInstanceId).isNotNull(); List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter()); Assertions.assertThat(tasks).hasSize(1); TaskSummary task = tasks.get(0); userTaskService.release(task.getId(), "salaboy"); assertThatExceptionOfType(TaskNotFoundException.class).isThrownBy(() -> { userTaskAdminService.addPotentialOwners("wrong-one", task.getId(), false, factory.newUser("john")); }) .withMessageContaining("Task with id " + task.getId() + " is not associated with wrong-one"); tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter()); Assertions.assertThat(tasks).hasSize(0); }
@Test public void testGetTaskInstancesAsPotOwners() { String PO_TASK_QUERY = "select ti.taskId, ti.activationTime, ti.actualOwner, ti.createdBy, ti.createdOn, ti.deploymentId, " + "ti.description, ti.dueDate, ti.name, ti.parentId, ti.priority, ti.processId, ti.processInstanceId, " + "ti.processSessionId, ti.status, ti.workItemId, oe.id, eo.entity_id " + "from AuditTaskImpl ti " + "left join PeopleAssignments_PotOwners po on ti.taskId = po.task_id " + "left join OrganizationalEntity oe on po.entity_id = oe.id " + " left join PeopleAssignments_ExclOwners eo on ti.taskId = eo.task_id "; SqlQueryDefinition query = new SqlQueryDefinition("getMyTaskInstances", "jdbc/testDS1", Target.PO_TASK); query.setExpression(PO_TASK_QUERY); queryService.registerQuery(query); List<QueryDefinition> queries = queryService.getQueries(new QueryContext()); assertNotNull(queries); assertEquals(1, queries.size()); QueryDefinition registeredQuery = queries.get(0); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); registeredQuery = queryService.getQuery(query.getName()); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); Map<String, Object> params = new HashMap<String, Object>(); params.put("approval_document", "initial content"); processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params); assertNotNull(processInstanceId); identityProvider.setName("notvalid"); List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(0, taskInstanceLogs.size()); identityProvider.setName("salaboy"); taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(1, taskInstanceLogs.size()); List<TaskSummary> taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext()); assertNotNull(taskSummaries); assertEquals(1, taskSummaries.size()); identityProvider.setName("Administrator"); userTaskAdminService.addPotentialOwners(taskSummaries.get(0).getId(), false, factory.newUser("john")); identityProvider.setName("salaboy"); taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(1, taskInstanceLogs.size()); taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext()); assertNotNull(taskSummaries); assertEquals(1, taskSummaries.size()); QueryParam[] parameters = QueryParam.getBuilder().append(QueryParam.groupBy(COLUMN_NAME)).append(QueryParam.count(COLUMN_TASKID)).get(); Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters); assertNotNull(instances); assertEquals(1, instances.size()); List<Object> result = instances.iterator().next(); assertNotNull(result); assertEquals(2, result.size()); assertTrue(result.get(1) instanceof Number); assertEquals(2, ((Number) result.get(1)).intValue()); processService.abortProcessInstance(processInstanceId); processInstanceId = null; }
@Test public void testGetTaskInstancesAsPotOwnersMultipleInstances() { String PO_TASK_QUERY = "select ti.taskId, ti.activationTime, ti.actualOwner, ti.createdBy, ti.createdOn, ti.deploymentId, " + "ti.description, ti.dueDate, ti.name, ti.parentId, ti.priority, ti.processId, ti.processInstanceId, " + "ti.processSessionId, ti.status, ti.workItemId, oe.id, eo.entity_id " + "from AuditTaskImpl ti " + "left join PeopleAssignments_PotOwners po on ti.taskId = po.task_id " + "left join OrganizationalEntity oe on po.entity_id = oe.id " + " left join PeopleAssignments_ExclOwners eo on ti.taskId = eo.task_id "; SqlQueryDefinition query = new SqlQueryDefinition("getMyTaskInstances", "jdbc/testDS1", Target.PO_TASK); query.setExpression(PO_TASK_QUERY); queryService.registerQuery(query); List<QueryDefinition> queries = queryService.getQueries(new QueryContext()); assertNotNull(queries); assertEquals(1, queries.size()); QueryDefinition registeredQuery = queries.get(0); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); registeredQuery = queryService.getQuery(query.getName()); assertNotNull(registeredQuery); assertEquals(query.getName(), registeredQuery.getName()); assertEquals(query.getSource(), registeredQuery.getSource()); assertEquals(query.getExpression(), registeredQuery.getExpression()); assertEquals(query.getTarget(), registeredQuery.getTarget()); Map<String, Object> params = new HashMap<String, Object>(); params.put("approval_document", "initial content"); processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params); assertNotNull(processInstanceId); Long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params); assertNotNull(processInstanceId); assertNotNull(processInstanceId2); identityProvider.setName("notvalid"); List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(0, taskInstanceLogs.size()); identityProvider.setName("salaboy"); taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(2, taskInstanceLogs.size()); identityProvider.setName("Administrator"); userTaskAdminService.addPotentialOwners(taskInstanceLogs.get(0).getTaskId(), false, factory.newUser("john")); identityProvider.setName("salaboy"); taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext()); assertNotNull(taskInstanceLogs); assertEquals(2, taskInstanceLogs.size()); processService.abortProcessInstance(processInstanceId); processInstanceId = null; processService.abortProcessInstance(processInstanceId2); processInstanceId2 = null; }