02-01-2012 09:00 AM
TaskQuery TaskQuery#taskVariableValueLike(String variableName, String variableValue);
TaskQuery TaskQuery#processVariableValueLike(String variableName, String variableValue);
package org.activiti.engine.task;
public interface TaskQuery extends Query<TaskQuery, Task>{
:
TaskQuery TaskQuery#taskVariableValueLike(String variableName, String variableValue);
TaskQuery TaskQuery#processVariableValueLike(String variableName, String variableValue);
:
package org.activiti.engine.impl;
public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements TaskQuery {
:
public TaskQuery taskVariableValueLike(String variableName, String variableValue) {
variables.add(new TaskQueryVariableValue(variableName, variableValue, QueryOperator.LIKE, true));
return this;
}
public TaskQuery processVariableValueLike(String variableName, String variableValue) {
variables.add(new TaskQueryVariableValue(variableName, variableValue, QueryOperator.LIKE, false));
return this;
}
:
:
<foreach item="var" collection="variables" index="index">
<if test="!var.taskVariable">
<!– When process instance variable is queried for, taskId should be null –>
and A${index}.TASK_ID_ is null
</if>
and A${index}.NAME_= #{var.name}
<if test="!var.type.equals('null')">
and A${index}.TYPE_ = #{var.type}
</if>
<!– Variable value –>
<if test="var.textValue != null && var.longValue == null && var.doubleValue == null">
<if test="var.operator.equals('EQUALS')">
and A${index}.TEXT_ = #{var.textValue}
</if>
<if test="var.operator.equals('LIKE')">
and A${index}.TEXT_ like #{var.textValue}
</if>
</if>
<if test="var.textValue2 != null">
<if test="var.operator.equals('EQUALS')">
and A${index}.TEXT2_ = #{var.textValue2}
</if>
<if test="var.operator.equals('LIKE')">
and A${index}.TEXT2_ like #{var.textValue2}
</if>
</if>
<if test="var.longValue != null">
and A${index}.LONG_ = #{var.longValue}
</if>
<if test="var.doubleValue != null">
and A${index}.DOUBLE_ = #{var.doubleValue}
</if>
<!– Null variable type –>
<if test="var.textValue == null && var.textValue2 == null && var.longValue == null && var.doubleValue == null">
and A${index}.TEXT_ is null and A${index}.TEXT2_ is null and A${index}.LONG_ is null and A${index}.DOUBLE_ is null and A${index}.BYTEARRAY_ID_ is null
</if>
</foreach>
</where>
</sql>
</mapper>
package org.activiti.engine.test.api.task;
:
public class TaskQueryTest extends PluggableActivitiTestCase {
:
@Deployment(resources={"org/activiti/engine/test/api/task/TaskQueryTest.testTaskVariableValueEquals.bpmn20.xml"})
public void testTaskVariableValueLike() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
// No task should be found for an unexisting var
assertEquals(0, taskService.createTaskQuery().taskVariableValueEquals("unexistingVar", "value").count());
// Create a map with a variable for all default types
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("longVar", 928374L);
variables.put("shortVar", (short) 123);
variables.put("integerVar", 1234);
variables.put("stringVar", "stringValue");
variables.put("booleanVar", true);
Date date = Calendar.getInstance().getTime();
variables.put("dateVar", date);
variables.put("nullVar", null);
taskService.setVariablesLocal(task.getId(), variables);
// Test query matches
assertEquals(1, taskService.createTaskQuery().taskVariableValueLike("stringVar", "stringValue").count());
assertEquals(1, taskService.createTaskQuery().taskVariableValueLike("stringVar", "s%").count());
assertEquals(1, taskService.createTaskQuery().taskVariableValueLike("stringVar", "string%").count());
assertEquals(1, taskService.createTaskQuery().taskVariableValueLike("stringVar", "%").count());
// Test query for other values on existing variables
assertEquals(0, taskService.createTaskQuery().taskVariableValueLike("stringVar", "999").count());
}
@Deployment(resources={"org/activiti/engine/test/api/task/TaskQueryTest.testProcessVariableValueEquals.bpmn20.xml"})
public void testProcessVariableValueLike() throws Exception {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("longVar", 928374L);
variables.put("shortVar", (short) 123);
variables.put("integerVar", 1234);
variables.put("stringVar", "stringValue");
variables.put("booleanVar", true);
Date date = Calendar.getInstance().getTime();
variables.put("dateVar", date);
variables.put("nullVar", null);
// Start process-instance with all types of variables
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
// Test query matches
assertEquals(1, taskService.createTaskQuery().processVariableValueLike("stringVar", "stringValue").count());
assertEquals(1, taskService.createTaskQuery().processVariableValueLike("stringVar", "s%").count());
assertEquals(1, taskService.createTaskQuery().processVariableValueLike("stringVar", "str%").count());
assertEquals(1, taskService.createTaskQuery().processVariableValueLike("stringVar", "string%").count());
// Test query for other values on existing variables
assertEquals(0, taskService.createTaskQuery().taskVariableValueLike("stringVar", "999").count());
// Test querying for task variables don't match the process-variables
assertEquals(0, taskService.createTaskQuery().taskVariableValueLike("stringVar", "stringValue").count());
}
02-02-2012 06:24 AM
02-06-2012 05:52 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.