Permalink
Browse files

ACT-1731: Binary variables fetched with task now get loaded in-context

  • Loading branch information...
1 parent 0b7e5fb commit 136859b6e4100d80c34bfc5c43964c8c8e4362de @frederikheremans frederikheremans committed Jul 1, 2013
@@ -723,9 +723,60 @@ public boolean isSuspended() {
return variables;
}
public List<VariableInstanceEntity> getQueryVariables() {
+ if(queryVariables == null && Context.getCommandContext() != null) {
+ queryVariables = new VariableInitializingList();
+ }
return queryVariables;
}
+
public void setQueryVariables(List<VariableInstanceEntity> queryVariables) {
this.queryVariables = queryVariables;
}
+
+ /**
+ * List that initialized binary variable values if command-context is active.
+ *
+ * @author Frederik Heremans
+ */
+ private class VariableInitializingList extends ArrayList<VariableInstanceEntity> {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void add(int index, VariableInstanceEntity e) {
+ super.add(index, e);
+ initializeBinaryVariable(e);
+ }
+
+ @Override
+ public boolean add(VariableInstanceEntity e) {
+ initializeBinaryVariable(e);
+ return super.add(e);
+ }
+ @Override
+ public boolean addAll(Collection< ? extends VariableInstanceEntity> c) {
+ for(VariableInstanceEntity e : c) {
+ initializeBinaryVariable(e);
+ }
+ return super.addAll(c);
+ }
+ @Override
+ public boolean addAll(int index, Collection< ? extends VariableInstanceEntity> c) {
+ for(VariableInstanceEntity e : c) {
+ initializeBinaryVariable(e);
+ }
+ return super.addAll(index, c);
+ }
+
+ /**
+ * If the passed {@link VariableInstanceEntity} is a binary variable and the command-context is active,
+ * the variable value is fetched to ensure the byte-array is populated.
+ */
+ @SuppressWarnings("deprecation")
+ protected void initializeBinaryVariable(VariableInstanceEntity e) {
+ if(Context.getCommandContext() != null && e != null && e.getByteArrayValueId() != null) {
+ e.getValue();
+ }
+ }
+ }
}
@@ -59,12 +59,14 @@ public void tearDown() throws Exception {
public void testQuery() {
Task task = (Task) taskService.createTaskQuery().includeTaskLocalVariables().taskAssignee("gonzo").singleResult();
Map<String, Object> variableMap = task.getTaskLocalVariables();
- assertEquals(2, variableMap.size());
+ assertEquals(3, variableMap.size());
assertEquals(0, task.getProcessVariables().size());
assertNotNull(variableMap.get("testVar"));
assertEquals("someVariable", variableMap.get("testVar"));
assertNotNull(variableMap.get("testVar2"));
assertEquals(123, variableMap.get("testVar2"));
+ assertNotNull(variableMap.get("testVarBinary"));
+ assertEquals("This is a binary variable", new String((byte[]) variableMap.get("testVarBinary")));
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(3, tasks.size());
@@ -75,12 +77,14 @@ public void testQuery() {
Map<String, Object> startMap = new HashMap<String, Object>();
startMap.put("processVar", true);
+ startMap.put("binaryVariable", "This is a binary process variable".getBytes());
runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("kermit").singleResult();
- assertEquals(1, task.getProcessVariables().size());
+ assertEquals(2, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
assertTrue((Boolean) task.getProcessVariables().get("processVar"));
+ assertEquals("This is a binary process variable", new String((byte[]) task.getProcessVariables().get("binaryVariable")));
taskService.setVariable(task.getId(), "anotherProcessVar", 123);
taskService.setVariableLocal(task.getId(), "localVar", "test");
@@ -91,14 +95,15 @@ public void testQuery() {
assertEquals("test", task.getTaskLocalVariables().get("localVar"));
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("kermit").singleResult();
- assertEquals(2, task.getProcessVariables().size());
+ assertEquals(3, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
assertEquals(true, task.getProcessVariables().get("processVar"));
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
+ assertEquals("This is a binary process variable", new String((byte[]) task.getProcessVariables().get("binaryVariable")));
tasks = taskService.createTaskQuery().includeTaskLocalVariables().taskCandidateUser("kermit").list();
assertEquals(2, tasks.size());
- assertEquals(1, tasks.get(0).getTaskLocalVariables().size());
+ assertEquals(2, tasks.get(0).getTaskLocalVariables().size());
assertEquals("test", tasks.get(0).getTaskLocalVariables().get("test"));
assertEquals(0, tasks.get(0).getProcessVariables().size());
@@ -113,17 +118,18 @@ public void testQuery() {
assertEquals("test", task.getTaskLocalVariables().get("localVar"));
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("kermit").taskVariableValueEquals("localVar", "test").singleResult();
- assertEquals(2, task.getProcessVariables().size());
+ assertEquals(3, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
assertEquals(true, task.getProcessVariables().get("processVar"));
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
task = (Task) taskService.createTaskQuery().includeTaskLocalVariables().includeProcessVariables().taskAssignee("kermit").singleResult();
- assertEquals(2, task.getProcessVariables().size());
+ assertEquals(3, task.getProcessVariables().size());
assertEquals(1, task.getTaskLocalVariables().size());
assertEquals("test", task.getTaskLocalVariables().get("localVar"));
assertEquals(true, task.getProcessVariables().get("processVar"));
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
+ assertEquals("This is a binary process variable", new String((byte[]) task.getProcessVariables().get("binaryVariable")));
}
/**
@@ -144,6 +150,7 @@ public void testQuery() {
taskService.saveTask(task);
ids.add(task.getId());
taskService.setVariableLocal(task.getId(), "test", "test");
+ taskService.setVariableLocal(task.getId(), "testBinary", "This is a binary variable".getBytes());
taskService.addCandidateUser(task.getId(), "kermit");
}
@@ -156,6 +163,7 @@ public void testQuery() {
taskService.saveTask(task);
taskService.setAssignee(task.getId(), "gonzo");
taskService.setVariableLocal(task.getId(), "testVar", "someVariable");
+ taskService.setVariableLocal(task.getId(), "testVarBinary", "This is a binary variable".getBytes());
taskService.setVariableLocal(task.getId(), "testVar2", 123);
ids.add(task.getId());

0 comments on commit 136859b

Please sign in to comment.