Search in sources :

Example 1 with TaskReassignment

use of org.jbpm.services.api.admin.TaskReassignment in project jbpm by kiegroup.

the class UserTaskAdminServiceImplTest method testReassignNotStartedAndCancel.

@Test(timeout = 10000)
public void testReassignNotStartedAndCancel() throws Exception {
    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);
    Collection<TaskReassignment> reassignments = userTaskAdminService.getTaskReassignments(task.getId(), false);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(0);
    Long reassignmentId = userTaskAdminService.reassignWhenNotStarted(task.getId(), "2s", factory.newUser("john"));
    reassignments = userTaskAdminService.getTaskReassignments(task.getId(), true);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(1);
    userTaskAdminService.cancelReassignment(task.getId(), reassignmentId);
    reassignments = userTaskAdminService.getTaskReassignments(task.getId(), true);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(0);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) TaskSummary(org.kie.api.task.model.TaskSummary) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 2 with TaskReassignment

use of org.jbpm.services.api.admin.TaskReassignment in project jbpm by kiegroup.

the class UserTaskAdminServiceImplTest method testReassignNotCompleted.

@Test(timeout = 10000)
public void testReassignNotCompleted() throws Exception {
    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.start(task.getId(), "salaboy");
    Collection<TaskReassignment> reassignments = userTaskAdminService.getTaskReassignments(task.getId(), false);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(0);
    userTaskAdminService.reassignWhenNotCompleted(task.getId(), "2s", factory.newUser("john"));
    reassignments = userTaskAdminService.getTaskReassignments(task.getId(), true);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(1);
    CountDownListenerFactory.getExistingTask("userTaskAdminService").waitTillCompleted();
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(0);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    Assertions.assertThat(tasks).hasSize(1);
    reassignments = userTaskAdminService.getTaskReassignments(task.getId(), true);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(0);
    reassignments = userTaskAdminService.getTaskReassignments(task.getId(), false);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(1);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) TaskSummary(org.kie.api.task.model.TaskSummary) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 3 with TaskReassignment

use of org.jbpm.services.api.admin.TaskReassignment in project jbpm by kiegroup.

the class ListTaskReassignmentsCommand method execute.

@Override
public List<TaskReassignment> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    List<TaskReassignment> reassignmantsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getReassignments().isEmpty()).map(d -> {
        Reassignment r = d.getEscalations().get(0).getReassignments().get(0);
        return new TaskReassignmentImpl(d.getId(), get(r.getDocumentation()), d.getDate(), r.getPotentialOwners(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskReassignment> reassignmantsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getReassignments().isEmpty()).map(d -> {
        Reassignment r = d.getEscalations().get(0).getReassignments().get(0);
        return new TaskReassignmentImpl(d.getId(), get(r.getDocumentation()), d.getDate(), r.getPotentialOwners(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskReassignment> result = new ArrayList<>();
    result.addAll(reassignmantsNotStarted);
    result.addAll(reassignmantsNotCompleted);
    if (activeOnly) {
        logger.debug("Removing already completed deadlines from the result");
        result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
    }
    return result;
}
Also used : Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) I18NText(org.kie.api.task.model.I18NText) TaskReassignmentImpl(org.jbpm.kie.services.impl.admin.TaskReassignmentImpl) Collectors(java.util.stream.Collectors) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) ArrayList(java.util.ArrayList) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) List(java.util.List) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) Reassignment(org.kie.internal.task.api.model.Reassignment) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) ArrayList(java.util.ArrayList) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskReassignmentImpl(org.jbpm.kie.services.impl.admin.TaskReassignmentImpl) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) Reassignment(org.kie.internal.task.api.model.Reassignment)

Example 4 with TaskReassignment

use of org.jbpm.services.api.admin.TaskReassignment in project jbpm by kiegroup.

the class UserTaskAdminServiceImplTest method testReassignNotCompletedInvalidOrgEntities.

@Test(timeout = 10000)
public void testReassignNotCompletedInvalidOrgEntities() throws Exception {
    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.start(task.getId(), "salaboy");
    Collection<TaskReassignment> reassignments = userTaskAdminService.getTaskReassignments(task.getId(), false);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(0);
    Assertions.assertThatThrownBy(() -> {
        userTaskAdminService.reassignWhenNotCompleted(task.getId(), "2s", null);
    }).hasMessage("Invalid org entity");
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) TaskSummary(org.kie.api.task.model.TaskSummary) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 5 with TaskReassignment

use of org.jbpm.services.api.admin.TaskReassignment in project jbpm by kiegroup.

the class UserTaskAdminServiceImplTest method testReassignNotCompletedInvalidTimeExpression.

@Test(timeout = 10000)
public void testReassignNotCompletedInvalidTimeExpression() throws Exception {
    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.start(task.getId(), "salaboy");
    Collection<TaskReassignment> reassignments = userTaskAdminService.getTaskReassignments(task.getId(), false);
    Assertions.assertThat(reassignments).isNotNull();
    Assertions.assertThat(reassignments).hasSize(0);
    Assertions.assertThatThrownBy(() -> {
        userTaskAdminService.reassignWhenNotCompleted(task.getId(), "2ssssssss", factory.newUser("john"));
    }).hasMessage("Error parsing time string: [ 2ssssssss ]");
    Assertions.assertThatThrownBy(() -> {
        userTaskAdminService.reassignWhenNotCompleted(task.getId(), null, factory.newUser("john"));
    }).hasMessage("Invalid time expression");
    Assertions.assertThatThrownBy(() -> {
        userTaskAdminService.reassignWhenNotCompleted(task.getId(), "", factory.newUser("john"));
    }).hasMessage("Invalid time expression");
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) TaskSummary(org.kie.api.task.model.TaskSummary) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

TaskReassignment (org.jbpm.services.api.admin.TaskReassignment)5 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)4 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4 Test (org.junit.Test)4 TaskSummary (org.kie.api.task.model.TaskSummary)4 QueryFilter (org.kie.internal.query.QueryFilter)4 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 TaskReassignmentImpl (org.jbpm.kie.services.impl.admin.TaskReassignmentImpl)1 TaskContext (org.jbpm.services.task.commands.TaskContext)1 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 Context (org.kie.api.runtime.Context)1 I18NText (org.kie.api.task.model.I18NText)1 Task (org.kie.api.task.model.Task)1 Deadlines (org.kie.internal.task.api.model.Deadlines)1 InternalTask (org.kie.internal.task.api.model.InternalTask)1 Reassignment (org.kie.internal.task.api.model.Reassignment)1 Logger (org.slf4j.Logger)1