提交 1d1c29cf 编写于 作者: E erikwinlof
上级 3f711470
/* 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.Map;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* Returns a list of deployments
*
* @author Erik Winlof
*/
public class DeploymentDelete extends ActivitiWebScript {
/**
* Deletes the deployment.
*
* @param req The webscripts request
* @param status The webscripts status
* @param cache The webscript cache
* @param model The webscripts template model
*/
@Override
protected void executeWebScript(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
String deploymentId = req.getMandatoryPathParameter("deploymentId");
Boolean cascade = req.getBoolean("cascade", false);
if (cascade) {
getRepositoryService().deleteDeployment(deploymentId);
}
else {
getRepositoryService().deleteDeploymentCascade(deploymentId);
}
}
}
/* 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 org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiStreamingWebScript;
import org.springframework.extensions.webscripts.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
public class DeploymentResourceGet extends ActivitiStreamingWebScript {
/**
* Prepares details about the process engine for the webscript template.
*
* @param req The activiti webscript request
* @param res The webscript response
*/
@Override
protected void executeStreamingWebScript(ActivitiRequest req, WebScriptResponse res) {
String deploymentId = req.getMandatoryPathParameter("deploymentId"),
resourceName = req.getMandatoryPathParameter("resourceName");
InputStream resource = getRepositoryService().getResourceAsStream(deploymentId, resourceName);
if (resource != null) {
try {
streamResponse(res, resource, new Date(0), null, true, resourceName, getMimeType(resource));
} catch (IOException e) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "The resource with name '" + resourceName + "' for deployment with id '" + deploymentId + "' could not be streamed: " + e.getMessage());
}
}
else {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "There is no resource with name '" + resourceName + "' for deployment with id '" + deploymentId + "'.");
}
}
}
\ No newline at end of file
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.rest.api.repository;
import java.util.Map;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.engine.repository.DeploymentQueryProperty;
import org.activiti.rest.util.ActivitiPagingWebScript;
import org.activiti.rest.util.ActivitiRequest;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* Returns a list of deployments
*
* @author Erik Winlof
*/
public class DeploymentsGet extends ActivitiPagingWebScript
{
public DeploymentsGet() {
properties.put("id", DeploymentQueryProperty.DEPLOYMENT_ID);
properties.put("name", DeploymentQueryProperty.NAME);
properties.put("deploymentTime", DeploymentQueryProperty.DEPLOY_TIME);
}
/**
* Prepares deployment info for the webscript template.
*
* @param req The webscripts request
* @param status The webscripts status
* @param cache The webscript cache
* @param model The webscripts template model
*/
@Override
protected void executeWebScript(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
DeploymentQuery deploymentQuery = getRepositoryService().createDeploymentQuery();
paginateList(req, deploymentQuery, "deployments", model, "id");
}
}
......@@ -57,7 +57,7 @@ public class ActivitiPagingWebScript extends ActivitiWebScript
{
QueryProperty qp = properties.get(sort);
if (qp == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param 'sort' is not a valid, '" + sort + "'is not a valid property");
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param 'sort' is not a valid, '" + sort + "' is not a valid property");
}
query.orderBy(qp);
if (order.equals("asc"))
......
<webscript>
<shortname>Deployment Resource</shortname>
<description>Returns a deployment resource</description>
<url>/deployment/{deploymentId}/resource/{resourceName}</url>
<authentication>user</authentication>
<format default="">argument</format>
</webscript>
<webscript>
<shortname>Delete Deployment</shortname>
<description>Deletes a deployment</description>
<url>/deployment/{deploymentId}?cascade={boolean}</url>
<authentication>user</authentication>
<format default="json">argument</format>
</webscript>
<webscript>
<shortname>Deployments</shortname>
<description>Returns a list of deployments</description>
<url>/deployments</url>
<authentication>user</authentication>
<format default="json">argument</format>
</webscript>
<#import "../activiti.lib.ftl" as activitiLib>
<#import "repository.lib.ftl" as deploymentLib>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"data": <@deploymentLib.printDeploymentList deployments/>,
<@activitiLib.printPagination/>
}
</#escape>
<#macro printDeploymentList deploymentList>
[
<#list deployments as deployment>
{
<@printDeployment deployment/>
}<#if deployment_has_next>,</#if>
</#list>
]
</#macro>
<#macro printDeployment deployment>
"id": "${deployment.id?js_string}",
"name": "${deployment.name?js_string}",
"deploymentTime": <#if deployment.deploymentTime??>"${iso8601Date(deployment.deploymentTime)}"<#else>null</#if>
</#macro>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册