Skip to content

Commit

Permalink
#3659: Return definition category
Browse files Browse the repository at this point in the history
  • Loading branch information
amporsim committed Sep 15, 2023
1 parent 5dd3aff commit 7ce16f5
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public interface HistoricProcessInstance {
/** The version of the process definition of the process instance. */
Integer getProcessDefinitionVersion();

/**
* The category of the process definition of the process instance.
*/
String getProcessDefinitionCategory();

/**
* The deployment id of the process definition of the process instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected void updateExecutions(CommandContext commandContext, ProcessDefinition
String previousProcessDefinitionId = processInstance.getProcessDefinitionId();
processInstance.setProcessDefinitionId(processDefinitionEntity.getId());
processInstance.setProcessDefinitionVersion(processDefinitionEntity.getVersion());
processInstance.setProcessDefinitionCategory(processDefinitionEntity.getCategory());

ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
List<TaskEntity> currentTasks = processEngineConfiguration.getTaskServiceConfiguration().getTaskService()
Expand Down Expand Up @@ -175,6 +176,7 @@ protected void updateExecutions(CommandContext commandContext, ProcessDefinition
for (ExecutionEntity childExecution : childExecutions) {
childExecution.setProcessDefinitionId(processDefinitionEntity.getId());
childExecution.setProcessDefinitionVersion(processDefinitionEntity.getVersion());
childExecution.setProcessDefinitionCategory(processDefinitionEntity.getCategory());
}

updateExecutions(commandContext, processDefinitionEntity, processInstance, childExecutions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface ExecutionEntity extends DelegateExecution, Execution, ProcessIn
Comparator<ExecutionEntity> EXECUTION_ENTITY_START_TIME_ASC_COMPARATOR = comparing(ProcessInstance::getStartTime);

void setBusinessKey(String businessKey);

void setBusinessStatus(String businessStatus);

void setProcessDefinitionId(String processDefinitionId);
Expand All @@ -54,6 +54,8 @@ public interface ExecutionEntity extends DelegateExecution, Execution, ProcessIn

void setProcessDefinitionVersion(Integer processDefinitionVersion);

void setProcessDefinitionCategory(String processDefinitionCategory);

void setDeploymentId(String deploymentId);

ExecutionEntity getProcessInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ public class ExecutionEntityImpl extends AbstractBpmnEngineVariableScopeEntity i
*/
protected Integer processDefinitionVersion;

/**
* persisted reference to the process definition version.
*/
protected String processDefinitionCategory;

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

/**
* Persisted reference to the current position in the diagram within the {@link #processDefinitionId}.
*
*
* @see #activityId
* @see #setActivityId(String)
* @see #getActivityId()
Expand Down Expand Up @@ -463,6 +468,19 @@ public void setProcessDefinitionVersion(Integer processDefinitionVersion) {
this.processDefinitionVersion = processDefinitionVersion;
}

@Override
public String getProcessDefinitionCategory() {
if (StringUtils.isEmpty(processDefinitionCategory) && StringUtils.isNotEmpty(processDefinitionId)) {
resolveProcessDefinitionInfo();
}
return processDefinitionCategory;
}

@Override
public void setProcessDefinitionCategory(String processDefinitionCategory) {
this.processDefinitionCategory = processDefinitionCategory;
}

@Override
public String getDeploymentId() {
if (StringUtils.isEmpty(deploymentId) && StringUtils.isNotEmpty(processDefinitionId)) {
Expand Down Expand Up @@ -1472,6 +1490,7 @@ protected void resolveProcessDefinitionInfo() {
this.processDefinitionKey = processDefinition.getKey();
this.processDefinitionName = processDefinition.getName();
this.processDefinitionVersion = processDefinition.getVersion();
this.processDefinitionCategory = processDefinition.getCategory();
this.deploymentId = processDefinition.getDeploymentId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public ExecutionEntity createProcessInstanceExecution(ProcessDefinition processD
processInstanceExecution.setProcessDefinitionKey(processDefinition.getKey());
processInstanceExecution.setProcessDefinitionName(processDefinition.getName());
processInstanceExecution.setProcessDefinitionVersion(processDefinition.getVersion());
processInstanceExecution.setProcessDefinitionCategory(processDefinition.getCategory());
processInstanceExecution.setDeploymentId(processDefinition.getDeploymentId());
processInstanceExecution.setBusinessKey(businessKey);
processInstanceExecution.setBusinessStatus(businessStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface HistoricProcessInstanceEntity extends HistoricScopeInstanceEnti
void setEndActivityId(String endActivityId);

void setBusinessKey(String businessKey);

void setBusinessStatus(String businessStatus);

void setStartUserId(String startUserId);
Expand All @@ -53,18 +53,20 @@ public interface HistoricProcessInstanceEntity extends HistoricScopeInstanceEnti

void setProcessDefinitionVersion(Integer processDefinitionVersion);

void setProcessDefinitionCategory(String processDefinitionCategory);

void setDeploymentId(String deploymentId);

void setCallbackId(String callbackId);

void setCallbackType(String callbackType);

void setReferenceId(String referenceId);

void setReferenceType(String referenceType);

void setPropagatedStageInstanceId(String propagatedStageInstanceId);

List<HistoricVariableInstanceEntity> getQueryVariables();

void setQueryVariables(List<HistoricVariableInstanceEntity> queryVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class HistoricProcessInstanceEntityImpl extends HistoricScopeInstanceEnti
protected String processDefinitionKey;
protected String processDefinitionName;
protected Integer processDefinitionVersion;
protected String processDefinitionCategory;
protected String deploymentId;
protected String callbackId;
protected String callbackType;
Expand All @@ -68,6 +69,7 @@ public HistoricProcessInstanceEntityImpl(ExecutionEntity processInstance) {
this.processDefinitionKey = processInstance.getProcessDefinitionKey();
this.processDefinitionName = processInstance.getProcessDefinitionName();
this.processDefinitionVersion = processInstance.getProcessDefinitionVersion();
this.processDefinitionCategory = processInstance.getProcessDefinitionCategory();
this.deploymentId = processInstance.getDeploymentId();
this.startActivityId = processInstance.getStartActivityId();
this.startTime = processInstance.getStartTime();
Expand Down Expand Up @@ -101,6 +103,7 @@ public Object getPersistentState() {
persistentState.put("processDefinitionKey", processDefinitionKey);
persistentState.put("processDefinitionName", processDefinitionName);
persistentState.put("processDefinitionVersion", processDefinitionVersion);
persistentState.put("processDefinitionCategory", processDefinitionCategory);
persistentState.put("deploymentId", deploymentId);
persistentState.put("callbackId", callbackId);
persistentState.put("callbackType", callbackType);
Expand Down Expand Up @@ -258,6 +261,16 @@ public void setProcessDefinitionVersion(Integer processDefinitionVersion) {
this.processDefinitionVersion = processDefinitionVersion;
}

@Override
public String getProcessDefinitionCategory() {
return processDefinitionCategory;
}

@Override
public void setProcessDefinitionCategory(String processDefinitionCategory) {
this.processDefinitionCategory = processDefinitionCategory;
}

@Override
public String getDeploymentId() {
return deploymentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public interface ProcessInstance extends Execution {
*/
Integer getProcessDefinitionVersion();

/**
* The category of the process definition of the process instance.
*/
String getProcessDefinitionCategory();

/**
* The deployment id of the process definition of the process instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
<result property="processDefinitionName" column="ProcessDefinitionName" jdbcType="VARCHAR" />
<result property="processDefinitionKey" column="ProcessDefinitionKey" jdbcType="VARCHAR" />
<result property="processDefinitionVersion" column="ProcessDefinitionVersion" jdbcType="INTEGER" />
<result property="processDefinitionCategory" column="ProcessDefinitionCategory" jdbcType="VARCHAR"/>
<result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />

<result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
Expand Down Expand Up @@ -474,6 +475,7 @@
<result property="processDefinitionName" column="ProcessDefinitionName" jdbcType="VARCHAR" />
<result property="processDefinitionKey" column="ProcessDefinitionKey" jdbcType="VARCHAR" />
<result property="processDefinitionVersion" column="ProcessDefinitionVersion" jdbcType="INTEGER" />
<result property="processDefinitionCategory" column="ProcessDefinitionCategory" jdbcType="VARCHAR"/>
<result property="deploymentId" column="DeploymentId" jdbcType="VARCHAR" />
<result property="activityId" column="ACT_ID_" jdbcType="VARCHAR" />
<result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
Expand Down Expand Up @@ -581,71 +583,77 @@
and IS_ACTIVE_ = #{parameter.isActive}
</select>

<select id="selectExecutionsByParentExecutionAndActivityIds" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject" resultMap="executionResultMap">
select *
from ${prefix}ACT_RU_EXECUTION
where PARENT_ID_ = #{parameter.parentExecutionId}
and ACT_ID_ in
<foreach item="activityId" collection="parameter.activityIds" open="(" separator="," close=")">
#{activityId}
</foreach>
</select>
<select id="selectExecutionsByParentExecutionAndActivityIds" parameterType="org.flowable.common.engine.impl.db.ListQueryParameterObject"
resultMap="executionResultMap">
select *
from ${prefix}ACT_RU_EXECUTION
where PARENT_ID_ = #{parameter.parentExecutionId}
and ACT_ID_ in
<foreach item="activityId" collection="parameter.activityIds" open="(" separator="," close=")">
#{activityId}
</foreach>
</select>

<select id="selectExecutionsByQueryCriteria" parameterType="org.flowable.engine.impl.ExecutionQueryImpl" resultMap="executionResultMap">
<if test="needsPaging">${limitBefore}</if>
SELECT RES.* <if test="needsPaging">${limitBetween}</if>, 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}
<if test="needsPaging">${limitAfter}</if>
</select>
<select id="selectExecutionsByQueryCriteria" parameterType="org.flowable.engine.impl.ExecutionQueryImpl" resultMap="executionResultMap">
<if test="needsPaging">${limitBefore}</if>
SELECT RES.* <if test="needsPaging">${limitBetween}</if>, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as
ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.CATEGORY_ as ProcessDefinitionCategory, P.DEPLOYMENT_ID_ as DeploymentId
<include refid="selectExecutionsByQueryCriteriaSql"/>
${orderBy}
<if test="needsPaging">${limitAfter}</if>
</select>

<select id="selectExecutionCountByQueryCriteria" parameterType="org.flowable.engine.impl.ExecutionQueryImpl" resultType="long">
select count(distinct RES.ID_)
<include refid="selectExecutionsByQueryCriteriaSql"/>
</select>
<select id="selectExecutionCountByQueryCriteria" parameterType="org.flowable.engine.impl.ExecutionQueryImpl" resultType="long">
select count(distinct RES.ID_)
<include refid="selectExecutionsByQueryCriteriaSql"/>
</select>

<!-- same as selectExecutionsByQueryCriteria, but with different parameterType -->
<select id="selectProcessInstanceByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceResultMap">
<if test="needsPaging">${limitBefore}</if>
SELECT RES.* <if test="needsPaging">${limitBetween}</if>, 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}
<if test="needsPaging">${limitAfter}</if>
</select>
<!-- same as selectExecutionsByQueryCriteria, but with different parameterType -->
<select id="selectProcessInstanceByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceResultMap">
<if test="needsPaging">${limitBefore}</if>
SELECT RES.* <if test="needsPaging">${limitBetween}</if>, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as
ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.CATEGORY_ as ProcessDefinitionCategory, P.DEPLOYMENT_ID_ as DeploymentId
<include refid="selectExecutionsByQueryCriteriaSql"/>
${orderBy}
<if test="needsPaging">${limitAfter}</if>
</select>

<select id="selectProcessInstanceCountByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultType="long">
select count(distinct RES.ID_)
<include refid="selectExecutionsByQueryCriteriaSql"/>
</select>
<select id="selectProcessInstanceCountByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultType="long">
select count(distinct RES.ID_)
<include refid="selectExecutionsByQueryCriteriaSql"/>
</select>

<sql id="selectExecutionsByQueryCriteriaSql">
from ${prefix}ACT_RU_EXECUTION RES
<!-- Doing an inner join on the definition table is OK, since it is a 1:1 relationship -->
inner join ${prefix}ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_
<include refid="commonSelectExecutionsByQueryCriteriaSql"/>
</sql>
<sql id="selectExecutionsByQueryCriteriaSql">
from ${prefix}ACT_RU_EXECUTION RES
<!-- Doing an inner join on the definition table is OK, since it is a 1:1 relationship -->
inner join ${prefix}ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_
<include refid="commonSelectExecutionsByQueryCriteriaSql"/>
</sql>

<select id="selectProcessInstanceWithVariablesByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl" resultMap="processInstanceAndVariablesResultMap">
SELECT RES.*,
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.META_INFO_ as VAR_META_INFO_,
VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_,
VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT2_, VAR.LONG_ as VAR_LONG_
FROM (
<select id="selectProcessInstanceWithVariablesByQueryCriteria" parameterType="org.flowable.engine.impl.ProcessInstanceQueryImpl"
resultMap="processInstanceAndVariablesResultMap">
SELECT RES.*,
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.META_INFO_ as VAR_META_INFO_,
VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_,
VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT2_, VAR.LONG_ as VAR_LONG_
FROM (
<!-- top 100 percent is only needed when doing order by in a subselect -->
<if test="needsPaging">${limitBefore}</if>
SELECT <if test="_databaseId == 'mssql'">top 100 percent</if> RES.* <if test="needsPaging">${limitBetween}</if>, P.KEY_ as ProcessDefinitionKey, P.ID_ as ProcessDefinitionId, P.NAME_ as ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.DEPLOYMENT_ID_ as DeploymentId
SELECT <if test="_databaseId == 'mssql'">top 100 percent</if> RES.* <if test="needsPaging">${limitBetween}</if>, P.KEY_ as ProcessDefinitionKey, P.ID_
as ProcessDefinitionId, P.NAME_ as ProcessDefinitionName, P.VERSION_ as ProcessDefinitionVersion, P.CATEGORY_ as ProcessDefinitionCategory,
P.DEPLOYMENT_ID_ as DeploymentId
<include refid="selectProcessInstanceWithVariablesByQueryCriteriaSql"/>
${orderBy}
<if test="needsPaging">${limitAfter}</if>
) RES
left outer join ${prefix}ACT_RU_VARIABLE VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
<if test="needsProcessDefinitionOuterJoin">
inner join ${prefix}ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_
</if>
${outerJoinOrderBy}
</select>
) RES
left outer join ${prefix}ACT_RU_VARIABLE VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
<if test="needsProcessDefinitionOuterJoin">
inner join ${prefix}ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_
</if>
${outerJoinOrderBy}
</select>

<sql id="selectProcessInstanceWithVariablesByQueryCriteriaSql">
from ${prefix}ACT_RU_EXECUTION RES
Expand Down
Loading

0 comments on commit 7ce16f5

Please sign in to comment.