Skip to content

Commit

Permalink
Added deployment id query option + more process definition info to Pr…
Browse files Browse the repository at this point in the history
…ocessInstance object
  • Loading branch information
tijsrademakers committed Aug 11, 2014
1 parent a349dcf commit d568fe2
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public interface HistoricProcessInstanceQuery extends Query<HistoricProcessInsta

/** Only select historic process instances with the given business key */
HistoricProcessInstanceQuery processInstanceBusinessKey(String processInstanceBusinessKey);

/** Only select historic process instances that are defined by a process
* definition with the given deployment identifier. */
HistoricProcessInstanceQuery deploymentId(String deploymentId);

/** Only select historic process instances that are completely finished. */
HistoricProcessInstanceQuery finished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ExecutionQueryImpl extends AbstractVariableQueryImpl<ExecutionQuery
// Execution entity/table
protected String name;
protected String nameLike;
protected String deploymentId;

public ExecutionQueryImpl() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl<
protected String processInstanceId;
protected String processDefinitionId;
protected String businessKey;
protected String deploymentId;
protected boolean finished = false;
protected boolean unfinished = false;
protected String startedBy;
Expand Down Expand Up @@ -96,6 +97,11 @@ public HistoricProcessInstanceQuery processInstanceBusinessKey(String businessKe
this.businessKey = businessKey;
return this;
}

public HistoricProcessInstanceQuery deploymentId(String deploymentId) {
this.deploymentId = deploymentId;
return this;
}

public HistoricProcessInstanceQuery finished() {
this.finished = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ProcessInstanceQueryImpl extends AbstractVariableQueryImpl<ProcessI
protected String processDefinitionName;
protected Set<String> processInstanceIds;
protected String processDefinitionKey;
protected String deploymentId;
protected String superProcessInstanceId;
protected String subProcessInstanceId;
protected boolean excludeSubprocesses;
Expand Down Expand Up @@ -152,6 +153,11 @@ public ProcessInstanceQueryImpl processDefinitionKey(String processDefinitionKey
return this;
}

public ProcessInstanceQueryImpl deploymentId(String deploymentId) {
this.deploymentId = deploymentId;
return this;
}

public ProcessInstanceQuery superProcessInstanceId(String superProcessInstanceId) {
this.superProcessInstanceId = superProcessInstanceId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.BulkDeleteable;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.HasRevision;
import org.activiti.engine.impl.db.PersistentObject;
Expand Down Expand Up @@ -178,6 +177,26 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
* @see #getProcessDefinition()
*/
protected String processDefinitionId;

/**
* persisted reference to the process definition key.
*/
protected String processDefinitionKey;

/**
* persisted reference to the process definition name.
*/
protected String processDefinitionName;

/**
* persisted reference to the process definition version.
*/
protected Integer processDefinitionVersion;

/**
* persisted reference to the deployment id.
*/
protected String deploymentId;

/**
* persisted reference to the current position in the diagram within the
Expand Down Expand Up @@ -717,6 +736,38 @@ public String getProcessDefinitionId() {
return processDefinitionId;
}

public String getProcessDefinitionKey() {
return processDefinitionKey;
}

public void setProcessDefinitionKey(String processDefinitionKey) {
this.processDefinitionKey = processDefinitionKey;
}

public String getProcessDefinitionName() {
return processDefinitionName;
}

public void setProcessDefinitionName(String processDefinitionName) {
this.processDefinitionName = processDefinitionName;
}

public Integer getProcessDefinitionVersion() {
return processDefinitionVersion;
}

public void setProcessDefinitionVersion(Integer processDefinitionVersion) {
this.processDefinitionVersion = processDefinitionVersion;
}

public String getDeploymentId() {
return deploymentId;
}

public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}

/** for setting the process definition, this setter must be used as subclasses can override */
protected void ensureProcessDefinitionInitialized() {
if ((processDefinition == null) && (processDefinitionId != null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @author Tom Baeyens
* @author Joram Barrez
* @author Daniel Meyer
* @author Tijs Rademakers
*/
public interface ProcessInstance extends Execution {

Expand All @@ -31,6 +32,26 @@ public interface ProcessInstance extends Execution {
*/
String getProcessDefinitionId();

/**
* The name of the process definition of the process instance.
*/
String getProcessDefinitionName();

/**
* The key of the process definition of the process instance.
*/
String getProcessDefinitionKey();

/**
* The version of the process definition of the process instance.
*/
Integer getProcessDefinitionVersion();

/**
* The deployment id of the process definition of the process instance.
*/
String getDeploymentId();

/**
* The business key of this process instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public interface ProcessInstanceQuery extends Query<ProcessInstanceQuery, Proces
* with the given id.
*/
ProcessInstanceQuery processDefinitionId(String processDefinitionId);

/**
* Select the process instances which are defined by a deployment
* with the given id.
*/
ProcessInstanceQuery deploymentId(String deploymentId);

/**
* Select the process instances which are a sub process instance of the given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@
<result property="name" column="NAME_" jdbcType="VARCHAR" />
</resultMap>

<resultMap id="processInstanceResultMap" type="org.activiti.engine.impl.persistence.entity.ExecutionEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR" />
<result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
<result property="processDefinitionName" column="ProcessDefinitionName" jdbcType="VARCHAR" />
<result property="processDefinitionKey" column="ProcessDefinitionKey" jdbcType="VARCHAR" />
<result property="processDefinitionVersion" column="ProcessDefinitionVersion" jdbcType="INTEGER" />
<result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />
<result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
<result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
<result property="isConcurrent" column="IS_CONCURRENT_" jdbcType="BOOLEAN" />
<result property="isScope" column="IS_SCOPE_" jdbcType="BOOLEAN" />
<result property="isEventScope" column="IS_EVENT_SCOPE_" jdbcType="BOOLEAN" />
<result property="parentId" column="PARENT_ID_" jdbcType="VARCHAR" />
<result property="superExecutionId" column="SUPER_EXEC_" jdbcType="VARCHAR" />
<result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/>
<result property="cachedEntityState" column="CACHED_ENT_STATE_" jdbcType="INTEGER"/>
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
<result property="name" column="NAME_" jdbcType="VARCHAR" />
</resultMap>

<resultMap id="executionAndVariablesResultMap" type="org.activiti.engine.impl.persistence.entity.ExecutionEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER" />
Expand Down Expand Up @@ -142,6 +165,43 @@
</collection>
</resultMap>

<resultMap id="processInstanceAndVariablesResultMap" type="org.activiti.engine.impl.persistence.entity.ExecutionEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR" />
<result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
<result property="processDefinitionName" column="ProcessDefinitionName" jdbcType="VARCHAR" />
<result property="processDefinitionKey" column="ProcessDefinitionKey" jdbcType="VARCHAR" />
<result property="processDefinitionVersion" column="ProcessDefinitionVersion" jdbcType="INTEGER" />
<result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />
<result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
<result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
<result property="isConcurrent" column="IS_CONCURRENT_" jdbcType="BOOLEAN" />
<result property="isScope" column="IS_SCOPE_" jdbcType="BOOLEAN" />
<result property="isEventScope" column="IS_EVENT_SCOPE_" jdbcType="BOOLEAN" />
<result property="parentId" column="PARENT_ID_" jdbcType="VARCHAR" />
<result property="superExecutionId" column="SUPER_EXEC_" jdbcType="VARCHAR" />
<result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/>
<result property="cachedEntityState" column="CACHED_ENT_STATE_" jdbcType="INTEGER"/>
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
<result property="name" column="NAME_" jdbcType="VARCHAR" />
<collection property="queryVariables" column="EXECUTION_ID_" javaType="ArrayList" ofType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
<id property="id" column="VAR_ID_"/>
<result property="name" column="VAR_NAME_" javaType="String" jdbcType="VARCHAR" />
<result property="type" column="VAR_TYPE_" javaType="org.activiti.engine.impl.variable.VariableType" jdbcType="VARCHAR" />
<result property="revision" column="VAR_REV_" jdbcType="INTEGER" />
<result property="processInstanceId" column="VAR_PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="executionId" column="VAR_EXECUTION_ID_" jdbcType="VARCHAR" />
<result property="taskId" column="VAR_TASK_ID_" jdbcType="VARCHAR" />
<result property="byteArrayRef" column="VAR_BYTEARRAY_ID_" typeHandler="ByteArrayRefTypeHandler"/>
<result property="doubleValue" column="VAR_DOUBLE_" jdbcType="DOUBLE" />
<result property="textValue" column="VAR_TEXT_" jdbcType="VARCHAR" />
<result property="textValue2" column="VAR_TEXT2_" jdbcType="VARCHAR" />
<result property="longValue" column="VAR_LONG_" jdbcType="BIGINT" />
</collection>
</resultMap>

<!-- EXECUTION SELECT -->

<select id="selectExecution" parameterType="string" resultMap="executionResultMap">
Expand Down Expand Up @@ -178,9 +238,9 @@
</select>

<!-- same as selectExecutionsByQueryCriteria, but with different parameterType -->
<select id="selectProcessInstanceByQueryCriteria" parameterType="org.activiti.engine.impl.ProcessInstanceQueryImpl" resultMap="executionResultMap">
<select id="selectProcessInstanceByQueryCriteria" parameterType="org.activiti.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceResultMap">
${limitBefore}
select distinct RES.* ${limitBetween}, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId
select distinct RES.* ${limitBetween}, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.DEPLOYMENT_ID_ as DeploymentId
<include refid="selectExecutionsByQueryCriteriaSql"/>
${orderBy}
${limitAfter}
Expand All @@ -197,9 +257,9 @@
<include refid="commonSelectExecutionsByQueryCriteriaSql"/>
</sql>

<select id="selectProcessInstanceWithVariablesByQueryCriteria" parameterType="org.activiti.engine.impl.ProcessInstanceQueryImpl" resultMap="executionAndVariablesResultMap">
<select id="selectProcessInstanceWithVariablesByQueryCriteria" parameterType="org.activiti.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceAndVariablesResultMap">
${limitBefore}
select distinct RES.*, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId,
select distinct RES.*, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.DEPLOYMENT_ID_ as DeploymentId,
VAR.ID_ as VAR_ID_, VAR.NAME_ as VAR_NAME_, VAR.TYPE_ as VAR_TYPE_, VAR.REV_ as VAR_REV_,
VAR.PROC_INST_ID_ as VAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as VAR_EXECUTION_ID_, VAR.TASK_ID_ as VAR_TASK_ID_,
VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_,
Expand All @@ -210,9 +270,9 @@
${limitAfter}
</select>

<select id="selectProcessInstanceWithVariablesByQueryCriteria_mssql_or_db2" parameterType="org.activiti.engine.impl.ProcessInstanceQueryImpl" resultMap="executionAndVariablesResultMap">
<select id="selectProcessInstanceWithVariablesByQueryCriteria_mssql_or_db2" parameterType="org.activiti.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceAndVariablesResultMap">
${limitBefore}
select distinct TEMPRES_ID_ as ID_, TEMPP_KEY_ as ProcessDefinitionKey, TEMPP_ID_ as ProcessDefinitionId,
select distinct TEMPRES_ID_ as ID_, TEMPP_KEY_ as ProcessDefinitionKey, TEMPP_ID_ as ProcessDefinitionId, TEMPP.NAME_ as ProcessDefinitionName, TEMPP.VERSION_ as ProcessDefinitionVersion, TEMPP.DEPLOYMENT_ID_ as DeploymentId,
TEMPRES_REV_ as REV_, TEMPRES_ACT_ID_ as ACT_ID_,
TEMPRES_BUSINESS_KEY_ as BUSINESS_KEY_, TEMPRES_IS_ACTIVE_ as IS_ACTIVE_,
TEMPRES_IS_CONCURRENT_ as IS_CONCURRENT_, TEMPRES_IS_SCOPE_ as IS_SCOPE_,
Expand All @@ -224,7 +284,7 @@
TEMPVAR_BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, TEMPVAR_DOUBLE_ as VAR_DOUBLE_,
TEMPVAR_TEXT_ as VAR_TEXT_, TEMPVAR_TEXT2_ as VAR_TEXT2_, TEMPVAR_LONG_ as VAR_LONG_
${limitOuterJoinBetween}
RES.ID_ as TEMPRES_ID_, RES.REV_ as TEMPRES_REV_, P.KEY_ as TEMPP_KEY_, P.ID_ as TEMPP_ID_,
RES.ID_ as TEMPRES_ID_, RES.REV_ as TEMPRES_REV_, P.KEY_ as TEMPP_KEY_, P.ID_ as TEMPP_ID_, P.NAME_ as TEMPP_NAME_, P.VERSION_ as TEMPP_VERSION_, P.DEPLOYMENT_ID_ as TEMPP.DEPLOYMENT_ID_,
RES.ACT_ID_ as TEMPRES_ACT_ID_, RES.PROC_INST_ID_ as TEMPRES_PROC_INST_ID_,
RES.BUSINESS_KEY_ as TEMPRES_BUSINESS_KEY_, RES.IS_ACTIVE_ as TEMPRES_IS_ACTIVE_,
RES.IS_CONCURRENT_ as TEMPRES_IS_CONCURRENT_, RES.IS_SCOPE_ as TEMPRES_IS_SCOPE_,
Expand Down Expand Up @@ -268,6 +328,9 @@
<if test="businessKey != null and includeChildExecutionsWithBusinessKeyQuery">
inner join ${prefix}ACT_RU_EXECUTION INST on RES.PROC_INST_ID_ = INST.ID_
</if>
<if test="deploymentId != null">
left outer join ${prefix}ACT_RE_PROCDEF DEPLOY_P ON RES.PROC_DEF_ID_ = DEPLOY_P.ID_
</if>
<where>
<if test="onlyProcessInstances">
RES.PARENT_ID_ is null
Expand Down Expand Up @@ -305,6 +368,9 @@
<if test="parentId != null">
and RES.PARENT_ID_ = #{parentId}
</if>
<if test="deploymentId != null">
and DEPLOY_P.DEPLOYMENT_ID_ = #{deploymentId}
</if>
<if test="superProcessInstanceId != null">
<!-- A sub process instance is stored under a certain *execution*, potentially nested.
A sub process instance is NOT stored under the process instanc, hence the following: -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="businessKey" column="BUSINESS_KEY_" jdbcType="VARCHAR"/>
<result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
<result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />
<result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
<result property="endTime" column="END_TIME_" jdbcType="TIMESTAMP" />
<result property="durationInMillis" column="DURATION_" jdbcType="BIGINT" />
Expand Down Expand Up @@ -218,7 +219,10 @@
</if>
<foreach collection="queryVariableValues" index="index" item="queryVariableValue">
inner join ${prefix}ACT_HI_VARINST A${index} on RES.PROC_INST_ID_ = A${index}.PROC_INST_ID_
</foreach>
</foreach>
<if test="deploymentId != null">
left outer join ${prefix}ACT_RE_PROCDEF DEPLOY_P ON RES.PROC_DEF_ID_ = DEPLOY_P.ID_
</if>
<where>
<if test="processInstanceId != null">
RES.PROC_INST_ID_ = #{processInstanceId}
Expand All @@ -238,7 +242,9 @@
<if test="businessKey != null">
and RES.BUSINESS_KEY_ = #{businessKey}
</if>

<if test="deploymentId != null">
and DEPLOY_P.DEPLOYMENT_ID_ = #{deploymentId}
</if>
<if test="startedBefore != null">
and RES.START_TIME_ &lt;= #{startedBefore}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ public void testHistoricProcessInstanceQueryByProcessInstanceIdsNull() {
assertTextPresent("Set of process instance ids is null", re.getMessage());
}
}

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByDeploymentId() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
HashSet<String> processInstanceIds = new HashSet<String>();
for (int i = 0; i < 4; i++) {
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
}
processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());

HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentId(deployment.getId());
assertEquals(5, processInstanceQuery.count());

List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
assertNotNull(processInstances);
assertEquals(5, processInstances.size());

processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentId("invalid");
assertEquals(0, processInstanceQuery.count());
}

@Deployment(resources = { "org/activiti/engine/test/api/runtime/concurrentExecution.bpmn20.xml" })
public void testHistoricVariableInstancesOnParallelExecution() {
Expand Down
Loading

0 comments on commit d568fe2

Please sign in to comment.