Tidy up of task-instance related REST APIs (path and workflowInstance are now part of simple task response).

Also removed detailed=true parameter from my tasks dashlet so it gets smaller JSON response, everything it needs is now in the simple task response payload.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21573 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2010-08-03 15:10:50 +00:00
parent d2ceb3bc73
commit d6914eda7a
4 changed files with 86 additions and 73 deletions

View File

@@ -11,6 +11,7 @@
"description": "${task.description}", "description": "${task.description}",
"state": "${task.state}", "state": "${task.state}",
"typeDefinitionTitle": "${task.typeDefinitionTitle}", "typeDefinitionTitle": "${task.typeDefinitionTitle}",
"path": "${task.path}",
"isPooled": ${task.isPooled?string}, "isPooled": ${task.isPooled?string},
"owner": "owner":
<#if task.owner??> <#if task.owner??>
@@ -23,10 +24,10 @@
null, null,
</#if> </#if>
"properties": "properties":
<@propertiesJSON properties=task.properties /> <@propertiesJSON properties=task.properties />,
<#if detailed>, "workflowInstance":
"path": "${task.path}", <@workflowInstanceJSON workflowInstance=task.workflowInstance/><#if detailed>,
"workflowInstance": <@workflowInstanceJSON workflowInstance=task.workflowInstance/>,
"definition": "definition":
{ {
"id": "${task.definition.id}", "id": "${task.definition.id}",
@@ -60,80 +61,79 @@
} }
} }
</#if> </#if>
} }
</#escape> </#escape>
</#macro> </#macro>
<#-- Renders a map of properties --> <#-- Renders a map of properties -->
<#macro propertiesJSON properties> <#macro propertiesJSON properties>
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
<#list properties?keys as key> <#list properties?keys as key>
"${key}": "${key}":
<#if properties[key]??> <#if properties[key]??>
<#assign val=properties[key]> <#assign val=properties[key]>
<#if val?is_boolean == true> <#if val?is_boolean == true>
${val?string} ${val?string}
<#elseif val?is_number == true> <#elseif val?is_number == true>
${val?c} ${val?c}
<#elseif val?is_sequence> <#elseif val?is_sequence>
[ [
<#list val as element> <#list val as element>
"${element?string}"<#if (element_has_next)>,</#if> "${element?string}"<#if (element_has_next)>,</#if>
</#list> </#list>
] ]
<#else>
"${shortQName(val?string)}"
</#if>
<#else> <#else>
null "${shortQName(val?string)}"
</#if> </#if>
<#if (key_has_next)>,</#if> <#else>
</#list> null
} </#if><#if (key_has_next)>,</#if>
</#list>
}
</#escape> </#escape>
</#macro> </#macro>
<#-- Renders a workflow instance. --> <#-- Renders a workflow instance. -->
<#macro workflowInstanceJSON workflowInstance detailed=false> <#macro workflowInstanceJSON workflowInstance detailed=false>
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
"id": "${workflowInstance.id}", "id": "${workflowInstance.id}",
"url": "${workflowInstance.url}", "url": "${workflowInstance.url}",
"name": "${workflowInstance.name}", "name": "${workflowInstance.name}",
"title": "${workflowInstance.title}", "title": "${workflowInstance.title}",
"description": "${workflowInstance.description}", "description": "${workflowInstance.description}",
"isActive": ${workflowInstance.isActive?string}, "isActive": ${workflowInstance.isActive?string},
"startDate": "${workflowInstance.startDate}", "startDate": "${workflowInstance.startDate}",
"endDate": <#if workflowInstance.endDate??>"${workflowInstance.endDate}"<#else>null</#if>, "endDate": <#if workflowInstance.endDate??>"${workflowInstance.endDate}"<#else>null</#if>,
"initiator": "initiator":
<#if workflowInstance.initiator??> <#if workflowInstance.initiator??>
{ {
"userName": "${workflowInstance.initiator.userName}", "userName": "${workflowInstance.initiator.userName}",
"firstName": "${workflowInstance.initiator.firstName}", "firstName": "${workflowInstance.initiator.firstName}",
"lastName": "${workflowInstance.initiator.lastName}" "lastName": "${workflowInstance.initiator.lastName}"
}, },
<#else> <#else>
null, null,
</#if> </#if>
"definitionUrl": "${workflowInstance.definitionUrl}" "definitionUrl": "${workflowInstance.definitionUrl}"<#if detailed>,
<#if detailed>, "dueDate": <#if workflowInstance.dueDate??>"${workflowInstance.dueDate}"<#else>null</#if>,
"dueDate": <#if workflowInstance.dueDate??>"${workflowInstance.dueDate}"<#else>null</#if>, "priority": <#if workflowInstance.priority??>${workflowInstance.priority?c}<#else>null</#if>,
"priority": <#if workflowInstance.priority??>${workflowInstance.priority?c}<#else>null</#if>, "context": <#if workflowInstance.context??>"${workflowInstance.context}"<#else>null</#if>,
"context": <#if workflowInstance.context??>"${workflowInstance.context}"<#else>null</#if>, "package": "${workflowInstance.package}",
"package": "${workflowInstance.package}", "startTaskInstanceId": "${workflowInstance.startTaskInstanceId}",
"startTaskInstanceId": "${workflowInstance.startTaskInstanceId}", "definition":
"definition": <@worflowDefinitionLib.workflowDefinitionJSON workflowDefinition=workflowInstance.definition detailed=true/> <@worflowDefinitionLib.workflowDefinitionJSON workflowDefinition=workflowInstance.definition detailed=true/>
<#if workflowInstance.tasks??>, <#if workflowInstance.tasks??>,
"tasks": "tasks":
[ [
<#list workflowInstance.tasks as task> <#list workflowInstance.tasks as task>
<@taskJSON task=task/> <@taskJSON task=task/>
<#if task_has_next>,</#if> <#if task_has_next>,</#if>
</#list> </#list>
] ]
</#if> </#if>
</#if> </#if>
} }
</#escape> </#escape>
</#macro> </#macro>

View File

@@ -164,12 +164,18 @@ public class WorkflowModelBuilder
model.put(TASK_DESCRIPTION, task.getDescription()); model.put(TASK_DESCRIPTION, task.getDescription());
model.put(TASK_STATE, task.getState().name()); model.put(TASK_STATE, task.getState().name());
model.put(TASK_TYPE_DEFINITION_TITLE, task.getDefinition().getMetadata().getTitle()); model.put(TASK_TYPE_DEFINITION_TITLE, task.getDefinition().getMetadata().getTitle());
model.put(TASK_PATH, getUrl(task.getPath()));
model.put(TASK_IS_POOLED, isPooled(task.getProperties())); model.put(TASK_IS_POOLED, isPooled(task.getProperties()));
Serializable owner = task.getProperties().get(ContentModel.PROP_OWNER); Serializable owner = task.getProperties().get(ContentModel.PROP_OWNER);
model.put(TASK_OWNER, getPersonModel( owner)); model.put(TASK_OWNER, getPersonModel( owner));
// task properties
model.put(TASK_PROPERTIES, buildProperties(task, propertyFilters)); model.put(TASK_PROPERTIES, buildProperties(task, propertyFilters));
// workflow instance part
model.put(TASK_WORKFLOW_INSTANCE, buildSimple(task.getPath().getInstance()));
return model; return model;
} }
@@ -182,11 +188,6 @@ public class WorkflowModelBuilder
{ {
Map<String, Object> model = buildSimple(workflowTask, null); Map<String, Object> model = buildSimple(workflowTask, null);
model.put(TASK_PATH, getUrl(workflowTask.getPath()));
// workflow instance part
model.put(TASK_WORKFLOW_INSTANCE, buildSimple(workflowTask.getPath().getInstance()));
// definition part // definition part
model.put(TASK_DEFINITION, buildTaskDefinition(workflowTask.getDefinition(), workflowTask)); model.put(TASK_DEFINITION, buildTaskDefinition(workflowTask.getDefinition(), workflowTask));

View File

@@ -102,6 +102,14 @@ public class WorkflowModelBuilderTest extends TestCase
String dateStr = (String) props.get("test_date"); String dateStr = (String) props.get("test_date");
assertEquals(date, ISO8601DateFormat.parse(dateStr)); assertEquals(date, ISO8601DateFormat.parse(dateStr));
Map<String, Object> workflowInstance = (Map<String, Object>)model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE);
assertNotNull(workflowInstance);
WorkflowInstance instance = task.getPath().getInstance();
assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDateStr = ISO8601DateFormat.format(instance.getStartDate());
assertEquals(startDateStr, workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, new ArrayList<NodeRef>(0)); task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, new ArrayList<NodeRef>(0));
model = builder.buildSimple(task, null); model = builder.buildSimple(task, null);
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED)); assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));

View File

@@ -126,9 +126,13 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
assertEquals(personManager.getFirstName(USER2), owner.getString("firstName")); assertEquals(personManager.getFirstName(USER2), owner.getString("firstName"));
assertEquals(personManager.getLastName(USER2), owner.getString("lastName")); assertEquals(personManager.getLastName(USER2), owner.getString("lastName"));
// JSONObject properties = result.getJSONObject("properties"); JSONObject properties = result.getJSONObject("properties");
assertNotNull(properties);
//TODO Add more tests to check property filtering and pooled actors. JSONObject instance = result.getJSONObject("workflowInstance");
assertNotNull(instance);
// TODO: Add more tests to check property filtering and pooled actors.
} }
public void testTaskInstanceGet() throws Exception public void testTaskInstanceGet() throws Exception