提交 eb9acf7b 编写于 作者: T tijsrademakers

Added form key to historic task instance

上级 8d17190c
......@@ -72,6 +72,9 @@ public interface HistoricTaskInstance {
/** Task definition key. */
String getTaskDefinitionKey();
/** Task form key. */
String getFormKey();
/** Task priority **/
int getPriority();
......
......@@ -17,11 +17,13 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.impl.HistoricActivityInstanceQueryImpl;
import org.activiti.engine.impl.cfg.IdGenerator;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.form.TaskFormHandler;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.impl.persistence.AbstractManager;
import org.activiti.engine.impl.persistence.entity.CommentEntity;
......@@ -39,6 +41,7 @@ import org.activiti.engine.impl.pvm.runtime.InterpretableExecution;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.task.Event;
import org.activiti.engine.task.IdentityLink;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -460,11 +463,21 @@ public class HistoryManager extends AbstractManager {
/**
* Record task definition key change, if audit history is enabled.
*/
public void recordTaskDefinitionKeyChange(String taskId, String taskDefinitionKey) {
public void recordTaskDefinitionKeyChange(TaskEntity task, String taskDefinitionKey) {
if (isHistoryLevelAtLeast(HistoryLevel.AUDIT)) {
HistoricTaskInstanceEntity historicTaskInstance = getDbSqlSession().selectById(HistoricTaskInstanceEntity.class, taskId);
HistoricTaskInstanceEntity historicTaskInstance = getDbSqlSession().selectById(HistoricTaskInstanceEntity.class, task.getId());
if (historicTaskInstance!=null) {
historicTaskInstance.setTaskDefinitionKey(taskDefinitionKey);
if (taskDefinitionKey != null) {
TaskFormHandler taskFormHandler = task.getTaskDefinition().getTaskFormHandler();
if (taskFormHandler != null) {
TaskFormData formData = taskFormHandler.createTaskForm(task);
if (StringUtils.isNotEmpty(formData.getFormKey())) {
historicTaskInstance.setFormKey(formData.getFormKey());
}
}
}
}
}
}
......
......@@ -36,6 +36,7 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
protected String owner;
protected String assignee;
protected String taskDefinitionKey;
protected String formKey;
protected int priority;
protected Date dueDate;
protected Date claimTime;
......@@ -45,7 +46,7 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
public HistoricTaskInstanceEntity(TaskEntity task, ExecutionEntity execution) {
this.id = task.getId();
if (execution!=null) {
if (execution != null) {
this.processDefinitionId = execution.getProcessDefinitionId();
this.processInstanceId = execution.getProcessInstanceId();
this.executionId = execution.getId();
......@@ -57,6 +58,7 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
this.assignee = task.getAssignee();
this.startTime = ClockUtil.getCurrentTime();
this.taskDefinitionKey = task.getTaskDefinitionKey();
this.setPriority(task.getPriority());
this.setDueDate(task.getDueDate());
}
......@@ -73,6 +75,7 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
persistentState.put("description", description);
persistentState.put("deleteReason", deleteReason);
persistentState.put("taskDefinitionKey", taskDefinitionKey);
persistentState.put("formKey", formKey);
persistentState.put("priority", priority);
if(parentTaskId != null) {
persistentState.put("parentTaskId", parentTaskId);
......@@ -117,6 +120,12 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
public void setTaskDefinitionKey(String taskDefinitionKey) {
this.taskDefinitionKey = taskDefinitionKey;
}
public String getFormKey() {
return formKey;
}
public void setFormKey(String formKey) {
this.formKey = formKey;
}
public int getPriority() {
return priority;
}
......
......@@ -544,7 +544,7 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
CommandContext commandContext = Context.getCommandContext();
if(commandContext != null) {
commandContext.getHistoryManager().recordTaskDefinitionKeyChange(id, taskDefinitionKey);
commandContext.getHistoryManager().recordTaskDefinitionKeyChange(this, taskDefinitionKey);
}
}
......@@ -622,7 +622,7 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
CommandContext commandContext = Context.getCommandContext();
if(commandContext != null) {
commandContext.getHistoryManager().recordTaskDefinitionKeyChange(id, taskDefinitionKey);
commandContext.getHistoryManager().recordTaskDefinitionKeyChange(this, taskDefinitionKey);
}
}
......
......@@ -54,6 +54,7 @@ create table ACT_HI_TASKINST (
DELETE_REASON_ varchar(4000),
PRIORITY_ integer,
DUE_DATE_ timestamp,
FORM_KEY_ varchar(255),
primary key (ID_)
);
......
......@@ -50,6 +50,7 @@ create table ACT_HI_TASKINST (
DELETE_REASON_ varchar(4000),
PRIORITY_ integer,
DUE_DATE_ timestamp,
FORM_KEY_ varchar(255),
primary key (ID_)
);
......
......@@ -50,6 +50,7 @@ create table ACT_HI_TASKINST (
DELETE_REASON_ nvarchar(4000),
PRIORITY_ int,
DUE_DATE_ datetime,
FORM_KEY_ nvarchar(255),
primary key (ID_)
);
......
......@@ -51,6 +51,7 @@ create table ACT_HI_TASKINST (
DELETE_REASON_ varchar(4000),
PRIORITY_ integer,
DUE_DATE_ datetime,
FORM_KEY_ varchar(255),
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......
......@@ -50,6 +50,7 @@ create table ACT_HI_TASKINST (
DELETE_REASON_ NVARCHAR2(2000),
PRIORITY_ INTEGER,
DUE_DATE_ TIMESTAMP(6),
FORM_KEY_ NVARCHAR2(255),
primary key (ID_)
);
......
......@@ -51,6 +51,7 @@ create table ACT_HI_TASKINST (
DELETE_REASON_ varchar(4000),
PRIORITY_ integer,
DUE_DATE_ timestamp,
FORM_KEY_ varchar(255),
primary key (ID_)
);
......
drop index ACT_IDX_EXEC_BUSKEY;
drop index ACT_IDX_TASK_CREATE;
drop index ACT_IDX_IDENT_LNK_USER;
drop index ACT_IDX_IDENT_LNK_GROUP;
drop index ACT_IDX_VARIABLE_TASK_ID;
alter table ACT_GE_BYTEARRAY
drop constraint ACT_FK_BYTEARR_DEPL;
alter table ACT_RU_EXECUTION
drop constraint ACT_FK_EXE_PROCINST;
alter table ACT_RU_EXECUTION
drop constraint ACT_FK_EXE_PARENT;
alter table ACT_RU_EXECUTION
drop constraint ACT_FK_EXE_SUPER;
drop index if exists ACT_IDX_EXEC_BUSKEY;
drop index if exists ACT_IDX_TASK_CREATE;
drop index if exists ACT_IDX_IDENT_LNK_USER;
drop index if exists ACT_IDX_IDENT_LNK_GROUP;
drop index if exists ACT_IDX_VARIABLE_TASK_ID;
drop index if exists ACT_IDX_EVENT_SUBSCR_CONFIG_;
drop index if exists ACT_IDX_ATHRZ_PROCEDEF;
alter table ACT_RU_EXECUTION
drop constraint ACT_FK_EXE_PROCDEF;
alter table ACT_RU_EXECUTION
drop constraint ACT_UNIQ_RU_BUS_KEY;
alter table ACT_RU_IDENTITYLINK
drop constraint ACT_FK_TSKASS_TASK;
alter table ACT_RU_IDENTITYLINK
drop constraint ACT_FK_ATHRZ_PROCEDEF;
alter table ACT_RU_TASK
drop constraint ACT_FK_TASK_EXE;
alter table ACT_RU_TASK
drop constraint ACT_FK_TASK_PROCINST;
alter table ACT_RU_TASK
drop constraint ACT_FK_TASK_PROCDEF;
alter table ACT_RU_VARIABLE
drop constraint ACT_FK_VAR_EXE;
alter table ACT_RU_VARIABLE
drop constraint ACT_FK_VAR_PROCINST;
alter table ACT_RU_VARIABLE
drop constraint ACT_FK_VAR_BYTEARRAY;
alter table ACT_RU_JOB
drop constraint ACT_FK_JOB_EXCEPTION;
alter table ACT_RU_EVENT_SUBSCR
drop constraint ACT_FK_EVENT_EXEC;
alter table ACT_RE_PROCDEF
drop constraint ACT_UNIQ_PROCDEF;
alter table ACT_RE_MODEL
drop constraint ACT_FK_MODEL_SOURCE;
alter table ACT_RE_MODEL
drop constraint ACT_FK_MODEL_SOURCE_EXTRA;
alter table ACT_RE_MODEL
drop constraint ACT_FK_MODEL_DEPLOYMENT;
drop index ACT_IDX_EVENT_SUBSCR_CONFIG_;
drop index ACT_IDX_ATHRZ_PROCEDEF;
drop table ACT_GE_PROPERTY if exists;
drop table ACT_GE_BYTEARRAY if exists;
drop table ACT_RE_DEPLOYMENT if exists;
drop table ACT_RE_MODEL if exists;
drop table ACT_RU_EXECUTION if exists;
drop table ACT_RU_JOB if exists;
drop table ACT_RE_PROCDEF if exists;
drop table ACT_RU_TASK if exists;
drop table ACT_RU_IDENTITYLINK if exists;
drop table ACT_RU_VARIABLE if exists;
drop table ACT_RU_EVENT_SUBSCR if exists;
drop table if exists ACT_GE_PROPERTY cascade constraints;
drop table if exists ACT_GE_BYTEARRAY cascade constraints;
drop table if exists ACT_RE_DEPLOYMENT cascade constraints;
drop table if exists ACT_RE_MODEL cascade constraints;
drop table if exists ACT_RU_EXECUTION cascade constraints;
drop table if exists ACT_RU_JOB cascade constraints;
drop table if exists ACT_RE_PROCDEF cascade constraints;
drop table if exists ACT_RU_TASK cascade constraints;
drop table if exists ACT_RU_IDENTITYLINK cascade constraints;
drop table if exists ACT_RU_VARIABLE cascade constraints;
drop table if exists ACT_RU_EVENT_SUBSCR cascade constraints;
drop index ACT_IDX_HI_PRO_INST_END;
drop index ACT_IDX_HI_PRO_I_BUSKEY;
drop index ACT_IDX_HI_ACT_INST_START;
drop index ACT_IDX_HI_ACT_INST_END;
drop index ACT_IDX_HI_DETAIL_PROC_INST;
drop index ACT_IDX_HI_DETAIL_ACT_INST;
drop index ACT_IDX_HI_DETAIL_TIME;
drop index ACT_IDX_HI_DETAIL_NAME;
drop index ACT_IDX_HI_DETAIL_TASK_ID;
drop index ACT_IDX_HI_PROCVAR_PROC_INST;
drop index ACT_IDX_HI_PROCVAR_NAME_TYPE;
drop index ACT_IDX_HI_ACT_INST_PROCINST;
alter table ACT_HI_PROCINST
drop constraint ACT_UNIQ_HI_BUS_KEY;
drop index if exists ACT_IDX_HI_PRO_INST_END;
drop index if exists ACT_IDX_HI_PRO_I_BUSKEY;
drop index if exists ACT_IDX_HI_ACT_INST_START;
drop index if exists ACT_IDX_HI_ACT_INST_END;
drop index if exists ACT_IDX_HI_DETAIL_PROC_INST;
drop index if exists ACT_IDX_HI_DETAIL_ACT_INST;
drop index if exists ACT_IDX_HI_DETAIL_TIME;
drop index if exists ACT_IDX_HI_DETAIL_NAME;
drop index if exists ACT_IDX_HI_DETAIL_TASK_ID;
drop index if exists ACT_IDX_HI_PROCVAR_PROC_INST;
drop index if exists ACT_IDX_HI_PROCVAR_NAME_TYPE;
drop index if exists ACT_IDX_HI_ACT_INST_PROCINST;
drop table ACT_HI_PROCINST if exists;
drop table ACT_HI_ACTINST if exists;
drop table ACT_HI_VARINST if exists;
drop table ACT_HI_TASKINST if exists;
drop table ACT_HI_DETAIL if exists;
drop table ACT_HI_COMMENT if exists;
drop table ACT_HI_ATTACHMENT if exists;
drop table if exists ACT_HI_PROCINST cascade constraints;
drop table if exists ACT_HI_ACTINST cascade constraints;
drop table if exists ACT_HI_VARINST cascade constraints;
drop table if exists ACT_HI_TASKINST cascade constraints;
drop table if exists ACT_HI_DETAIL cascade constraints;
drop table if exists ACT_HI_COMMENT cascade constraints;
drop table if exists ACT_HI_ATTACHMENT cascade constraints;
alter table ACT_ID_MEMBERSHIP
drop constraint ACT_FK_MEMB_GROUP;
alter table ACT_ID_MEMBERSHIP
drop constraint ACT_FK_MEMB_USER;
drop table ACT_ID_INFO if exists;
drop table ACT_ID_GROUP if exists;
drop table ACT_ID_MEMBERSHIP if exists;
drop table ACT_ID_USER if exists;
drop table if exists ACT_ID_INFO cascade constraints;
drop table if exists ACT_ID_GROUP cascade constraints;
drop table if exists ACT_ID_MEMBERSHIP cascade constraints;
drop table if exists ACT_ID_USER cascade constraints;
......@@ -37,6 +37,7 @@
DURATION_,
DELETE_REASON_,
TASK_DEF_KEY_,
FORM_KEY_,
PRIORITY_,
DUE_DATE_
) values (
......@@ -55,6 +56,7 @@
#{durationInMillis ,jdbcType=BIGINT},
#{deleteReason ,jdbcType=VARCHAR},
#{taskDefinitionKey ,jdbcType=VARCHAR},
#{formKey ,jdbcType=VARCHAR},
#{priority, jdbcType=INTEGER},
#{dueDate, jdbcType=TIMESTAMP}
)
......@@ -75,6 +77,7 @@
DURATION_ = #{durationInMillis ,jdbcType=BIGINT},
DELETE_REASON_ = #{deleteReason ,jdbcType=VARCHAR},
TASK_DEF_KEY_ = #{taskDefinitionKey ,jdbcType=VARCHAR},
FORM_KEY_ = #{formKey ,jdbcType=VARCHAR},
PRIORITY_ = #{priority, jdbcType=INTEGER},
DUE_DATE_ = #{dueDate, jdbcType=TIMESTAMP}
where ID_ = #{id}
......@@ -104,6 +107,7 @@
<result property="durationInMillis" column="DURATION_" jdbcType="BIGINT" />
<result property="deleteReason" column="DELETE_REASON_" jdbcType="VARCHAR" />
<result property="taskDefinitionKey" column="TASK_DEF_KEY_" jdbcType="VARCHAR" />
<result property="formKey" column="FORM_KEY_" jdbcType="VARCHAR" />
<result property="priority" column="PRIORITY_" jdbcType="INTEGER" />
<result property="dueDate" column="DUE_DATE_" jdbcType="TIMESTAMP" />
</resultMap>
......
Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_VARINST');
alter table ACT_HI_TASKINST
add CLAIM_TIME_ timestamp;
alter table ACT_HI_TASKINST
add FORM_KEY_ varchar(255);
Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_TASKINST');
alter table ACT_HI_TASKINST
add CLAIM_TIME_ timestamp;
add CLAIM_TIME_ timestamp;
alter table ACT_HI_TASKINST
add FORM_KEY_ varchar(255);
\ No newline at end of file
alter table ACT_HI_TASKINST
add CLAIM_TIME_ datetime;
alter table ACT_HI_TASKINST
add FORM_KEY_ nvarchar(255);
\ No newline at end of file
alter table ACT_HI_TASKINST
add CLAIM_TIME_ datetime;
alter table ACT_HI_TASKINST
add FORM_KEY_ varchar(255);
\ No newline at end of file
alter table ACT_HI_TASKINST
add CLAIM_TIME_ TIMESTAMP(6);
add CLAIM_TIME_ TIMESTAMP(6);
alter table ACT_HI_TASKINST
add FORM_KEY_ NVARCHAR2(255);
\ No newline at end of file
alter table ACT_HI_TASKINST
add column CLAIM_TIME_ timestamp;
alter table ACT_HI_TASKINST
add column FORM_KEY_ varchar(255);
\ No newline at end of file
......@@ -16,8 +16,9 @@ package org.activiti.engine.test.history;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
......@@ -35,7 +36,9 @@ public class HistoricTaskInstanceTest extends PluggableActivitiTestCase {
@Deployment
public void testHistoricTaskInstance() throws Exception {
String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest").getId();
Map<String, Object> varMap = new HashMap<String, Object>();
varMap.put("formKeyVar", "expressionFormKey");
String processInstanceId = runtimeService.startProcessInstanceByKey("HistoricTaskInstanceTest", varMap).getId();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
......@@ -60,6 +63,7 @@ public class HistoricTaskInstanceTest extends PluggableActivitiTestCase {
assertEquals(dueDate, historicTaskInstance.getDueDate());
assertEquals("kermit", historicTaskInstance.getAssignee());
assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
assertNull(historicTaskInstance.getEndTime());
assertNull(historicTaskInstance.getDurationInMillis());
assertNull(historicTaskInstance.getWorkTimeInMillis());
......@@ -72,6 +76,7 @@ public class HistoricTaskInstanceTest extends PluggableActivitiTestCase {
historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
assertNotNull(historicTaskInstance.getClaimTime());
assertNull(historicTaskInstance.getWorkTimeInMillis());
assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
taskService.complete(taskId);
......@@ -86,6 +91,7 @@ public class HistoricTaskInstanceTest extends PluggableActivitiTestCase {
assertEquals("kermit", historicTaskInstance.getAssignee());
assertEquals(TaskEntity.DELETE_REASON_COMPLETED, historicTaskInstance.getDeleteReason());
assertEquals(taskDefinitionKey, historicTaskInstance.getTaskDefinitionKey());
assertEquals("expressionFormKey", historicTaskInstance.getFormKey());
assertNotNull(historicTaskInstance.getEndTime());
assertNotNull(historicTaskInstance.getDurationInMillis());
assertNotNull(historicTaskInstance.getClaimTime());
......@@ -159,6 +165,10 @@ public class HistoricTaskInstanceTest extends PluggableActivitiTestCase {
assertEquals(1, historyService.createHistoricTaskInstanceQuery().processDefinitionKey("HistoricTaskQueryTest").count());
assertEquals(0, historyService.createHistoricTaskInstanceQuery().processDefinitionKey("unexistingdefinitionkey").count());
// Form key
HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(finishedInstance.getId()).singleResult();
assertEquals("formKeyTest", historicTask.getFormKey());
// Assignee
assertEquals(1, historyService.createHistoricTaskInstanceQuery().taskAssignee("kermit").count());
......
......@@ -10,7 +10,7 @@
<sequenceFlow id="flow1" sourceRef="start" targetRef="task" />
<userTask id="task" name="Clean up">
<userTask id="task" name="Clean up" activiti:formKey="#{formKeyVar}">
<documentation>
Schedule an engineering meeting for next week with the new hire.
</documentation>
......
......@@ -10,7 +10,7 @@
<sequenceFlow id="flow1" sourceRef="start" targetRef="task" />
<userTask id="task" name="Clean up">
<userTask id="task" name="Clean up" activiti:formKey="testFormKey">
<documentation>
Historic task description
</documentation>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册