Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发团队
Flowable Engine
提交
c71f6154
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,发现更多精彩内容 >>
提交
c71f6154
编写于
4月 02, 2013
作者:
F
Frederik Heremans
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added new deployment-resources REST
上级
174a75ab
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
629 addition
and
71 deletion
+629
-71
modules/activiti-common-rest/src/main/java/org/activiti/rest/api/SecuredResource.java
.../src/main/java/org/activiti/rest/api/SecuredResource.java
+32
-15
modules/activiti-rest/src/main/java/org/activiti/rest/api/RestUrls.java
...ti-rest/src/main/java/org/activiti/rest/api/RestUrls.java
+20
-3
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/DeploymentArtifactResource.java
.../activiti/rest/api/legacy/DeploymentArtifactResource.java
+2
-1
modules/activiti-rest/src/main/java/org/activiti/rest/api/legacy/DeploymentArtifactsResource.java
...activiti/rest/api/legacy/DeploymentArtifactsResource.java
+2
-1
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResource.java
.../org/activiti/rest/api/repository/DeploymentResource.java
+2
-2
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceCollectionResource.java
.../api/repository/DeploymentResourceCollectionResource.java
+62
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceDataResource.java
...i/rest/api/repository/DeploymentResourceDataResource.java
+77
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceResource.java
...iviti/rest/api/repository/DeploymentResourceResource.java
+64
-0
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceResponse.java
...iviti/rest/api/repository/DeploymentResourceResponse.java
+49
-0
modules/activiti-rest/src/main/java/org/activiti/rest/application/RestServicesInit.java
.../java/org/activiti/rest/application/RestServicesInit.java
+8
-2
modules/activiti-rest/src/test/java/org/activiti/rest/api/legacy/LegacyDeploymentResourseTest.java
...ctiviti/rest/api/legacy/LegacyDeploymentResourseTest.java
+89
-15
modules/activiti-rest/src/test/java/org/activiti/rest/api/repository/DeploymentCollectionResourceTest.java
...rest/api/repository/DeploymentCollectionResourceTest.java
+0
-32
modules/activiti-rest/src/test/java/org/activiti/rest/api/repository/DeploymentResourceResourceTest.java
...i/rest/api/repository/DeploymentResourceResourceTest.java
+135
-0
modules/activiti-rest/src/test/java/org/activiti/rest/api/repository/DeploymentResourcesResourceTest.java
.../rest/api/repository/DeploymentResourcesResourceTest.java
+87
-0
未找到文件。
modules/activiti-common-rest/src/main/java/org/activiti/rest/api/SecuredResource.java
浏览文件 @
c71f6154
...
...
@@ -13,6 +13,8 @@
package
org.activiti.rest.api
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.text.MessageFormat
;
import
java.util.HashMap
;
import
java.util.Iterator
;
...
...
@@ -37,6 +39,36 @@ public class SecuredResource extends ServerResource {
protected
String
loggedInUser
;
/**
* Create a full URL to a rest-resource.
*
* @param urlFragments fragments of the URL, relative to the base of the rest-application.
* @param arguments arguments to replace the placeholders in the urlFragments, using the {@link MessageFormat}
* conventions (eg. <code>{0}</code> is replaced by first argument value).
*/
public
String
createFullResourceUrl
(
String
[]
urlFragments
,
Object
...
arguments
)
{
Reference
url
=
getRequest
().
getRootRef
().
clone
();
for
(
String
urlFragment
:
urlFragments
)
{
url
.
addSegment
(
MessageFormat
.
format
(
urlFragment
,
arguments
));
}
return
url
.
toString
();
}
/**
* Get a request attribute value, decoded.
*/
protected
String
getAttribute
(
String
name
)
{
String
value
=
(
String
)
getRequest
().
getAttributes
().
get
(
name
);
if
(
value
!=
null
)
{
try
{
return
URLDecoder
.
decode
(
value
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
uee
)
{
throw
new
IllegalStateException
(
"JVM does not support UTF-8 encoding."
,
uee
);
}
}
return
null
;
}
protected
boolean
authenticate
()
{
return
authenticate
(
null
);
}
...
...
@@ -95,19 +127,4 @@ public class SecuredResource extends ServerResource {
}
return
variables
;
}
/**
* Create a full URL to a rest-resource.
*
* @param urlFragments fragments of the URL, relative to the base of the rest-application.
* @param arguments arguments to replace the placeholders in the urlFragments, using the {@link MessageFormat}
* conventions (eg. <code>{0}</code> is replaced by first argument value).
*/
public
String
createFullResourceUrl
(
String
[]
urlFragments
,
Object
...
arguments
)
{
Reference
url
=
getRequest
().
getRootRef
().
clone
();
for
(
String
urlFragment
:
urlFragments
)
{
url
.
addSegment
(
MessageFormat
.
format
(
urlFragment
,
arguments
));
}
return
url
.
toString
();
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/RestUrls.java
浏览文件 @
c71f6154
...
...
@@ -27,10 +27,9 @@ public final class RestUrls {
*/
public
static
final
String
SEGMENT_REPOSITORY_RESOURCES
=
"repository"
;
/**
* Segment for deployment resources: <i>deployment</i>
*/
public
static
final
String
SEGMENT_DEPLOYMENT_RESOURCE
=
"deployments"
;
public
static
final
String
SEGMENT_DEPLOYMENT_ARTIFACT_RESOURCE
=
"resources"
;
public
static
final
String
SEGMENT_DEPLOYMENT_ARTIFACT_RESOURCE_CONTENT
=
"resourcedata"
;
/**
* URL template for the deployment collection: <i>repository/deployments</i>
...
...
@@ -42,6 +41,24 @@ public final class RestUrls {
*/
public
static
final
String
[]
URL_DEPLOYMENT
=
{
SEGMENT_REPOSITORY_RESOURCES
,
SEGMENT_DEPLOYMENT_RESOURCE
,
"{0}"
};
/**
* URL template listing deployment resources: <i>repository/deployments/{0:deploymentId}/resources/{1}:resourceId</i>
*/
public
static
final
String
[]
URL_DEPLOYMENT_RESOURCES
=
{
SEGMENT_REPOSITORY_RESOURCES
,
SEGMENT_DEPLOYMENT_RESOURCE
,
"{0}"
,
SEGMENT_DEPLOYMENT_ARTIFACT_RESOURCE
};
/**
* URL template for a single deployment resource: <i>repository/deployments/{0:deploymentId}/resources/{1}:resourceId</i>
*/
public
static
final
String
[]
URL_DEPLOYMENT_RESOURCE
=
{
SEGMENT_REPOSITORY_RESOURCES
,
SEGMENT_DEPLOYMENT_RESOURCE
,
"{0}"
,
SEGMENT_DEPLOYMENT_ARTIFACT_RESOURCE
,
"{1}"
};
/**
* URL template for a single deployment resource content: <i>repository/deployments/{0:deploymentId}/resourcedata/{1}:resourceId</i>
*/
public
static
final
String
[]
URL_DEPLOYMENT_RESOURCE_CONTENT
=
{
SEGMENT_REPOSITORY_RESOURCES
,
SEGMENT_DEPLOYMENT_RESOURCE
,
"{0}"
,
SEGMENT_DEPLOYMENT_ARTIFACT_RESOURCE_CONTENT
,
"{1}"
};
/**
* Creates an url based on the passed fragments and replaces any placeholders with the given arguments. The
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/
repositor
y/DeploymentArtifactResource.java
→
modules/activiti-rest/src/main/java/org/activiti/rest/api/
legac
y/DeploymentArtifactResource.java
浏览文件 @
c71f6154
...
...
@@ -11,7 +11,7 @@
* limitations under the License.
*/
package
org.activiti.rest.api.
repositor
y
;
package
org.activiti.rest.api.
legac
y
;
import
java.io.InputStream
;
...
...
@@ -25,6 +25,7 @@ import org.restlet.resource.Get;
/**
* @author Tijs Rademakers
*/
@Deprecated
public
class
DeploymentArtifactResource
extends
SecuredResource
{
@Get
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/
repositor
y/DeploymentArtifactsResource.java
→
modules/activiti-rest/src/main/java/org/activiti/rest/api/
legac
y/DeploymentArtifactsResource.java
浏览文件 @
c71f6154
...
...
@@ -11,7 +11,7 @@
* limitations under the License.
*/
package
org.activiti.rest.api.
repositor
y
;
package
org.activiti.rest.api.
legac
y
;
import
java.util.List
;
...
...
@@ -28,6 +28,7 @@ import org.restlet.resource.Get;
/**
* @author Tijs Rademakers
*/
@Deprecated
public
class
DeploymentArtifactsResource
extends
SecuredResource
{
@Get
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResource.java
浏览文件 @
c71f6154
...
...
@@ -33,7 +33,7 @@ public class DeploymentResource extends SecuredResource {
public
DeploymentResponse
getDeployment
()
{
if
(
authenticate
()
==
false
)
return
null
;
String
deploymentId
=
(
String
)
getRequest
().
getAttributes
().
get
(
"deploymentId"
);
String
deploymentId
=
getAttribute
(
"deploymentId"
);
if
(
deploymentId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"The deploymentId cannot be null"
);
}
...
...
@@ -54,7 +54,7 @@ public class DeploymentResource extends SecuredResource {
public
void
deleteDeployment
()
{
if
(
authenticate
()
==
false
)
return
;
String
deploymentId
=
(
String
)
getRequest
().
getAttributes
().
get
(
"deploymentId"
);
String
deploymentId
=
getAttribute
(
"deploymentId"
);
Boolean
cascade
=
RequestUtil
.
getBoolean
(
getQuery
(),
"cascade"
,
false
);
if
(
cascade
)
{
...
...
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceCollectionResource.java
0 → 100644
浏览文件 @
c71f6154
/* 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.repository
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.activiti.engine.ActivitiIllegalArgumentException
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.repository.Deployment
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.RestUrls
;
import
org.activiti.rest.api.SecuredResource
;
import
org.restlet.resource.Get
;
/**
* @author Frederik Heremans
*/
public
class
DeploymentResourceCollectionResource
extends
SecuredResource
{
@Get
public
List
<
DeploymentResourceResponse
>
getDeploymentResources
()
{
if
(
authenticate
()
==
false
)
return
null
;
String
deploymentId
=
getAttribute
(
"deploymentId"
);
if
(
deploymentId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"No deployment id provided"
);
}
// Check if deployment exists
Deployment
deployment
=
ActivitiUtil
.
getRepositoryService
().
createDeploymentQuery
().
deploymentId
(
deploymentId
).
singleResult
();
if
(
deployment
==
null
)
{
throw
new
ActivitiObjectNotFoundException
(
"Could not find a deployment with id '"
+
deploymentId
+
"'."
,
Deployment
.
class
);
}
List
<
String
>
resourceList
=
ActivitiUtil
.
getRepositoryService
().
getDeploymentResourceNames
(
deploymentId
);
// Add additional metadata to the artifact-strings before returning
List
<
DeploymentResourceResponse
>
resposeList
=
new
ArrayList
<
DeploymentResourceResponse
>();
String
resourceUrl
=
null
;
String
resourceContentUrl
=
null
;
for
(
String
resource
:
resourceList
)
{
resourceUrl
=
createFullResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE
,
deploymentId
,
resource
);
resourceContentUrl
=
createFullResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE_CONTENT
,
deploymentId
,
resource
);
resposeList
.
add
(
new
DeploymentResourceResponse
(
resource
,
resourceUrl
,
resourceContentUrl
));
}
return
resposeList
;
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceDataResource.java
0 → 100644
浏览文件 @
c71f6154
/* 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.repository
;
import
java.io.InputStream
;
import
java.util.List
;
import
org.activiti.engine.ActivitiIllegalArgumentException
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.repository.Deployment
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.SecuredResource
;
import
org.restlet.data.MediaType
;
import
org.restlet.representation.InputRepresentation
;
import
org.restlet.resource.Get
;
/**
* @author Frederik Heremans
*/
public
class
DeploymentResourceDataResource
extends
SecuredResource
{
@Get
public
InputRepresentation
getDeploymentResource
()
{
if
(
authenticate
()
==
false
)
return
null
;
String
deploymentId
=
getAttribute
(
"deploymentId"
);
if
(
deploymentId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"No deployment id provided"
);
}
String
resourceId
=
getAttribute
(
"resourceId"
);
if
(
resourceId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"No resource id provided"
);
}
// Check if deployment exists
Deployment
deployment
=
ActivitiUtil
.
getRepositoryService
().
createDeploymentQuery
().
deploymentId
(
deploymentId
).
singleResult
();
if
(
deployment
==
null
)
{
throw
new
ActivitiObjectNotFoundException
(
"Could not find a deployment with id '"
+
deploymentId
+
"'."
,
Deployment
.
class
);
}
List
<
String
>
resourceList
=
ActivitiUtil
.
getRepositoryService
().
getDeploymentResourceNames
(
deploymentId
);
if
(
resourceList
.
contains
(
resourceId
))
{
final
InputStream
resourceStream
=
ActivitiUtil
.
getRepositoryService
().
getResourceAsStream
(
deploymentId
,
resourceId
);
// TODO: Externalize mime-type-mappings?
MediaType
mediaType
=
null
;
String
lowerResourceName
=
resourceId
.
toLowerCase
();
if
(
lowerResourceName
.
endsWith
(
"png"
))
{
mediaType
=
MediaType
.
IMAGE_PNG
;
}
else
if
(
lowerResourceName
.
endsWith
(
"xml"
)
||
lowerResourceName
.
endsWith
(
"bpmn"
))
{
mediaType
=
MediaType
.
TEXT_XML
;
}
else
{
mediaType
=
MediaType
.
APPLICATION_ALL
;
}
return
new
InputRepresentation
(
resourceStream
,
mediaType
);
}
else
{
// Resource not found in deployment
throw
new
ActivitiObjectNotFoundException
(
"Could not find a resource with id '"
+
resourceId
+
"' in deployment '"
+
deploymentId
+
"'."
,
String
.
class
);
}
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceResource.java
0 → 100644
浏览文件 @
c71f6154
/* 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.repository
;
import
java.util.List
;
import
org.activiti.engine.ActivitiIllegalArgumentException
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.repository.Deployment
;
import
org.activiti.rest.api.ActivitiUtil
;
import
org.activiti.rest.api.RestUrls
;
import
org.activiti.rest.api.SecuredResource
;
import
org.restlet.resource.Get
;
/**
* @author Frederik Heremans
*/
public
class
DeploymentResourceResource
extends
SecuredResource
{
@Get
public
DeploymentResourceResponse
getDeploymentResource
()
{
if
(
authenticate
()
==
false
)
return
null
;
String
deploymentId
=
getAttribute
(
"deploymentId"
);
if
(
deploymentId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"No deployment id provided"
);
}
String
resourceId
=
getAttribute
(
"resourceId"
);
if
(
resourceId
==
null
)
{
throw
new
ActivitiIllegalArgumentException
(
"No resource id provided"
);
}
// Check if deployment exists
Deployment
deployment
=
ActivitiUtil
.
getRepositoryService
().
createDeploymentQuery
().
deploymentId
(
deploymentId
).
singleResult
();
if
(
deployment
==
null
)
{
throw
new
ActivitiObjectNotFoundException
(
"Could not find a deployment with id '"
+
deploymentId
+
"'."
,
Deployment
.
class
);
}
List
<
String
>
resourceList
=
ActivitiUtil
.
getRepositoryService
().
getDeploymentResourceNames
(
deploymentId
);
if
(
resourceList
.
contains
(
resourceId
))
{
// Build resource representation
String
resourceUrl
=
createFullResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE
,
deploymentId
,
resourceId
);
String
resourceContentUrl
=
createFullResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE_CONTENT
,
deploymentId
,
resourceId
);
return
new
DeploymentResourceResponse
(
resourceId
,
resourceUrl
,
resourceContentUrl
);
}
else
{
// Resource not found in deployment
throw
new
ActivitiObjectNotFoundException
(
"Could not find a resource with id '"
+
resourceId
+
"' in deployment '"
+
deploymentId
+
"'."
,
String
.
class
);
}
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/api/repository/DeploymentResourceResponse.java
0 → 100644
浏览文件 @
c71f6154
package
org.activiti.rest.api.repository
;
/* 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.
*/
/**
* @author Frederik Heremans
*/
public
class
DeploymentResourceResponse
{
private
String
id
;
private
String
url
;
private
String
contentUrl
;
public
DeploymentResourceResponse
(
String
resourceId
,
String
url
,
String
contentUrl
)
{
setId
(
resourceId
);
setUrl
(
url
);
setContentUrl
(
contentUrl
);
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setContentUrl
(
String
contentUrl
)
{
this
.
contentUrl
=
contentUrl
;
}
public
String
getContentUrl
()
{
return
contentUrl
;
}
}
modules/activiti-rest/src/main/java/org/activiti/rest/application/RestServicesInit.java
浏览文件 @
c71f6154
...
...
@@ -13,6 +13,8 @@ import org.activiti.rest.api.identity.UserGroupsResource;
import
org.activiti.rest.api.identity.UserPictureResource
;
import
org.activiti.rest.api.identity.UserResource
;
import
org.activiti.rest.api.identity.UserSearchResource
;
import
org.activiti.rest.api.legacy.DeploymentArtifactResource
;
import
org.activiti.rest.api.legacy.DeploymentArtifactsResource
;
import
org.activiti.rest.api.legacy.DeploymentDeleteResource
;
import
org.activiti.rest.api.legacy.DeploymentUploadResource
;
import
org.activiti.rest.api.legacy.DeploymentsDeleteResource
;
...
...
@@ -35,10 +37,11 @@ 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.StartProcessInstanceResource
;
import
org.activiti.rest.api.repository.DeploymentArtifactResource
;
import
org.activiti.rest.api.repository.DeploymentArtifactsResource
;
import
org.activiti.rest.api.repository.DeploymentCollectionResource
;
import
org.activiti.rest.api.repository.DeploymentResource
;
import
org.activiti.rest.api.repository.DeploymentResourceCollectionResource
;
import
org.activiti.rest.api.repository.DeploymentResourceDataResource
;
import
org.activiti.rest.api.repository.DeploymentResourceResource
;
import
org.activiti.rest.api.repository.SimpleWorkflowResource
;
import
org.activiti.rest.api.task.TaskAddResource
;
import
org.activiti.rest.api.task.TaskAttachmentAddResource
;
...
...
@@ -60,6 +63,9 @@ public class RestServicesInit {
// New REST-urls
router
.
attach
(
"/repository/deployments"
,
DeploymentCollectionResource
.
class
);
router
.
attach
(
"/repository/deployments/{deploymentId}"
,
DeploymentResource
.
class
);
router
.
attach
(
"/repository/deployments/{deploymentId}/resources"
,
DeploymentResourceCollectionResource
.
class
);
router
.
attach
(
"/repository/deployments/{deploymentId}/resources/{resourceId}"
,
DeploymentResourceResource
.
class
);
router
.
attach
(
"/repository/deployments/{deploymentId}/resourcedata/{resourceId}"
,
DeploymentResourceDataResource
.
class
);
// Old rest-urls
router
.
attach
(
"/process-engine"
,
ProcessEngineResource
.
class
);
...
...
modules/activiti-rest/src/test/java/org/activiti/rest/api/legacy/LegacyDeploymentResourseTest.java
浏览文件 @
c71f6154
...
...
@@ -2,6 +2,8 @@ package org.activiti.rest.api.legacy;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
...
...
@@ -27,7 +29,9 @@ import org.restlet.resource.ResourceException;
* POST /deployment,
* DELETE /deployment/{deploymentId},
* GET /deployments,
* POST /deployments/delete
* POST /deployments/delete,
* GET /deployment/{deploymentId}/resources,
* GET /deployment/{deploymentId}/resources/{resourceName}
*
* @author Frederik Heremans
*/
...
...
@@ -275,24 +279,94 @@ public class LegacyDeploymentResourseTest extends BaseRestTestCase {
* Test deleting multiple deployments.
* POST deployments/delete
*/
public
void
testDeleteMultipleDeploymentsUnexisting
()
throws
Exception
{
public
void
testDeleteMultipleDeploymentsUnexisting
()
throws
Exception
{
try
{
ClientResource
client
=
getAuthenticatedClient
(
"deployments/delete"
);
ObjectNode
requestNode
=
objectMapper
.
createObjectNode
();
ArrayNode
deploymentIds
=
objectMapper
.
createArrayNode
();
deploymentIds
.
add
(
"unexisting"
);
requestNode
.
put
(
"deploymentIds"
,
deploymentIds
);
try
{
client
.
post
(
requestNode
);
fail
(
"Exception expected"
);
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
());
assertEquals
(
"Could not find a deployment with id 'unexisting'."
,
expected
.
getStatus
().
getDescription
());
}
}
finally
{
// Always cleanup any created deployments, even if the test failed
List
<
Deployment
>
deployments
=
repositoryService
.
createDeploymentQuery
().
list
();
for
(
Deployment
deployment
:
deployments
)
{
repositoryService
.
deleteDeployment
(
deployment
.
getId
(),
true
);
}
}
}
/**
* Test get all resources in a deployment.
* GET /deployment/{deploymentId}/resources
*/
public
void
testGetDeploymentResources
()
throws
Exception
{
try
{
Deployment
deployment
=
repositoryService
.
createDeployment
().
name
(
"Deployment 1"
)
.
addClasspathResource
(
"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
)
.
addInputStream
(
"test.png"
,
new
ByteArrayInputStream
(
"test-content"
.
getBytes
()))
.
deploy
();
ClientResource
client
=
getAuthenticatedClient
(
"deployment/"
+
deployment
.
getId
()
+
"/resources"
);
Representation
response
=
client
.
get
();
assertEquals
(
Status
.
SUCCESS_OK
,
client
.
getResponse
().
getStatus
());
JsonNode
resourcesNode
=
objectMapper
.
readTree
(
response
.
getStream
()).
get
(
"resources"
);
assertEquals
(
2L
,
resourcesNode
.
size
());
List
<
String
>
resources
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
resourcesNode
.
size
();
i
++)
{
resources
.
add
(
resourcesNode
.
get
(
i
).
getTextValue
());
}
assertTrue
(
resources
.
contains
(
"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
));
assertTrue
(
resources
.
contains
(
"test.png"
));
}
finally
{
// Always cleanup any created deployments, even if the test failed
List
<
Deployment
>
deployments
=
repositoryService
.
createDeploymentQuery
().
list
();
for
(
Deployment
deployment
:
deployments
)
{
repositoryService
.
deleteDeployment
(
deployment
.
getId
(),
true
);
}
}
}
/**
* Test get all resources in a deployment.
* GET /deployment/{deploymentId}/resources/{resourceName}
*/
public
void
testGetDeploymentResource
()
throws
Exception
{
try
{
ClientResource
client
=
getAuthenticatedClient
(
"deployments/delete"
);
Deployment
deployment
=
repositoryService
.
createDeployment
().
name
(
"Deployment 1"
)
.
addClasspathResource
(
"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
)
.
addInputStream
(
"test.png"
,
new
ByteArrayInputStream
(
"test-content"
.
getBytes
()))
.
deploy
();
ObjectNode
requestNode
=
objectMapper
.
createObjectNode
();
ArrayNode
deploymentIds
=
objectMapper
.
createArrayNode
();
deploymentIds
.
add
(
"unexisting"
);
requestNode
.
put
(
"deploymentIds"
,
deploymentIds
);
ClientResource
client
=
getAuthenticatedClient
(
"deployment/"
+
deployment
.
getId
()
+
"/resource/org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
);
try
{
client
.
post
(
requestNode
);
fail
(
"Exception expected"
);
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
()
);
assertEquals
(
"Could not find a deployment with id 'unexisting'."
,
expected
.
getStatus
().
getDescription
()
);
}
Representation
response
=
client
.
get
();
assertEquals
(
Status
.
SUCCESS_OK
,
client
.
getResponse
().
getStatus
()
);
// Read returned and original content
ByteArrayOutputStream
responseContent
=
new
ByteArrayOutputStream
();
IOUtils
.
copy
(
response
.
getStream
(),
responseContent
);
ByteArrayOutputStream
requestContent
=
new
ByteArrayOutputStream
(
);
IOUtils
.
copy
(
ReflectUtil
.
getResourceAsStream
(
"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
),
requestContent
);
// Compare response with content that is deployed
assertTrue
(
"Returned content doesn't match deployed content"
,
Arrays
.
equals
(
requestContent
.
toByteArray
(),
responseContent
.
toByteArray
()));
}
finally
{
// Always cleanup any created deployments, even if the test failed
...
...
modules/activiti-rest/src/test/java/org/activiti/rest/api/repository/DeploymentCollectionResourceTest.java
浏览文件 @
c71f6154
...
...
@@ -125,36 +125,4 @@ public class DeploymentCollectionResourceTest extends BaseRestTestCase {
}
}
}
// /**
// * Test deleting deployments.
// * DELETE repository/deployments
// */
// public void testDeleteDeployment() throws Exception {
//
// try {
// repositoryService.createDeployment().name("Deployment 1")
// .addClasspathResource("org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml")
// .deploy();
// repositoryService.createDeployment().name("Deployment 2")
// .addClasspathResource("org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml")
// .deploy();
//
// assertEquals(2L, repositoryService.createDeploymentQuery().count());
//
// ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION));
// client.delete();
//
// assertEquals(Status.SUCCESS_NO_CONTENT, client.getResponse().getStatus());
// assertEquals(0L, repositoryService.createDeploymentQuery().count());
//
// } finally {
// // Always cleanup any created deployments, even if the test failed
// List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
// for(Deployment deployment : deployments) {
// repositoryService.deleteDeployment(deployment.getId(), true);
// }
// }
// }
}
modules/activiti-rest/src/test/java/org/activiti/rest/api/repository/DeploymentResourceResourceTest.java
0 → 100644
浏览文件 @
c71f6154
package
org.activiti.rest.api.repository
;
import
java.io.ByteArrayInputStream
;
import
java.util.List
;
import
org.activiti.engine.repository.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 resources that is part of a deployment.
*
* @author Frederik Heremans
*/
public
class
DeploymentResourceResourceTest
extends
BaseRestTestCase
{
/**
* Test getting a single resource, deployed in a deployment.
* GET repository/deployments/{deploymentId}/resources/{resourceId}
*/
public
void
testGetDeploymentResource
()
throws
Exception
{
try
{
String
rawResourceName
=
"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
;
Deployment
deployment
=
repositoryService
.
createDeployment
().
name
(
"Deployment 1"
)
.
addClasspathResource
(
rawResourceName
)
.
addInputStream
(
"test.txt"
,
new
ByteArrayInputStream
(
"Test content"
.
getBytes
()))
.
deploy
();
// Build up the URL manually to make sure resource-id gets encoded correctly as one piece
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCES
,
deployment
.
getId
()));
client
.
getReference
().
addSegment
(
rawResourceName
);
Representation
response
=
client
.
get
();
// Id contains slashes so it will be encoded by the client
String
encodedResourceId
=
client
.
getReference
().
getLastSegment
(
false
);
// Check "OK" status
assertEquals
(
Status
.
SUCCESS_OK
,
client
.
getResponse
().
getStatus
());
JsonNode
responseNode
=
objectMapper
.
readTree
(
response
.
getStream
());
// Check URL's for the resource
assertTrue
(
responseNode
.
get
(
"url"
).
getTextValue
().
endsWith
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE
,
deployment
.
getId
(),
encodedResourceId
)));
assertTrue
(
responseNode
.
get
(
"contentUrl"
).
getTextValue
().
endsWith
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE_CONTENT
,
deployment
.
getId
(),
encodedResourceId
)));
}
finally
{
// Always cleanup any created deployments, even if the test failed
List
<
Deployment
>
deployments
=
repositoryService
.
createDeploymentQuery
().
list
();
for
(
Deployment
deployment
:
deployments
)
{
repositoryService
.
deleteDeployment
(
deployment
.
getId
(),
true
);
}
}
}
/**
* Test getting a single resource for an unexisting deployment.
* GET repository/deployments/{deploymentId}/resources/{resourceId}
*/
public
void
testGetDeploymentResourceUnexistingDeployment
()
throws
Exception
{
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE
,
"unexisting"
,
"resource.png"
));
try
{
client
.
get
();
fail
(
"Expected 404 status, but was: "
+
client
.
getStatus
());
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
());
assertEquals
(
"Could not find a deployment with id 'unexisting'."
,
expected
.
getStatus
().
getDescription
());
}
}
/**
* Test getting an unexisting resource for an existing deployment.
* GET repository/deployments/{deploymentId}/resources/{resourceId}
*/
public
void
testGetDeploymentResourceUnexistingResource
()
throws
Exception
{
try
{
Deployment
deployment
=
repositoryService
.
createDeployment
().
name
(
"Deployment 1"
)
.
addInputStream
(
"test.txt"
,
new
ByteArrayInputStream
(
"Test content"
.
getBytes
()))
.
deploy
();
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE
,
deployment
.
getId
(),
"unexisting-resource.png"
));
try
{
client
.
get
();
fail
(
"Expected 404 status, but was: "
+
client
.
getStatus
());
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
());
assertEquals
(
"Could not find a resource with id 'unexisting-resource.png' in deployment '"
+
deployment
.
getId
()
+
"'."
,
expected
.
getStatus
().
getDescription
());
}
}
finally
{
// Always cleanup any created deployments, even if the test failed
List
<
Deployment
>
deployments
=
repositoryService
.
createDeploymentQuery
().
list
();
for
(
Deployment
deployment
:
deployments
)
{
repositoryService
.
deleteDeployment
(
deployment
.
getId
(),
true
);
}
}
}
/**
* Test getting a deployment resource content.
* GET repository/deployments/{deploymentId}/resources/{resourceId}
*/
public
void
testGetDeploymentResourceContent
()
throws
Exception
{
try
{
Deployment
deployment
=
repositoryService
.
createDeployment
().
name
(
"Deployment 1"
)
.
addInputStream
(
"test.txt"
,
new
ByteArrayInputStream
(
"Test content"
.
getBytes
()))
.
deploy
();
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE_CONTENT
,
deployment
.
getId
(),
"test.txt"
));
client
.
get
();
String
responseAsString
=
client
.
getResponse
().
getEntityAsText
();
assertNotNull
(
responseAsString
);
assertEquals
(
"Test content"
,
responseAsString
);
}
finally
{
// Always cleanup any created deployments, even if the test failed
List
<
Deployment
>
deployments
=
repositoryService
.
createDeploymentQuery
().
list
();
for
(
Deployment
deployment
:
deployments
)
{
repositoryService
.
deleteDeployment
(
deployment
.
getId
(),
true
);
}
}
}
}
modules/activiti-rest/src/test/java/org/activiti/rest/api/repository/DeploymentResourcesResourceTest.java
0 → 100644
浏览文件 @
c71f6154
package
org.activiti.rest.api.repository
;
import
java.io.ByteArrayInputStream
;
import
java.util.List
;
import
org.activiti.engine.repository.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 listing the resources that are part of a deployment.
*
* @author Frederik Heremans
*/
public
class
DeploymentResourcesResourceTest
extends
BaseRestTestCase
{
/**
* Test getting all resources for a single deployment.
* GET repository/deployments/{deploymentId}/resources
*/
public
void
testGetDeploymentResources
()
throws
Exception
{
try
{
Deployment
deployment
=
repositoryService
.
createDeployment
().
name
(
"Deployment 1"
)
.
addClasspathResource
(
"org/activiti/rest/api/repository/oneTaskProcess.bpmn20.xml"
)
.
addInputStream
(
"test.txt"
,
new
ByteArrayInputStream
(
"Test content"
.
getBytes
()))
.
deploy
();
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCES
,
deployment
.
getId
()));
Representation
response
=
client
.
get
();
// Check "OK" status
assertEquals
(
Status
.
SUCCESS_OK
,
client
.
getResponse
().
getStatus
());
JsonNode
responseNode
=
objectMapper
.
readTree
(
response
.
getStream
());
assertTrue
(
responseNode
.
isArray
());
assertEquals
(
2
,
responseNode
.
size
());
// Since resources can be returned in any arbitrary order, find the right one to check
JsonNode
txtNode
=
null
;
for
(
int
i
=
0
;
i
<
responseNode
.
size
();
i
++)
{
if
(
"test.txt"
.
equals
(
responseNode
.
get
(
i
).
get
(
"id"
).
getTextValue
()))
{
txtNode
=
responseNode
.
get
(
i
);
break
;
}
}
// Check URL's for the resource
assertNotNull
(
txtNode
);
assertTrue
(
txtNode
.
get
(
"url"
).
getTextValue
().
endsWith
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE
,
deployment
.
getId
(),
"test.txt"
)));
assertTrue
(
txtNode
.
get
(
"contentUrl"
).
getTextValue
().
endsWith
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCE_CONTENT
,
deployment
.
getId
(),
"test.txt"
)));
}
finally
{
// Always cleanup any created deployments, even if the test failed
List
<
Deployment
>
deployments
=
repositoryService
.
createDeploymentQuery
().
list
();
for
(
Deployment
deployment
:
deployments
)
{
repositoryService
.
deleteDeployment
(
deployment
.
getId
(),
true
);
}
}
}
/**
* Test getting all resources for a single unexisting deployment.
* GET repository/deployments/{deploymentId}/resources
*/
public
void
testGetDeploymentResourcesUnexistingDeployment
()
throws
Exception
{
ClientResource
client
=
getAuthenticatedClient
(
RestUrls
.
createRelativeResourceUrl
(
RestUrls
.
URL_DEPLOYMENT_RESOURCES
,
"unexisting"
));
try
{
client
.
get
();
fail
(
"Expected 404 status, but was: "
+
client
.
getStatus
());
}
catch
(
ResourceException
expected
)
{
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
expected
.
getStatus
());
assertEquals
(
"Could not find a deployment with id 'unexisting'."
,
expected
.
getStatus
().
getDescription
());
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录