提交 241ed9a5 编写于 作者: R Robert Hafner 提交者: Tijs Rademakers

Merge of ACT-4000

上级 a4cd78c6
......@@ -18,7 +18,8 @@ import org.activiti.engine.query.Query;
/**
* Programmatic querying for {@link HistoricVariableInstance}s.
*
* @author Christian Lipphardt (camunda)
* @author Joram Barrez
* @author Tijs Rademakers
*/
public interface HistoricVariableInstanceQuery extends Query<HistoricVariableInstanceQuery, HistoricVariableInstance> {
......@@ -28,30 +29,25 @@ public interface HistoricVariableInstanceQuery extends Query<HistoricVariableIns
/** Only select historic process variables with the given process instance. */
HistoricVariableInstanceQuery processInstanceId(String processInstanceId);
/** Only select historic process variables with the given id. **/
HistoricVariableInstanceQuery executionId(String executionId);
/** Only select historic process variables with the given task. */
HistoricVariableInstanceQuery taskId(String taskId);
/** Only select historic process variables with the given variable name. */
HistoricVariableInstanceQuery variableName(String variableName);
/**
* Only select historic process variables where the given variable name is
* like.
*/
/** Only select historic process variables where the given variable name is like. */
HistoricVariableInstanceQuery variableNameLike(String variableNameLike);
/** Only select historic process variables which were not set task-local. */
HistoricVariableInstanceQuery excludeTaskVariables();
/**
* Don't initialize variable values. This is foremost a way to deal with
* variable delete queries
*/
/** Don't initialize variable values. This is foremost a way to deal with variable delete queries */
HistoricVariableInstanceQuery excludeVariableInitialization();
/**
* only select historic process variables with the given name and value
*/
/** only select historic process variables with the given name and value */
HistoricVariableInstanceQuery variableValueEquals(String variableName, Object variableValue);
HistoricVariableInstanceQuery orderByProcessInstanceId();
......
......@@ -28,13 +28,15 @@ import org.activiti.engine.impl.variable.JPAEntityVariableType;
import org.activiti.engine.impl.variable.VariableTypes;
/**
* @author Christian Lipphardt (camunda)
* @author Joram Barrez
* @author Tijs Rademakers
*/
public class HistoricVariableInstanceQueryImpl extends AbstractQuery<HistoricVariableInstanceQuery, HistoricVariableInstance> implements HistoricVariableInstanceQuery {
private static final long serialVersionUID = 1L;
protected String id;
protected String taskId;
protected String executionId;
protected String processInstanceId;
protected String activityInstanceId;
protected String variableName;
......@@ -67,6 +69,14 @@ public class HistoricVariableInstanceQueryImpl extends AbstractQuery<HistoricVar
return this;
}
public HistoricVariableInstanceQueryImpl executionId(String executionId) {
if (executionId == null) {
throw new ActivitiIllegalArgumentException("Execution id is null");
}
this.executionId = executionId;
return this;
}
public HistoricVariableInstanceQuery activityInstanceId(String activityInstanceId) {
this.activityInstanceId = activityInstanceId;
return this;
......
......@@ -111,6 +111,9 @@
<if test="processInstanceId != null">
RES.PROC_INST_ID_ = #{processInstanceId}
</if>
<if test="executionId != null">
RES.EXECUTION_ID_ = #{executionId}
</if>
<if test="taskId != null">
and RES.TASK_ID_ = #{taskId}
</if>
......
......@@ -31,7 +31,6 @@ import org.activiti.engine.task.TaskQuery;
import org.activiti.engine.test.Deployment;
/**
* @author Christian Lipphardt (camunda)
* @author Joram Barrez
*/
public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
......@@ -39,8 +38,7 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
@Deployment(resources = { "org/activiti/examples/bpmn/callactivity/orderProcess.bpmn20.xml", "org/activiti/examples/bpmn/callactivity/checkCreditProcess.bpmn20.xml" })
public void testOrderProcessWithCallActivity() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
// After the process has started, the 'verify credit history' task
// should be active
// After the process has started, the 'verify credit history' task should be active
ProcessInstance pi = runtimeService.startProcessInstanceByKey("orderProcess");
TaskQuery taskQuery = taskService.createTaskQuery();
Task verifyCreditTask = taskQuery.singleResult();
......@@ -51,8 +49,7 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
assertNotNull(subProcessInstance);
assertEquals(pi.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(subProcessInstance.getId()).singleResult().getId());
// Completing the task with approval, will end the subprocess and
// continue the original process
// Completing the task with approval, will end the subprocess and continue the original process
taskService.complete(verifyCreditTask.getId(), CollectionUtil.singletonMap("creditApproved", true));
Task prepareAndShipTask = taskQuery.singleResult();
assertEquals("Prepare and Ship", prepareAndShipTask.getName());
......@@ -212,8 +209,7 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
runtimeService.deleteProcessInstance(processInstance.getId(), "deleted");
assertProcessEnded(processInstance.getId());
// check that process variable is set even if the process is
// canceled and not ended normally
// check that process variable is set even if the process is canceled and not ended normally
assertEquals(1, historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableValueEquals("testVar", "Hallo Christian").count());
}
}
......@@ -262,14 +258,10 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
assertEquals("usertask2", historicActivityInstance2.getActivityId());
/*
* This is OK! The variable is set on the root execution, on a
* execution never run through the activity, where the process
* instances stands when calling the set Variable. But the
* ActivityId of this flow node is used. So the execution id's
* doesn't have to be equal.
* This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances stands when calling the set Variable. But the
* ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
*
* execution id: On which execution it was set activity id: in which
* activity was the process instance when setting the variable
* execution id: On which execution it was set activity id: in which activity was the process instance when setting the variable
*/
assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
......@@ -304,8 +296,7 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
historyService.deleteHistoricProcessInstance(processInstance.getId());
// recheck variables
// this is a bug: all variables was deleted after delete a history
// processinstance
// this is a bug: all variables was deleted after delete a history processinstance
count = historyService.createHistoricVariableInstanceQuery().count();
assertEquals(2, count);
}
......@@ -401,17 +392,14 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
runtimeService.setVariable(processInstance.getId(), "firstVar", "789");
assertEquals("789", getHistoricVariable("firstVar").getValue());
// type is changed from text to integer and back again. same result
// expected(?)
// type is changed from text to integer and back again. same result expected(?)
runtimeService.setVariable(processInstance.getId(), "secondVar", "123");
assertEquals("123", getHistoricVariable("secondVar").getValue());
runtimeService.setVariable(processInstance.getId(), "secondVar", 456);
// there are now 2 historic variables, so the following does not
// work
// there are now 2 historic variables, so the following does not work
assertEquals(456, getHistoricVariable("secondVar").getValue());
runtimeService.setVariable(processInstance.getId(), "secondVar", "789");
// there are now 3 historic variables, so the following does not
// work
// there are now 3 historic variables, so the following does not work
assertEquals("789", getHistoricVariable("secondVar").getValue());
taskService.complete(task.getId());
......@@ -424,4 +412,26 @@ public class HistoricVariableInstanceTest extends PluggableActivitiTestCase {
return historyService.createHistoricVariableInstanceQuery().variableName(variableName).singleResult();
}
@Deployment
public void testRestrictByExecutionId() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
TaskQuery taskQuery = taskService.createTaskQuery();
Task userTask = taskQuery.singleResult();
assertEquals("userTask1", userTask.getName());
taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));
assertProcessEnded(processInstance.getId());
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().executionId(processInstance.getId()).list();
assertEquals(1, variables.size());
HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
assertEquals("test456", historicVariable.getTextValue());
assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
assertEquals(3, historyService.createHistoricDetailQuery().count());
}
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
xmlns:signavio="http://www.signavio.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exporter="Signavio Process Editor, http://www.signavio.com"
exporterVersion=""
expressionLanguage="http://www.w3.org/1999/XPath"
id="sid-7b4298e2-d37d-4b00-ab34-579ea52b2d35"
targetNamespace="http://www.signavio.com/bpmn20"
typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="myProc" name="P3.bpmn20.xml">
<startEvent id="theStart" name="" />
<sequenceFlow id="sid-8EC53ABF-E45D-40F2-B53B-1D62B3531224" name="" sourceRef="theStart" targetRef="theScriptTask"/>
<scriptTask id="theScriptTask" name="Execute script" scriptFormat="groovy">
<script>
// Using def in Groovy makes the variable script-local
// It will not be stored autmatically (which is the case when not using def)
def scriptVar = "test123"
execution.setVariable("myVar", scriptVar)
</script>
</scriptTask>
<sequenceFlow id="sid-7CD58A88-0C17-4B28-BF0A-1A0695C77012" name="" sourceRef="theScriptTask" targetRef="userTask1"/>
<userTask id="userTask1" name="userTask1">
<humanPerformer id="sid-6fb5b033-ee58-438c-abf4-e4e2fdd543e7">
<resourceAssignmentExpression id="sid-d2837c98-373d-4700-b533-7662e95fc69d">
<formalExpression id="sid-d0113065-5fa3-4fb1-b361-2423defefd9d">fozzie</formalExpression>
</resourceAssignmentExpression>
</humanPerformer>
</userTask>
<sequenceFlow id="sid-A8708B31-2F4E-409C-A649-C75F7B52E66B" name="" sourceRef="userTask1" targetRef="theScriptTask1"/>
<scriptTask id="theScriptTask1" name="Execute script" scriptFormat="groovy">
<script>
// Using def in Groovy makes the variable script-local
// It will not be stored autmatically (which is the case when not using def)
def scriptVar = "test456"
execution.setVariable("myVar", scriptVar)
</script>
</scriptTask>
<sequenceFlow id="sid-A8708B31-2F4E-409C-A649-C75F7B52E66A" name="" sourceRef="theScriptTask1" targetRef="theEnd1"/>
<endEvent id="theEnd1" name="" />
</process>
</definitions>
......@@ -59,6 +59,10 @@ public class HistoricVariableInstanceBaseResource {
query.taskId(queryRequest.getTaskId());
}
if (queryRequest.getExecutionId() != null) {
query.executionId(queryRequest.getExecutionId());
}
if (queryRequest.getProcessInstanceId() != null) {
query.processInstanceId(queryRequest.getProcessInstanceId());
}
......@@ -69,6 +73,7 @@ public class HistoricVariableInstanceBaseResource {
if (queryRequest.getVariableNameLike() != null) {
query.variableNameLike(queryRequest.getVariableNameLike());
}
if (queryRequest.getVariables() != null) {
......
......@@ -42,6 +42,10 @@ public class HistoricVariableInstanceCollectionResource extends HistoricVariable
query.setTaskId(allRequestParams.get("taskId"));
}
if (allRequestParams.get("executionId") != null) {
query.setExecutionId(allRequestParams.get("executionId"));
}
if (allRequestParams.get("processInstanceId") != null) {
query.setProcessInstanceId(allRequestParams.get("processInstanceId"));
}
......@@ -53,7 +57,6 @@ public class HistoricVariableInstanceCollectionResource extends HistoricVariable
if (allRequestParams.get("variableNameLike") != null) {
query.setVariableNameLike(allRequestParams.get("variableNameLike"));
}
return getQueryResponse(query, allRequestParams);
}
}
......@@ -27,6 +27,7 @@ public class HistoricVariableInstanceQueryRequest {
private Boolean excludeTaskVariables;
private String taskId;
private String executionId;
private String processInstanceId;
private String variableName;
private String variableNameLike;
......@@ -48,6 +49,14 @@ public class HistoricVariableInstanceQueryRequest {
this.taskId = taskId;
}
public String getExecutionId() {
return executionId;
}
public void setExecutionId(String executionId) {
this.executionId = executionId;
}
public String getProcessInstanceId() {
return processInstanceId;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册