提交 33883942 编写于 作者: E erikwinlof

Support for multi-operations, REST API doc updates & switch to Spring Surf RC2

- Multiple jobs may now be executed: ACT-138 
- Multiple deployments may now be deleted: ACT-139
- Now using Spring Surf RC2
- Refactored the ActivitiWebScriptBody to ActivitiBodyObject  
- REST API Chapter updated
上级 c35e987d
......@@ -71,7 +71,7 @@
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-surf</artifactId>
<version>1.0.0.M3</version>
<version>1.0.0-RC2</version>
</dependency>
</dependencies>
......
......@@ -19,6 +19,7 @@ import javax.servlet.http.HttpSession;
import org.activiti.cycle.CycleService;
import org.activiti.cycle.impl.CycleServiceImpl;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
......@@ -46,9 +47,7 @@ public class ActionExecutionPut extends ActivitiWebScript {
String artifactId = req.getMandatoryString("artifactId");
String actionId = req.getMandatoryString("actionName");
ActivitiRequest.ActivitiWebScriptBody body = req.getBody();
Map<String, Object> parameters = req.getFormVariables(body);
Map<String, Object> parameters = req.getFormVariables();
try {
this.cycleService.executeParameterizedAction(connectorId, artifactId, actionId, parameters);
model.put("result", true);
......
......@@ -22,6 +22,7 @@ import org.activiti.cycle.RepositoryArtifactLink;
import org.activiti.cycle.impl.CycleServiceImpl;
import org.activiti.cycle.impl.RepositoryArtifactLinkImpl;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
......@@ -45,10 +46,10 @@ public class ArtifactLinkPost extends ActivitiWebScript {
protected void executeWebScript(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
init(req);
ActivitiRequest.ActivitiWebScriptBody body = req.getBody();
ActivitiRequestObject obj = req.getBody();
String srcConnectorId = req.getMandatoryString(body, "connectorId");
String srcArtifactId = req.getMandatoryString(body, "artifactId");
String srcConnectorId = req.getMandatoryString(obj, "connectorId");
String srcArtifactId = req.getMandatoryString(obj, "artifactId");
// String srcElementName = req.getMandatoryString("sourceElementName");
// String srcElementId = req.getMandatoryString("sourceElementId");
......@@ -56,8 +57,8 @@ public class ArtifactLinkPost extends ActivitiWebScript {
// String tgtElementName = req.getMandatoryString("targetElementName");
// String tgtElementId = req.getMandatoryString("targetElementId");
String tgtConnectorId = req.getMandatoryString(body, "targetConnectorId");
String tgtArtifactId = req.getMandatoryString(body, "targetArtifactId");
String tgtConnectorId = req.getMandatoryString(obj, "targetConnectorId");
String tgtArtifactId = req.getMandatoryString(obj, "targetArtifactId");
RepositoryArtifact srcArtifact = cycleService.getRepositoryArtifact(srcConnectorId, srcArtifactId);
RepositoryArtifact tgtArtifact = cycleService.getRepositoryArtifact(tgtConnectorId, tgtArtifactId);
......
......@@ -21,7 +21,7 @@ import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Returns signalData, metadata and paging info about a table.
* Executes a job
*
* @author Erik Winlof
*/
......
/* 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.management;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import java.util.List;
import java.util.Map;
/**
* Executes multiple job
*
* @author Erik Winlof
*/
public class JobsExecutePost extends ActivitiWebScript {
/**
* Deletes deployments.
*
* @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) {
ActivitiRequestObject obj = req.getBody();
List deploymentIds = req.getMandatoryList(obj, "jobIds", ActivitiRequestObject.STRING);
for (Object jobId : deploymentIds) {
getManagementService().executeJob((String) jobId);
}
}
}
......@@ -13,10 +13,10 @@
package org.activiti.rest.api.process;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import java.util.Map;
......@@ -38,9 +38,9 @@ public class ProcessInstancePost extends ActivitiWebScript {
*/
@Override
protected void executeWebScript(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
ActivitiRequest.ActivitiWebScriptBody body = req.getBody();
String processDefinitionId = req.getMandatoryString(body, "processDefinitionId");
Map<String, Object> variables = req.getFormVariables(body);
ActivitiRequestObject obj = req.getBody();
String processDefinitionId = req.getMandatoryString(obj, "processDefinitionId");
Map<String, Object> variables = req.getFormVariables();
variables.remove("processDefinitionId");
model.put("instance", getRuntimeService().startProcessInstanceById(processDefinitionId, variables));
}
......
......@@ -21,7 +21,7 @@ import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* Returns a list of deployments
* Deletes a single deployment
*
* @author Erik Winlof
*/
......@@ -40,10 +40,10 @@ public class DeploymentDelete extends ActivitiWebScript {
String deploymentId = req.getMandatoryPathParameter("deploymentId");
Boolean cascade = req.getBoolean("cascade", false);
if (cascade) {
getRepositoryService().deleteDeployment(deploymentId);
getRepositoryService().deleteDeploymentCascade(deploymentId);
}
else {
getRepositoryService().deleteDeploymentCascade(deploymentId);
getRepositoryService().deleteDeployment(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 java.util.List;
import java.util.Map;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
/**
* Deletes a list of deployments.
*
* @author Erik Winlof
*/
public class DeploymentsDeletePost extends ActivitiWebScript {
/**
* Deletes deployments.
*
* @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) {
Boolean cascade = req.getBoolean("cascade", false);
ActivitiRequestObject obj = req.getBody();
List deploymentIds = req.getMandatoryList(obj, "deploymentIds", ActivitiRequestObject.STRING);
for (Object deploymentId : deploymentIds) {
if (cascade) {
getRepositoryService().deleteDeploymentCascade((String) deploymentId);
}
else {
getRepositoryService().deleteDeployment((String) deploymentId);
}
}
}
}
......@@ -13,6 +13,7 @@
package org.activiti.rest.api.task;
import org.activiti.rest.util.ActivitiRequest;
import org.activiti.rest.util.ActivitiRequestObject;
import org.activiti.rest.util.ActivitiWebScript;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
......@@ -39,8 +40,7 @@ public class TaskOperationPut extends ActivitiWebScript {
protected void executeWebScript(ActivitiRequest req, Status status, Cache cache, Map<String, Object> model) {
String taskId = req.getMandatoryPathParameter("taskId");
String operation = req.getMandatoryPathParameter("operation");
ActivitiRequest.ActivitiWebScriptBody body = req.getBody();
Map<String, Object> variables = req.getFormVariables(body);
Map<String, Object> variables = req.getFormVariables();
String currentUserId = req.getCurrentUserId();
if ("start".equals(operation)) {
throw new WebScriptException(Status.STATUS_NOT_IMPLEMENTED, "Not implemented in this version");
......
......@@ -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 valid, '" + sort + "' is not a valid property");
}
query.orderBy(qp);
if (order.equals("asc"))
......@@ -69,7 +69,7 @@ public class ActivitiPagingWebScript extends ActivitiWebScript
query.desc();
}
else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param 'order' is not a valid : '" + order + "', must be 'asc' or 'desc'");
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param 'order' is not valid : '" + order + "', must be 'asc' or 'desc'");
}
}
......
......@@ -12,7 +12,6 @@
*/
package org.activiti.rest.util;
import org.activiti.engine.impl.util.json.JSONObject;
import org.springframework.extensions.surf.util.Base64;
import org.springframework.extensions.surf.util.ISO8601DateFormat;
import org.springframework.extensions.webscripts.Status;
......@@ -23,10 +22,7 @@ import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
/**
* Helper class that wrapps the webscript request to perform methods upon it.
......@@ -103,16 +99,16 @@ public class ActivitiRequest {
}
/**
* Returns the webscript request body in an abstracted form so multiple
* Returns the webscript request obj in an abstracted form so multiple
* formats may be implemented seamlessly in the future.
*
* @return The webscript requests body
* @return The webscript requests obj
*/
public ActivitiWebScriptBody getBody() {
public ActivitiRequestObject getBody() {
try {
return new ActivitiWebScriptBody(req);
return new JSONRequestObject(req);
} catch (IOException e) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Can't read body");
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Can't read obj");
}
}
......@@ -280,26 +276,63 @@ public class ActivitiRequest {
}
/**
* Gets a string parameter from the body
* Gets a string parameter from the obj
*
* @param body The activiti webscript request body
* @param obj The activiti webscript request obj
* @param param The name of the string parameter
* @return The value of the string body parameter
* @throws WebScriptException if string body parameter isn't present
* @return The value of the string obj parameter
* @throws WebScriptException if string obj parameter isn't present
*/
public String getMandatoryString(ActivitiWebScriptBody body, String param) {
return checkString(body.getString(param), param, true);
public String getMandatoryString(ActivitiRequestObject obj, String param) {
return checkString(obj.getString(param), param, true);
}
/**
* Gets a string parameter from the obj
*
* @param obj The activiti webscript request obj
* @param param The name of the string parameter
* @return The value of the string obj parameter
* @throws WebScriptException if string obj parameter isn't present
*/
public List getMandatoryList(ActivitiRequestObject obj, String param, String type) {
List list = (List) checkObject(obj.getList(param), param, true);
for (Object item : list) {
if (item == null) {
throw getInvalidTypeException(param, null, ActivitiRequestObject.ARRAY);
}
if (type != null) {
if (item instanceof String && !type.equals(ActivitiRequestObject.STRING)) {
throw getInvalidTypeException(param, item.toString(), ActivitiRequestObject.STRING + " array");
}
if (item instanceof Date && !type.equals(ActivitiRequestObject.DATE)) {
throw getInvalidTypeException(param, item.toString(), ActivitiRequestObject.DATE + " array");
}
if (item instanceof Integer && !type.equals(ActivitiRequestObject.INTEGER)) {
throw getInvalidTypeException(param, item.toString(), ActivitiRequestObject.INTEGER + " array");
}
if (item instanceof Boolean && !type.equals(ActivitiRequestObject.BOOLEAN)) {
throw getInvalidTypeException(param, item.toString(), ActivitiRequestObject.BOOLEAN + " array");
}
if (item instanceof ActivitiRequestObject && !type.equals(ActivitiRequestObject.OBJECT)) {
throw getInvalidTypeException(param, item.toString(), ActivitiRequestObject.OBJECT + " array");
}
if (item instanceof List && !type.equals(ActivitiRequestObject.ARRAY)) {
throw getInvalidTypeException(param, item.toString(), ActivitiRequestObject.ARRAY + " array");
}
}
}
return list;
}
/**
* Gets a parameter as Map
*
* @param body The activiti webscript request body
* @return The value of the string body parameter
* @throws WebScriptException if string body parameter isn't present
* @return The value of the string obj parameter
* @throws WebScriptException if string obj parameter isn't present
*/
public Map<String, Object> getFormVariables(ActivitiWebScriptBody body) {
return body.getFormVariables();
public Map<String, Object> getFormVariables() {
return getBody().getFormVariables();
}
/**
......@@ -347,13 +380,13 @@ public class ActivitiRequest {
* @param param The name of the parameter
* @return A date based on the value parameter
*/
private Date parseDate(String value, String param)
public static Date parseDate(String value, String param)
{
try {
return ISO8601DateFormat.parse(value.replaceAll(" ", "+"));
}
catch (NumberFormatException nfe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param '" + param + "' is not a valid iso8601 date value: '" + value + "'");
throw getInvalidTypeException(param, value, "iso8601 date");
}
}
......@@ -364,13 +397,13 @@ public class ActivitiRequest {
* @param param The name of the parameter
* @return An integer based on the value parameter
*/
private Integer parseInt(String value, String param)
public static Integer parseInt(String value, String param)
{
try {
return Integer.parseInt(value);
}
catch (NumberFormatException nfe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param '" + param + "' is not a valid int value: '" + value + "'");
throw getInvalidTypeException(param, value, "integer");
}
}
......@@ -381,100 +414,16 @@ public class ActivitiRequest {
* @param param The name of the parameter
* @return A boolean based on the value parameter
*/
private Boolean parseBoolean(String value, String param)
public static Boolean parseBoolean(String value, String param)
{
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
return Boolean.parseBoolean(value);
}
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param '" + param + "' is not a valid bool value: '" + value + "'");
throw getInvalidTypeException(param, value, "bool");
}
/**
* A class that wraps the webscripts request body so multiple formats such as
* XML may be supported in the future.
*/
public class ActivitiWebScriptBody {
/**
* The json body
*/
private JSONObject jsonBody = null;
/**
* Constructor
*
* @param req The webscript request
* @throws IOException if body of correct format cannot be created
*/
ActivitiWebScriptBody(WebScriptRequest req) throws IOException {
jsonBody = new JSONObject(req.getContent().getContent());
}
/**
* Gets a body parameter string value.
*
* @param param The name of the parameter
* @return The string value of the parameter
*/
String getString(String param) {
return jsonBody.getString(param);
}
/**
* Gets a body parameter string value.
*
* @param param The name of the parameter
* @return The string value of the parameter
*/
int getInt(String param) {
return jsonBody.getInt(param);
}
/**
* Gets the body as a map.
*
* @return The body as a map
*/
Map<String, Object> getFormVariables() {
Map<String, Object> map = new HashMap<String, Object>();
Iterator keys = jsonBody.keys();
String key, typeKey, type;
String[] keyPair;
Object value;
while (keys.hasNext()) {
key = (String) keys.next();
keyPair = key.split("_");
if (keyPair.length == 1) {
typeKey = keyPair[0] + "_type";
if (jsonBody.has(typeKey)) {
type = jsonBody.getString(typeKey);
if (type.equals("Integer")) {
value = jsonBody.getInt(key);
} else if (type.equals("Boolean")) {
value = jsonBody.getBoolean(key);
} else if (type.equals("Date")) {
value = jsonBody.getString(key);
} else if (type.equals("User")) {
value = jsonBody.getString(key);
} else if (type.equals("String")) {
value = jsonBody.getString(key);
} else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter '" + keyPair[0] + "' is of unknown type '" + type + "'");
}
} else {
value = jsonBody.get(key);
}
map.put(key, value);
} else if (keyPair.length == 2) {
if (keyPair[1].equals("required")) {
if (!jsonBody.has(keyPair[0]) || jsonBody.get(keyPair[0]) == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter '" + keyPair[0] + "' has no value");
}
}
}
}
return map;
}
public static WebScriptException getInvalidTypeException(String param, String value, String type) {
return new WebScriptException(Status.STATUS_BAD_REQUEST, "Value for param '" + param + "' is not a valid " + type + " value: '" + value + "'");
}
}
/* 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.util;
import java.util.List;
import java.util.Map;
/**
* Interface for hiding json or xml parsing of request body
*
* @author Erik Winlof
*/
public interface ActivitiRequestObject {
public static final String STRING = "string";
public static final String INTEGER = "integer";
public static final String BOOLEAN = "boolean";
public static final String DATE = "iso8601 date";
public static final String OBJECT = "object";
public static final String ARRAY = "array";
public String getString(String param);
public Integer getInt(String param);
public Boolean getBoolean(String param);
public ActivitiRequestObject getBodyObject(String param);
public List getList(String param);
public Map<String, Object> getFormVariables();
}
/* 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.util;
import org.activiti.engine.impl.util.json.JSONArray;
import org.activiti.engine.impl.util.json.JSONObject;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import java.io.IOException;
import java.util.*;
public class JSONRequestObject implements ActivitiRequestObject {
/**
* The json json
*/
private JSONObject json = null;
/**
* Constructor
*
* @param req The webscript request
* @throws java.io.IOException if json of correct format cannot be created
*/
JSONRequestObject(WebScriptRequest req) throws IOException {
json = new JSONObject(req.getContent().getContent());
}
/**
* Constructor
*
* @param jsonObject The webscript request
*/
JSONRequestObject(JSONObject jsonObject){
json = jsonObject;
}
/**
* Gets a json parameter string value.
*
* @param param The name of the parameter
* @return The string value of the parameter
*/
public String getString(String param) {
Object value = json.get(param);
if (value == null) {
return null;
}
if(value instanceof String) {
return json.getString(param);
}
throw ActivitiRequest.getInvalidTypeException(param, value.toString(), STRING);
}
/**
* Gets a json parameter string value.
*
* @param param The name of the parameter
* @return The string value of the parameter
*/
public Integer getInt(String param) {
Object value = json.get(param);
if (value == null) {
return null;
}
if(value instanceof String) {
return json.getInt(param);
}
throw ActivitiRequest.getInvalidTypeException(param, value.toString(), INTEGER);
}
/**
* Gets a json parameter boolean value.
*
* @param param The name of the parameter
* @return The boolean value of the parameter
*/
public Boolean getBoolean(String param) {
Object value = json.get(param);
if (value == null) {
return null;
}
if(value instanceof Boolean) {
return json.getBoolean(param);
}
throw ActivitiRequest.getInvalidTypeException(param, value.toString(), BOOLEAN);
}
/**
* Gets a json parameter boolean value.
*
* @param param The name of the parameter
* @return The boolean value of the parameter
*/
public Date getDate(String param) {
Object value = json.get(param);
if (value == null) {
return null;
}
if(value instanceof String) {
return ActivitiRequest.parseDate(json.getString(param), param);
}
throw ActivitiRequest.getInvalidTypeException(param, value.toString(), DATE);
}
/**
* Gets a json parameter string value.
*
* @param param The name of the parameter
* @return The string value of the parameter
*/
public JSONRequestObject getBodyObject(String param) {
Object value = json.get(param);
if (value == null) {
return null;
}
if(value instanceof JSONObject) {
return new JSONRequestObject(json.getJSONObject(param));
}
throw ActivitiRequest.getInvalidTypeException(param, value.toString(), OBJECT);
}
/**
* Gets a json parameter string value.
*
* @param param The name of the parameter
* @return The string value of the parameter
*/
public List getList(String param) {
Object value = json.get(param);
if (value == null) {
return null;
}
if(value instanceof JSONArray) {
return toList(json.getJSONArray(param));
}
throw ActivitiRequest.getInvalidTypeException(param, value.toString(), ARRAY);
}
/**
* Converts a JSONArray to a List
*
* @param jsonArray
* @return
*/
private List toList(JSONArray jsonArray) {
List list = new ArrayList();
Object obj;
for (int i = 0; i < jsonArray.length(); i++) {
obj = jsonArray.get(i);
if (obj instanceof JSONArray) {
list.add(toList((JSONArray) obj));
}
if (obj instanceof JSONObject) {
list.add(new JSONRequestObject((JSONObject) obj));
}
else {
list.add(obj);
}
}
return list;
}
/**
* Gets the json as a map.
*
* @return The json as a map
*/
public Map<String, Object> getFormVariables() {
Map<String, Object> map = new HashMap<String, Object>();
Iterator keys = json.keys();
String key, typeKey, type;
String[] keyPair;
Object value;
while (keys.hasNext()) {
key = (String) keys.next();
keyPair = key.split("_");
if (keyPair.length == 1) {
typeKey = keyPair[0] + "_type";
if (json.has(typeKey)) {
type = json.getString(typeKey);
if (type.equals("Integer")) {
value = json.getInt(key);
} else if (type.equals("Boolean")) {
value = json.getBoolean(key);
} else if (type.equals("Date")) {
value = json.getString(key);
} else if (type.equals("User")) {
value = json.getString(key);
} else if (type.equals("String")) {
value = json.getString(key);
} else {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter '" + keyPair[0] + "' is of unknown type '" + type + "'");
}
} else {
value = json.get(key);
}
map.put(key, value);
} else if (keyPair.length == 2) {
if (keyPair[1].equals("required")) {
if (!json.has(keyPair[0]) || json.get(keyPair[0]) == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter '" + keyPair[0] + "' has no value");
}
}
}
}
return map;
}
}
<#import "management.lib.ftl" as managementLib>
<#escape x as jsonUtils.encodeJSONString(x)>
{
<@managementLib.printJob job/>,
<#if stacktrace??>"stacktrace": "${stacktrace?js_string}"</#if>
<@managementLib.printJob job/>
<#if stacktrace??>, "stacktrace": "${stacktrace}"</#if>
}
</#escape>
<webscript>
<shortname>Execute Jobs</shortname>
<description>Executes multiple jobs defined as a body object attribute of type string array named "jobIds"</description>
<url>/management/jobs/execute</url>
<authentication>admin</authentication>
<format default="json">argument</format>
</webscript>
\ No newline at end of file
<#escape x as jsonUtils.encodeJSONString(x)>
{
"success": true
}
</#escape>
\ No newline at end of file
<webscript>
<shortname>Delete Deployments</shortname>
<description>Deletes multiple deployments defined as a body object attribute of type string array named "deploymentIds"</description>
<url>/deployments/delete?cascade={cascade?}</url>
<authentication>user</authentication>
<format default="json">argument</format>
</webscript>
......@@ -101,6 +101,11 @@
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.repository.deployments-delete.post"
class="org.activiti.rest.api.repository.DeploymentsDeletePost"
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.engine.process-engine.get"
class="org.activiti.rest.api.engine.ProcessEngineGet"
parent="activitiWebScript">
......@@ -156,6 +161,11 @@
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.management.jobs-execute.post"
class="org.activiti.rest.api.management.JobsExecutePost"
parent="activitiWebScript">
</bean>
<bean id="webscript.org.activiti.rest.api.management.job.get"
class="org.activiti.rest.api.management.JobGet"
parent="activitiWebScript">
......
......@@ -79,7 +79,7 @@
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-surf-application</artifactId>
<version>1.0.0.M3</version>
<version>1.0.0-RC2</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
......
......@@ -21,7 +21,18 @@
<para>
Each REST API call has its individual authorization level and you must be logged in as a user to invoke a REST API
call (except for the /login service). Authentication is done using Basic HTTP Authentication, so if you logged in as
admin to browse the REST API, as described above, you should be able to perform all calls as described below.
an admin (i.e. kermit) to browse the REST API, as described above, you should be able to perform all calls as
described below.
</para>
<para>
The API follows normal REST API conventions using GET for read operations, POST for creating objects, PUT for updating and
performing operations on already created objects and finally DELETE for deleting objects. When performing a call
that affects multiple objects POST is used on all such operations for consistency and making sure that an unlimited
number of objects may be used. The reason for using POST is that the HTTP DELETE method doesn't implicitly allow
request bodies and therefore, a call using DELETE, in theory, could get it's request body stripped out by a proxy.
So to be certain this doesn't happen we use POST, even when PUT could have been used to update multiple objects,
for consistency.
</para>
<para>
......@@ -140,6 +151,40 @@
</itemizedlist>
</section>
<section>
<title>Delete Deployments</title>
<para>
Deletes multiple deployment.
</para>
<itemizedlist>
<listitem>
<para>
<emphasis role="bold">Request: </emphasis>
<literal>POST /deployments?cascade={cascade?}</literal>
<programlisting>
{
"deploymentIds": [ "10", "11" ]
}</programlisting>
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">API: </emphasis>
<literal>ProcessEngines.getProcessEngine(configuredProcessEngineName).getRepositoryService().deleteDeployment(deploymentId)</literal>
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">Response:</emphasis>
<programlisting>
{
"success": true
}</programlisting>
</para>
</listitem>
</itemizedlist>
</section>
</section>
<!-- ENGINE -->
......@@ -785,7 +830,13 @@
{
"data": [
{
TODO: Fill with example values when jobs are activated
"id": "212",
"executionId": "211",
"retries": -1,
"processInstanceId": "210",
"dueDate": null,
"assignee": null,
"exceptionMessage": "Can\'t find scripting engine for \'groovy\'"
}
],
"total": 1,
......@@ -822,7 +873,14 @@
<emphasis role="bold">Response:</emphasis>
<programlisting>
{
TODO: Fill with example values when jobs are activated
"id": "212",
"executionId": "211",
"retries": -1,
"processInstanceId": "210",
"dueDate": null,
"assignee": null,
"exceptionMessage": "Can\'t find scripting engine for \'groovy\'",
"stacktrace": "org.activiti.engine.ActivitiException: Can't find scripting engine for 'groovy'\n\tat ..."
}</programlisting>
</para>
</listitem>
......@@ -844,7 +902,41 @@
<listitem>
<para>
<emphasis role="bold">API:</emphasis>
<literal>ProcessEngines.getProcessEngine(configuredProcessEngineName).executeJob(jobId)</literal>
<literal>ProcessEngines.getProcessEngine(configuredProcessEngineName).getManagementService().executeJob(jobId)</literal>
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">Response:</emphasis>
<programlisting>
{
"success": true
}</programlisting>
</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Execute Jobs</title>
<para>
Executes multiple job.
</para>
<itemizedlist>
<listitem>
<para>
<emphasis role="bold">Request:</emphasis>
<literal>POST /management/jobs/execute</literal>
<programlisting>
{
"jobIds": [ "212" ]
}</programlisting>
</para>
</listitem>
<listitem>
<para>
<emphasis role="bold">API:</emphasis>
<literal>ProcessEngines.getProcessEngine(configuredProcessEngineName).getManagementService().executeJob(jobId)</literal>
</para>
</listitem>
<listitem>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册