}
public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, boolean returnVariables,
Map<String, Object> runtimeVariableMap, List<HistoricVariableInstance> historicVariableList, String serverRootUrl) {
ProcessInstanceResponse result = new ProcessInstanceResponse();
result.setActivityId(processInstance.getActivityId());
result.setBusinessKey(processInstance.getBusinessKey());
result.setId(processInstance.getId());
result.setProcessDefinitionId(processInstance.getProcessDefinitionId());
result.setProcessDefinitionUrl(formatUrl(serverRootUrl, RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()));
result.setEnded(processInstance.isEnded());
result.setSuspended(processInstance.isSuspended());
result.setUrl(formatUrl(serverRootUrl, RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
result.setTenantId(processInstance.getTenantId());
//Added by Ryan Johnston
if (processInstance.isEnded()) {
//Process complete. Note the same in the result.
result.setCompleted(true);
} else {
//Process not complete. Note the same in the result.
result.setCompleted(false);
}
if (returnVariables) {
if (processInstance.isEnded()) {
if (historicVariableList != null) {
for (HistoricVariableInstance historicVariable : historicVariableList) {
result.addVariable(createRestVariable(historicVariable.getVariableName(), historicVariable.getValue(),
RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, serverRootUrl));
}
}
} else {
if (runtimeVariableMap != null) {
for (String name : runtimeVariableMap.keySet()) {
result.addVariable(createRestVariable(name, runtimeVariableMap.get(name),
RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, serverRootUrl));
}
}
}
}