Search in sources :

Example 1 with OrgEntities

use of org.kie.server.api.model.admin.OrgEntities 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);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 2 with OrgEntities

use of org.kie.server.api.model.admin.OrgEntities 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);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 3 with OrgEntities

use of org.kie.server.api.model.admin.OrgEntities 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);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 4 with OrgEntities

use of org.kie.server.api.model.admin.OrgEntities in project droolsjbpm-integration by kiegroup.

the class UserTaskAdminServiceIntegrationTest method testCancelReassign.

private void testCancelReassign(boolean whenNotStarted) throws Exception {
    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);
        changeUser(USER_YODA);
        List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        Assertions.assertThat(tasks).hasSize(1);
        long taskId = tasks.get(0).getId();
        taskClient.claimTask(CONTAINER_ID, taskId, USER_YODA);
        changeUser(USER_ADMINISTRATOR);
        List<TaskReassignment> reassignments = userTaskAdminClient.getTaskReassignments(CONTAINER_ID, taskId, true);
        Assertions.assertThat(reassignments).isNotNull();
        Assertions.assertThat(reassignments).hasSize(0);
        OrgEntities reassign = OrgEntities.builder().users(asList(USER_JOHN)).build();
        Long reassignmentId = null;
        if (whenNotStarted) {
            reassignmentId = userTaskAdminClient.reassignWhenNotStarted(CONTAINER_ID, taskId, "10s", reassign);
        } else {
            reassignmentId = userTaskAdminClient.reassignWhenNotCompleted(CONTAINER_ID, taskId, "10s", reassign);
        }
        reassignments = userTaskAdminClient.getTaskReassignments(CONTAINER_ID, taskId, true);
        Assertions.assertThat(reassignments).isNotNull();
        Assertions.assertThat(reassignments).hasSize(1);
        userTaskAdminClient.cancelReassignment(CONTAINER_ID, taskId, reassignmentId);
        reassignments = userTaskAdminClient.getTaskReassignments(CONTAINER_ID, taskId, true);
        Assertions.assertThat(reassignments).isNotNull();
        Assertions.assertThat(reassignments).hasSize(0);
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : HashMap(java.util.HashMap) TaskReassignment(org.kie.server.api.model.admin.TaskReassignment) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities)

Example 5 with OrgEntities

use of org.kie.server.api.model.admin.OrgEntities in project droolsjbpm-integration by kiegroup.

the class UserTaskAdminServiceIntegrationTest method testAddRemovePotOwnersByDifferentUser.

@Test
public void testAddRemovePotOwnersByDifferentUser() 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> potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_YODA, "PM", "HR");
        OrgEntities add = OrgEntities.builder().users(asList(USER_JOHN)).build();
        userTaskAdminClient.addPotentialOwners(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(4);
        Assertions.assertThat(potOwners).contains(USER_YODA, USER_JOHN, "PM", "HR");
        userTaskAdminClient.removePotentialOwnerUsers(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), USER_YODA);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_JOHN, "PM", "HR");
        userTaskAdminClient.removePotentialOwnerGroups(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), "PM", "HR");
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(1);
        Assertions.assertThat(potOwners).contains(USER_JOHN);
        add = OrgEntities.builder().users(asList(USER_YODA)).groups(asList("PM")).build();
        userTaskAdminClient.addPotentialOwners(USER_SECOND_ADMINISTRATOR, CONTAINER_ID, task.getId(), false, add);
        instance = taskClient.getTaskInstance(CONTAINER_ID, task.getId(), false, false, true);
        Assertions.assertThat(instance).isNotNull();
        potOwners = instance.getPotentialOwners();
        Assertions.assertThat(potOwners).hasSize(3);
        Assertions.assertThat(potOwners).contains(USER_YODA, USER_JOHN, "PM");
    } finally {
        if (processInstanceId != null) {
            processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
        }
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) HashMap(java.util.HashMap) TaskSummary(org.kie.server.api.model.instance.TaskSummary) OrgEntities(org.kie.server.api.model.admin.OrgEntities) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

OrgEntities (org.kie.server.api.model.admin.OrgEntities)25 Test (org.junit.Test)22 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)22 HashMap (java.util.HashMap)21 TaskSummary (org.kie.server.api.model.instance.TaskSummary)21 TaskInstance (org.kie.server.api.model.instance.TaskInstance)8 ArrayList (java.util.ArrayList)3 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)1 TaskReassignment (org.kie.server.api.model.admin.TaskReassignment)1 ByTaskIdContainerLocator (org.kie.server.services.jbpm.locator.ByTaskIdContainerLocator)1