Search in sources :

Example 1 with TaskVariable

use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.

the class PersonTaskVariablesIndexer method index.

@Override
public List<TaskVariable> index(String name, Object variable) {
    Person person = (Person) variable;
    List<TaskVariable> indexed = new ArrayList<TaskVariable>();
    TaskVariableImpl personNameVar = new TaskVariableImpl();
    personNameVar.setName("person.name");
    personNameVar.setValue(person.getName());
    indexed.add(personNameVar);
    TaskVariableImpl personAgeVar = new TaskVariableImpl();
    personAgeVar.setName("person.age");
    personAgeVar.setValue(person.getAge() + "");
    indexed.add(personAgeVar);
    return indexed;
}
Also used : TaskVariableImpl(org.jbpm.services.task.audit.impl.model.TaskVariableImpl) TaskVariable(org.kie.internal.task.api.TaskVariable) ArrayList(java.util.ArrayList) Person(org.jbpm.services.task.audit.service.objects.Person)

Example 2 with TaskVariable

use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.

the class TaskAuditBaseTest method testVariableIndexInputAndOutputWithCustomIdexer.

@Test
public void testVariableIndexInputAndOutputWithCustomIdexer() {
    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("person", new Person("john", 25));
    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(3, inputVars.size());
    Map<String, String> vars = collectVariableNameAndValue(inputVars);
    assertTrue(vars.containsKey("firstVariable"));
    assertTrue(vars.containsKey("person.name"));
    assertTrue(vars.containsKey("person.age"));
    assertEquals("string content", vars.get("firstVariable"));
    assertEquals("john", vars.get("person.name"));
    assertEquals("25", vars.get("person.age"));
    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());
    Map<String, Object> outputVariables = new HashMap<String, Object>();
    outputVariables.put("reply", "updated content");
    outputVariables.put("person", new Person("mary", 28));
    // 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(3, outputVars.size());
    Map<String, String> outvars = collectVariableNameAndValue(outputVars);
    assertTrue(outvars.containsKey("reply"));
    assertTrue(vars.containsKey("person.name"));
    assertTrue(vars.containsKey("person.age"));
    assertEquals("updated content", outvars.get("reply"));
    assertEquals("mary", outvars.get("person.name"));
    assertEquals("28", outvars.get("person.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) Person(org.jbpm.services.task.audit.service.objects.Person) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 3 with TaskVariable

use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.

the class TaskAuditBaseTest method testVariableIndexInputAndOutputWitlLongTextTrimmed.

@Test
public void testVariableIndexInputAndOutputWitlLongTextTrimmed() {
    System.setProperty("org.jbpm.task.var.log.length", "10");
    try {
        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"));
        // the variable was longer that 10 so it had to be trimmed
        assertEquals("string con", 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("Just a sho", outvars.get("reply"));
        assertEquals("25", outvars.get("age"));
    } finally {
        System.clearProperty("org.jbpm.task.var.log.length");
    }
}
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 4 with TaskVariable

use of org.kie.internal.task.api.TaskVariable 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 5 with TaskVariable

use of org.kie.internal.task.api.TaskVariable 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)

Aggregations

TaskVariable (org.kie.internal.task.api.TaskVariable)11 HashMap (java.util.HashMap)8 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)7 TaskFluent (org.jbpm.services.task.utils.TaskFluent)7 Test (org.junit.Test)7 Task (org.kie.api.task.model.Task)7 TaskSummary (org.kie.api.task.model.TaskSummary)7 AuditTask (org.kie.internal.task.api.AuditTask)7 ArrayList (java.util.ArrayList)2 TaskVariableImpl (org.jbpm.services.task.audit.impl.model.TaskVariableImpl)2 Person (org.jbpm.services.task.audit.service.objects.Person)2 Date (java.util.Date)1 Map (java.util.Map)1 TaskIndexerManager (org.jbpm.services.task.audit.variable.TaskIndexerManager)1 TaskVariableIndexer (org.kie.internal.task.api.TaskVariableIndexer)1