提交 fe62bf93 编写于 作者: T trademak

Added query possibility in HistoricProcessInstance to search for process...

Added query possibility in HistoricProcessInstance to search for process instances that have a specific super process instance.
This makes it possible to retrieve sub processes created via a call activity based on the parent process instance id.
上级 c4d5732e
......@@ -60,4 +60,6 @@ public interface HistoricProcessInstanceQuery extends Query<HistoricProcessInsta
/** Order by the duration of the process instance (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricProcessInstanceQuery orderByProcessInstanceDuration();
HistoricProcessInstanceQuery superProcessInstanceId(String superProcessInstanceId);
}
......@@ -32,6 +32,7 @@ public class HistoricProcessInstanceQueryImpl extends AbstractQuery<HistoricProc
protected boolean finished = false;
protected boolean unfinished = false;
protected String startedBy;
protected String superProcessInstanceId;
public HistoricProcessInstanceQueryImpl() {
}
......@@ -74,6 +75,11 @@ public class HistoricProcessInstanceQueryImpl extends AbstractQuery<HistoricProc
return this;
}
public HistoricProcessInstanceQuery superProcessInstanceId(String superProcessInstanceId) {
this.superProcessInstanceId = superProcessInstanceId;
return this;
}
public HistoricProcessInstanceQuery orderByProcessInstanceBusinessKey() {
return orderBy(HistoricProcessInstanceQueryProperty.BUSINESS_KEY);
}
......@@ -127,5 +133,11 @@ public class HistoricProcessInstanceQueryImpl extends AbstractQuery<HistoricProc
public String getStartedBy() {
return startedBy;
}
public String getSuperProcessInstanceId() {
return superProcessInstanceId;
}
public void setSuperProcessInstanceId(String superProcessInstanceId) {
this.superProcessInstanceId = superProcessInstanceId;
}
}
\ No newline at end of file
......@@ -31,6 +31,7 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
protected String businessKey;
protected String startUserId;
protected String startActivityId;
protected String superProcessInstanceId;
public HistoricProcessInstanceEntity() {
}
......@@ -43,6 +44,7 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
startTime = ClockUtil.getCurrentTime();
startUserId = Authentication.getAuthenticatedUserId();
startActivityId = processInstance.getActivityId();
superProcessInstanceId = processInstance.getSuperExecution() != null ? processInstance.getSuperExecution().getProcessInstanceId() : null;
}
......@@ -52,6 +54,7 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
persistentState.put("durationInMillis", durationInMillis);
persistentState.put("deleteReason", deleteReason);
persistentState.put("endStateName", endActivityId);
persistentState.put("superProcessInstanceId", superProcessInstanceId);
return persistentState;
}
......@@ -82,4 +85,11 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
public void setStartActivityId(String startUserId) {
this.startActivityId = startUserId;
}
public String getSuperProcessInstanceId() {
return superProcessInstanceId;
}
public void setSuperProcessInstanceId(String superProcessInstanceId) {
this.superProcessInstanceId = superProcessInstanceId;
}
}
......@@ -9,6 +9,7 @@ create table ACT_HI_PROCINST (
START_USER_ID_ varchar(255),
START_ACT_ID_ varchar(255),
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
UNI_BUSINESS_KEY varchar (255) not null generated always as (case when "BUSINESS_KEY_" is null then "ID_" else "BUSINESS_KEY_" end),
UNI_PROC_DEF_ID varchar (64) not null generated always as (case when "PROC_DEF_ID_" is null then "ID_" else "PROC_DEF_ID_" end),
primary key (ID_),
......
......@@ -9,6 +9,7 @@ create table ACT_HI_PROCINST (
START_USER_ID_ varchar(255),
START_ACT_ID_ varchar(255),
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
primary key (ID_),
unique (PROC_INST_ID_)
);
......
......@@ -9,6 +9,7 @@ create table ACT_HI_PROCINST (
START_USER_ID_ nvarchar(255),
START_ACT_ID_ nvarchar(255),
END_ACT_ID_ nvarchar(255),
SUPER_PROCESS_INSTANCE_ID_ nvarchar(64),
primary key (ID_),
unique (PROC_INST_ID_)
);
......
......@@ -9,6 +9,7 @@ create table ACT_HI_PROCINST (
START_USER_ID_ varchar(255),
START_ACT_ID_ varchar(255),
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
primary key (ID_),
unique (PROC_INST_ID_),
unique ACT_UNIQ_HI_BUS_KEY (PROC_DEF_ID_, BUSINESS_KEY_)
......
......@@ -9,6 +9,7 @@ create table ACT_HI_PROCINST (
START_USER_ID_ NVARCHAR2(255),
START_ACT_ID_ NVARCHAR2(255),
END_ACT_ID_ NVARCHAR2(255),
SUPER_PROCESS_INSTANCE_ID_ NVARCHAR2(64),
primary key (ID_),
unique (PROC_INST_ID_)
);
......
......@@ -9,6 +9,7 @@ create table ACT_HI_PROCINST (
START_USER_ID_ varchar(255),
START_ACT_ID_ varchar(255),
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
primary key (ID_),
unique (PROC_INST_ID_),
unique (PROC_DEF_ID_, BUSINESS_KEY_)
......
......@@ -31,7 +31,8 @@
DURATION_,
START_USER_ID_,
START_ACT_ID_,
END_ACT_ID_
END_ACT_ID_,
SUPER_PROCESS_INSTANCE_ID_
) values (
#{id ,jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
......@@ -42,7 +43,8 @@
#{durationInMillis ,jdbcType=BIGINT},
#{startUserId, jdbcType=VARCHAR},
#{startActivityId, jdbcType=VARCHAR},
#{endActivityId, jdbcType=VARCHAR}
#{endActivityId, jdbcType=VARCHAR},
#{superProcessInstanceId, jdbcType=VARCHAR},
)
</insert>
......@@ -76,6 +78,7 @@
<result property="startUserId" column="START_USER_ID_" jdbcType="VARCHAR" />
<result property="startActivityId" column="START_ACT_ID_" jdbcType="VARCHAR" />
<result property="endActivityId" column="END_ACT_ID_" jdbcType="VARCHAR" />
<result property="superProcessInstanceId" column="SUPER_PROCESS_INSTANCE_ID_" jdbcType="VARCHAR" />
</resultMap>
<!-- HISTORIC PROCESS INSTANCE SELECT -->
......@@ -125,6 +128,10 @@
<if test="startedBy != null">
and HPI.START_USER_ID_ = #{startedBy}
</if>
<if test="superProcessInstanceId != null">
and HPI.SUPER_PROCESS_INSTANCE_ID_ = #{superProcessInstanceId}
</if>
</where>
</sql>
......
......@@ -17,8 +17,10 @@ import java.util.List;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.impl.util.CollectionUtil;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.activiti.engine.test.Deployment;
/**
......@@ -57,4 +59,27 @@ public class HistoryServiceTest extends PluggableActivitiTestCase {
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
assertEquals("theEnd", historicProcessInstance.getEndActivityId());
}
@Deployment(resources={
"org/activiti/examples/bpmn/callactivity/orderProcess.bpmn20.xml",
"org/activiti/examples/bpmn/callactivity/checkCreditProcess.bpmn20.xml"
})
public void testOrderProcessWithCallActivity() {
// 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();
// 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());
//verify
HistoricProcessInstance historicProcessInstance =
historyService.createHistoricProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
assertNotNull(historicProcessInstance);
assertTrue(historicProcessInstance.getProcessDefinitionId().contains("checkCreditProcess"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册