use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class QueryDataServiceIntegrationTest method testQueryDataServiceReplaceQuery.
@Test
public void testQueryDataServiceReplaceQuery() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("stringData", "waiting for signal");
parameters.put("personData", createPersonInstance(CONTAINER_ID));
Long pid = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
QueryDefinition query = new QueryDefinition();
query.setName("getTasksByState");
query.setSource(System.getProperty("org.kie.server.persistence.ds", "jdbc/jbpm-ds"));
query.setExpression("select * from AuditTaskImpl where status = 'Reserved'");
query.setTarget("CUSTOM");
try {
queryClient.registerQuery(query);
List<TaskInstance> tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
assertNotNull(tasks);
assertEquals(1, tasks.size());
Long taskId = tasks.get(0).getId();
query.setExpression("select * from AuditTaskImpl where status = 'InProgress'");
QueryDefinition replaced = queryClient.replaceQuery(query);
assertNotNull(replaced);
assertEquals(query.getName(), replaced.getName());
assertEquals(query.getSource(), replaced.getSource());
assertEquals(query.getExpression(), replaced.getExpression());
assertEquals(query.getTarget(), replaced.getTarget());
assertNotNull(replaced.getColumns());
assertEquals(replaced.getColumns().size(), 18);
tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
assertNotNull(tasks);
assertEquals(0, tasks.size());
taskClient.startTask(CONTAINER_ID, taskId, USER_YODA);
tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals(taskId, tasks.get(0).getId());
} finally {
processClient.abortProcessInstance(CONTAINER_ID, pid);
queryClient.unregisterQuery(query.getName());
}
}
use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class RollingUpdateUserTaskServiceIntegrationTest method testGetTaskInputAndOutputWithAlias.
@Test
public void testGetTaskInputAndOutputWithAlias() throws Exception {
try {
changeUser(USER_ADMINISTRATOR);
Long pid = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION);
assertThat(pid).isNotNull().isGreaterThan(0);
ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ALIAS, pid);
assertThat(processInstance).isNotNull();
List<TaskSummary> taskList = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
assertThat(taskList).hasSize(1);
TaskSummary taskSummary = taskList.get(0);
Map<String, Object> inputContent = taskClient.getTaskInputContentByTaskId(CONTAINER_ALIAS, taskSummary.getId());
assertThat(inputContent).isNotNull().hasSize(4);
assertThat(inputContent.get("new content")).isNull();
Map<String, Object> data = new HashMap<>();
data.put("new content", "test");
userTaskAdminClient.addTaskInputs(CONTAINER_ALIAS, taskSummary.getId(), data);
// check this method too
TaskInstance taskInstance = taskClient.getTaskInstance(CONTAINER_ALIAS, taskSummary.getId(), false, false, false);
assertThat(taskInstance).isNotNull();
assertThat(taskInstance.getId()).isEqualTo(taskSummary.getId());
inputContent = taskClient.getTaskInputContentByTaskId(CONTAINER_ALIAS, taskSummary.getId());
assertThat(inputContent).isNotNull().hasSize(5);
assertThat(inputContent.get("new content")).isEqualTo("test");
userTaskAdminClient.removeTaskInputs(CONTAINER_ALIAS, taskSummary.getId(), "new content");
inputContent = taskClient.getTaskInputContentByTaskId(CONTAINER_ALIAS, taskSummary.getId());
assertThat(inputContent).isNotNull().hasSize(4);
assertThat(inputContent.get("new content")).isNull();
Map<String, Object> outputContent = taskClient.getTaskOutputContentByTaskId(CONTAINER_ALIAS, taskSummary.getId());
assertThat(outputContent).isNotNull().hasSize(0);
taskClient.saveTaskContent(CONTAINER_ALIAS, taskSummary.getId(), data);
outputContent = taskClient.getTaskOutputContentByTaskId(CONTAINER_ALIAS, taskSummary.getId());
assertThat(outputContent).isNotNull().hasSize(1);
assertThat(outputContent.get("new content")).isEqualTo("test");
data.put("Outcome", "Approved");
taskClient.completeAutoProgress(CONTAINER_ALIAS, taskSummary.getId(), USER_YODA, data);
outputContent = taskClient.getTaskOutputContentByTaskId(CONTAINER_ALIAS, taskSummary.getId());
assertThat(outputContent).isNotNull().hasSize(2);
assertThat(outputContent.get("new content")).isEqualTo("test");
assertThat(outputContent.get("Outcome")).isEqualTo("Approved");
} finally {
// In case the test fails, we need to switch back to YODA user
changeUser(USER_YODA);
}
}
use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class UserTaskAdminServiceIntegrationTest method testAddRemoveBusinessAdminsByDifferentUser.
@Test
public void testAddRemoveBusinessAdminsByDifferentUser() throws Exception {
// Different user cannot be used for JMS as security adapter holds just information about current user
assumeFalse(configuration.isJms());
changeUser(USER_ADMINISTRATOR);
Map<String, Object> parameters = new HashMap<String, Object>();
Long processInstanceId = null;
try {
processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
Assertions.assertThat(processInstanceId).isNotNull();
Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
Assertions.assertThat(tasks).hasSize(1);
TaskSummary task = tasks.get(0);
TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
List<String> businessAdmins = instance.getBusinessAdmins();
Assertions.assertThat(businessAdmins).hasSize(2);
Assertions.assertThat(businessAdmins).contains(USER_ADMINISTRATOR, "Administrators");
OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
userTaskAdminClient.addBusinessAdmins(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
businessAdmins = instance.getBusinessAdmins();
Assertions.assertThat(businessAdmins).hasSize(3);
Assertions.assertThat(businessAdmins).contains(USER_ADMINISTRATOR, "Administrators", USER_JOHN);
userTaskAdminClient.removeBusinessAdminUsers(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), USER_JOHN);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
businessAdmins = instance.getBusinessAdmins();
Assertions.assertThat(businessAdmins).hasSize(2);
Assertions.assertThat(businessAdmins).contains(USER_ADMINISTRATOR, "Administrators");
add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("Administrators2")).build();
userTaskAdminClient.addBusinessAdmins(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
businessAdmins = instance.getBusinessAdmins();
Assertions.assertThat(businessAdmins).hasSize(4);
Assertions.assertThat(businessAdmins).contains(USER_YODA, USER_ADMINISTRATOR, "Administrators", "Administrators2");
userTaskAdminClient.removeBusinessAdminGroups(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), "Administrators2");
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
businessAdmins = instance.getBusinessAdmins();
Assertions.assertThat(businessAdmins).hasSize(3);
Assertions.assertThat(businessAdmins).contains(USER_YODA, USER_ADMINISTRATOR, "Administrators");
} finally {
if (processInstanceId != null) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
}
}
}
use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class UserTaskAdminServiceIntegrationTest method testAddRemoveExcludedOwnersByDifferentUser.
@Test
public void testAddRemoveExcludedOwnersByDifferentUser() throws Exception {
// Different user cannot be used for JMS as security adapter holds just information about current user
assumeFalse(configuration.isJms());
changeUser(USER_ADMINISTRATOR);
Map<String, Object> parameters = new HashMap<String, Object>();
Long processInstanceId = null;
try {
processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
Assertions.assertThat(processInstanceId).isNotNull();
Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
Assertions.assertThat(tasks).hasSize(1);
TaskSummary task = tasks.get(0);
TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
List<String> excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(0);
OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
userTaskAdminClient.addExcludedOwners(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(1);
Assertions.assertThat(excludedOwners).contains(USER_JOHN);
userTaskAdminClient.removeExcludedOwnerUsers(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), USER_JOHN);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(0);
add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("PM")).build();
userTaskAdminClient.addExcludedOwners(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(2);
Assertions.assertThat(excludedOwners).contains(USER_YODA, "PM");
userTaskAdminClient.removeExcludedOwnerGroups(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), "PM");
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(1);
Assertions.assertThat(excludedOwners).contains(USER_YODA);
} finally {
if (processInstanceId != null) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
}
}
}
use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class UserTaskAdminServiceIntegrationTest method testAddRemoveExcludedOwners.
@Test
public void testAddRemoveExcludedOwners() throws Exception {
changeUser(USER_ADMINISTRATOR);
Map<String, Object> parameters = new HashMap<String, Object>();
Long processInstanceId = null;
try {
processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, parameters);
Assertions.assertThat(processInstanceId).isNotNull();
Assertions.assertThat(processInstanceId.longValue()).isGreaterThan(0);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
Assertions.assertThat(tasks).hasSize(1);
TaskSummary task = tasks.get(0);
TaskInstance instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
List<String> excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(0);
OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
userTaskAdminClient.addExcludedOwners(CONTAINER_ID, task.getId(), false, add);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(1);
Assertions.assertThat(excludedOwners).contains(USER_JOHN);
userTaskAdminClient.removeExcludedOwnerUsers(CONTAINER_ID, task.getId(), USER_JOHN);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(0);
add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("PM")).build();
userTaskAdminClient.addExcludedOwners(CONTAINER_ID, task.getId(), false, add);
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(2);
Assertions.assertThat(excludedOwners).contains(USER_YODA, "PM");
userTaskAdminClient.removeExcludedOwnerGroups(CONTAINER_ID, task.getId(), "PM");
instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
Assertions.assertThat(instance).isNotNull();
excludedOwners = instance.getExcludedOwners();
Assertions.assertThat(excludedOwners).hasSize(1);
Assertions.assertThat(excludedOwners).contains(USER_YODA);
} finally {
if (processInstanceId != null) {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
}
}
}
Aggregations