private List stageHistoryAsJson(PipelineInstanceModel pipelineInstanceModel, StageInstanceModels stageHistory) {
List json = new ArrayList();
for (StageInstanceModel stageHistoryItem : stageHistory) {
Map<String, Object> jsonMap = new LinkedHashMap<>();
jsonMap.put("stageName", stageHistoryItem.getName());
jsonMap.put("stageId", stageHistoryItem.getId());
jsonMap.put("stageStatus", stageHistoryItem.getState().toString());
StageIdentifier stageIdentifier = new StageIdentifier(pipelineInstanceModel.getPipelineIdentifier(),
stageHistoryItem.getName(), stageHistoryItem.getCounter());
jsonMap.put("stageLocator", encodeInUtf8(stageIdentifier.stageLocator()));
jsonMap.put("getCanRun", Boolean.toString(stageHistoryItem.getCanRun()));
jsonMap.put("getCanCancel", Boolean.toString(stageHistoryItem.getCanCancel()));
jsonMap.put("scheduled", Boolean.toString(stageHistoryItem.isScheduled()));
jsonMap.put("stageCounter", stageHistoryItem.getCounter());
handleApproval(stageHistoryItem, jsonMap);
json.add(jsonMap);
}
return json;
}