Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发团队
Flowable Engine
提交
628e5d46
F
Flowable Engine
项目概览
开发团队
/
Flowable Engine
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Flowable Engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
628e5d46
编写于
5月 21, 2013
作者:
F
Frederik Heremans
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added process-instance GET, DELETE and GET of collection
上级
31a4ba82
变更
18
显示空白变更内容
内联
并排
Showing
18 changed file
with
980 addition
and
242 deletion
+980
-242
modules/activiti-rest/src/main/java/org/activiti/rest/api/RestResponseFactory.java
.../main/java/org/activiti/rest/api/RestResponseFactory.java
+13
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/process/LegacyProcessInstanceResource.java
...est/api/legacy/process/LegacyProcessInstanceResource.java
+262
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/process/LegacyProcessInstancesPaginateList.java
...pi/legacy/process/LegacyProcessInstancesPaginateList.java
+4
-4
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/process/LegacyProcessInstancesResource.java
...st/api/legacy/process/LegacyProcessInstancesResource.java
+4
-4
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/process/LegacyProcessInstancesResponse.java
...st/api/legacy/process/LegacyProcessInstancesResponse.java
+3
-3
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceBasedResource.java
...tiviti/rest/api/process/ProcessInstanceBasedResource.java
+75
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceCollectionResource.java
...i/rest/api/process/ProcessInstanceCollectionResource.java
+103
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstancePaginateList.java
...ctiviti/rest/api/process/ProcessInstancePaginateList.java
+46
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceQueryRequest.java
...ctiviti/rest/api/process/ProcessInstanceQueryRequest.java
+110
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceResource.java
...rg/activiti/rest/api/process/ProcessInstanceResource.java
+27
-223
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceResponse.java
...rg/activiti/rest/api/process/ProcessInstanceResponse.java
+74
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentCollectionResource.java
...iti/rest/api/repository/DeploymentCollectionResource.java
+2
-2
modules/activiti-rest/src/main/java/org/activiti/rest/application/RestServicesInit.java
.../java/org/activiti/rest/application/RestServicesInit.java
+9
-4
modules/activiti-rest/src/test/java/org/activiti/rest/api/legacy/SignalEventSubscriptionResourceTest.java
.../rest/api/legacy/SignalEventSubscriptionResourceTest.java
+1
-1
modules/activiti-rest/src/test/java/org/activiti/rest/api/legacy/StartProcessInstanceResourceTest.java
...iti/rest/api/legacy/StartProcessInstanceResourceTest.java
+1
-1
modules/activiti-rest/src/test/java/org/activiti/rest/api/runtime/ProcessInstanceCollectionResourceTest.java
...st/api/runtime/ProcessInstanceCollectionResourceTest.java
+98
-0
modules/activiti-rest/src/test/java/org/activiti/rest/api/runtime/ProcessInstanceResourceTest.java
...ctiviti/rest/api/runtime/ProcessInstanceResourceTest.java
+114
-0
modules/activiti-rest/src/test/resources/org/activiti/rest/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml
...untime/ProcessInstanceResourceTest.process-one.bpmn20.xml
+34
-0
未找到文件。
modules/activiti-rest/src/main/java/org/activiti/rest/api/RestResponseFactory.java
浏览文件 @
628e5d46
...
@@ -23,6 +23,7 @@ import org.activiti.engine.impl.bpmn.deployer.BpmnDeployer;
...
@@ -23,6 +23,7 @@ import org.activiti.engine.impl.bpmn.deployer.BpmnDeployer;
import
org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity
;
import
org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity
;
import
org.activiti.engine.repository.Deployment
;
import
org.activiti.engine.repository.Deployment
;
import
org.activiti.engine.repository.ProcessDefinition
;
import
org.activiti.engine.repository.ProcessDefinition
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.engine.task.Attachment
;
import
org.activiti.engine.task.Attachment
;
import
org.activiti.engine.task.Comment
;
import
org.activiti.engine.task.Comment
;
import
org.activiti.engine.task.Event
;
import
org.activiti.engine.task.Event
;
...
@@ -42,6 +43,7 @@ import org.activiti.rest.api.engine.variable.RestVariableConverter;
...
@@ -42,6 +43,7 @@ import org.activiti.rest.api.engine.variable.RestVariableConverter;
import
org.activiti.rest.api.engine.variable.ShortRestVariableConverter
;
import
org.activiti.rest.api.engine.variable.ShortRestVariableConverter
;
import
org.activiti.rest.api.engine.variable.StringRestVariableConverter
;
import
org.activiti.rest.api.engine.variable.StringRestVariableConverter
;
import
org.activiti.rest.api.identity.RestIdentityLink
;
import
org.activiti.rest.api.identity.RestIdentityLink
;
import
org.activiti.rest.api.process.ProcessInstanceResponse
;
import
org.activiti.rest.api.repository.DeploymentResourceResponse
;
import
org.activiti.rest.api.repository.DeploymentResourceResponse
;
import
org.activiti.rest.api.repository.DeploymentResourceResponse.DeploymentResourceType
;
import
org.activiti.rest.api.repository.DeploymentResourceResponse.DeploymentResourceType
;
import
org.activiti.rest.api.repository.DeploymentResponse
;
import
org.activiti.rest.api.repository.DeploymentResponse
;
...
@@ -307,6 +309,17 @@ public class RestResponseFactory {
...
@@ -307,6 +309,17 @@ public class RestResponseFactory {
return
result
;
return
result
;
}
}
public
ProcessInstanceResponse
createProcessInstanceResponse
(
SecuredResource
securedResource
,
ProcessInstance
processInstance
)
{
ProcessInstanceResponse
result
=
new
ProcessInstanceResponse
();
result
.
setActivityId
(
processInstance
.
getActivityId
());
result
.
setBusinessKey
(
processInstance
.
getBusinessKey
());
result
.
setId
(
processInstance
.
getId
());
result
.
setProcessDefinitionUrl
(
securedResource
.
createFullResourceUrl
(
RestUrls
.
URL_PROCESS_DEFINITION
,
processInstance
.
getProcessDefinitionId
()));
result
.
setSuspended
(
processInstance
.
isSuspended
());
result
.
setUrl
(
securedResource
.
createFullResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE
,
processInstance
.
getId
()));
return
result
;
}
/**
/**
* Called once when the converters need to be initialized. Override of custom conversion
* Called once when the converters need to be initialized. Override of custom conversion
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/process/LegacyProcessInstanceResource.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.legacy.process
;
import
java.util.List
;
import
java.util.Map
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.history.HistoricActivityInstance
;
import
org.activiti.engine.history.HistoricDetail
;
import
org.activiti.engine.history.HistoricProcessInstance
;
import
org.activiti.engine.history.HistoricTaskInstance
;
import
org.activiti.engine.history.HistoricVariableUpdate
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.RequestUtil
;
import
org.activiti.rest.api.SecuredResource
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.node.ArrayNode
;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.restlet.resource.Delete
;
import
org.restlet.resource.Get
;
/**
* @author Tijs Rademakers
*/
public
class
LegacyProcessInstanceResource
extends
SecuredResource
{
@Get
public
ObjectNode
getProcessInstance
()
{
if
(
authenticate
()
==
false
)
return
null
;
String
processInstanceId
=
(
String
)
getRequest
().
getAttributes
().
get
(
"processInstanceId"
);
HistoricProcessInstance
instance
=
ActivitiUtil
.
getHistoryService
()
.
createHistoricProcessInstanceQuery
()
.
processInstanceId
(
processInstanceId
)
.
singleResult
();
if
(
instance
==
null
)
{
throw
new
ActivitiObjectNotFoundException
(
"Process instance not found for id "
+
processInstanceId
,
ProcessInstance
.
class
);
}
ObjectNode
responseJSON
=
new
ObjectMapper
().
createObjectNode
();
responseJSON
.
put
(
"processInstanceId"
,
instance
.
getId
());
if
(
instance
.
getBusinessKey
()
!=
null
)
{
responseJSON
.
put
(
"businessKey"
,
instance
.
getBusinessKey
());
}
else
{
responseJSON
.
putNull
(
"businessKey"
);
}
responseJSON
.
put
(
"processDefinitionId"
,
instance
.
getProcessDefinitionId
());
responseJSON
.
put
(
"startTime"
,
RequestUtil
.
dateToString
(
instance
.
getStartTime
()));
responseJSON
.
put
(
"startActivityId"
,
instance
.
getStartActivityId
());
if
(
instance
.
getStartUserId
()
!=
null
)
{
responseJSON
.
put
(
"startUserId"
,
instance
.
getStartUserId
());
}
else
{
responseJSON
.
putNull
(
"startUserId"
);
}
if
(
instance
.
getEndTime
()
==
null
)
{
responseJSON
.
put
(
"completed"
,
false
);
}
else
{
responseJSON
.
put
(
"completed"
,
true
);
responseJSON
.
put
(
"endTime"
,
RequestUtil
.
dateToString
(
instance
.
getEndTime
()));
responseJSON
.
put
(
"endActivityId"
,
instance
.
getEndActivityId
());
responseJSON
.
put
(
"duration"
,
instance
.
getDurationInMillis
());
}
addTaskList
(
processInstanceId
,
responseJSON
);
addActivityList
(
processInstanceId
,
responseJSON
);
addVariableList
(
processInstanceId
,
responseJSON
);
return
responseJSON
;
}
@Delete
public
ObjectNode
deleteProcessInstance
()
{
if
(
authenticate
()
==
false
)
return
null
;
String
processInstanceId
=
(
String
)
getRequest
().
getAttributes
().
get
(
"processInstanceId"
);
ActivitiUtil
.
getRuntimeService
().
deleteProcessInstance
(
processInstanceId
,
"REST API"
);
ObjectNode
successNode
=
new
ObjectMapper
().
createObjectNode
();
successNode
.
put
(
"success"
,
true
);
return
successNode
;
}
private
void
addTaskList
(
String
processInstanceId
,
ObjectNode
responseJSON
)
{
List
<
HistoricTaskInstance
>
taskList
=
ActivitiUtil
.
getHistoryService
()
.
createHistoricTaskInstanceQuery
()
.
processInstanceId
(
processInstanceId
)
.
orderByHistoricTaskInstanceStartTime
()
.
asc
()
.
list
();
if
(
taskList
!=
null
&&
taskList
.
size
()
>
0
)
{
ArrayNode
tasksJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"tasks"
,
tasksJSON
);
for
(
HistoricTaskInstance
historicTaskInstance
:
taskList
)
{
ObjectNode
taskJSON
=
new
ObjectMapper
().
createObjectNode
();
taskJSON
.
put
(
"taskId"
,
historicTaskInstance
.
getId
());
taskJSON
.
put
(
"taskDefinitionKey"
,
historicTaskInstance
.
getTaskDefinitionKey
());
if
(
historicTaskInstance
.
getName
()
!=
null
)
{
taskJSON
.
put
(
"taskName"
,
historicTaskInstance
.
getName
());
}
else
{
taskJSON
.
putNull
(
"taskName"
);
}
if
(
historicTaskInstance
.
getDescription
()
!=
null
)
{
taskJSON
.
put
(
"description"
,
historicTaskInstance
.
getDescription
());
}
else
{
taskJSON
.
putNull
(
"description"
);
}
if
(
historicTaskInstance
.
getOwner
()
!=
null
)
{
taskJSON
.
put
(
"owner"
,
historicTaskInstance
.
getOwner
());
}
else
{
taskJSON
.
putNull
(
"owner"
);
}
if
(
historicTaskInstance
.
getAssignee
()
!=
null
)
{
taskJSON
.
put
(
"assignee"
,
historicTaskInstance
.
getAssignee
());
}
else
{
taskJSON
.
putNull
(
"assignee"
);
}
taskJSON
.
put
(
"startTime"
,
RequestUtil
.
dateToString
(
historicTaskInstance
.
getStartTime
()));
if
(
historicTaskInstance
.
getDueDate
()
!=
null
)
{
taskJSON
.
put
(
"dueDate"
,
RequestUtil
.
dateToString
(
historicTaskInstance
.
getDueDate
()));
}
else
{
taskJSON
.
putNull
(
"dueDate"
);
}
if
(
historicTaskInstance
.
getEndTime
()
==
null
)
{
taskJSON
.
put
(
"completed"
,
false
);
}
else
{
taskJSON
.
put
(
"completed"
,
true
);
taskJSON
.
put
(
"endTime"
,
RequestUtil
.
dateToString
(
historicTaskInstance
.
getEndTime
()));
taskJSON
.
put
(
"duration"
,
historicTaskInstance
.
getDurationInMillis
());
}
tasksJSON
.
add
(
taskJSON
);
}
}
}
private
void
addActivityList
(
String
processInstanceId
,
ObjectNode
responseJSON
)
{
List
<
HistoricActivityInstance
>
activityList
=
ActivitiUtil
.
getHistoryService
()
.
createHistoricActivityInstanceQuery
()
.
processInstanceId
(
processInstanceId
)
.
orderByHistoricActivityInstanceStartTime
()
.
asc
()
.
list
();
if
(
activityList
!=
null
&&
activityList
.
size
()
>
0
)
{
ArrayNode
activitiesJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"activities"
,
activitiesJSON
);
for
(
HistoricActivityInstance
historicActivityInstance
:
activityList
)
{
ObjectNode
activityJSON
=
new
ObjectMapper
().
createObjectNode
();
activityJSON
.
put
(
"activityId"
,
historicActivityInstance
.
getActivityId
());
if
(
historicActivityInstance
.
getActivityName
()
!=
null
)
{
activityJSON
.
put
(
"activityName"
,
historicActivityInstance
.
getActivityName
());
}
else
{
activityJSON
.
putNull
(
"activityName"
);
}
activityJSON
.
put
(
"activityType"
,
historicActivityInstance
.
getActivityType
());
activityJSON
.
put
(
"startTime"
,
RequestUtil
.
dateToString
(
historicActivityInstance
.
getStartTime
()));
if
(
historicActivityInstance
.
getEndTime
()
==
null
)
{
activityJSON
.
put
(
"completed"
,
false
);
}
else
{
activityJSON
.
put
(
"completed"
,
true
);
activityJSON
.
put
(
"endTime"
,
RequestUtil
.
dateToString
(
historicActivityInstance
.
getEndTime
()));
activityJSON
.
put
(
"duration"
,
historicActivityInstance
.
getDurationInMillis
());
}
activitiesJSON
.
add
(
activityJSON
);
}
}
}
private
void
addVariableList
(
String
processInstanceId
,
ObjectNode
responseJSON
)
{
try
{
Map
<
String
,
Object
>
variableMap
=
ActivitiUtil
.
getRuntimeService
()
.
getVariables
(
processInstanceId
);
if
(
variableMap
!=
null
&&
variableMap
.
size
()
>
0
)
{
ArrayNode
variablesJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"variables"
,
variablesJSON
);
for
(
String
key
:
variableMap
.
keySet
())
{
Object
variableValue
=
variableMap
.
get
(
key
);
ObjectNode
variableJSON
=
new
ObjectMapper
().
createObjectNode
();
variableJSON
.
put
(
"variableName"
,
key
);
if
(
variableValue
!=
null
)
{
if
(
variableValue
instanceof
Boolean
)
{
variableJSON
.
put
(
"variableValue"
,
(
Boolean
)
variableValue
);
}
else
if
(
variableValue
instanceof
Long
)
{
variableJSON
.
put
(
"variableValue"
,
(
Long
)
variableValue
);
}
else
if
(
variableValue
instanceof
Double
)
{
variableJSON
.
put
(
"variableValue"
,
(
Double
)
variableValue
);
}
else
if
(
variableValue
instanceof
Float
)
{
variableJSON
.
put
(
"variableValue"
,
(
Float
)
variableValue
);
}
else
if
(
variableValue
instanceof
Integer
)
{
variableJSON
.
put
(
"variableValue"
,
(
Integer
)
variableValue
);
}
else
{
variableJSON
.
put
(
"variableValue"
,
variableValue
.
toString
());
}
}
else
{
variableJSON
.
putNull
(
"variableValue"
);
}
variablesJSON
.
add
(
variableJSON
);
}
}
}
catch
(
Exception
e
)
{
// Absorb possible error that the execution could not be found
}
List
<
HistoricDetail
>
historyVariableList
=
ActivitiUtil
.
getHistoryService
()
.
createHistoricDetailQuery
()
.
processInstanceId
(
processInstanceId
)
.
variableUpdates
()
.
orderByTime
()
.
desc
()
.
list
();
if
(
historyVariableList
!=
null
&&
historyVariableList
.
size
()
>
0
)
{
ArrayNode
variablesJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"historyVariables"
,
variablesJSON
);
for
(
HistoricDetail
historicDetail
:
historyVariableList
)
{
HistoricVariableUpdate
variableUpdate
=
(
HistoricVariableUpdate
)
historicDetail
;
ObjectNode
variableJSON
=
new
ObjectMapper
().
createObjectNode
();
variableJSON
.
put
(
"variableName"
,
variableUpdate
.
getVariableName
());
if
(
variableUpdate
.
getValue
()
!=
null
)
{
if
(
variableUpdate
.
getValue
()
instanceof
Boolean
)
{
variableJSON
.
put
(
"variableValue"
,
(
Boolean
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Long
)
{
variableJSON
.
put
(
"variableValue"
,
(
Long
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Double
)
{
variableJSON
.
put
(
"variableValue"
,
(
Double
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Float
)
{
variableJSON
.
put
(
"variableValue"
,
(
Float
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Integer
)
{
variableJSON
.
put
(
"variableValue"
,
(
Integer
)
variableUpdate
.
getValue
());
}
else
{
variableJSON
.
put
(
"variableValue"
,
variableUpdate
.
getValue
().
toString
());
}
}
else
{
variableJSON
.
putNull
(
"variableValue"
);
}
variableJSON
.
put
(
"variableType"
,
variableUpdate
.
getVariableTypeName
());
variableJSON
.
put
(
"revision"
,
variableUpdate
.
getRevision
());
variableJSON
.
put
(
"time"
,
RequestUtil
.
dateToString
(
variableUpdate
.
getTime
()));
variablesJSON
.
add
(
variableJSON
);
}
}
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/
process/
ProcessInstancesPaginateList.java
→
modules/activiti-rest/src/main/java/org/activiti/rest/api/
legacy/process/Legacy
ProcessInstancesPaginateList.java
浏览文件 @
628e5d46
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.activiti.rest.api.process
;
package
org.activiti.rest.api.
legacy.
process
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -22,14 +22,14 @@ import org.activiti.rest.api.AbstractPaginateList;
...
@@ -22,14 +22,14 @@ import org.activiti.rest.api.AbstractPaginateList;
/**
/**
* @author Tijs Rademakers
* @author Tijs Rademakers
*/
*/
public
class
ProcessInstancesPaginateList
extends
AbstractPaginateList
{
public
class
Legacy
ProcessInstancesPaginateList
extends
AbstractPaginateList
{
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
@Override
@Override
protected
List
processList
(
List
list
)
{
protected
List
processList
(
List
list
)
{
List
<
ProcessInstancesResponse
>
processResponseList
=
new
ArrayList
<
ProcessInstancesResponse
>();
List
<
LegacyProcessInstancesResponse
>
processResponseList
=
new
ArrayList
<
Legacy
ProcessInstancesResponse
>();
for
(
Object
instance
:
list
)
{
for
(
Object
instance
:
list
)
{
processResponseList
.
add
(
new
ProcessInstancesResponse
(
processResponseList
.
add
(
new
Legacy
ProcessInstancesResponse
(
(
HistoricProcessInstance
)
instance
));
(
HistoricProcessInstance
)
instance
));
}
}
return
processResponseList
;
return
processResponseList
;
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/
process/
ProcessInstancesResource.java
→
modules/activiti-rest/src/main/java/org/activiti/rest/api/
legacy/process/Legacy
ProcessInstancesResource.java
浏览文件 @
628e5d46
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.activiti.rest.api.process
;
package
org.activiti.rest.api.
legacy.
process
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -27,11 +27,11 @@ import org.restlet.resource.Get;
...
@@ -27,11 +27,11 @@ import org.restlet.resource.Get;
/**
/**
* @author Tijs Rademakers
* @author Tijs Rademakers
*/
*/
public
class
ProcessInstancesResource
extends
SecuredResource
{
public
class
Legacy
ProcessInstancesResource
extends
SecuredResource
{
Map
<
String
,
QueryProperty
>
properties
=
new
HashMap
<
String
,
QueryProperty
>();
Map
<
String
,
QueryProperty
>
properties
=
new
HashMap
<
String
,
QueryProperty
>();
public
ProcessInstancesResource
()
{
public
Legacy
ProcessInstancesResource
()
{
properties
.
put
(
"id"
,
HistoricProcessInstanceQueryProperty
.
PROCESS_INSTANCE_ID_
);
properties
.
put
(
"id"
,
HistoricProcessInstanceQueryProperty
.
PROCESS_INSTANCE_ID_
);
properties
.
put
(
"processDefinitionId"
,
HistoricProcessInstanceQueryProperty
.
PROCESS_DEFINITION_ID
);
properties
.
put
(
"processDefinitionId"
,
HistoricProcessInstanceQueryProperty
.
PROCESS_DEFINITION_ID
);
properties
.
put
(
"businessKey"
,
HistoricProcessInstanceQueryProperty
.
BUSINESS_KEY
);
properties
.
put
(
"businessKey"
,
HistoricProcessInstanceQueryProperty
.
BUSINESS_KEY
);
...
@@ -49,7 +49,7 @@ public class ProcessInstancesResource extends SecuredResource {
...
@@ -49,7 +49,7 @@ public class ProcessInstancesResource extends SecuredResource {
query
=
processDefinitionId
==
null
?
query
:
query
.
processDefinitionId
(
processDefinitionId
);
query
=
processDefinitionId
==
null
?
query
:
query
.
processDefinitionId
(
processDefinitionId
);
query
=
processInstanceKey
==
null
?
query
:
query
.
processInstanceBusinessKey
(
processInstanceKey
);
query
=
processInstanceKey
==
null
?
query
:
query
.
processInstanceBusinessKey
(
processInstanceKey
);
DataResponse
response
=
new
ProcessInstancesPaginateList
().
paginateList
(
getQuery
(),
query
,
"id"
,
properties
);
DataResponse
response
=
new
Legacy
ProcessInstancesPaginateList
().
paginateList
(
getQuery
(),
query
,
"id"
,
properties
);
return
response
;
return
response
;
}
}
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/
process/
ProcessInstancesResponse.java
→
modules/activiti-rest/src/main/java/org/activiti/rest/api/
legacy/process/Legacy
ProcessInstancesResponse.java
浏览文件 @
628e5d46
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.activiti.rest.api.process
;
package
org.activiti.rest.api.
legacy.
process
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -21,7 +21,7 @@ import org.activiti.rest.api.RequestUtil;
...
@@ -21,7 +21,7 @@ import org.activiti.rest.api.RequestUtil;
/**
/**
* @author Tijs Rademakers
* @author Tijs Rademakers
*/
*/
public
class
ProcessInstancesResponse
implements
Serializable
{
public
class
Legacy
ProcessInstancesResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
...
@@ -31,7 +31,7 @@ public class ProcessInstancesResponse implements Serializable {
...
@@ -31,7 +31,7 @@ public class ProcessInstancesResponse implements Serializable {
String
startTime
;
String
startTime
;
String
startUserId
;
String
startUserId
;
public
ProcessInstancesResponse
(
HistoricProcessInstance
processInstance
)
{
public
Legacy
ProcessInstancesResponse
(
HistoricProcessInstance
processInstance
)
{
this
.
setId
(
processInstance
.
getId
());
this
.
setId
(
processInstance
.
getId
());
this
.
setBusinessKey
(
processInstance
.
getBusinessKey
());
this
.
setBusinessKey
(
processInstance
.
getBusinessKey
());
this
.
setStartTime
(
RequestUtil
.
dateToString
(
processInstance
.
getStartTime
()));
this
.
setStartTime
(
RequestUtil
.
dateToString
(
processInstance
.
getStartTime
()));
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceBasedResource.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.process
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.activiti.engine.impl.ProcessInstanceQueryProperty
;
import
org.activiti.engine.query.QueryProperty
;
import
org.activiti.engine.runtime.ProcessInstanceQuery
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.DataResponse
;
import
org.activiti.rest.api.SecuredResource
;
import
org.restlet.data.Form
;
/**
* @author Frederik Heremans
*/
public
class
ProcessInstanceBasedResource
extends
SecuredResource
{
private
static
Map
<
String
,
QueryProperty
>
allowedSortProperties
=
new
HashMap
<
String
,
QueryProperty
>();
static
{
allowedSortProperties
.
put
(
"processDefinitionId"
,
ProcessInstanceQueryProperty
.
PROCESS_DEFINITION_ID
);
allowedSortProperties
.
put
(
"processDefinitionKey"
,
ProcessInstanceQueryProperty
.
PROCESS_DEFINITION_KEY
);
allowedSortProperties
.
put
(
"id"
,
ProcessInstanceQueryProperty
.
PROCESS_INSTANCE_ID
);
}
protected
DataResponse
getQueryResponse
(
ProcessInstanceQueryRequest
queryRequest
,
Form
urlQuery
)
{
ProcessInstanceQuery
query
=
ActivitiUtil
.
getRuntimeService
().
createProcessInstanceQuery
();
// Populate query based on request
if
(
queryRequest
.
getProcessInstanceId
()
!=
null
)
{
query
.
processInstanceId
(
queryRequest
.
getProcessInstanceId
());
}
if
(
queryRequest
.
getProcessDefinitionKey
()
!=
null
)
{
query
.
processDefinitionKey
(
queryRequest
.
getProcessDefinitionKey
());
}
if
(
queryRequest
.
getProcessDefinitionId
()
!=
null
)
{
query
.
processDefinitionId
(
queryRequest
.
getProcessDefinitionId
());
}
if
(
queryRequest
.
getProcessBusinessKey
()
!=
null
)
{
query
.
processInstanceBusinessKey
(
queryRequest
.
getProcessBusinessKey
());
}
if
(
queryRequest
.
getInvolvedUser
()
!=
null
)
{
query
.
involvedUser
(
queryRequest
.
getInvolvedUser
());
}
if
(
queryRequest
.
getSuspended
()
!=
null
)
{
if
(
queryRequest
.
getSuspended
())
{
query
.
suspended
();
}
else
{
query
.
active
();
}
}
if
(
queryRequest
.
getSubProcessInstanceId
()
!=
null
)
{
query
.
subProcessInstanceId
(
queryRequest
.
getSubProcessInstanceId
());
}
if
(
queryRequest
.
getSuperProcessInstanceId
()
!=
null
)
{
query
.
superProcessInstanceId
(
queryRequest
.
getSuperProcessInstanceId
());
}
return
new
ProcessInstancePaginateList
(
this
).
paginateList
(
urlQuery
,
query
,
"id"
,
allowedSortProperties
);
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceCollectionResource.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.process
;
import
org.activiti.engine.ActivitiIllegalArgumentException
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.DataResponse
;
import
org.restlet.data.Form
;
import
org.restlet.data.Status
;
import
org.restlet.resource.Delete
;
import
org.restlet.resource.Get
;
/**
* @author Frederik Heremans
*/
public
class
ProcessInstanceCollectionResource
extends
ProcessInstanceBasedResource
{
@Get
public
DataResponse
getProcessInstances
()
{
if
(!
authenticate
())
{
return
null
;
}
Form
urlQuery
=
getQuery
();
// Populate query based on request
ProcessInstanceQueryRequest
queryRequest
=
new
ProcessInstanceQueryRequest
();
if
(
getQueryParameter
(
"id"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setProcessInstanceId
(
getQueryParameter
(
"id"
,
urlQuery
));
}
if
(
getQueryParameter
(
"processDefinitionKey"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setProcessDefinitionKey
(
getQueryParameter
(
"processDefinitionKey"
,
urlQuery
));
}
if
(
getQueryParameter
(
"processDefinitionId"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setProcessDefinitionId
(
getQueryParameter
(
"processDefinitionId"
,
urlQuery
));
}
if
(
getQueryParameter
(
"businessKey"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setProcessBusinessKey
(
getQueryParameter
(
"businessKey"
,
urlQuery
));
}
if
(
getQueryParameter
(
"involvedUser"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setInvolvedUser
(
getQueryParameter
(
"involvedUser"
,
urlQuery
));
}
if
(
getQueryParameter
(
"suspended"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setSuspended
(
getQueryParameterAsBoolean
(
"suspended"
,
urlQuery
));
}
if
(
getQueryParameter
(
"superProcessInstanceId"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setSuperProcessInstanceId
(
getQueryParameter
(
"superProcessInstanceId"
,
urlQuery
));
}
if
(
getQueryParameter
(
"subProcessInstanceId"
,
urlQuery
)
!=
null
)
{
queryRequest
.
setSubProcessInstanceId
(
getQueryParameter
(
"subProcessInstanceId"
,
urlQuery
));
}
return
getQueryResponse
(
queryRequest
,
urlQuery
);
}
@Delete
public
void
deleteProcessInstance
()
{
if
(!
authenticate
())
{
return
;
}
ProcessInstance
processInstance
=
getProcessInstanceFromRequest
();
String
deleteReason
=
getQueryParameter
(
"deleteReason"
,
getQuery
());
ActivitiUtil
.
getRuntimeService
().
deleteProcessInstance
(
processInstance
.
getId
(),
deleteReason
);
setStatus
(
Status
.
SUCCESS_NO_CONTENT
);
}
protected
ProcessInstance
getProcessInstanceFromRequest
()
{
String
processInstanceId
=
getAttribute
(
"processInstanceId"
);
if
(
processInstanceId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"The processInstanceId cannot be null"
);
}
ProcessInstance
processInstance
=
ActivitiUtil
.
getRuntimeService
().
createProcessInstanceQuery
()
.
processInstanceId
(
processInstanceId
).
singleResult
();
if
(
processInstance
==
null
)
{
throw
new
ActivitiObjectNotFoundException
(
"Could not find a process instance with id '"
+
processInstanceId
+
"'."
,
ProcessInstance
.
class
);
}
return
processInstance
;
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstancePaginateList.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.process
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.rest.api.AbstractPaginateList
;
import
org.activiti.rest.api.RestResponseFactory
;
import
org.activiti.rest.api.SecuredResource
;
import
org.activiti.rest.application.ActivitiRestServicesApplication
;
/**
* @author Frederik Heremans
*/
public
class
ProcessInstancePaginateList
extends
AbstractPaginateList
{
private
SecuredResource
resource
;
public
ProcessInstancePaginateList
(
SecuredResource
resource
)
{
this
.
resource
=
resource
;
}
@SuppressWarnings
(
"rawtypes"
)
@Override
protected
List
processList
(
List
list
)
{
List
<
ProcessInstanceResponse
>
responseList
=
new
ArrayList
<
ProcessInstanceResponse
>();
RestResponseFactory
restResponseFactory
=
resource
.
getApplication
(
ActivitiRestServicesApplication
.
class
).
getRestResponseFactory
();
for
(
Object
instance
:
list
)
{
responseList
.
add
(
restResponseFactory
.
createProcessInstanceResponse
(
resource
,
(
ProcessInstance
)
instance
));
}
return
responseList
;
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceQueryRequest.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.process
;
import
java.util.List
;
import
org.activiti.rest.api.task.QueryVariable
;
import
org.codehaus.jackson.annotate.JsonTypeInfo
;
import
org.codehaus.jackson.annotate.JsonTypeInfo.Id
;
/**
* @author Frederik Heremans
*/
public
class
ProcessInstanceQueryRequest
{
private
String
processInstanceId
;
private
String
processBusinessKey
;
private
String
processDefinitionId
;
private
String
processDefinitionKey
;
private
String
superProcessInstanceId
;
private
String
subProcessInstanceId
;
private
String
involvedUser
;
private
Boolean
suspended
;
private
List
<
QueryVariable
>
variables
;
public
String
getProcessInstanceId
()
{
return
processInstanceId
;
}
public
void
setProcessInstanceId
(
String
processInstanceId
)
{
this
.
processInstanceId
=
processInstanceId
;
}
public
String
getProcessBusinessKey
()
{
return
processBusinessKey
;
}
public
void
setProcessBusinessKey
(
String
processBusinessKey
)
{
this
.
processBusinessKey
=
processBusinessKey
;
}
public
String
getProcessDefinitionId
()
{
return
processDefinitionId
;
}
public
void
setProcessDefinitionId
(
String
processDefinitionId
)
{
this
.
processDefinitionId
=
processDefinitionId
;
}
public
String
getProcessDefinitionKey
()
{
return
processDefinitionKey
;
}
public
void
setProcessDefinitionKey
(
String
processDefinitionKey
)
{
this
.
processDefinitionKey
=
processDefinitionKey
;
}
public
String
getSuperProcessInstanceId
()
{
return
superProcessInstanceId
;
}
public
void
setSuperProcessInstanceId
(
String
superProcessInstanceId
)
{
this
.
superProcessInstanceId
=
superProcessInstanceId
;
}
public
String
getSubProcessInstanceId
()
{
return
subProcessInstanceId
;
}
public
void
setSubProcessInstanceId
(
String
subProcessInstanceId
)
{
this
.
subProcessInstanceId
=
subProcessInstanceId
;
}
public
String
getInvolvedUser
()
{
return
involvedUser
;
}
public
void
setInvolvedUser
(
String
involvedUser
)
{
this
.
involvedUser
=
involvedUser
;
}
public
Boolean
getSuspended
()
{
return
suspended
;
}
public
void
setSuspended
(
Boolean
suspended
)
{
this
.
suspended
=
suspended
;
}
@JsonTypeInfo
(
use
=
Id
.
CLASS
,
defaultImpl
=
QueryVariable
.
class
)
public
List
<
QueryVariable
>
getVariables
()
{
return
variables
;
}
public
void
setVariables
(
List
<
QueryVariable
>
variables
)
{
this
.
variables
=
variables
;
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceResource.java
浏览文件 @
628e5d46
...
@@ -13,250 +13,54 @@
...
@@ -13,250 +13,54 @@
package
org.activiti.rest.api.process
;
package
org.activiti.rest.api.process
;
import
java.util.List
;
import
org.activiti.engine.ActivitiIllegalArgumentException
;
import
java.util.Map
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.history.HistoricActivityInstance
;
import
org.activiti.engine.history.HistoricDetail
;
import
org.activiti.engine.history.HistoricProcessInstance
;
import
org.activiti.engine.history.HistoricTaskInstance
;
import
org.activiti.engine.history.HistoricVariableUpdate
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.RequestUtil
;
import
org.activiti.rest.api.SecuredResource
;
import
org.activiti.rest.api.SecuredResource
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.activiti.rest.application.ActivitiRestServicesApplication
;
import
org.codehaus.jackson.node.ArrayNode
;
import
org.restlet.data.Status
;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.restlet.resource.Delete
;
import
org.restlet.resource.Delete
;
import
org.restlet.resource.Get
;
import
org.restlet.resource.Get
;
/**
/**
* @author
Tijs Rademaker
s
* @author
Frederik Hereman
s
*/
*/
public
class
ProcessInstanceResource
extends
SecuredResource
{
public
class
ProcessInstanceResource
extends
SecuredResource
{
@Get
@Get
public
ObjectNode
getProcessInstance
()
{
public
ProcessInstanceResponse
getProcessInstance
()
{
if
(
authenticate
()
==
false
)
return
null
;
if
(!
authenticate
())
{
return
null
;
String
processInstanceId
=
(
String
)
getRequest
().
getAttributes
().
get
(
"processInstanceId"
);
HistoricProcessInstance
instance
=
ActivitiUtil
.
getHistoryService
()
.
createHistoricProcessInstanceQuery
()
.
processInstanceId
(
processInstanceId
)
.
singleResult
();
if
(
instance
==
null
)
{
throw
new
ActivitiObjectNotFoundException
(
"Process instance not found for id "
+
processInstanceId
,
ProcessInstance
.
class
);
}
ObjectNode
responseJSON
=
new
ObjectMapper
().
createObjectNode
();
responseJSON
.
put
(
"processInstanceId"
,
instance
.
getId
());
if
(
instance
.
getBusinessKey
()
!=
null
)
{
responseJSON
.
put
(
"businessKey"
,
instance
.
getBusinessKey
());
}
else
{
responseJSON
.
putNull
(
"businessKey"
);
}
}
responseJSON
.
put
(
"processDefinitionId"
,
instance
.
getProcessDefinitionId
());
return
getApplication
(
ActivitiRestServicesApplication
.
class
).
getRestResponseFactory
()
responseJSON
.
put
(
"startTime"
,
RequestUtil
.
dateToString
(
instance
.
getStartTime
()));
.
createProcessInstanceResponse
(
this
,
getProcessInstanceFromRequest
());
responseJSON
.
put
(
"startActivityId"
,
instance
.
getStartActivityId
());
if
(
instance
.
getStartUserId
()
!=
null
)
{
responseJSON
.
put
(
"startUserId"
,
instance
.
getStartUserId
());
}
else
{
responseJSON
.
putNull
(
"startUserId"
);
}
if
(
instance
.
getEndTime
()
==
null
)
{
responseJSON
.
put
(
"completed"
,
false
);
}
else
{
responseJSON
.
put
(
"completed"
,
true
);
responseJSON
.
put
(
"endTime"
,
RequestUtil
.
dateToString
(
instance
.
getEndTime
()));
responseJSON
.
put
(
"endActivityId"
,
instance
.
getEndActivityId
());
responseJSON
.
put
(
"duration"
,
instance
.
getDurationInMillis
());
}
addTaskList
(
processInstanceId
,
responseJSON
);
addActivityList
(
processInstanceId
,
responseJSON
);
addVariableList
(
processInstanceId
,
responseJSON
);
return
responseJSON
;
}
}
@Delete
@Delete
public
ObjectNode
deleteProcessInstance
()
{
public
void
deleteProcessInstance
()
{
if
(
authenticate
()
==
false
)
return
null
;
if
(!
authenticate
())
{
return
;
String
processInstanceId
=
(
String
)
getRequest
().
getAttributes
().
get
(
"processInstanceId"
);
ActivitiUtil
.
getRuntimeService
().
deleteProcessInstance
(
processInstanceId
,
"REST API"
);
ObjectNode
successNode
=
new
ObjectMapper
().
createObjectNode
();
successNode
.
put
(
"success"
,
true
);
return
successNode
;
}
}
ProcessInstance
processInstance
=
getProcessInstanceFromRequest
();
String
deleteReason
=
getQueryParameter
(
"deleteReason"
,
getQuery
());
private
void
addTaskList
(
String
processInstanceId
,
ObjectNode
responseJSON
)
{
ActivitiUtil
.
getRuntimeService
().
deleteProcessInstance
(
processInstance
.
getId
(),
deleteReason
);
List
<
HistoricTaskInstance
>
taskList
=
ActivitiUtil
.
getHistoryService
()
setStatus
(
Status
.
SUCCESS_NO_CONTENT
);
.
createHistoricTaskInstanceQuery
()
.
processInstanceId
(
processInstanceId
)
.
orderByHistoricTaskInstanceStartTime
()
.
asc
()
.
list
();
if
(
taskList
!=
null
&&
taskList
.
size
()
>
0
)
{
ArrayNode
tasksJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"tasks"
,
tasksJSON
);
for
(
HistoricTaskInstance
historicTaskInstance
:
taskList
)
{
ObjectNode
taskJSON
=
new
ObjectMapper
().
createObjectNode
();
taskJSON
.
put
(
"taskId"
,
historicTaskInstance
.
getId
());
taskJSON
.
put
(
"taskDefinitionKey"
,
historicTaskInstance
.
getTaskDefinitionKey
());
if
(
historicTaskInstance
.
getName
()
!=
null
)
{
taskJSON
.
put
(
"taskName"
,
historicTaskInstance
.
getName
());
}
else
{
taskJSON
.
putNull
(
"taskName"
);
}
if
(
historicTaskInstance
.
getDescription
()
!=
null
)
{
taskJSON
.
put
(
"description"
,
historicTaskInstance
.
getDescription
());
}
else
{
taskJSON
.
putNull
(
"description"
);
}
if
(
historicTaskInstance
.
getOwner
()
!=
null
)
{
taskJSON
.
put
(
"owner"
,
historicTaskInstance
.
getOwner
());
}
else
{
taskJSON
.
putNull
(
"owner"
);
}
if
(
historicTaskInstance
.
getAssignee
()
!=
null
)
{
taskJSON
.
put
(
"assignee"
,
historicTaskInstance
.
getAssignee
());
}
else
{
taskJSON
.
putNull
(
"assignee"
);
}
taskJSON
.
put
(
"startTime"
,
RequestUtil
.
dateToString
(
historicTaskInstance
.
getStartTime
()));
if
(
historicTaskInstance
.
getDueDate
()
!=
null
)
{
taskJSON
.
put
(
"dueDate"
,
RequestUtil
.
dateToString
(
historicTaskInstance
.
getDueDate
()));
}
else
{
taskJSON
.
putNull
(
"dueDate"
);
}
if
(
historicTaskInstance
.
getEndTime
()
==
null
)
{
taskJSON
.
put
(
"completed"
,
false
);
}
else
{
taskJSON
.
put
(
"completed"
,
true
);
taskJSON
.
put
(
"endTime"
,
RequestUtil
.
dateToString
(
historicTaskInstance
.
getEndTime
()));
taskJSON
.
put
(
"duration"
,
historicTaskInstance
.
getDurationInMillis
());
}
tasksJSON
.
add
(
taskJSON
);
}
}
}
}
private
void
addActivityList
(
String
processInstanceId
,
ObjectNode
responseJSON
)
{
List
<
HistoricActivityInstance
>
activityList
=
ActivitiUtil
.
getHistoryService
()
.
createHistoricActivityInstanceQuery
()
.
processInstanceId
(
processInstanceId
)
.
orderByHistoricActivityInstanceStartTime
()
.
asc
()
.
list
();
if
(
activityList
!=
null
&&
activityList
.
size
()
>
0
)
{
ArrayNode
activitiesJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"activities"
,
activitiesJSON
);
for
(
HistoricActivityInstance
historicActivityInstance
:
activityList
)
{
ObjectNode
activityJSON
=
new
ObjectMapper
().
createObjectNode
();
activityJSON
.
put
(
"activityId"
,
historicActivityInstance
.
getActivityId
());
if
(
historicActivityInstance
.
getActivityName
()
!=
null
)
{
activityJSON
.
put
(
"activityName"
,
historicActivityInstance
.
getActivityName
());
}
else
{
activityJSON
.
putNull
(
"activityName"
);
}
activityJSON
.
put
(
"activityType"
,
historicActivityInstance
.
getActivityType
());
activityJSON
.
put
(
"startTime"
,
RequestUtil
.
dateToString
(
historicActivityInstance
.
getStartTime
()));
if
(
historicActivityInstance
.
getEndTime
()
==
null
)
{
activityJSON
.
put
(
"completed"
,
false
);
}
else
{
activityJSON
.
put
(
"completed"
,
true
);
activityJSON
.
put
(
"endTime"
,
RequestUtil
.
dateToString
(
historicActivityInstance
.
getEndTime
()));
activityJSON
.
put
(
"duration"
,
historicActivityInstance
.
getDurationInMillis
());
}
activitiesJSON
.
add
(
activityJSON
);
}
}
}
private
void
addVariableList
(
String
processInstanceId
,
ObjectNode
responseJSON
)
{
try
{
protected
ProcessInstance
getProcessInstanceFromRequest
()
{
Map
<
String
,
Object
>
variableMap
=
ActivitiUtil
.
getRuntimeService
()
String
processInstanceId
=
getAttribute
(
"processInstanceId"
);
.
getVariables
(
processInstanceId
);
if
(
processInstanceId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"The processInstanceId cannot be null"
);
if
(
variableMap
!=
null
&&
variableMap
.
size
()
>
0
)
{
ArrayNode
variablesJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"variables"
,
variablesJSON
);
for
(
String
key
:
variableMap
.
keySet
())
{
Object
variableValue
=
variableMap
.
get
(
key
);
ObjectNode
variableJSON
=
new
ObjectMapper
().
createObjectNode
();
variableJSON
.
put
(
"variableName"
,
key
);
if
(
variableValue
!=
null
)
{
if
(
variableValue
instanceof
Boolean
)
{
variableJSON
.
put
(
"variableValue"
,
(
Boolean
)
variableValue
);
}
else
if
(
variableValue
instanceof
Long
)
{
variableJSON
.
put
(
"variableValue"
,
(
Long
)
variableValue
);
}
else
if
(
variableValue
instanceof
Double
)
{
variableJSON
.
put
(
"variableValue"
,
(
Double
)
variableValue
);
}
else
if
(
variableValue
instanceof
Float
)
{
variableJSON
.
put
(
"variableValue"
,
(
Float
)
variableValue
);
}
else
if
(
variableValue
instanceof
Integer
)
{
variableJSON
.
put
(
"variableValue"
,
(
Integer
)
variableValue
);
}
else
{
variableJSON
.
put
(
"variableValue"
,
variableValue
.
toString
());
}
}
else
{
variableJSON
.
putNull
(
"variableValue"
);
}
variablesJSON
.
add
(
variableJSON
);
}
}
}
catch
(
Exception
e
)
{
// Absorb possible error that the execution could not be found
}
}
List
<
HistoricDetail
>
historyVariableList
=
ActivitiUtil
.
getHistoryService
()
ProcessInstance
processInstance
=
ActivitiUtil
.
getRuntimeService
().
createProcessInstanceQuery
()
.
createHistoricDetailQuery
()
.
processInstanceId
(
processInstanceId
).
singleResult
();
.
processInstanceId
(
processInstanceId
)
if
(
processInstance
==
null
)
{
.
variableUpdates
()
throw
new
ActivitiObjectNotFoundException
(
"Could not find a process instance with id '"
+
processInstanceId
+
"'."
,
ProcessInstance
.
class
);
.
orderByTime
()
.
desc
()
.
list
();
if
(
historyVariableList
!=
null
&&
historyVariableList
.
size
()
>
0
)
{
ArrayNode
variablesJSON
=
new
ObjectMapper
().
createArrayNode
();
responseJSON
.
put
(
"historyVariables"
,
variablesJSON
);
for
(
HistoricDetail
historicDetail
:
historyVariableList
)
{
HistoricVariableUpdate
variableUpdate
=
(
HistoricVariableUpdate
)
historicDetail
;
ObjectNode
variableJSON
=
new
ObjectMapper
().
createObjectNode
();
variableJSON
.
put
(
"variableName"
,
variableUpdate
.
getVariableName
());
if
(
variableUpdate
.
getValue
()
!=
null
)
{
if
(
variableUpdate
.
getValue
()
instanceof
Boolean
)
{
variableJSON
.
put
(
"variableValue"
,
(
Boolean
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Long
)
{
variableJSON
.
put
(
"variableValue"
,
(
Long
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Double
)
{
variableJSON
.
put
(
"variableValue"
,
(
Double
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Float
)
{
variableJSON
.
put
(
"variableValue"
,
(
Float
)
variableUpdate
.
getValue
());
}
else
if
(
variableUpdate
.
getValue
()
instanceof
Integer
)
{
variableJSON
.
put
(
"variableValue"
,
(
Integer
)
variableUpdate
.
getValue
());
}
else
{
variableJSON
.
put
(
"variableValue"
,
variableUpdate
.
getValue
().
toString
());
}
}
else
{
variableJSON
.
putNull
(
"variableValue"
);
}
variableJSON
.
put
(
"variableType"
,
variableUpdate
.
getVariableTypeName
());
variableJSON
.
put
(
"revision"
,
variableUpdate
.
getRevision
());
variableJSON
.
put
(
"time"
,
RequestUtil
.
dateToString
(
variableUpdate
.
getTime
()));
variablesJSON
.
add
(
variableJSON
);
}
}
}
return
processInstance
;
}
}
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/process/ProcessInstanceResponse.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.process
;
/**
* @author Frederik Heremans
*/
public
class
ProcessInstanceResponse
{
protected
String
id
;
protected
String
url
;
protected
String
businessKey
;
protected
boolean
suspended
;
protected
String
processDefinitionUrl
;
protected
String
activityId
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getBusinessKey
()
{
return
businessKey
;
}
public
void
setBusinessKey
(
String
businessKey
)
{
this
.
businessKey
=
businessKey
;
}
public
boolean
isSuspended
()
{
return
suspended
;
}
public
void
setSuspended
(
boolean
suspended
)
{
this
.
suspended
=
suspended
;
}
public
String
getProcessDefinitionUrl
()
{
return
processDefinitionUrl
;
}
public
void
setProcessDefinitionUrl
(
String
processDefinitionUrl
)
{
this
.
processDefinitionUrl
=
processDefinitionUrl
;
}
public
String
getActivityId
()
{
return
activityId
;
}
public
void
setActivityId
(
String
activityId
)
{
this
.
activityId
=
activityId
;
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentCollectionResource.java
浏览文件 @
628e5d46
...
@@ -47,9 +47,9 @@ public class DeploymentCollectionResource extends SecuredResource {
...
@@ -47,9 +47,9 @@ public class DeploymentCollectionResource extends SecuredResource {
protected
static
final
String
DEPRECATED_API_DEPLOYMENT_SEGMENT
=
"deployment"
;
protected
static
final
String
DEPRECATED_API_DEPLOYMENT_SEGMENT
=
"deployment"
;
Map
<
String
,
QueryProperty
>
allowedSortProperties
=
new
HashMap
<
String
,
QueryProperty
>();
private
static
Map
<
String
,
QueryProperty
>
allowedSortProperties
=
new
HashMap
<
String
,
QueryProperty
>();
public
DeploymentCollectionResource
()
{
static
{
allowedSortProperties
.
put
(
"id"
,
DeploymentQueryProperty
.
DEPLOYMENT_ID
);
allowedSortProperties
.
put
(
"id"
,
DeploymentQueryProperty
.
DEPLOYMENT_ID
);
allowedSortProperties
.
put
(
"name"
,
DeploymentQueryProperty
.
DEPLOYMENT_NAME
);
allowedSortProperties
.
put
(
"name"
,
DeploymentQueryProperty
.
DEPLOYMENT_NAME
);
allowedSortProperties
.
put
(
"deployTime"
,
DeploymentQueryProperty
.
DEPLOY_TIME
);
allowedSortProperties
.
put
(
"deployTime"
,
DeploymentQueryProperty
.
DEPLOY_TIME
);
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/application/RestServicesInit.java
浏览文件 @
628e5d46
...
@@ -13,9 +13,9 @@ import org.activiti.rest.api.identity.UserGroupsResource;
...
@@ -13,9 +13,9 @@ import org.activiti.rest.api.identity.UserGroupsResource;
import
org.activiti.rest.api.identity.UserPictureResource
;
import
org.activiti.rest.api.identity.UserPictureResource
;
import
org.activiti.rest.api.identity.UserResource
;
import
org.activiti.rest.api.identity.UserResource
;
import
org.activiti.rest.api.identity.UserSearchResource
;
import
org.activiti.rest.api.identity.UserSearchResource
;
import
org.activiti.rest.api.legacy.LegacyTaskAttachmentResource
;
import
org.activiti.rest.api.legacy.TaskAddResource
;
import
org.activiti.rest.api.legacy.TaskAddResource
;
import
org.activiti.rest.api.legacy.TaskAttachmentAddResource
;
import
org.activiti.rest.api.legacy.TaskAttachmentAddResource
;
import
org.activiti.rest.api.legacy.LegacyTaskAttachmentResource
;
import
org.activiti.rest.api.legacy.TaskFormResource
;
import
org.activiti.rest.api.legacy.TaskFormResource
;
import
org.activiti.rest.api.legacy.TaskOperationResource
;
import
org.activiti.rest.api.legacy.TaskOperationResource
;
import
org.activiti.rest.api.legacy.TaskPropertiesResource
;
import
org.activiti.rest.api.legacy.TaskPropertiesResource
;
...
@@ -28,6 +28,8 @@ import org.activiti.rest.api.legacy.deployment.DeploymentDeleteResource;
...
@@ -28,6 +28,8 @@ import org.activiti.rest.api.legacy.deployment.DeploymentDeleteResource;
import
org.activiti.rest.api.legacy.deployment.DeploymentUploadResource
;
import
org.activiti.rest.api.legacy.deployment.DeploymentUploadResource
;
import
org.activiti.rest.api.legacy.deployment.DeploymentsDeleteResource
;
import
org.activiti.rest.api.legacy.deployment.DeploymentsDeleteResource
;
import
org.activiti.rest.api.legacy.deployment.DeploymentsResource
;
import
org.activiti.rest.api.legacy.deployment.DeploymentsResource
;
import
org.activiti.rest.api.legacy.process.LegacyProcessInstanceResource
;
import
org.activiti.rest.api.legacy.process.LegacyProcessInstancesResource
;
import
org.activiti.rest.api.legacy.process.ProcessDefinitionsResource
;
import
org.activiti.rest.api.legacy.process.ProcessDefinitionsResource
;
import
org.activiti.rest.api.legacy.task.LegacyTaskResource
;
import
org.activiti.rest.api.legacy.task.LegacyTaskResource
;
import
org.activiti.rest.api.management.JobExecuteResource
;
import
org.activiti.rest.api.management.JobExecuteResource
;
...
@@ -40,11 +42,11 @@ import org.activiti.rest.api.management.TablesResource;
...
@@ -40,11 +42,11 @@ import org.activiti.rest.api.management.TablesResource;
import
org.activiti.rest.api.process.ProcessDefinitionDiagramResource
;
import
org.activiti.rest.api.process.ProcessDefinitionDiagramResource
;
import
org.activiti.rest.api.process.ProcessDefinitionFormResource
;
import
org.activiti.rest.api.process.ProcessDefinitionFormResource
;
import
org.activiti.rest.api.process.ProcessDefinitionPropertiesResource
;
import
org.activiti.rest.api.process.ProcessDefinitionPropertiesResource
;
import
org.activiti.rest.api.process.ProcessInstanceCollectionResource
;
import
org.activiti.rest.api.process.ProcessInstanceDiagramResource
;
import
org.activiti.rest.api.process.ProcessInstanceDiagramResource
;
import
org.activiti.rest.api.process.ProcessInstanceResource
;
import
org.activiti.rest.api.process.ProcessInstanceResource
;
import
org.activiti.rest.api.process.ProcessInstanceSignalExecutionResource
;
import
org.activiti.rest.api.process.ProcessInstanceSignalExecutionResource
;
import
org.activiti.rest.api.process.ProcessInstanceTaskResource
;
import
org.activiti.rest.api.process.ProcessInstanceTaskResource
;
import
org.activiti.rest.api.process.ProcessInstancesResource
;
import
org.activiti.rest.api.process.SignalEventSubscriptionResource
;
import
org.activiti.rest.api.process.SignalEventSubscriptionResource
;
import
org.activiti.rest.api.process.StartProcessInstanceResource
;
import
org.activiti.rest.api.process.StartProcessInstanceResource
;
import
org.activiti.rest.api.repository.DeploymentCollectionResource
;
import
org.activiti.rest.api.repository.DeploymentCollectionResource
;
...
@@ -104,6 +106,9 @@ public class RestServicesInit {
...
@@ -104,6 +106,9 @@ public class RestServicesInit {
router
.
attach
(
"/runtime/tasks/{taskId}/attachments/{attachmentId}"
,
TaskAttachmentResource
.
class
);
router
.
attach
(
"/runtime/tasks/{taskId}/attachments/{attachmentId}"
,
TaskAttachmentResource
.
class
);
router
.
attach
(
"/runtime/tasks/{taskId}/attachments/{attachmentId}/content"
,
TaskAttachmentContentResource
.
class
);
router
.
attach
(
"/runtime/tasks/{taskId}/attachments/{attachmentId}/content"
,
TaskAttachmentContentResource
.
class
);
router
.
attach
(
"/runtime/process-instances/{processInstanceId}"
,
ProcessInstanceResource
.
class
);
router
.
attach
(
"/runtime/process-instances"
,
ProcessInstanceCollectionResource
.
class
);
router
.
attach
(
"/query/tasks"
,
TaskQueryResource
.
class
);
router
.
attach
(
"/query/tasks"
,
TaskQueryResource
.
class
);
// Old rest-urls
// Old rest-urls
...
@@ -125,9 +130,9 @@ public class RestServicesInit {
...
@@ -125,9 +130,9 @@ public class RestServicesInit {
router
.
attach
(
"/groups"
,
GroupSearchResource
.
class
);
router
.
attach
(
"/groups"
,
GroupSearchResource
.
class
);
router
.
attach
(
"/process-definitions"
,
ProcessDefinitionsResource
.
class
);
router
.
attach
(
"/process-definitions"
,
ProcessDefinitionsResource
.
class
);
router
.
attach
(
"/process-instances"
,
ProcessInstancesResource
.
class
);
router
.
attach
(
"/process-instances"
,
Legacy
ProcessInstancesResource
.
class
);
router
.
attach
(
"/process-instance"
,
StartProcessInstanceResource
.
class
);
router
.
attach
(
"/process-instance"
,
StartProcessInstanceResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}"
,
ProcessInstanceResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}"
,
Legacy
ProcessInstanceResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}/diagram"
,
ProcessInstanceDiagramResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}/diagram"
,
ProcessInstanceDiagramResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}/tasks"
,
ProcessInstanceTaskResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}/tasks"
,
ProcessInstanceTaskResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}/signal"
,
ProcessInstanceSignalExecutionResource
.
class
);
router
.
attach
(
"/process-instance/{processInstanceId}/signal"
,
ProcessInstanceSignalExecutionResource
.
class
);
...
...
modules/activiti-rest/src/test/java/org/activiti/rest/api/
process
/SignalEventSubscriptionResourceTest.java
→
modules/activiti-rest/src/test/java/org/activiti/rest/api/
legacy
/SignalEventSubscriptionResourceTest.java
浏览文件 @
628e5d46
package
org.activiti.rest.api.
process
;
package
org.activiti.rest.api.
legacy
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
...
modules/activiti-rest/src/test/java/org/activiti/rest/api/
process
/StartProcessInstanceResourceTest.java
→
modules/activiti-rest/src/test/java/org/activiti/rest/api/
legacy
/StartProcessInstanceResourceTest.java
浏览文件 @
628e5d46
package
org.activiti.rest.api.
process
;
package
org.activiti.rest.api.
legacy
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
...
modules/activiti-rest/src/test/java/org/activiti/rest/api/runtime/ProcessInstanceCollectionResourceTest.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.runtime
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.engine.test.Deployment
;
import
org.activiti.rest.BaseRestTestCase
;
import
org.activiti.rest.api.RestUrls
;
import
org.codehaus.jackson.JsonNode
;
import
org.restlet.data.Status
;
import
org.restlet.representation.Representation
;
import
org.restlet.resource.ClientResource
;
import
org.restlet.resource.ResourceException
;
/**
* Test for all REST-operations related to a single Process instance resource.
*
* @author Frederik Heremans
*/
public
class
ProcessInstanceCollectionResourceTest
extends
BaseRestTestCase
{
/**
* Test getting a single process instance.
*/
@Deployment
(
resources
=
{
"org/activiti/rest/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml"
})
public
void
testGetProcessInstance
()
throws
Exception
{
ProcessInstance
processInstance
=
runtimeService
.
startProcessInstanceByKey
(
"processOne"
,
"myBusinessKey"
);
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE
,
processInstance
.
getId
()));
Representation
response
=
client
.
get
();
assertEquals
(
Status
.
SUCCESS_OK
,
client
.
getResponse
().
getStatus
());
// Check resulting instance
JsonNode
responseNode
=
objectMapper
.
readTree
(
response
.
getStream
());
assertNotNull
(
responseNode
);
assertEquals
(
processInstance
.
getId
(),
responseNode
.
get
(
"id"
).
getTextValue
());
assertEquals
(
"myBusinessKey"
,
responseNode
.
get
(
"businessKey"
).
getTextValue
());
assertEquals
(
"processTask"
,
responseNode
.
get
(
"activityId"
).
getTextValue
());
assertFalse
(
responseNode
.
get
(
"suspended"
).
getBooleanValue
());
assertTrue
(
responseNode
.
get
(
"url"
).
asText
().
endsWith
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE
,
processInstance
.
getId
())));
assertTrue
(
responseNode
.
get
(
"processDefinitionUrl"
).
asText
().
endsWith
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_DEFINITION
,
encode
(
processInstance
.
getProcessDefinitionId
()))));
}
/**
* Test getting an unexisting process instance.
*/
public
void
testGetUnexistingProcessInstance
()
{
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE
,
"unexistingpi"
));
try
{
client
.
get
();
fail
(
"Exception expected"
);
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
());
assertEquals
(
"Could not find a process instance with id 'unexistingpi'."
,
expected
.
getStatus
().
getDescription
());
}
}
/**
* Test deleting a single process instance.
*/
@Deployment
(
resources
=
{
"org/activiti/rest/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml"
})
public
void
testDeleteProcessInstance
()
{
ProcessInstance
processInstance
=
runtimeService
.
startProcessInstanceByKey
(
"processOne"
,
"myBusinessKey"
);
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE
,
processInstance
.
getId
()));
client
.
delete
();
assertEquals
(
Status
.
SUCCESS_NO_CONTENT
,
client
.
getResponse
().
getStatus
());
// Check if process-instance is gone
assertEquals
(
0
,
runtimeService
.
createProcessInstanceQuery
().
processInstanceId
(
processInstance
.
getId
()).
count
());
}
/**
* Test deleting an unexisting process instance.
*/
public
void
testDeleteUnexistingProcessInstance
()
{
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE
,
"unexistingpi"
));
try
{
client
.
delete
();
fail
(
"Exception expected"
);
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
());
assertEquals
(
"Could not find a process instance with id 'unexistingpi'."
,
expected
.
getStatus
().
getDescription
());
}
}
}
modules/activiti-rest/src/test/java/org/activiti/rest/api/runtime/ProcessInstanceResourceTest.java
0 → 100644
浏览文件 @
628e5d46
/* 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.rest.api.runtime
;
import
org.activiti.engine.runtime.ProcessInstance
;
import
org.activiti.engine.test.Deployment
;
import
org.activiti.rest.BaseRestTestCase
;
import
org.activiti.rest.api.RestUrls
;
/**
* Test for all REST-operations related to a single Process instance resource.
*
* @author Frederik Heremans
*/
public
class
ProcessInstanceResourceTest
extends
BaseRestTestCase
{
/**
* Test getting a single process instance.
*/
@Deployment
(
resources
=
{
"org/activiti/rest/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml"
})
public
void
testGetProcessInstance
()
throws
Exception
{
ProcessInstance
processInstance
=
runtimeService
.
startProcessInstanceByKey
(
"processOne"
,
"myBusinessKey"
);
String
id
=
processInstance
.
getId
();
runtimeService
.
addUserIdentityLink
(
id
,
"kermit"
,
"whatever"
);
// Test without any parameters
String
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
);
assertResultsPresentInDataResponse
(
url
,
id
);
// Process instance id
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?id="
+
id
;
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?id=anotherId"
;
assertResultsPresentInDataResponse
(
url
);
// Process instance business key
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?businessKey=myBusinessKey"
;
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?businessKey=anotherBusinessKey"
;
assertResultsPresentInDataResponse
(
url
);
// Process definition key
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?processDefinitionKey=processOne"
;
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?processDefinitionKey=processTwo"
;
assertResultsPresentInDataResponse
(
url
);
// Process definition id
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?processDefinitionId="
+
processInstance
.
getProcessDefinitionId
();
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?processDefinitionId=anotherId"
;
assertResultsPresentInDataResponse
(
url
);
// Involved user
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?involvedUser=kermit"
;
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?involvedUser=gonzo"
;
assertResultsPresentInDataResponse
(
url
);
// Active process
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?suspended=false"
;
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?suspended=true"
;
assertResultsPresentInDataResponse
(
url
);
// Suspended process
runtimeService
.
suspendProcessInstanceById
(
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?suspended=true"
;
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?suspended=false"
;
assertResultsPresentInDataResponse
(
url
);
runtimeService
.
activateProcessInstanceById
(
id
);
// Complete first task in the process to have a subprocess created
taskService
.
complete
(
taskService
.
createTaskQuery
().
processInstanceId
(
id
).
singleResult
().
getId
());
ProcessInstance
subProcess
=
runtimeService
.
createProcessInstanceQuery
().
superProcessInstanceId
(
id
).
singleResult
();
assertNotNull
(
subProcess
);
// Super-process instance id
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?superProcessInstanceId="
+
id
;
assertResultsPresentInDataResponse
(
url
,
subProcess
.
getId
());
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?superProcessInstanceId=anotherId"
;
assertResultsPresentInDataResponse
(
url
);
// Sub-process instance id
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?subProcessInstanceId="
+
subProcess
.
getId
();
assertResultsPresentInDataResponse
(
url
,
id
);
url
=
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_PROCESS_INSTANCE_COLLECTION
)
+
"?subProcessInstanceId=anotherId"
;
assertResultsPresentInDataResponse
(
url
);
}
}
modules/activiti-rest/src/test/resources/org/activiti/rest/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml
0 → 100644
浏览文件 @
628e5d46
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns=
"http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti=
"http://activiti.org/bpmn"
targetNamespace=
"OneTaskCategory"
>
<process
id=
"processOne"
name=
"The One Task Process"
>
<documentation>
One task process description
</documentation>
<startEvent
id=
"theStart"
/>
<sequenceFlow
id=
"flow1"
sourceRef=
"theStart"
targetRef=
"processTask"
/>
<userTask
id=
"processTask"
name=
"Process task"
activiti:candidateUsers=
"kermit"
activiti:candidateGroups=
"sales"
>
<documentation>
Process task description
</documentation>
</userTask>
<sequenceFlow
id=
"flow2"
sourceRef=
"processTask"
targetRef=
"callSubProcess"
/>
<callActivity
id=
"callSubProcess"
calledElement=
"subProcess"
/>
<sequenceFlow
id=
"flow3"
sourceRef=
"callSubProcess"
targetRef=
"theEnd"
/>
<endEvent
id=
"theEnd"
/>
</process>
<process
id=
"subProcess"
>
<startEvent
id=
"subProcessStart"
/>
<sequenceFlow
sourceRef=
"subProcessStart"
targetRef=
"anotherTask"
/>
<userTask
id=
"anotherTask"
name=
"Process task"
activiti:candidateUsers=
"kermit"
activiti:candidateGroups=
"sales"
/>
<sequenceFlow
sourceRef=
"anotherTask"
targetRef=
"subProcessEnd"
/>
<endEvent
id=
"subProcessEnd"
/>
</process>
</definitions>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录