public RestResponseFactory() {
initializeVariableConverters();
}
public TaskResponse createTaskResponse(Task task, String serverRootUrl) {
TaskResponse response = new TaskResponse(task);
response.setUrl(formatUrl(serverRootUrl, RestUrls.URL_TASK, task.getId()));
// Add references to other resources, if needed
if (response.getParentTaskId() != null) {
response.setParentTaskUrl(formatUrl(serverRootUrl, RestUrls.URL_TASK, response.getParentTaskId()));
}
if (response.getProcessDefinitionId() != null) {
response.setProcessDefinitionUrl(formatUrl(serverRootUrl, RestUrls.URL_PROCESS_DEFINITION, response.getProcessDefinitionId()));
}
if (response.getExecutionId() != null) {
response.setExecutionUrl(formatUrl(serverRootUrl, RestUrls.URL_EXECUTION, response.getExecutionId()));
}
if (response.getProcessInstanceId() != null) {
response.setProcessInstanceUrl(formatUrl(serverRootUrl, RestUrls.URL_PROCESS_INSTANCE, response.getProcessInstanceId()));
}
if (task.getProcessVariables() != null) {
Map<String, Object> variableMap = task.getProcessVariables();
for (String name : variableMap.keySet()) {
response.addVariable(createRestVariable(name, variableMap.get(name),
RestVariableScope.GLOBAL, task.getId(), VARIABLE_TASK, false, serverRootUrl));
}
}
if (task.getTaskLocalVariables() != null) {
Map<String, Object> variableMap = task.getTaskLocalVariables();
for (String name : variableMap.keySet()) {
response.addVariable(createRestVariable(name, variableMap.get(name),
RestVariableScope.LOCAL, task.getId(), VARIABLE_TASK, false, serverRootUrl));
}
}
return response;