提交 39072df6 编写于 作者: T Tijs Rademakers 提交者: Henry Yan

first version to retrieve variables together with tasks

上级 659b2178
......@@ -31,6 +31,7 @@ import org.activiti.engine.task.TaskQuery;
* @author Joram Barrez
* @author Tom Baeyens
* @author Falko Menge
* @author Tijs Rademakers
*/
public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements TaskQuery {
......@@ -69,6 +70,8 @@ public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements Tas
protected Date dueAfter;
protected SuspensionState suspensionState;
protected boolean excludeSubtasks = false;
protected boolean includeTaskLocalVariables = false;
protected boolean includeProcessVariables = false;
public TaskQueryImpl() {
}
......@@ -382,6 +385,16 @@ public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements Tas
this.suspensionState = SuspensionState.ACTIVE;
return this;
}
public TaskQuery includeTaskLocalVariables() {
this.includeTaskLocalVariables = true;
return this;
}
public TaskQuery includeProcessVariables() {
this.includeProcessVariables = true;
return this;
}
public List<String> getCandidateGroups() {
if (candidateGroup!=null) {
......@@ -460,9 +473,15 @@ public class TaskQueryImpl extends AbstractQuery<TaskQuery, Task> implements Tas
public List<Task> executeList(CommandContext commandContext, Page page) {
ensureVariablesInitialized();
checkQueryOk();
return commandContext
.getTaskEntityManager()
.findTasksByQueryCriteria(this);
if (includeTaskLocalVariables || includeProcessVariables) {
return commandContext
.getTaskEntityManager()
.findTasksAndVariablesByQueryCriteria(this);
} else {
return commandContext
.getTaskEntityManager()
.findTasksByQueryCriteria(this);
}
}
public long executeCount(CommandContext commandContext) {
......
......@@ -36,7 +36,7 @@ public class IbatisVariableTypeHandler implements TypeHandler<VariableType> {
public VariableType getResult(ResultSet rs, String columnName) throws SQLException {
String typeName = rs.getString(columnName);
VariableType type = getVariableTypes().getVariableType(typeName);
if (type == null) {
if (type == null && typeName != null) {
throw new ActivitiException("unknown variable type name " + typeName);
}
return type;
......
......@@ -45,7 +45,7 @@ public class HistoricVariableInstanceEntityManager extends AbstractManager {
List<HistoricVariableInstanceEntity> cachedHistoricVariableInstances = getDbSqlSession().findInCache(HistoricVariableInstanceEntity.class);
for (HistoricVariableInstanceEntity historicProcessVariable : cachedHistoricVariableInstances) {
// Make sure we only delete the right ones (as we cannot make a proper query in the cache)
if (historicProcessVariable.getProcessInstanceId().equals(historicProcessInstanceId)) {
if (historicProcessInstanceId.equals(historicProcessVariable.getProcessInstanceId())) {
historicProcessVariable.delete();
}
}
......
......@@ -46,6 +46,7 @@ import org.activiti.engine.task.Task;
* @author Tom Baeyens
* @author Joram Barrez
* @author Falko Menge
* @author Tijs Rademakers
*/
public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask, Serializable, PersistentObject, HasRevision {
......@@ -87,6 +88,8 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
protected String eventName;
protected List<VariableInstanceEntity> queryVariables;
public TaskEntity() {
}
......@@ -697,4 +700,32 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
public boolean isSuspended() {
return suspensionState == SuspensionState.SUSPENDED.getStateCode();
}
public Map<String, Object> getTaskLocalVariables() {
Map<String, Object> variables = new HashMap<String, Object>();
if (queryVariables != null) {
for (VariableInstanceEntity variableInstance: queryVariables) {
if (variableInstance.getTaskId() != null) {
variables.put(variableInstance.getName(), variableInstance.getValue());
}
}
}
return variables;
}
public Map<String, Object> getProcessVariables() {
Map<String, Object> variables = new HashMap<String, Object>();
if (queryVariables != null) {
for (VariableInstanceEntity variableInstance: queryVariables) {
if (variableInstance.getTaskId() == null) {
variables.put(variableInstance.getName(), variableInstance.getValue());
}
}
}
return variables;
}
public List<VariableInstanceEntity> getQueryVariables() {
return queryVariables;
}
public void setQueryVariables(List<VariableInstanceEntity> queryVariables) {
this.queryVariables = queryVariables;
}
}
......@@ -109,6 +109,12 @@ public class TaskEntityManager extends AbstractManager {
final String query = "selectTaskByQueryCriteria";
return getDbSqlSession().selectList(query, taskQuery);
}
@SuppressWarnings("unchecked")
public List<Task> findTasksAndVariablesByQueryCriteria(TaskQueryImpl taskQuery) {
final String query = "selectTaskWithVariablesByQueryCriteria";
return getDbSqlSession().selectList(query, taskQuery);
}
public long findTaskCountByQueryCriteria(TaskQueryImpl taskQuery) {
return (Long) getDbSqlSession().selectOne("selectTaskCountByQueryCriteria", taskQuery);
......
......@@ -34,6 +34,7 @@ import org.activiti.engine.impl.variable.VariableTypes;
/**
* @author Tom Baeyens
* @author Joram Barrez
* @author Tijs Rademakers
*/
public abstract class VariableScopeImpl implements Serializable, VariableScope {
......
......@@ -13,12 +13,14 @@
package org.activiti.engine.task;
import java.util.Date;
import java.util.Map;
/** Represents one task for a human user.
*
* @author Joram Barrez
* @author Tijs Rademakers
*/
public interface Task {
......@@ -105,4 +107,10 @@ public interface Task {
/** Indicated whether this task is suspended or not. */
boolean isSuspended();
/** Returns the local task variables if requested in the task query */
Map<String, Object> getTaskLocalVariables();
/** Returns the process variables if requested in the task query */
Map<String, Object> getProcessVariables();
}
......@@ -24,6 +24,7 @@ import org.activiti.engine.query.Query;
*
* @author Joram Barrez
* @author Falko Menge
* @author Tijs Rademakers
*/
public interface TaskQuery extends Query<TaskQuery, Task>{
......@@ -254,6 +255,16 @@ public interface TaskQuery extends Query<TaskQuery, Task>{
*/
TaskQuery active();
/**
* Include local task variables in the task query result
*/
TaskQuery includeTaskLocalVariables();
/**
* Include global task variables in the task query result
*/
TaskQuery includeProcessVariables();
// ordering ////////////////////////////////////////////////////////////
/** Order by task id (needs to be followed by {@link #asc()} or {@link #desc()}). */
......
......@@ -76,6 +76,39 @@
<result property="dueDateWithoutCascade" column="DUE_DATE_" jdbcType="TIMESTAMP"/>
<result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER" />
</resultMap>
<resultMap id="taskAndVariablesResultMap" type="org.activiti.engine.impl.persistence.entity.TaskEntity">
<id property="id" column="ID_" jdbcType="VARCHAR"/>
<result property="revision" column="REV_" jdbcType="INTEGER"/>
<result property="nameWithoutCascade" column="NAME_" jdbcType="VARCHAR"/>
<result property="parentTaskIdWithoutCascade" column="PARENT_TASK_ID_" jdbcType="VARCHAR"/>
<result property="descriptionWithoutCascade" column="DESCRIPTION_" jdbcType="VARCHAR"/>
<result property="priorityWithoutCascade" column="PRIORITY_" jdbcType="INTEGER"/>
<result property="createTime" column="CREATE_TIME_" jdbcType="TIMESTAMP" />
<result property="ownerWithoutCascade" column="OWNER_" jdbcType="VARCHAR"/>
<result property="assigneeWithoutCascade" column="ASSIGNEE_" jdbcType="VARCHAR"/>
<result property="delegationStateString" column="DELEGATION_" jdbcType="VARCHAR"/>
<result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR"/>
<result property="taskDefinitionKeyWithoutCascade" column="TASK_DEF_KEY_" jdbcType="VARCHAR"/>
<result property="dueDateWithoutCascade" column="DUE_DATE_" jdbcType="TIMESTAMP"/>
<result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER" />
<collection property="queryVariables" column="TASK_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="byteArrayValueId" column="VAR_BYTEARRAY_ID_" jdbcType="VARCHAR" />
<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>
<!-- TASK SELECT -->
......@@ -115,6 +148,43 @@
<sql id="selectTaskByQueryCriteriaSql">
from ${prefix}ACT_RU_TASK RES
<include refid="commonSelectTaskByQueryCriteriaSql"/>
</sql>
<select id="selectTaskWithVariablesByQueryCriteria" parameterType="org.activiti.engine.impl.TaskQueryImpl" resultMap="taskAndVariablesResultMap">
${limitBefore}
select RES.*,
<if test="includeTaskLocalVariables || includeProcessVariables">
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_, VAR.TEXT_ as VAR_TEXT_,
VAR.DOUBLE_ as VAR_DOUBLE_, VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT_, VAR.LONG_ as VAR_LONG_
</if>
${limitBetween}
<include refid="selectTaskWithVariablesByQueryCriteriaSql"/>
${orderBy}
${limitAfter}
</select>
<sql id="selectTaskWithVariablesByQueryCriteriaSql">
from ${prefix}ACT_RU_TASK RES
<choose>
<when test="includeTaskLocalVariables &amp;&amp; includeProcessVariables">
left outer join ${prefix}ACT_RU_VARIABLE VAR ON RES.ID_ = VAR.TASK_ID_ or RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
</when>
<otherwise>
<if test="includeTaskLocalVariables">
left outer join ${prefix}ACT_RU_VARIABLE VAR ON RES.ID_ = VAR.TASK_ID_
</if>
<if test="includeProcessVariables">
left outer join ${prefix}ACT_RU_VARIABLE VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_ and VAR.TASK_ID_ is null
</if>
</otherwise>
</choose>
<include refid="commonSelectTaskByQueryCriteriaSql"/>
</sql>
<sql id="commonSelectTaskByQueryCriteriaSql">
<if test="candidateUser != null || candidateGroups != null">
inner join ${prefix}ACT_RU_IDENTITYLINK I on I.TASK_ID_ = RES.ID_
</if>
......
......@@ -2,173 +2,201 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
<mapper
namespace="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
<!-- VARIABLE INSTANCE INSERT -->
<insert id="insertVariableInstance" parameterType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
insert into ${prefix}ACT_RU_VARIABLE (ID_, REV_, TYPE_, NAME_, PROC_INST_ID_, EXECUTION_ID_, TASK_ID_, BYTEARRAY_ID_, DOUBLE_, LONG_ , TEXT_, TEXT2_)
<insert id="insertVariableInstance"
parameterType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
insert into ${prefix}ACT_RU_VARIABLE (ID_, REV_,
TYPE_, NAME_, PROC_INST_ID_, EXECUTION_ID_, TASK_ID_, BYTEARRAY_ID_,
DOUBLE_, LONG_ , TEXT_, TEXT2_)
values (
#{id, jdbcType=VARCHAR},
1,
#{type, jdbcType=VARCHAR },
#{name, jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
#{executionId, jdbcType=VARCHAR},
#{taskId, jdbcType=VARCHAR},
#{byteArrayValueId, jdbcType=VARCHAR},
#{doubleValue, jdbcType=DOUBLE},
#{longValue, jdbcType=BIGINT},
#{textValue, jdbcType=VARCHAR},
#{textValue2, jdbcType=VARCHAR}
#{id, jdbcType=VARCHAR},
1,
#{type, jdbcType=VARCHAR },
#{name, jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
#{executionId, jdbcType=VARCHAR},
#{taskId, jdbcType=VARCHAR},
#{byteArrayValueId, jdbcType=VARCHAR},
#{doubleValue, jdbcType=DOUBLE},
#{longValue, jdbcType=BIGINT},
#{textValue, jdbcType=VARCHAR},
#{textValue2, jdbcType=VARCHAR}
)
</insert>
<!-- VARIABLE INSTANCE UPDATE -->
<update id="updateVariableInstance" parameterType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
<update id="updateVariableInstance"
parameterType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
update ${prefix}ACT_RU_VARIABLE
set
REV_ = #{revisionNext, jdbcType=INTEGER},
EXECUTION_ID_ = #{executionId, jdbcType=VARCHAR},
BYTEARRAY_ID_ = #{byteArrayValueId, jdbcType=VARCHAR},
DOUBLE_ = #{doubleValue, jdbcType=DOUBLE},
LONG_ = #{longValue, jdbcType=BIGINT},
TEXT_ = #{textValue, jdbcType=VARCHAR},
TEXT2_ = #{textValue2, jdbcType=VARCHAR}
set
REV_ = #{revisionNext, jdbcType=INTEGER},
EXECUTION_ID_ = #{executionId, jdbcType=VARCHAR},
BYTEARRAY_ID_ = #{byteArrayValueId, jdbcType=VARCHAR},
DOUBLE_ = #{doubleValue, jdbcType=DOUBLE},
LONG_ = #{longValue, jdbcType=BIGINT},
TEXT_ = #{textValue, jdbcType=VARCHAR},
TEXT2_ = #{textValue2, jdbcType=VARCHAR}
where ID_ = #{id, jdbcType=VARCHAR}
and REV_ = #{revision, jdbcType=INTEGER}
and REV_ = #{revision, jdbcType=INTEGER}
</update>
<!-- VARIABLE INSTANCE DELETE -->
<delete id="deleteVariableInstance" parameterType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
delete from ${prefix}ACT_RU_VARIABLE where ID_ = #{id, jdbcType=VARCHAR} and REV_ = #{revision}
<delete id="deleteVariableInstance"
parameterType="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
delete from ${prefix}ACT_RU_VARIABLE where ID_ = #{id,
jdbcType=VARCHAR} and REV_ = #{revision}
</delete>
<!-- VARIABLE INSTANCE RESULTMAP -->
<resultMap id="variableInstanceResultMap" type="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER"/>
<result property="type" column="TYPE_" javaType="org.activiti.engine.impl.variable.VariableType" jdbcType="VARCHAR"/>
<result property="name" column="NAME_" javaType="String" jdbcType="VARCHAR" />
<resultMap id="variableInstanceResultMap" type="org.activiti.engine.impl.persistence.entity.VariableInstanceEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER" />
<result property="type" column="TYPE_" javaType="org.activiti.engine.impl.variable.VariableType" jdbcType="VARCHAR" />
<result property="name" column="NAME_" javaType="String" jdbcType="VARCHAR" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
<result property="taskId" column="TASK_ID_" jdbcType="VARCHAR" />
<result property="activityId" column="ACTIVITY_ID_" jdbcType="VARCHAR" />
<result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
<result property="isConcurrencyScope" column="IS_CONCURRENCY_SCOPE_" jdbcType="BOOLEAN" />
<result property="byteArrayValueId" column="BYTEARRAY_ID_" jdbcType="VARCHAR" />
<result property="doubleValue" column="DOUBLE_" jdbcType="DOUBLE" />
<result property="textValue" column="TEXT_" jdbcType="VARCHAR"/>
<result property="textValue2" column="TEXT2_" jdbcType="VARCHAR"/>
<result property="longValue" column="LONG_" jdbcType="BIGINT"/>
</resultMap>
<result property="activityId" column="ACTIVITY_ID_" jdbcType="VARCHAR" />
<result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
<result property="isConcurrencyScope" column="IS_CONCURRENCY_SCOPE_" jdbcType="BOOLEAN" />
<result property="byteArrayValueId" column="BYTEARRAY_ID_" jdbcType="VARCHAR" />
<result property="doubleValue" column="DOUBLE_" jdbcType="DOUBLE" />
<result property="textValue" column="TEXT_" jdbcType="VARCHAR" />
<result property="textValue2" column="TEXT2_" jdbcType="VARCHAR" />
<result property="longValue" column="LONG_" jdbcType="BIGINT" />
</resultMap>
<!-- VARIABLE INSTANCE SELECT -->
<select id="selectVariableInstance" parameterType="string" resultMap="variableInstanceResultMap">
select * from ${prefix}ACT_RU_VARIABLE where ID_ = #{id, jdbcType=VARCHAR}
<select id="selectVariableInstance" parameterType="string"
resultMap="variableInstanceResultMap">
select * from ${prefix}ACT_RU_VARIABLE where ID_ = #{id, jdbcType=VARCHAR}
</select>
<select id="selectVariablesByExecutionId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="variableInstanceResultMap">
select * from ${prefix}ACT_RU_VARIABLE
where EXECUTION_ID_ = #{parameter, jdbcType=VARCHAR}
and TASK_ID_ is null
<select id="selectVariablesByExecutionId"
parameterType="org.activiti.engine.impl.db.ListQueryParameterObject"
resultMap="variableInstanceResultMap">
select * from ${prefix}ACT_RU_VARIABLE
where EXECUTION_ID_ = #{parameter, jdbcType=VARCHAR}
and TASK_ID_ is null
</select>
<select id="selectVariablesByTaskId" parameterType="org.activiti.engine.impl.db.ListQueryParameterObject" resultMap="variableInstanceResultMap">
<select id="selectVariablesByTaskId"
parameterType="org.activiti.engine.impl.db.ListQueryParameterObject"
resultMap="variableInstanceResultMap">
select * from ${prefix}ACT_RU_VARIABLE where
TASK_ID_ = #{parameter, jdbcType=VARCHAR}
TASK_ID_ =
#{parameter, jdbcType=VARCHAR}
</select>
<!-- BYTE ARRAY INSERT -->
<insert id="insertByteArray" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
insert into ${prefix}ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_)
<insert id="insertByteArray"
parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
insert into ${prefix}ACT_GE_BYTEARRAY(ID_, REV_,
NAME_, BYTES_, DEPLOYMENT_ID_)
values (
#{id, jdbcType=VARCHAR},
1,
#{name, jdbcType=VARCHAR},
#{bytes, jdbcType=BLOB},
#{deploymentId, jdbcType=VARCHAR}
)
#{id, jdbcType=VARCHAR},
1,
#{name, jdbcType=VARCHAR},
#{bytes, jdbcType=BLOB},
#{deploymentId, jdbcType=VARCHAR}
)
</insert>
<!-- BYTE ARRAY UPDATE -->
<update id="updateByteArray" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
update ${prefix}ACT_GE_BYTEARRAY
<update id="updateByteArray"
parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
update ${prefix}ACT_GE_BYTEARRAY
set
REV_ = #{revisionNext, jdbcType=INTEGER},
BYTES_ = #{bytes, jdbcType=BLOB}
REV_ = #{revisionNext, jdbcType=INTEGER},
BYTES_ = #{bytes, jdbcType=BLOB}
where ID_ = #{id}
and REV_ = #{revision, jdbcType=INTEGER}
and REV_ = #{revision, jdbcType=INTEGER}
</update>
<!-- BYTE ARRAY DELETE -->
<select id="selectBytesOfByteArray" parameterType="string" resultType="hashmap">
select BYTES_ from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id} and REV_ = #{revision}
<select id="selectBytesOfByteArray" parameterType="string"
resultType="hashmap">
select BYTES_ from ${prefix}ACT_GE_BYTEARRAY where ID_ =
#{id} and REV_ = #{revision}
</select>
<delete id="deleteByteArraysForDeployment" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
delete from ${prefix}ACT_GE_BYTEARRAY where DEPLOYMENT_ID_ = #{id} and REV_ = #{revision}
<delete id="deleteByteArraysForDeployment"
parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
delete from ${prefix}ACT_GE_BYTEARRAY where
DEPLOYMENT_ID_ = #{id} and REV_ = #{revision}
</delete>
<delete id="deleteByteArray" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
delete from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id} and REV_ = #{revision}
<delete id="deleteByteArray"
parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
delete from ${prefix}ACT_GE_BYTEARRAY where ID_ =
#{id} and REV_ = #{revision}
</delete>
<delete id="deleteByteArrayNoRevisionCheck" parameterType="string">
delete from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id}
</delete>
<!-- BYTE ARRAY RESULTMAP -->
<resultMap id="byteArrayResultMap" type="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
<resultMap id="byteArrayResultMap"
type="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER"/>
<result property="name" column="NAME_" jdbcType="VARCHAR"/>
<result property="bytes" column="BYTES_" jdbcType="BLOB"/>
<result property="revision" column="REV_" jdbcType="INTEGER" />
<result property="name" column="NAME_" jdbcType="VARCHAR" />
<result property="bytes" column="BYTES_" jdbcType="BLOB" />
</resultMap>
<!-- BYTE ARRAY SELECT -->
<select id="selectByteArray" parameterType="string" resultMap="byteArrayResultMap">
select * from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id}
select * from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id}
</select>
<!-- Postgresql specific configuration -->
<resultMap id="byteArrayResultMap_postgres" type="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
<!-- Postgresql specific configuration -->
<resultMap id="byteArrayResultMap_postgres"
type="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="revision" column="REV_" jdbcType="INTEGER"/>
<result property="name" column="NAME_" jdbcType="VARCHAR"/>
<result property="bytes" column="BYTES_" jdbcType="BINARY"/>
<result property="revision" column="REV_" jdbcType="INTEGER" />
<result property="name" column="NAME_" jdbcType="VARCHAR" />
<result property="bytes" column="BYTES_" jdbcType="BINARY" />
</resultMap>
<select id="selectByteArray_postgres" parameterType="string" resultMap="byteArrayResultMap_postgres">
select * from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id}
<select id="selectByteArray_postgres" parameterType="string"
resultMap="byteArrayResultMap_postgres">
select * from ${prefix}ACT_GE_BYTEARRAY where ID_ = #{id}
</select>
<update id="updateByteArray_postgres" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
update ${prefix}ACT_GE_BYTEARRAY
<update id="updateByteArray_postgres"
parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
update ${prefix}ACT_GE_BYTEARRAY
set
REV_ = #{revisionNext, jdbcType=INTEGER},
BYTES_ = #{bytes, jdbcType=BINARY}
REV_ = #{revisionNext, jdbcType=INTEGER},
BYTES_ = #{bytes, jdbcType=BINARY}
where ID_ = #{id}
and REV_ = #{revision, jdbcType=INTEGER}
</update>
<insert id="insertByteArray_postgres" parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
insert into ${prefix}ACT_GE_BYTEARRAY(ID_, REV_, NAME_, BYTES_, DEPLOYMENT_ID_)
and REV_ = #{revision, jdbcType=INTEGER}
</update>
<insert id="insertByteArray_postgres"
parameterType="org.activiti.engine.impl.persistence.entity.ByteArrayEntity">
insert into ${prefix}ACT_GE_BYTEARRAY(ID_, REV_,
NAME_, BYTES_, DEPLOYMENT_ID_)
values (
#{id, jdbcType=VARCHAR},
1,
#{name, jdbcType=VARCHAR},
#{bytes, jdbcType=BINARY},
#{deploymentId, jdbcType=VARCHAR}
)
#{id, jdbcType=VARCHAR},
1,
#{name, jdbcType=VARCHAR},
#{bytes, jdbcType=BINARY},
#{deploymentId, jdbcType=VARCHAR}
)
</insert>
</mapper>
\ No newline at end of file
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test.api.task;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
/**
* @author Tijs Rademakers
*/
public class TaskAndVariablesQueryTest extends PluggableActivitiTestCase {
private List<String> taskIds;
public void setUp() throws Exception {
identityService.saveUser(identityService.newUser("kermit"));
identityService.saveUser(identityService.newUser("gonzo"));
identityService.saveUser(identityService.newUser("fozzie"));
identityService.saveGroup(identityService.newGroup("management"));
identityService.saveGroup(identityService.newGroup("accountancy"));
identityService.createMembership("kermit", "management");
identityService.createMembership("kermit", "accountancy");
identityService.createMembership("fozzie", "management");
taskIds = generateTestTasks();
}
public void tearDown() throws Exception {
identityService.deleteGroup("accountancy");
identityService.deleteGroup("management");
identityService.deleteUser("fozzie");
identityService.deleteUser("gonzo");
identityService.deleteUser("kermit");
taskService.deleteTasks(taskIds, true);
}
@Deployment
public void testQuery() {
Task task = (Task) taskService.createTaskQuery().includeTaskLocalVariables().taskAssignee("gonzo").singleResult();
Map<String, Object> variableMap = task.getTaskLocalVariables();
assertEquals(2, variableMap.size());
assertEquals(0, task.getProcessVariables().size());
assertNotNull(variableMap.get("testVar"));
assertEquals("someVariable", variableMap.get("testVar"));
assertNotNull(variableMap.get("testVar2"));
assertEquals(123, variableMap.get("testVar2"));
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(3, tasks.size());
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("gonzo").singleResult();
assertEquals(0, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
Map<String, Object> startMap = new HashMap<String, Object>();
startMap.put("processVar", true);
runtimeService.startProcessInstanceByKey("oneTaskProcess", startMap);
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("kermit").singleResult();
assertEquals(1, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
assertTrue((Boolean) task.getProcessVariables().get("processVar"));
taskService.setVariable(task.getId(), "anotherProcessVar", 123);
taskService.setVariableLocal(task.getId(), "localVar", "test");
task = (Task) taskService.createTaskQuery().includeTaskLocalVariables().taskAssignee("kermit").singleResult();
assertEquals(0, task.getProcessVariables().size());
assertEquals(1, task.getTaskLocalVariables().size());
assertEquals("test", task.getTaskLocalVariables().get("localVar"));
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("kermit").singleResult();
assertEquals(2, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
assertEquals(true, task.getProcessVariables().get("processVar"));
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
tasks = taskService.createTaskQuery().includeTaskLocalVariables().taskCandidateUser("kermit").list();
assertEquals(2, tasks.size());
assertEquals(1, tasks.get(0).getTaskLocalVariables().size());
assertEquals("test", tasks.get(0).getTaskLocalVariables().get("test"));
assertEquals(0, tasks.get(0).getProcessVariables().size());
tasks = taskService.createTaskQuery().includeProcessVariables().taskCandidateUser("kermit").list();
assertEquals(2, tasks.size());
assertEquals(0, tasks.get(0).getProcessVariables().size());
assertEquals(0, tasks.get(0).getTaskLocalVariables().size());
task = (Task) taskService.createTaskQuery().includeTaskLocalVariables().taskAssignee("kermit").taskVariableValueEquals("localVar", "test").singleResult();
assertEquals(0, task.getProcessVariables().size());
assertEquals(1, task.getTaskLocalVariables().size());
assertEquals("test", task.getTaskLocalVariables().get("localVar"));
task = (Task) taskService.createTaskQuery().includeProcessVariables().taskAssignee("kermit").taskVariableValueEquals("localVar", "test").singleResult();
assertEquals(2, task.getProcessVariables().size());
assertEquals(0, task.getTaskLocalVariables().size());
assertEquals(true, task.getProcessVariables().get("processVar"));
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
task = (Task) taskService.createTaskQuery().includeTaskLocalVariables().includeProcessVariables().taskAssignee("kermit").singleResult();
assertEquals(2, task.getProcessVariables().size());
assertEquals(1, task.getTaskLocalVariables().size());
assertEquals("test", task.getTaskLocalVariables().get("localVar"));
assertEquals(true, task.getProcessVariables().get("processVar"));
assertEquals(123, task.getProcessVariables().get("anotherProcessVar"));
}
/**
* Generates some test tasks. - 2 tasks where kermit is a candidate and 1 task
* where gonzo is assignee
*/
private List<String> generateTestTasks() throws Exception {
List<String> ids = new ArrayList<String>();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
// 2 tasks for kermit
ClockUtil.setCurrentTime(sdf.parse("01/01/2001 01:01:01.000"));
for (int i = 0; i < 2; i++) {
Task task = taskService.newTask();
task.setName("testTask");
task.setDescription("testTask description");
task.setPriority(3);
taskService.saveTask(task);
ids.add(task.getId());
taskService.setVariableLocal(task.getId(), "test", "test");
taskService.addCandidateUser(task.getId(), "kermit");
}
ClockUtil.setCurrentTime(sdf.parse("02/02/2002 02:02:02.000"));
// 1 task for gonzo
Task task = taskService.newTask();
task.setName("gonzoTask");
task.setDescription("gonzo description");
task.setPriority(4);
taskService.saveTask(task);
taskService.setAssignee(task.getId(), "gonzo");
taskService.setVariableLocal(task.getId(), "testVar", "someVariable");
taskService.setVariableLocal(task.getId(), "testVar2", 123);
ids.add(task.getId());
return ids;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples">
<process id="oneTaskProcess" name="The One Task Process">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="theProcessTask" />
<userTask id="theProcessTask" name="my process task" activiti:assignee="kermit" />
<sequenceFlow id="flow2" sourceRef="theProcessTask" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
</definitions>
......@@ -14,6 +14,7 @@
package org.activiti.explorer.ui.task.data;
import java.util.Date;
import java.util.Map;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.task.DelegationState;
......@@ -140,4 +141,12 @@ public class HistoricTaskWrapper implements Task {
public boolean isSuspended() {
return false;
}
public Map<String, Object> getTaskLocalVariables() {
return null;
}
public Map<String, Object> getProcessVariables() {
return null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册