public PipelineInstanceModel findPipelineInstance(String pipelineLabel) { if("latest".equals(pipelineLabel) && !pipelineInstances.isEmpty()){ return pipelineInstances.first(); } for (PipelineInstanceModel instance : pipelineInstances) { if (instance.getLabel().equals(pipelineLabel)) { return instance; } } return null; } }
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; }
String pipelineName = pipelineInstance.getName(); int pipelineCounter = pipelineInstance.getCounter(); String pipelineLabel = pipelineInstance.getLabel();
private void populatePipelineState(PipelineInstanceModel instance, Username username) { populatePlaceHolderStages(instance); populateCanRunStatus(username, instance); populateStageOperatePermission(instance, username); populateLockStatus(instance.getName(), username, instance); long id = pipelineTimeline.pipelineBefore(instance.getId()); if (id != -1) { PipelineInstanceModel prevPipeline = pipelineDao.loadHistory(id); instance.setPreviousPipelineLabel(prevPipeline.getLabel()); instance.setPreviousPipelineCounter(prevPipeline.getCounter()); } }
public static void toJSON(OutputWriter jsonOutputWriter, PipelineInstanceModel model) { jsonOutputWriter .addLinks(addLinks(model)) .add("label", model.getLabel()) .add("counter", model.getCounter()) .add("triggered_by", model.getApprovedByForDisplay()) .add("scheduled_at", model.getScheduledDate()) .addChild("_embedded", childWriter -> { childWriter.addChildList("stages", getStages(model)); }); }
public static void toJSON(OutputWriter jsonOutputWriter, PipelineInstanceModel model) { jsonOutputWriter .addLinks(addLinks(model)) .add("label", model.getLabel()) .add("counter", model.getCounter()) .add("triggered_by", model.getApprovedByForDisplay()) .add("scheduled_at", model.getScheduledDate()) .addChild("_embedded", childWriter -> { childWriter.addChildList("stages", getStages(model)); }); }
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; }