提交 95c0b213 编写于 作者: F Frederik Heremans

Added management/tables to REST

上级 f2555d18
......@@ -23,7 +23,7 @@ public class DataResponse {
int start;
String sort;
String order;
int size;
int size = Integer.MAX_VALUE;
public Object getData() {
return data;
......
......@@ -19,7 +19,6 @@ import org.activiti.engine.management.TableMetaData;
import org.activiti.engine.management.TablePage;
import org.activiti.engine.management.TablePageQuery;
import org.activiti.engine.runtime.JobQuery;
import org.activiti.engine.task.Task;
......
......@@ -45,6 +45,7 @@ import org.activiti.rest.api.engine.variable.RestVariableConverter;
import org.activiti.rest.api.engine.variable.ShortRestVariableConverter;
import org.activiti.rest.api.engine.variable.StringRestVariableConverter;
import org.activiti.rest.api.identity.RestIdentityLink;
import org.activiti.rest.api.management.TableResponse;
import org.activiti.rest.api.process.ExecutionResponse;
import org.activiti.rest.api.process.ProcessInstanceResponse;
import org.activiti.rest.api.repository.DeploymentResourceResponse;
......@@ -382,6 +383,14 @@ public class RestResponseFactory {
return result;
}
public TableResponse createTableResponse(SecuredResource securedResource, String name, Long count) {
TableResponse result = new TableResponse();
result.setName(name);
result.setCount(count);
result.setUrl(securedResource.createFullResourceUrl(RestUrls.URL_TABLE, name));
return result;
}
/**
* Called once when the converters need to be initialized. Override of custom conversion
......
......@@ -27,6 +27,7 @@ public final class RestUrls {
*/
public static final String SEGMENT_REPOSITORY_RESOURCES = "repository";
public static final String SEGMENT_RUNTIME_RESOURCES = "runtime";
public static final String SEGMENT_MANAGEMENT_RESOURCES = "management";
public static final String SEGMENT_QUERY_RESOURCES = "query";
public static final String SEGMENT_DEPLOYMENT_RESOURCE = "deployments";
......@@ -46,6 +47,7 @@ public final class RestUrls {
public static final String SEGMENT_IDENTITYLINKS_FAMILY_GROUPS = "groups";
public static final String SEGMENT_IDENTITYLINKS_FAMILY_USERS = "users";
public static final String SEGMENT_VARIABLE_DATA = "data";
public static final String SEGMENT_TABLES = "tables";
/**
* URL template for the deployment collection: <i>repository/deployments</i>
......@@ -201,7 +203,6 @@ public final class RestUrls {
*/
public static final String[] URL_PROCESS_INSTANCE_QUERY = {SEGMENT_QUERY_RESOURCES, SEGMENT_PROCESS_INSTANCE_RESOURCE};
/**
* URL template for a single process instance: <i>runtime/process-instances/{0:processInstanceId}</i>
*/
......@@ -227,6 +228,17 @@ public final class RestUrls {
*/
public static final String[] URL_PROCESS_INSTANCE_COMMENT = {SEGMENT_RUNTIME_RESOURCES, SEGMENT_PROCESS_INSTANCE_RESOURCE, "{0}", SEGMENT_COMMENTS, "{1}"};
/**
* URL template for the collection of tables: <i>management/tables</i>
*/
public static final String[] URL_TABLES_COLLECTION = {SEGMENT_MANAGEMENT_RESOURCES, SEGMENT_TABLES};
/**
* URL template for a single table: <i>management/tables/{0:tableName}</i>
*/
public static final String[] URL_TABLE = {SEGMENT_MANAGEMENT_RESOURCES, SEGMENT_TABLES, "{0}"};
/**
* Creates an url based on the passed fragments and replaces any placeholders with the given arguments. The
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import org.activiti.rest.api.ActivitiUtil;
import org.activiti.rest.api.SecuredResource;
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import org.activiti.engine.ActivitiException;
import org.activiti.rest.api.ActivitiUtil;
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import java.util.ArrayList;
import java.util.List;
......@@ -27,9 +27,9 @@ public class JobsPaginateList extends AbstractPaginateList {
@SuppressWarnings("rawtypes")
@Override
protected List processList(List list) {
List<JobResponse> responseList = new ArrayList<JobResponse>();
List<LegacyJobResponse> responseList = new ArrayList<LegacyJobResponse>();
for (Object job : list) {
responseList.add(new JobResponse((Job) job));
responseList.add(new LegacyJobResponse((Job) job));
}
return responseList;
}
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import java.util.Date;
import java.util.HashMap;
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import org.activiti.engine.runtime.Job;
import org.activiti.rest.api.ActivitiUtil;
......@@ -21,16 +21,16 @@ import org.restlet.resource.Get;
/**
* @author Tijs Rademakers
*/
public class JobResource extends SecuredResource {
public class LegacyJobResource extends SecuredResource {
@Get
public JobResponse getJob() {
public LegacyJobResponse getJob() {
if(authenticate(SecuredResource.ADMIN) == false) return null;
String jobId = (String) getRequest().getAttributes().get("jobId");
Job job = ActivitiUtil.getManagementService().createJobQuery().jobId(jobId).singleResult();
String stacktrace = ActivitiUtil.getManagementService().getJobExceptionStacktrace(jobId);
JobResponse response = new JobResponse(job);
LegacyJobResponse response = new LegacyJobResponse(job);
response.setStacktrace(stacktrace);
return response;
}
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import org.activiti.engine.runtime.Job;
import org.activiti.rest.api.RequestUtil;
......@@ -19,7 +19,7 @@ import org.activiti.rest.api.RequestUtil;
/**
* @author Tijs Rademakers
*/
public class JobResponse {
public class LegacyJobResponse {
String id;
String executionId;
......@@ -29,7 +29,7 @@ public class JobResponse {
String exceptionMessage;
String stacktrace;
public JobResponse(Job job) {
public LegacyJobResponse(Job job) {
setId(job.getId());
setExecutionId(job.getExecutionId());
setProcessInstanceId(job.getProcessInstanceId());
......
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import java.util.Date;
import java.util.List;
......@@ -31,7 +31,7 @@ import org.restlet.resource.Get;
/**
* @author Tijs Rademakers
*/
public class TableDataResource extends SecuredResource {
public class LegacyTableDataResource extends SecuredResource {
@Get
public ObjectNode getTableData() {
......
/* 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.management;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.management.TableMetaData;
import org.activiti.rest.api.ActivitiUtil;
import org.activiti.rest.api.SecuredResource;
import org.restlet.resource.Get;
/**
* @author Tijs Rademakers
*/
public class LegacyTableResource extends SecuredResource {
@Get
public TableMetaData getTableMetaData() {
if(authenticate(SecuredResource.ADMIN) == false) return null;
String tableName = (String) getRequest().getAttributes().get("tableName");
if(tableName == null) {
throw new ActivitiIllegalArgumentException("table name is required");
}
return ActivitiUtil.getManagementService().getTableMetaData(tableName);
}
}
......@@ -11,7 +11,7 @@
* limitations under the License.
*/
package org.activiti.rest.api.management;
package org.activiti.rest.api.legacy.management;
import java.util.ArrayList;
import java.util.Collections;
......
/* 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 java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.activiti.rest.api.ActivitiUtil;
import org.activiti.rest.api.RestResponseFactory;
import org.activiti.rest.api.SecuredResource;
import org.activiti.rest.application.ActivitiRestServicesApplication;
import org.restlet.resource.Get;
/**
* @author Frederik Heremans
*/
public class TableCollectionResource extends SecuredResource {
@Get
public List<TableResponse> getTables() {
if(authenticate() == false) return null;
List<TableResponse> tables = new ArrayList<TableResponse>();
Map<String, Long> tableCounts = ActivitiUtil.getManagementService().getTableCount();
RestResponseFactory factory = getApplication(ActivitiRestServicesApplication.class).getRestResponseFactory();
for(Entry<String, Long> entry : tableCounts.entrySet()) {
tables.add(factory.createTableResponse(this, entry.getKey(), entry.getValue()));
}
return tables;
}
}
......@@ -13,25 +13,44 @@
package org.activiti.rest.api.management;
import java.util.Map;
import java.util.Map.Entry;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.management.TableMetaData;
import org.activiti.engine.ActivitiObjectNotFoundException;
import org.activiti.rest.api.ActivitiUtil;
import org.activiti.rest.api.SecuredResource;
import org.activiti.rest.application.ActivitiRestServicesApplication;
import org.restlet.resource.Get;
/**
* @author Tijs Rademakers
* @author Frederik Heremans
*/
public class TableResource extends SecuredResource {
@Get
public TableMetaData getTableMetaData() {
if(authenticate(SecuredResource.ADMIN) == false) return null;
String tableName = (String) getRequest().getAttributes().get("tableName");
public TableResponse getTable() {
if(authenticate() == false) return null;
String tableName = getAttribute("tableName");
if(tableName == null) {
throw new ActivitiIllegalArgumentException("table name is required");
throw new ActivitiIllegalArgumentException("The tableName cannot be null");
}
return ActivitiUtil.getManagementService().getTableMetaData(tableName);
Map<String, Long> tableCounts = ActivitiUtil.getManagementService().getTableCount();
TableResponse response = null;
for(Entry<String, Long> entry : tableCounts.entrySet()) {
if(entry.getKey().equals(tableName)) {
response = getApplication(ActivitiRestServicesApplication.class).getRestResponseFactory()
.createTableResponse(this, entry.getKey(), entry.getValue());
break;
}
}
if(response == null) {
throw new ActivitiObjectNotFoundException("Could not find a table with name '" + tableName + "'.", String.class);
}
return response;
}
}
/* 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;
/**
* @author Frederik Heremans
*/
public class TableResponse {
protected String name;
protected String url;
protected Long count;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
}
......@@ -28,17 +28,19 @@ import org.activiti.rest.api.legacy.deployment.DeploymentDeleteResource;
import org.activiti.rest.api.legacy.deployment.DeploymentUploadResource;
import org.activiti.rest.api.legacy.deployment.DeploymentsDeleteResource;
import org.activiti.rest.api.legacy.deployment.DeploymentsResource;
import org.activiti.rest.api.legacy.management.JobExecuteResource;
import org.activiti.rest.api.legacy.management.JobsExecuteResource;
import org.activiti.rest.api.legacy.management.JobsResource;
import org.activiti.rest.api.legacy.management.LegacyJobResource;
import org.activiti.rest.api.legacy.management.LegacyTableDataResource;
import org.activiti.rest.api.legacy.management.LegacyTableResource;
import org.activiti.rest.api.legacy.management.TablesResource;
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.task.LegacyTaskResource;
import org.activiti.rest.api.management.JobExecuteResource;
import org.activiti.rest.api.management.JobResource;
import org.activiti.rest.api.management.JobsExecuteResource;
import org.activiti.rest.api.management.JobsResource;
import org.activiti.rest.api.management.TableDataResource;
import org.activiti.rest.api.management.TableCollectionResource;
import org.activiti.rest.api.management.TableResource;
import org.activiti.rest.api.management.TablesResource;
import org.activiti.rest.api.process.ExecutionCollectionResource;
import org.activiti.rest.api.process.ExecutionQueryResource;
import org.activiti.rest.api.process.ExecutionResource;
......@@ -128,6 +130,9 @@ public class RestServicesInit {
router.attach("/runtime/executions/{executionId}/variables/{variableName}", ExecutionVariableResource.class);
router.attach("/runtime/executions/{executionId}/variables/{variableName}/data", ExecutionVariableDataResource.class);
router.attach("/management/tables", TableCollectionResource.class);
router.attach("/management/tables/{tableName}", TableResource.class);
router.attach("/query/tasks", TaskQueryResource.class);
router.attach("/query/process-instances", ProcessInstanceQueryResource.class);
router.attach("/query/executions", ExecutionQueryResource.class);
......@@ -185,13 +190,13 @@ public class RestServicesInit {
router.attach("/deployment/{deploymentId}/resource/{resourceName}", DeploymentArtifactResource.class);
router.attach("/management/jobs", JobsResource.class);
router.attach("/management/job/{jobId}", JobResource.class);
router.attach("/management/job/{jobId}", LegacyJobResource.class);
router.attach("/management/job/{jobId}/execute", JobExecuteResource.class);
router.attach("/management/jobs/execute", JobsExecuteResource.class);
router.attach("/management/tables", TablesResource.class);
router.attach("/management/table/{tableName}", TableResource.class);
router.attach("/management/table/{tableName}/data", TableDataResource.class);
router.attach("/management/table/{tableName}", LegacyTableResource.class);
router.attach("/management/table/{tableName}/data", LegacyTableDataResource.class);
router.attach("/simple-workflow", SimpleWorkflowResource.class);
......
package org.activiti.rest.api.management;
import java.util.Map;
import org.activiti.rest.BaseRestTestCase;
import org.activiti.rest.api.RestUrls;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode;
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 the Table collection and a single
* table resource.
*
* @author Frederik Heremans
*/
public class TableResourceTest extends BaseRestTestCase {
/**
* Test getting tables. GET management/tables
*/
public void testGetTables() throws Exception {
Map<String, Long> tableCounts = managementService.getTableCount();
ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLES_COLLECTION));
Representation response = client.get();
assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
// Check table array
JsonNode responseNode = objectMapper.readTree(response.getStream());
assertNotNull(responseNode);
assertTrue(responseNode.isArray());
assertEquals(tableCounts.size(), responseNode.size());
for (int i = 0; i < responseNode.size(); i++) {
ObjectNode table = (ObjectNode) responseNode.get(i);
assertNotNull(table.get("name").getTextValue());
assertNotNull(table.get("count").getLongValue());
assertTrue(table.get("url").getTextValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE, table.get("name").getTextValue())));
assertEquals(((Long) tableCounts.get(table.get("name").getTextValue())).longValue(), table.get("count").getLongValue());
}
}
/**
* Test getting a single table. GET management/tables/{tableName}
*/
public void testGetTable() throws Exception {
Map<String, Long> tableCounts = managementService.getTableCount();
String tableNameToGet = tableCounts.keySet().iterator().next();
ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE, tableNameToGet));
Representation response = client.get();
assertEquals(Status.SUCCESS_OK, client.getResponse().getStatus());
// Check table
JsonNode responseNode = objectMapper.readTree(response.getStream());
assertNotNull(responseNode);
assertEquals(tableNameToGet, responseNode.get("name").getTextValue());
assertEquals(((Long) tableCounts.get(responseNode.get("name").getTextValue())).longValue(), responseNode.get("count").getLongValue());
assertTrue(responseNode.get("url").getTextValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE, tableNameToGet)));
}
public void testGetUnexistingTable() throws Exception {
ClientResource client = getAuthenticatedClient(RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE, "unexisting"));
try {
client.get();
fail("404 expected, but was: " + client.getResponse().getStatus());
} catch(ResourceException expected) {
assertEquals(Status.CLIENT_ERROR_NOT_FOUND, client.getResponse().getStatus());
assertEquals("Could not find a table with name 'unexisting'.", client.getResponse().getStatus().getDescription());
}
}
}
\ No newline at end of file
......@@ -3709,6 +3709,115 @@ Only the attachment name is required to create a new attachment.
</table>
</section>
</section>
<section>
<title>Database tables</title>
<section>
<title>List of tables</title>
<para>
<programlisting>GET management/tables</programlisting>
</para>
<para>
<table>
<title>Response codes</title>
<tgroup cols='2'>
<thead>
<row>
<entry>Response code</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>200</entry>
<entry>Indicates the request was successful.</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<emphasis role="bold">Success response body:</emphasis>
<programlisting>
[
{
"name":"ACT_RU_VARIABLE",
"url":"http://localhost:8182/management/tables/ACT_RU_VARIABLE",
"count":4528
},
{
"name":"ACT_RU_EVENT_SUBSCR",
"url":"http://localhost:8182/management/tables/ACT_RU_EVENT_SUBSCR",
"count":3
},
...
]</programlisting>
</para>
</section>
<section>
<title>Get a single table</title>
<para>
<programlisting>GET management/tables/{tableName}</programlisting>
</para>
<para>
<table>
<title>URL parameters</title>
<tgroup cols='3'>
<thead>
<row>
<entry>Parameter</entry>
<entry>Required</entry>
<entry>Value</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>tableName</entry>
<entry>Yes</entry>
<entry>String</entry>
<entry>The name of the table to get.</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<emphasis role="bold">Success response body:</emphasis>
<programlisting>
{
"name":"ACT_RE_PROCDEF",
"url":"http://localhost:8182/management/tables/ACT_RE_PROCDEF",
"count":60
}</programlisting>
<table>
<title>Response codes</title>
<tgroup cols='2'>
<thead>
<row>
<entry>Response code</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>200</entry>
<entry>Indicates the table exists and the table count is returned.</entry>
</row>
<row>
<entry>404</entry>
<entry>Indicates the requested table does not exist.</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</section>
</section>
<!-- Legacy -->
<section>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册