Search in sources :

Example 11 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testVariableIndexInputAndOutputWitlLongText.

@Test
public void testVariableIndexInputAndOutputWitlLongText() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("firstVariable", "string content");
    inputVariables.put("number", 1234);
    taskService.addTask(task, inputVariables);
    long taskId = task.getId();
    List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    List<TaskVariable> inputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.INPUT).build().getResultList();
    assertNotNull(inputVars);
    assertEquals(2, inputVars.size());
    Map<String, String> vars = collectVariableNameAndValue(inputVars);
    assertTrue(vars.containsKey("firstVariable"));
    assertTrue(vars.containsKey("number"));
    assertEquals("string content", vars.get("firstVariable"));
    assertEquals("1234", vars.get("number"));
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Reserved"));
    taskService.start(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    String reply = "Just a short part of the reply";
    String veryLongReply = reply;
    for (int i = 0; i < 15; i++) {
        veryLongReply += reply;
    }
    Map<String, Object> outputVariables = new HashMap<String, Object>();
    outputVariables.put("reply", veryLongReply);
    outputVariables.put("age", 25);
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", outputVariables);
    List<TaskVariable> outputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.OUTPUT).build().getResultList();
    assertNotNull(outputVars);
    assertEquals(2, outputVars.size());
    Map<String, String> outvars = collectVariableNameAndValue(outputVars);
    assertTrue(outvars.containsKey("reply"));
    assertTrue(outvars.containsKey("age"));
    assertEquals(veryLongReply, outvars.get("reply"));
    assertEquals("25", outvars.get("age"));
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskVariable(org.kie.internal.task.api.TaskVariable) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 12 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testUpdateTaskContentEvents.

@Test
public void testUpdateTaskContentEvents() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    assertAuditTaskInfoGroup("Knights Templer", "Ready", taskId);
    taskService.claim(taskId, "Darth Vader");
    assertAuditTaskInfo("Darth Vader", "Reserved", taskId);
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    assertAuditTaskInfo("Darth Vader", "InProgress", taskId);
    Map<String, Object> params = new HashMap<>();
    params.put("test", "value");
    taskService.addOutputContentFromUser(taskId, "Darth Vader", params);
    // Check is Complete
    params.clear();
    params.put("test", "updated");
    taskService.complete(taskId, "Darth Vader", params);
    assertAuditTaskInfo("Darth Vader", "Completed", taskId);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    Assertions.assertThat(taskEvents).hasSize(6);
    Assertions.assertThat(taskEvents.get(0).getType()).isEqualTo(TaskEventType.ADDED);
    Assertions.assertThat(taskEvents.get(0).getUserId()).isNull();
    Assertions.assertThat(taskEvents.get(1).getType()).isEqualTo(TaskEventType.CLAIMED);
    Assertions.assertThat(taskEvents.get(1).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(2).getType()).isEqualTo(TaskEventType.STARTED);
    Assertions.assertThat(taskEvents.get(2).getUserId()).isEqualTo("Darth Vader");
    // first update of data explicitly
    Assertions.assertThat(taskEvents.get(3).getType()).isEqualTo(TaskEventType.UPDATED);
    Assertions.assertThat(taskEvents.get(3).getUserId()).isEqualTo("Darth Vader");
    // next update of data through complete
    Assertions.assertThat(taskEvents.get(4).getType()).isEqualTo(TaskEventType.UPDATED);
    Assertions.assertThat(taskEvents.get(4).getUserId()).isEqualTo("Darth Vader");
    Assertions.assertThat(taskEvents.get(5).getType()).isEqualTo(TaskEventType.COMPLETED);
    Assertions.assertThat(taskEvents.get(5).getUserId()).isEqualTo("Darth Vader");
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskEvent(org.kie.internal.task.api.model.TaskEvent) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 13 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testSearchTasksByVariableNameAndValue.

@Test
public void testSearchTasksByVariableNameAndValue() {
    Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    String userId = "salaboy";
    String varName = "firstVariable";
    String varValue = "string content";
    inputVariables.put(varName, varValue);
    inputVariables.put("number", 1234);
    taskService.addTask(task, inputVariables);
    long taskId = task.getId();
    List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner(userId, null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    List<TaskVariable> inputVars = taskAuditService.taskVariableQuery().taskId(taskId).build().getResultList();
    assertNotNull(inputVars);
    assertEquals(2, inputVars.size());
    Map<String, String> vars = collectVariableNameAndValue(inputVars);
    assertTrue(vars.containsKey(varName));
    assertTrue(vars.containsKey("number"));
    assertEquals(varValue, vars.get(varName));
    assertEquals("1234", vars.get("number"));
    List<TaskSummary> tasksByVariable = taskService.taskSummaryQuery(userId).variableName(varName).and().variableValue(varValue).build().getResultList();
    assertNotNull(tasksByVariable);
    assertEquals(1, tasksByVariable.size());
    // search with value wild card
    tasksByVariable = taskService.taskSummaryQuery(userId).variableName(varName).and().regex().variableValue("string*").build().getResultList();
    assertNotNull(tasksByVariable);
    assertEquals(1, tasksByVariable.size());
    // search with name and value wild card
    tasksByVariable = taskService.taskSummaryQuery(userId).regex().variableName("first*").and().variableValue("string*").build().getResultList();
    assertNotNull(tasksByVariable);
    assertEquals(1, tasksByVariable.size());
    // search with unauthorized user
    tasksByVariable = taskService.taskSummaryQuery("WinterMute").regex().variableName(varName).and().variableValue(varValue).build().getResultList();
    assertNotNull(tasksByVariable);
    assertEquals(0, tasksByVariable.size());
    // search with non existing variable
    tasksByVariable = taskService.taskSummaryQuery(userId).regex().variableName("nonexistingvariable").and().variableValue(varValue).build().getResultList();
    assertNotNull(tasksByVariable);
    assertEquals(0, tasksByVariable.size());
    // search with not matching value
    tasksByVariable = taskService.taskSummaryQuery(userId).regex().variableName(varName).and().variableValue("updated content").build().getResultList();
    assertNotNull(tasksByVariable);
    assertEquals(0, tasksByVariable.size());
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskFluent(org.jbpm.services.task.utils.TaskFluent) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) TaskVariable(org.kie.internal.task.api.TaskVariable) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 14 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testExitAfterClaim.

@Test
public void testExitAfterClaim() {
    // One potential owner, should go straight to state Reserved
    Task task = new TaskFluent().setName("This is my task name 2").addPotentialGroup("Knights Templer").setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<TaskSummary> allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Ready"));
    taskService.claim(taskId, "Darth Vader");
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", null, null, null);
    assertEquals(1, allGroupAuditTasks.size());
    assertTrue(allGroupAuditTasks.get(0).getStatusId().equals("Reserved"));
    taskService.exit(taskId, "Administrator");
    List<AuditTask> allHistoryAuditTasks = taskAuditService.getAllAuditTasks(new QueryFilter(0, 0));
    assertEquals(1, allHistoryAuditTasks.size());
    allGroupAuditTasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", null, null, null);
    assertEquals(0, allGroupAuditTasks.size());
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) TaskSummary(org.kie.api.task.model.TaskSummary) AuditTask(org.kie.internal.task.api.AuditTask) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 15 with TaskFluent

use of org.jbpm.services.task.utils.TaskFluent in project jbpm by kiegroup.

the class TaskAuditBaseTest method testDueDateUpdate.

private void testDueDateUpdate(Date oldDate, Date newDate, boolean changeExpected) {
    Task task = new TaskFluent().setDueDate(oldDate).setAdminUser("Administrator").getTask();
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    taskService.setExpirationDate(taskId, newDate);
    task = taskService.getTaskById(taskId);
    Assertions.assertThat(task.getTaskData().getExpirationTime()).isEqualTo(newDate);
    List<AuditTask> auditTasks = taskAuditService.getAllAuditTasks(new QueryFilter());
    Assertions.assertThat(auditTasks).hasSize(1);
    Assertions.assertThat(auditTasks.get(0).getDueDate()).isEqualTo(newDate);
    List<TaskEvent> taskEvents = taskAuditService.getAllTaskEvents(taskId, new QueryFilter());
    if (changeExpected) {
        Assertions.assertThat(taskEvents).hasSize(2);
        Assertions.assertThat(taskEvents.get(1).getMessage()).contains(String.valueOf(oldDate), String.valueOf(newDate));
    } else {
        Assertions.assertThat(taskEvents).hasSize(1);
    }
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) QueryFilter(org.kie.internal.query.QueryFilter) TaskFluent(org.jbpm.services.task.utils.TaskFluent) TaskEvent(org.kie.internal.task.api.model.TaskEvent) AuditTask(org.kie.internal.task.api.AuditTask)

Aggregations

TaskFluent (org.jbpm.services.task.utils.TaskFluent)31 Task (org.kie.api.task.model.Task)26 AuditTask (org.kie.internal.task.api.AuditTask)25 Test (org.junit.Test)24 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)20 QueryFilter (org.kie.internal.query.QueryFilter)17 TaskSummary (org.kie.api.task.model.TaskSummary)14 HashMap (java.util.HashMap)9 TaskEvent (org.kie.internal.task.api.model.TaskEvent)8 TaskVariable (org.kie.internal.task.api.TaskVariable)7 ArrayList (java.util.ArrayList)4 I18NTextImpl (org.jbpm.services.task.impl.model.I18NTextImpl)2 I18NText (org.kie.api.task.model.I18NText)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 EntityManager (javax.persistence.EntityManager)1 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)1 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)1 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)1