提交 7fc0dc3b 编写于 作者: F frederikheremans

Introduced JSON template processing using JSONObjects

上级 7282cfc9
......@@ -46,7 +46,7 @@ public interface ManagementService {
/**
* Creates a {@link TablePageQuery} that can be used to fetch {@link TablePage}
* containing specific sections of table row signalData.
* containing specific sections of table row data.
*/
TablePageQuery createTablePageQuery();
......
......@@ -51,7 +51,7 @@
<artifactId>activiti-engine</artifactId>
<scope>provided</scope>
</dependency>
<!-- scope not "provided" to preserve transitive dependencies in activiti-webapp-rest etc. -->
<dependency>
<groupId>org.activiti</groupId>
......@@ -73,6 +73,14 @@
<artifactId>spring-surf</artifactId>
<version>1.0.0-RC2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -38,6 +38,7 @@ public class ProcessDefinitionsGet extends ActivitiPagingWebScript {
properties.put("key", ProcessDefinitionQueryProperty.PROCESS_DEFINITION_KEY);
properties.put("version", ProcessDefinitionQueryProperty.PROCESS_DEFINITION_VERSION);
properties.put("deploymentId", ProcessDefinitionQueryProperty.DEPLOYMENT_ID);
properties.put("name", ProcessDefinitionQueryProperty.PROCESS_DEFINITION_NAME);
}
/**
......
/* 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.builder;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Base class for implementing a {@link JSONObjectBuilder}. Adds utility methods
* for easy manipulation of JSON.
*
* @author Frederik Heremans
*/
public abstract class BaseJSONObjectBuilder implements JSONObjectBuilder {
protected String templateName;
public abstract JSONObject createJsonObject(Object model) throws JSONException;
@SuppressWarnings("unchecked")
protected Map<String, Object> getModelAsMap(Object model) {
if(model instanceof Map<?, ?>) {
return (Map<String, Object>) model;
}
throw new RuntimeException("The model is not a map");
}
public String getTemplateName() {
return templateName;
}
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
}
/* 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.builder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public interface JSONConverter<T> {
JSONObject getJSONObject(T object) throws JSONException;
T getObject(JSONObject jsonObject) throws JSONException;
}
/* 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.builder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Delegate for building {@link JSONObject}s from a model.
*
* @author Frederik Heremans
*/
public interface JSONObjectBuilder {
String getTemplateName();
JSONObject createJsonObject(Object model) throws JSONException;
}
/* 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.builder;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.processor.AbstractTemplateProcessor;
/**
* A Template Processor that passes the model on to a registered delegate class
* of type {@link JSONObjectBuilder}, which will create a {@link JSONObject}.
* The resulting JSONObject is written to the response.
*
* When no builder is defined for the required template,
* <code>hasTemplate(template)</code> returns false.
*
* @author Frederik Heremans
*/
public class JSONTemplateProcessor extends AbstractTemplateProcessor {
private static final String PROCESSOR_EXTENTION = "object";
private static final String PROCESSOR_EXTENTION_SUFFIX = "." + PROCESSOR_EXTENTION;
private static final String PROCESSOR_NAME = "JSONObject";
private static final Integer DEFAULT_INDENT_FACTOR = 2;
protected String defaultEncoding;
protected String templateNamePrefix;
protected ApplicationContext applicationContext;
protected Integer indentFactor = DEFAULT_INDENT_FACTOR;
private Map<String, JSONObjectBuilder> objectBuilders = new HashMap<String, JSONObjectBuilder>();
public boolean hasTemplate(String template) {
return objectBuilders.containsKey(getTemplateKey(template));
}
public void process(String template, Object model, Writer out) {
JSONObjectBuilder builder = objectBuilders.get(getTemplateKey(template));
if (builder == null) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Template " + template + " is registered on this this processor.");
}
try {
JSONObject resultObject = builder.createJsonObject(model);
writeJSON(resultObject, out);
} catch (JSONException jsone) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Error while creating JSONObject from model", jsone);
}
}
public void processString(String template, Object model, Writer out) {
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " does not support processing of template string.");
}
@Override
public void init() {
initializeObjectBuilders();
}
public void reset() {
initializeObjectBuilders();
}
protected void initializeObjectBuilders() {
if (applicationContext != null) {
// Search in context for all JSONObjectBuilders
Map<String, JSONObjectBuilder> buildersFromContext = applicationContext.getBeansOfType(JSONObjectBuilder.class);
Map<String, JSONObjectBuilder> newBuilders = new HashMap<String, JSONObjectBuilder>();
for (JSONObjectBuilder builder : buildersFromContext.values()) {
newBuilders.put(templateNamePrefix + builder.getTemplateName(), builder);
}
objectBuilders = newBuilders;
}
}
protected String getTemplateKey(String template) {
if (template != null) {
return template.replace(PROCESSOR_EXTENTION_SUFFIX, "");
}
return null;
}
protected void writeJSON(JSONObject object, Writer out) throws WebScriptException {
try {
if (indentFactor == 0) {
// When no indentation is required, we use JSONObject.write, which is
// cheaper than toString()
object.write(out);
} else {
out.write(object.toString(indentFactor));
}
} catch (JSONException jsone) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Error while writing JSONObject", jsone);
} catch (IOException ioe) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Error while writing JSONObject", ioe);
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
super.setApplicationContext(applicationContext);
this.applicationContext = applicationContext;
}
public String getDefaultEncoding() {
return defaultEncoding;
}
public String getName() {
return PROCESSOR_NAME;
}
public String getExtension() {
return PROCESSOR_EXTENTION;
}
public void setDefaultEncoding(String defaultEncoding) {
this.defaultEncoding = defaultEncoding;
}
public void setTemplateNamePrefix(String templateNamePrefix) {
this.templateNamePrefix = templateNamePrefix;
}
public void setIndentFactor(Integer indentFactor) {
if (indentFactor != null && indentFactor > 0) {
this.indentFactor = indentFactor;
} else {
this.indentFactor = DEFAULT_INDENT_FACTOR;
}
}
}
/* 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.builder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Creates an object representing a successful operation, regardless of the
* content of the model. If the builder is called, there was no exception during
* the execution of the webscript.
*
* @author Frederik Heremans
*/
public class SuccessObjectBuilder extends BaseJSONObjectBuilder {
@Override
public JSONObject createJsonObject(Object model) throws JSONException {
JSONObject result = new JSONObject();
result.put("success", true);
return result;
}
}
/* 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.builder.engine;
import java.util.Map;
import org.activiti.engine.ProcessEngineInfo;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class ProcessEngineObjectBuilder extends BaseJSONObjectBuilder {
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
JSONUtil.putRetainNull(result, "version", model.get("version"));
ProcessEngineInfo processEngineInfo = (ProcessEngineInfo) model.get("processEngineInfo");
if(processEngineInfo != null) {
JSONUtil.putRetainNull(result, "name", processEngineInfo.getName());
JSONUtil.putRetainNull(result, "resourceUrl", processEngineInfo.getResourceUrl());
JSONUtil.putRetainNull(result, "exception", processEngineInfo.getException());
}
return result;
}
}
/* 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.builder.identity;
import org.activiti.engine.identity.Group;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
class GroupJSONConverter implements JSONConverter<Group>{
public JSONObject getJSONObject(Group group) throws JSONException {
JSONObject json = new JSONObject();
JSONUtil.putEmptyStringIfNull(json, "id", group.getId());
JSONUtil.putEmptyStringIfNull(json, "name", group.getName());
JSONUtil.putEmptyStringIfNull(json, "type", group.getType());
return json;
}
public Group getObject(JSONObject jsonObject) {
throw new UnsupportedOperationException();
}
}
/* 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.builder.identity;
import java.util.Map;
import org.activiti.engine.identity.Group;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class GroupObjectBuilder extends BaseJSONObjectBuilder {
private GroupJSONConverter converter = new GroupJSONConverter();
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
Group group = (Group) model.get("group");
return converter.getJSONObject(group);
}
}
/* 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.builder.identity;
import java.util.List;
import java.util.Map;
import org.activiti.engine.identity.User;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class GroupUsersObjectBuilder extends BaseJSONObjectBuilder {
private UserJSONConverter converter = new UserJSONConverter();
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
List<User> users = (List<User>) model.get("users");
JSONArray groupsArray = JSONUtil.putNewArray(result, "data");
if(users != null) {
for(User user : users) {
groupsArray.put(converter.getJSONObject(user));
}
}
JSONUtil.putPagingInfo(result, model);
return result;
}
}
/* 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.builder.identity;
import java.util.List;
import java.util.Map;
import org.activiti.engine.identity.Group;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class UserGroupsObjectBuilder extends BaseJSONObjectBuilder {
private GroupJSONConverter converter = new GroupJSONConverter();
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
List<Group> groups = (List<Group>) model.get("groups");
JSONArray groupsArray = JSONUtil.putNewArray(result, "data");
if(groups != null) {
for(Group user : groups) {
groupsArray.put(converter.getJSONObject(user));
}
}
JSONUtil.putPagingInfo(result, model);
return result;
}
}
/* 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.builder.identity;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.identity.UserEntity;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
class UserJSONConverter implements JSONConverter<User> {
public JSONObject getJSONObject(User user) throws JSONException {
UserEntity userEntity = (UserEntity) user;
JSONObject json = new JSONObject();
JSONUtil.putEmptyStringIfNull(json, "id", userEntity.getId());
JSONUtil.putEmptyStringIfNull(json, "firstName", userEntity.getFirstName());
JSONUtil.putEmptyStringIfNull(json, "lastName", userEntity.getLastName());
JSONUtil.putEmptyStringIfNull(json, "email", userEntity.getEmail());
return json;
}
public User getObject(JSONObject jsonObject) {
throw new UnsupportedOperationException();
}
}
/* 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.builder.identity;
import java.util.Map;
import org.activiti.engine.identity.User;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class UserObjectBuilder extends BaseJSONObjectBuilder {
private UserJSONConverter converter = new UserJSONConverter();
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
User user = (User) model.get("user");
return converter.getJSONObject(user);
}
}
/* 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.builder.management;
import org.activiti.engine.runtime.Job;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class JobJSONConverter implements JSONConverter<Job> {
public JSONObject getJSONObject(Job job) throws JSONException {
JSONObject json = new JSONObject();
JSONUtil.putRetainNull(json, "id", job.getId());
JSONUtil.putRetainNull(json, "executionId", job.getExecutionId());
JSONUtil.putRetainNull(json, "retries", job.getRetries());
JSONUtil.putRetainNull(json, "processInstanceId", job.getProcessInstanceId());
String dueDate = JSONUtil.formatISO8601Date(job.getDuedate());
JSONUtil.putRetainNull(json, "dueDate", dueDate);
JSONUtil.putRetainNull(json, "exceptionMessage", job.getExceptionMessage());
return json;
}
public Job getObject(JSONObject jsonObject) throws JSONException {
throw new UnsupportedOperationException();
}
}
/* 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.builder.management;
import java.util.Map;
import org.activiti.engine.runtime.Job;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class JobObjectBuilder extends BaseJSONObjectBuilder {
private JobJSONConverter converter = new JobJSONConverter();
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
Job job = (Job) model.get("job");
JSONObject json = converter.getJSONObject(job);
// Also, add stacktrace. If null, property "stacktrace" won't be added
json.put("stacktrace", model.get("stacktrace"));
return json;
}
}
/* 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.builder.management;
import java.util.List;
import java.util.Map;
import org.activiti.engine.runtime.Job;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class JobsObjectBuilder extends BaseJSONObjectBuilder {
private JobJSONConverter converter = new JobJSONConverter();
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
JSONUtil.putPagingInfo(result, model);
List<Job> jobs = (List<Job>) model.get("jobs");
JSONArray taskArray = JSONUtil.putNewArray(result, "data");
if (jobs != null) {
for (Job job : jobs) {
taskArray.put(converter.getJSONObject(job));
}
}
return result;
}
}
/* 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.builder.management;
import java.lang.reflect.Array;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.activiti.engine.management.TablePage;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TableDataObjectBuilder extends BaseJSONObjectBuilder {
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
JSONObject result = new JSONObject();
JSONUtil.putPagingInfo(result, model);
JSONArray rows = JSONUtil.putNewArray(result, "data");
TablePage tablePage = (TablePage) model.get("tablePage");
if (tablePage != null) {
for (Map<String, Object> row : tablePage.getRows()) {
rows.put(createJSONObjectForRow(row));
}
}
return result;
}
private JSONObject createJSONObjectForRow(Map<String, Object> row) throws JSONException {
JSONObject json = new JSONObject();
for (Entry<String, Object> column : row.entrySet()) {
putColumnValue(json, column.getKey(), column.getValue());
}
return json;
}
protected void putColumnValue(JSONObject json, String key, Object value) throws JSONException {
if (value == null) {
JSONUtil.putRetainNull(json, key, null);
} else if (value instanceof List< ? >) {
json.put(key, ((List< ? >) value).size());
} else if (value.getClass().isArray()) {
json.put(key, Array.getLength(value));
} else if (value instanceof Date) {
String date = JSONUtil.formatISO8601Date((Date) value);
JSONUtil.putRetainNull(json, key, date);
} else {
// All other types can be handled by JSONObject
JSONUtil.putRetainNull(json, key, 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.builder.management;
import org.activiti.engine.management.TableMetaData;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TableMetaDataJSONConverter implements JSONConverter<TableMetaData> {
public JSONObject getJSONObject(TableMetaData tableMetaData) throws JSONException {
JSONObject json = new JSONObject();
JSONUtil.putRetainNull(json, "tableName", tableMetaData.getTableName());
JSONArray namesArray = JSONUtil.putNewArray(json, "columnNames");
if(tableMetaData.getColumnNames() != null) {
for(String columnName : tableMetaData.getColumnNames()) {
namesArray.put(columnName);
}
}
JSONArray typesArray = JSONUtil.putNewArray(json, "columnTypes");
if(tableMetaData.getColumnTypes() != null) {
for(String columnType : tableMetaData.getColumnTypes()) {
typesArray.put(columnType);
}
}
return json;
}
public TableMetaData getObject(JSONObject jsonObject) throws JSONException {
throw new UnsupportedOperationException();
}
}
/* 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.builder.management;
import java.util.Map;
import org.activiti.engine.management.TableMetaData;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TableObjectBuilder extends BaseJSONObjectBuilder {
private TableMetaDataJSONConverter converter = new TableMetaDataJSONConverter();
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
return converter.getJSONObject((TableMetaData) model.get("tableMetaData"));
}
}
/* 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.builder.management;
import java.util.List;
import java.util.Map;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TablesObjectBuilder extends BaseJSONObjectBuilder {
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
JSONObject result = new JSONObject();
JSONArray tablesArray = JSONUtil.putNewArray(result, "data");
List<String> tableNames = (List<String>) model.get("tableNames");
Map<String, Long> tableCounts = (Map<String, Long>) model.get("tables");
if(tableNames != null && tableCounts != null) {
for(String tableName : tableNames) {
JSONObject tableObject = new JSONObject();
tableObject.put("tableName", tableName);
JSONUtil.putDefault(tableObject, "total", tableCounts.get(tableName), 0);
tablesArray.put(tableObject);
}
}
return result;
}
}
/* 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.builder.process;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.model.RestProcessDefinition;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class ProcessDefinitionJSONConverter implements JSONConverter<ProcessDefinition> {
public JSONObject getJSONObject(ProcessDefinition processDefinition) throws JSONException {
JSONObject json = new JSONObject();
JSONUtil.putRetainNull(json, "id", processDefinition.getId());
JSONUtil.putRetainNull(json, "key", processDefinition.getKey());
JSONUtil.putRetainNull(json, "name", processDefinition.getName());
JSONUtil.putRetainNull(json, "version", processDefinition.getVersion());
JSONUtil.putRetainNull(json, "deploymentId", processDefinition.getDeploymentId());
JSONUtil.putRetainNull(json, "resourceName", processDefinition.getResourceName());
// TODO: custom handling, review when ACT-160 is fixed
if(processDefinition instanceof RestProcessDefinition) {
JSONUtil.putRetainNull(json, "startFormResourceKey", ((RestProcessDefinition) processDefinition).getStartFormResourceKey());
}
return json;
}
public ProcessDefinition getObject(JSONObject jsonObject) throws JSONException {
throw new UnsupportedOperationException();
}
}
/* 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.builder.process;
import java.util.Map;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.model.RestProcessDefinition;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class ProcessDefinitionObjectBuilder extends BaseJSONObjectBuilder {
private ProcessDefinitionJSONConverter converter = new ProcessDefinitionJSONConverter();
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
RestProcessDefinition procDef = (RestProcessDefinition) model.get("processDefinition");
return converter.getJSONObject(procDef);
}
}
/* 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.builder.process;
import java.util.List;
import java.util.Map;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class ProcessDefinitionsObjectBuilder extends BaseJSONObjectBuilder {
private ProcessDefinitionJSONConverter converter = new ProcessDefinitionJSONConverter();
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
JSONObject result = new JSONObject();
JSONUtil.putPagingInfo(result, model);
List<ProcessDefinition> definitions = (List<ProcessDefinition>) model.get("processDefinitions");
JSONArray dataArray = JSONUtil.putNewArray(result, "data");
for (ProcessDefinition processDefinition : definitions) {
JSONObject jsonTask = converter.getJSONObject(processDefinition);
dataArray.put(jsonTask);
}
return result;
}
}
/* 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.builder.process;
import java.util.List;
import org.activiti.engine.impl.pvm.runtime.ExecutionImpl;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class ProcessInstanceJSONConverter implements JSONConverter<ProcessInstance> {
public JSONObject getJSONObject(ProcessInstance processInstance) throws JSONException {
JSONObject json = new JSONObject();
JSONUtil.putRetainNull(json, "id", processInstance.getId());
JSONUtil.putRetainNull(json, "processDefinitionId", processInstance.getProcessDefinitionId());
JSONUtil.putRetainNull(json, "ended", processInstance.isEnded());
addActiveActivityNames(processInstance, json);
return json;
}
private void addActiveActivityNames(ProcessInstance processInstance, JSONObject object) throws JSONException {
if(processInstance instanceof ExecutionEntity) {
List<String> activeActivities = ((ExecutionImpl) processInstance).findActiveActivityIds();
JSONArray activityNames =JSONUtil.putNewArray(object, "activityNames");
for (String activity : activeActivities) {
activityNames.put(activity);
}
}
}
public ProcessInstance getObject(JSONObject jsonObject) throws JSONException {
throw new UnsupportedOperationException();
}
}
/* 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.builder.process;
import java.util.Map;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class ProcessInstanceObjectBuilder extends BaseJSONObjectBuilder {
private ProcessInstanceJSONConverter converter = new ProcessInstanceJSONConverter();
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
ProcessInstance processInstance = (ProcessInstance) model.get("processInstance");
return converter.getJSONObject(processInstance);
}
}
/* 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.builder.repository;
import org.activiti.engine.repository.Deployment;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class DeploymentJSONConverter implements JSONConverter<Deployment> {
public JSONObject getJSONObject(Deployment deployment) throws JSONException {
JSONObject json = new JSONObject();
JSONUtil.putRetainNull(json, "id", deployment.getId());
JSONUtil.putRetainNull(json, "name", deployment.getName());
String deploymentTime = JSONUtil.formatISO8601Date(deployment.getDeploymentTime());
JSONUtil.putRetainNull(json, "deploymentTime", deploymentTime);
return json;
}
public Deployment getObject(JSONObject jsonObject) throws JSONException {
throw new UnsupportedOperationException();
}
}
/* 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.builder.repository;
import java.util.List;
import java.util.Map;
import org.activiti.engine.repository.Deployment;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class DeploymentsObjectBuilder extends BaseJSONObjectBuilder {
private DeploymentJSONConverter converter = new DeploymentJSONConverter();
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
List<Deployment> deployments = (List<Deployment>) model.get("deployments");
JSONUtil.putPagingInfo(result, model);
JSONArray deploymentsArray = JSONUtil.putNewArray(result, "data");
if (deployments != null) {
for (Deployment deployment : deployments) {
deploymentsArray.put(converter.getJSONObject(deployment));
}
}
return result;
}
}
/* 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.builder.task;
import java.util.Map;
import org.activiti.engine.task.Task;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TaskGetObjectBuilder extends BaseJSONObjectBuilder{
private TaskJSONConverter converter = new TaskJSONConverter();
@Override
public JSONObject createJsonObject(Object modelObject) throws JSONException {
Map<String, Object> model = getModelAsMap(modelObject);
return converter.getJSONObject((Task) model.get("task"));
}
}
/* 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.builder.task;
import org.activiti.engine.impl.task.TaskEntity;
import org.activiti.engine.task.Task;
import org.activiti.rest.builder.JSONConverter;
import org.activiti.rest.model.RestTask;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TaskJSONConverter implements JSONConverter<Task> {
public JSONObject getJSONObject(Task object) throws JSONException {
JSONObject json = new JSONObject();
TaskEntity task = (TaskEntity) object;
if(task != null) {
JSONUtil.putRetainNull(json, "id", task.getId());
JSONUtil.putRetainNull(json, "name", task.getName());
JSONUtil.putRetainNull(json, "description", task.getDescription());
JSONUtil.putRetainNull(json, "priority", task.getPriority());
JSONUtil.putRetainNull(json, "assignee", task.getAssignee());
JSONUtil.putRetainNull(json, "executionId", task.getExecutionId());
JSONUtil.putRetainNull(json, "processInstanceId", task.getProcessInstanceId());
// TODO: custom handling, review when ACT-160 is fixed
if(task instanceof RestTask) {
// Custom handling, extra field is present
JSONUtil.putRetainNull(json, "formResourceKey", ((RestTask)task).getFormResourceKey());
}
}
return json;
}
public Task getObject(JSONObject jsonObject) throws JSONException {
throw new UnsupportedOperationException();
}
}
/* 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.builder.task;
import java.util.Map;
import java.util.Map.Entry;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TaskSummaryObjectBuilder extends BaseJSONObjectBuilder {
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
JSONObject assigned = JSONUtil.putNewObject(result, "assigned");
assigned.put("total", model.get("assigned"));
JSONObject unassigned = JSONUtil.putNewObject(result, "unassigned");
unassigned.put("total", model.get("unassigned"));
JSONObject groups = JSONUtil.putNewObject(unassigned, "groups");
Map<String, Long> unassignedByGroup = (Map<String, Long>) model.get("unassignedByGroup");
for(Entry<String, Long> groupEntry : unassignedByGroup.entrySet()) {
groups.put(groupEntry.getKey(), groupEntry.getValue());
}
return result;
}
}
/* 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.builder.task;
import java.util.List;
import java.util.Map;
import org.activiti.engine.task.Task;
import org.activiti.rest.builder.BaseJSONObjectBuilder;
import org.activiti.rest.util.JSONUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @author Frederik Heremans
*/
public class TasksGetObjectBuilder extends BaseJSONObjectBuilder {
private TaskJSONConverter converter = new TaskJSONConverter();
@Override
@SuppressWarnings("unchecked")
public JSONObject createJsonObject(Object modelObject) throws JSONException {
JSONObject result = new JSONObject();
Map<String, Object> model = getModelAsMap(modelObject);
JSONUtil.putPagingInfo(result, model);
List<Task> tasks = (List<Task>) model.get("tasks");
JSONArray taskArray = JSONUtil.putNewArray(result, "data");
if(tasks != null) {
for(Task task : tasks) {
taskArray.put(converter.getJSONObject(task));
}
}
return result;
}
}
/* 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.Calendar;
import java.util.Date;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.surf.util.ISO8601DateFormat;
/**
* Util class containing methods for handling common JSON operations.
*
* @author Frederik Heremans
*/
public abstract class JSONUtil {
/**
* Puts the given value in the {@link JSONObject}. When the value is null,
* {@link JSONObject#NULL} is put as value, resulting in an explicit NULL
* value in the rendered JSON output.
*/
public static void putRetainNull(JSONObject object, String key, Object value) throws JSONException {
putDefault(object, key, value, JSONObject.NULL);
}
/**
* Puts the given value in the {@link JSONObject}. When the value is null,
* an empty string is used as value.
*/
public static void putEmptyStringIfNull(JSONObject object, String key, Object value) throws JSONException {
putDefault(object, key, value, "");
}
public static void putDefault(JSONObject object, String key, Object value, Object defaultValue) throws JSONException {
if (value == null) {
value = defaultValue;
}
object.put(key, value);
}
public static void putPagingInfo(JSONObject object, Map<String, Object> model) throws JSONException {
putDefault(object, "total", model.get("total"), 0L);
putDefault(object, "start", model.get("start"), 0L);
putDefault(object, "size", model.get("size"), 0L);
object.put("sort", model.get("sort"));
object.put("order", model.get("order"));
}
public static JSONObject putNewObject(JSONObject base, String key) throws JSONException {
JSONObject newObject = new JSONObject();
base.put(key, newObject);
return newObject;
}
public static JSONArray putNewArray(JSONObject base, String key) throws JSONException {
JSONArray newArray = new JSONArray();
base.put(key, newArray);
return newArray;
}
public static String formatISO8601Date(Calendar calendar) {
if(calendar != null) {
return ISO8601DateFormat.format(calendar.getTime());
}
return null;
}
public static String formatISO8601Date(Date date) {
if(date != null) {
return ISO8601DateFormat.format(date);
}
return null;
}
}
......@@ -51,6 +51,14 @@
parent="webscript">
<property name="config" ref="config"/>
</bean>
<!-- Plug in custom template processor based on JSONObjects -->
<bean id="jsonObjectTemplateProcessor" class="org.activiti.rest.builder.JSONTemplateProcessor">
<property name="templateProcessorRegistry" ref="webscripts.web.templateregistry" />
<property name="defaultEncoding" value="UTF-8" />
<property name="templateNamePrefix" value="org/activiti/rest/api/" />
<property name="indentFactor" value="2" />
</bean>
<!--
Java backed webscripts needs to be registered.
......@@ -65,26 +73,47 @@
class="org.activiti.rest.api.identity.LoginPost"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.identity.login.post.json.builder"
class="org.activiti.rest.builder.SuccessObjectBuilder">
<property name="templateName" value="identity/login.post.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.identity.user.get"
class="org.activiti.rest.api.identity.UserGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.identity.user.get.json.builder"
class="org.activiti.rest.builder.identity.UserObjectBuilder">
<property name="templateName" value="identity/user.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.identity.user-groups.get"
class="org.activiti.rest.api.identity.UserGroupsGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.identity.user-groups.get.json.builder"
class="org.activiti.rest.builder.identity.UserGroupsObjectBuilder">
<property name="templateName" value="identity/user-groups.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.identity.group.get"
class="org.activiti.rest.api.identity.GroupGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.identity.group.get.json.builder"
class="org.activiti.rest.builder.identity.GroupObjectBuilder">
<property name="templateName" value="identity/group.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.identity.group-users.get"
class="org.activiti.rest.api.identity.GroupUsersGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.identity.group-users.get.json.builder"
class="org.activiti.rest.builder.identity.GroupUsersObjectBuilder">
<property name="templateName" value="identity/group-users.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.repository.deployment-resource.get"
class="org.activiti.rest.api.repository.DeploymentResourceGet"
......@@ -95,36 +124,65 @@
class="org.activiti.rest.api.repository.DeploymentsGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.repository.deployments.get.json.builder"
class="org.activiti.rest.builder.repository.DeploymentsObjectBuilder">
<property name="templateName" value="repository/deployments.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.repository.deployment.delete"
class="org.activiti.rest.api.repository.DeploymentDelete"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.repository.deployment.delete.json.builder"
class="org.activiti.rest.builder.SuccessObjectBuilder">
<property name="templateName" value="repository/deployment.delete.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.repository.deployments-delete.post"
class="org.activiti.rest.api.repository.DeploymentsDeletePost"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.repository.deployments-demete.post.json.builder"
class="org.activiti.rest.builder.SuccessObjectBuilder">
<property name="templateName" value="repository/deployments-delete.post.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.engine.process-engine.get"
class="org.activiti.rest.api.engine.ProcessEngineGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.engine.process-engine.get.json.builder"
class=" org.activiti.rest.builder.engine.ProcessEngineObjectBuilder">
<property name="templateName" value="engine/process-engine.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.process.process-definition.get"
class="org.activiti.rest.api.process.ProcessDefinitionGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.process.process-definition.get.json.builder"
class="org.activiti.rest.builder.process.ProcessDefinitionObjectBuilder">
<property name="templateName" value="process/process-definition.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.process.process-definition-form.get"
class="org.activiti.rest.api.process.ProcessDefinitionFormGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.process.process-instance.post.json.builder"
class="org.activiti.rest.builder.process.ProcessInstanceObjectBuilder">
<property name="templateName" value="process/process-instance.post.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.process.process-definitions.get"
class="org.activiti.rest.api.process.ProcessDefinitionsGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.process.process-definitions.get.json.builder"
class="org.activiti.rest.builder.process.ProcessDefinitionsObjectBuilder">
<property name="templateName" value="process/process-definitions.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.process.process-instance.post"
class="org.activiti.rest.api.process.ProcessInstancePost"
......@@ -135,6 +193,11 @@
class="org.activiti.rest.api.task.TaskGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.task.task.get.json.builder"
class="org.activiti.rest.builder.task.TaskGetObjectBuilder">
<property name="templateName" value="task/task.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.task.task-form.get"
class="org.activiti.rest.api.task.TaskFormGet"
......@@ -145,51 +208,93 @@
class="org.activiti.rest.api.task.TasksGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.task.tasks.get.json.builder"
class="org.activiti.rest.builder.task.TasksGetObjectBuilder">
<property name="templateName" value="task/tasks.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.task.tasks-summary.get"
class="org.activiti.rest.api.task.TasksSummaryGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.task.tasks-summary.get.json.builder"
class="org.activiti.rest.builder.task.TaskSummaryObjectBuilder">
<property name="templateName" value="task/tasks-summary.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.task.task-operation.put"
class="org.activiti.rest.api.task.TaskOperationPut"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.task.task-operation.put.json.builder"
class="org.activiti.rest.builder.SuccessObjectBuilder">
<property name="templateName" value="task/task-operation.put.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.job-execute.put"
class="org.activiti.rest.api.management.JobExecutePut"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.job-execute.put.json.builder"
class="org.activiti.rest.builder.SuccessObjectBuilder">
<property name="templateName" value="management/job-execute.put.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.jobs-execute.post"
class="org.activiti.rest.api.management.JobsExecutePost"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.jobd-execute.post.json.builder"
class="org.activiti.rest.builder.SuccessObjectBuilder">
<property name="templateName" value="management/jobs-execute.post.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.job.get"
class="org.activiti.rest.api.management.JobGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.job.get.json.builder"
class="org.activiti.rest.builder.management.JobObjectBuilder">
<property name="templateName" value="management/job.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.jobs.get"
class="org.activiti.rest.api.management.JobsGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.jobs.get.json.builder"
class="org.activiti.rest.builder.management.JobsObjectBuilder">
<property name="templateName" value="management/jobs.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.table.get"
class="org.activiti.rest.api.management.TableGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.table.get.json.builder"
class="org.activiti.rest.builder.management.TableObjectBuilder">
<property name="templateName" value="management/table.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.tables.get"
class="org.activiti.rest.api.management.TablesGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.tables.get.json.builder"
class="org.activiti.rest.builder.management.TablesObjectBuilder">
<property name="templateName" value="management/tables.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.management.table-data.get"
class="org.activiti.rest.api.management.TableDataGet"
parent="activitiWebScript">
</bean>
<bean id="org.activiti.rest.api.management.table-data.get.json.builder"
class="org.activiti.rest.builder.management.TableDataObjectBuilder">
<property name="templateName" value="management/table-data.get.json" />
</bean>
<bean id="webscript.org.activiti.rest.api.cycle.child-nodes.get"
class="org.activiti.rest.api.cycle.ChildNodesGet"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册