As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
Huh, what is the rest2 webapp?
<bean id="jsonObjectTemplateProcessor" class="org.activiti.rest.builder.JSONTemplateProcessor"><br> <property name="templateProcessorRegistry" ref="webscripts.web.templateregistry" /><br> <property name="defaultEncoding" value="UTF-8" /><br> <property name="templateNamePrefix" value="org/activiti/rest/api/" /><br> <property name="indentFactor" value="2" /><br> </bean>
<bean id="org.activiti.rest.api.repository.deployments.get.json.builder" <br> class="org.activiti.rest.builder.repository.DeploymentsObjectBuilder"><br> <property name="templateName" value="repository/deployments.get.json" /><br> </bean>
public interface JSONObjectBuilder {<br><br> String getTemplateName();<br> JSONObject createJsonObject(Object model) throws JSONException;<br> <br>}<br>
private DeploymentJSONConverter converter = new DeploymentJSONConverter();<br><br> @Override<br> @SuppressWarnings("unchecked")<br> public JSONObject createJsonObject(Object modelObject) throws JSONException {<br> JSONObject result = new JSONObject();<br> Map<String, Object> model = getModelAsMap(modelObject);<br> List<Deployment> deployments = (List<Deployment>) model.get("deployments");<br><br> JSONUtil.putPagingInfo(result, model);<br> JSONArray deploymentsArray = JSONUtil.putNewArray(result, "data");<br><br> if (deployments != null) {<br> for (Deployment deployment : deployments) {<br> deploymentsArray.put(converter.getJSONObject(deployment));<br> }<br> }<br> return result;<br> }
public class DeploymentJSONConverter implements JSONConverter<Deployment> {<br><br><br> public JSONObject getJSONObject(Deployment deployment) throws JSONException {<br> JSONObject json = new JSONObject();<br> JSONUtil.putRetainNull(json, "id", deployment.getId());<br> JSONUtil.putRetainNull(json, "name", deployment.getName());<br> <br> String deploymentTime = JSONUtil.formatISO8601Date(deployment.getDeploymentTime());<br> JSONUtil.putRetainNull(json, "deploymentTime", deploymentTime);<br> <br> return json;<br> }<br><br>…<br>
Once we are confident about the solution, the ftl's are removed and JSONObject stuff kicks in.[…]WDYT?
{<br> "id": "${processDefinition.id}",<br> "key": "${processDefinition.key}",<br> "name": <#if processDefinition.name??>"${processDefinition.name}"<#else>null</#if>,<br> "version": ${processDefinition.version},<br> "deploymentId": "${processDefinition.deploymentId}",<br> "resourceName": "${processDefinition.resourceName}",<br> "startFormResourceKey": <#if processDefinition.startFormResourceKey??>"${processDefinition.startFormResourceKey}"<#else>null</#if><br>}
B. The amount of code lines needed are much greater, just consider the condition examples below to be written in java.
C. The benefit of getting a toJSON method in all pojos and use them in the rest api is not realistic since the pojo model will never match the services methods in 100%, some examples:- Task (resourceName isn't included anymore therefore needing a whole new class RestTask on some objects but not all, confusing an creates even more code to maintain)- RestProcessDefinition (same story as line above)
E. "modern" frameworks like rails, django use templates making it easier to use.
F. Freemarker is a robust framework with very good documentation: http://freemarker.sourceforge.net/docs/index.html
G. We don't use the webscripts framework in a way its not intended.
There are 2 reasons that are not addressed by freemarker templates:1) Learning curve.[…]2) Less indirection.