private List historyAsJson(BaseCollection<PipelineInstanceModel> pipelineHistory) { List json = new ArrayList(); for (PipelineInstanceModel item : pipelineHistory) { Map<String, Object> jsonMap = new LinkedHashMap<>(); jsonMap.put("pipelineId", item.getId()); jsonMap.put("label", item.getLabel()); jsonMap.put("counterOrLabel", item.getPipelineIdentifier().instanceIdentifier()); jsonMap.put("scheduled_date", timeConverter.getHumanReadableStringWithTimeZone(item.getScheduledDate())); jsonMap.put("scheduled_timestamp", item.getScheduledDate() != null ? item.getScheduledDate().getTime() : null); jsonMap.put("buildCauseBy", item.getApprovedByForDisplay()); jsonMap.put("modification_date", getModificationDate(item)); jsonMap.put("materialRevisions", materialRevisionsJson(item)); jsonMap.put("stages", stageHistoryAsJson(item, item.getStageHistory())); jsonMap.put("revision", item.getRevisionOfLatestModification()); jsonMap.put("comment", item.getComment()); json.add(jsonMap); } return json; }
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; }
private void populateCanRunStatus(Username username, PipelineInstanceModel pipelineInstanceModel) { for (StageInstanceModel stageHistoryItem : pipelineInstanceModel.getStageHistory()) { boolean canRun = scheduleService.canRun( pipelineInstanceModel.getPipelineIdentifier(), stageHistoryItem.getName(), CaseInsensitiveString.str(username.getUsername()), pipelineInstanceModel.hasPreviousStageBeenScheduled( stageHistoryItem.getName())); stageHistoryItem.setCanRun(canRun); } populatePipelineCanRunStatus(username, pipelineInstanceModel); }
public Document toXml(XmlWriterContext writerContext) { DOMElement root = new DOMElement("pipeline"); root.addAttribute("name", pipeline.getName()).addAttribute("counter", String.valueOf(pipeline.getCounter())).addAttribute("label", pipeline.getLabel()); Document document = new DOMDocument(root); String baseUrl = writerContext.getBaseUrl(); root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(baseUrl)); root.addElement("id").addCDATA(pipeline.getPipelineIdentifier().asURN()); PipelineTimelineEntry pipelineAfter = pipeline.getPipelineAfter(); if (pipelineAfter != null) { addTimelineLink(root, baseUrl, "insertedBefore", pipelineAfter); } PipelineTimelineEntry pipelineBefore = pipeline.getPipelineBefore(); if (pipelineBefore != null) { addTimelineLink(root, baseUrl, "insertedAfter", pipelineBefore); } root.addElement("scheduleTime").addText(DateUtils.formatISO8601(pipeline.getScheduledDate())); Element materials = root.addElement("materials"); for (MaterialRevision materialRevision : pipeline.getCurrentRevisions()) { populateXml(materials, materialRevision, writerContext); } Element stages = root.addElement("stages"); for (StageInstanceModel stage : pipeline.getStageHistory()) { if (! (stage instanceof NullStageHistoryItem)) { stages.addElement("stage").addAttribute("href", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), stage.getId())); } } root.addElement("approvedBy").addCDATA(pipeline.getApprovedBy()); return document; }