use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.
the class JPATaskLifeCycleEventListener method indexAndPersistVariables.
protected void indexAndPersistVariables(Task task, Map<String, Object> variables, TaskPersistenceContext persistenceContext, VariableType type) {
TaskIndexerManager manager = TaskIndexerManager.get();
for (Map.Entry<String, Object> variable : variables.entrySet()) {
if (SKIPPED_TASK_VARIABLES.contains(variable.getKey()) || variable.getValue() == null) {
continue;
}
List<TaskVariable> taskVars = manager.index(task, variable.getKey(), variable.getValue());
if (taskVars != null) {
for (TaskVariable tVariable : taskVars) {
tVariable.setType(type);
persistenceContext.persist(tVariable);
}
}
}
}
use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.
the class StringTaskVariableIndexer method index.
@Override
public List<TaskVariable> index(String name, Object variable) {
List<TaskVariable> indexed = new ArrayList<TaskVariable>();
TaskVariableImpl taskVariable = new TaskVariableImpl();
taskVariable.setName(name);
taskVariable.setValue(variable.toString());
indexed.add(taskVariable);
return indexed;
}
use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.
the class TaskIndexerManager method index.
public List<TaskVariable> index(Task task, String variableName, Object variable) {
for (TaskVariableIndexer indexer : indexers) {
if (indexer.accept(variable)) {
List<TaskVariable> indexed = indexer.index(variableName, variable);
if (indexed != null) {
// populate all indexed variables with task information
for (TaskVariable taskVariable : indexed) {
taskVariable.setTaskId(task.getId());
taskVariable.setTaskId(task.getId());
taskVariable.setProcessInstanceId(task.getTaskData().getProcessInstanceId());
taskVariable.setProcessId(task.getTaskData().getProcessId());
taskVariable.setModificationDate(new Date());
}
return indexed;
}
}
}
return null;
}
use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.
the class TaskAuditBaseTest method testSearchTasksByVariable.
@Test
public void testSearchTasksByVariable() {
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"));
List<TaskSummary> tasksByVariable = taskService.taskSummaryQuery("salaboy").variableName("firstVariable").build().getResultList();
assertNotNull(tasksByVariable);
assertEquals(1, tasksByVariable.size());
// search by unauthorized user
tasksByVariable = taskService.taskSummaryQuery("WinterMute").variableName("fistVariable").build().getResultList();
assertNotNull(tasksByVariable);
assertEquals(0, tasksByVariable.size());
// search by not existing variable
tasksByVariable = taskService.taskSummaryQuery("salaboy").variableName("notexistingVariable").build().getResultList();
assertNotNull(tasksByVariable);
assertEquals(0, tasksByVariable.size());
// search by variable name with wildcard
tasksByVariable = taskService.taskSummaryQuery("salaboy").regex().variableName("first*").build().getResultList();
assertNotNull(tasksByVariable);
assertNotNull(tasksByVariable);
assertEquals(1, tasksByVariable.size());
}
use of org.kie.internal.task.api.TaskVariable in project jbpm by kiegroup.
the class TaskAuditBaseTest method testVariableIndexInputAndUpdateOutput.
@Test
public void testVariableIndexInputAndUpdateOutput() {
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());
// update task output
Map<String, Object> outputVariables = new HashMap<String, Object>();
outputVariables.put("reply", "updated content");
outputVariables.put("age", 25);
taskService.addOutputContentFromUser(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("updated content", outvars.get("reply"));
assertEquals("25", outvars.get("age"));
// Check is Complete
outputVariables = new HashMap<String, Object>();
outputVariables.put("reply", "completed content");
outputVariables.put("age", 44);
outputVariables.put("reason", "rework, please");
taskService.complete(taskId, "Darth Vader", outputVariables);
outputVars = taskAuditService.taskVariableQuery().taskId(taskId).intersect().type(VariableType.OUTPUT).build().getResultList();
assertNotNull(outputVars);
assertEquals(3, outputVars.size());
outvars = collectVariableNameAndValue(outputVars);
assertTrue(outvars.containsKey("reply"));
assertTrue(outvars.containsKey("age"));
assertTrue(outvars.containsKey("reason"));
assertEquals("completed content", outvars.get("reply"));
assertEquals("44", outvars.get("age"));
assertEquals("rework, please", outvars.get("reason"));
}
Aggregations