Search in sources :

Example 6 with NullStageHistoryItem

use of com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem in project gocd by gocd.

the class ViewCacheKeyTest method shouldGenerateKeyForPipelineModelViewFragment.

@Test
public void shouldGenerateKeyForPipelineModelViewFragment() {
    PipelineModel model = new PipelineModel("pipelineName", true, true, PipelinePauseInfo.notPaused()).updateAdministrability(true);
    StageInstanceModels stages = new StageInstanceModels();
    stages.add(stageInstance("stageName", 13, JobState.Building, JobResult.Unknown));
    stages.add(new NullStageHistoryItem("stage2", true));
    PipelineInstanceModel pipelineInstance = PipelineInstanceModel.createPipeline("pipelineName", 10, "label-10", BuildCause.createExternal(), stages);
    pipelineInstance.setId(12);
    model.addPipelineInstance(pipelineInstance);
    StageInstanceModels stages2 = new StageInstanceModels();
    stages2.add(stageInstance("stageName", 7, JobState.Completed, JobResult.Passed));
    stages2.add(stageInstance("stage2", 10, JobState.Assigned, JobResult.Unknown));
    PipelineInstanceModel pipelineInstance2 = PipelineInstanceModel.createPipeline("pipelineName", 7, "label-7", BuildCause.createExternal(), stages2);
    pipelineInstance2.setId(14);
    model.addPipelineInstance(pipelineInstance2);
    assertThat(viewCacheKey.forPipelineModelBox(model), is("view_dashboardPipelineFragment_pipelineName{false|false|false}[12|stageName|13|Building|stage2|0|Unknown|][14|stageName|7|Passed|stage2|10|Building|]true|true|false|||true"));
}
Also used : NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel) Test(org.junit.Test)

Example 7 with NullStageHistoryItem

use of com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem in project gocd by gocd.

the class ViewCacheKeyTest method shouldGenerateKeyForPipelineModelViewFragmentWithoutSpecialCharactersInPauseCause.

@Test
public void shouldGenerateKeyForPipelineModelViewFragmentWithoutSpecialCharactersInPauseCause() {
    PipelinePauseInfo pauseInfo = new PipelinePauseInfo(true, "pause& @Cause #with $special %char &*(){';/.,<>?", "admin");
    PipelineModel model = new PipelineModel("pipelineName", true, true, pauseInfo).updateAdministrability(true);
    StageInstanceModels stages = new StageInstanceModels();
    stages.add(stageInstance("stageName", 13, JobState.Building, JobResult.Unknown));
    stages.add(new NullStageHistoryItem("stage2", true));
    PipelineInstanceModel pipelineInstance = PipelineInstanceModel.createPipeline("pipelineName", 10, "label-10", BuildCause.createExternal(), stages);
    pipelineInstance.setId(12);
    model.addPipelineInstance(pipelineInstance);
    StageInstanceModels stages2 = new StageInstanceModels();
    stages2.add(stageInstance("stageName", 7, JobState.Completed, JobResult.Passed));
    stages2.add(stageInstance("stage2", 10, JobState.Assigned, JobResult.Unknown));
    PipelineInstanceModel pipelineInstance2 = PipelineInstanceModel.createPipeline("pipelineName", 7, "label-7", BuildCause.createExternal(), stages2);
    pipelineInstance2.setId(14);
    model.addPipelineInstance(pipelineInstance2);
    assertThat(viewCacheKey.forPipelineModelBox(model), is("view_dashboardPipelineFragment_pipelineName{false|false|false}[12|stageName|13|Building|stage2|0|Unknown|][14|stageName|7|Passed|stage2|10|Building|]true|true|true|pauseCausewithspecialchar|admin|true"));
}
Also used : NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel) Test(org.junit.Test)

Example 8 with NullStageHistoryItem

use of com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem in project gocd by gocd.

the class PipelineXmlViewModel method toXml.

@Override
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;
}
Also used : NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) Element(org.dom4j.Element) DOMElement(org.dom4j.dom.DOMElement) DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement) Document(org.dom4j.Document) DOMDocument(org.dom4j.dom.DOMDocument) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry)

Example 9 with NullStageHistoryItem

use of com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem in project gocd by gocd.

the class PipelineXmlRepresenter method toXml.

@Override
public Document toXml(XmlWriterContext ctx) {
    String self = ctx.pipelineXmlLink(instance.getName(), instance.getCounter());
    DocumentBuilder builder = DocumentBuilder.withRoot("pipeline").attr("name", instance.getName()).attr("counter", instance.getCounter()).link(self, "self").cdataNode("id", instance.getPipelineIdentifier().asURN()).textNode("scheduleTime", instance.getScheduledDate());
    PipelineTimelineEntry pipelineAfter = instance.getPipelineAfter();
    if (pipelineAfter != null) {
        builder.link(ctx.pipelineXmlLink(pipelineAfter.getPipelineName(), pipelineAfter.getId()), "insertedBefore");
    }
    PipelineTimelineEntry pipelineBefore = instance.getPipelineBefore();
    if (pipelineBefore != null) {
        builder.link(ctx.pipelineXmlLink(pipelineBefore.getPipelineName(), pipelineBefore.getId()), "insertedAfter");
    }
    builder.node("materials", materialBuilder -> {
        instance.getLatestRevisions().forEach(revision -> {
            this.populateMaterials(materialBuilder, revision, ctx);
        });
    });
    builder.node("stages", stagesBuilder -> {
        instance.getStageHistory().stream().filter(stage -> !(stage instanceof NullStageHistoryItem)).forEach(stage -> stagesBuilder.node("stage", stageBuilder -> stageBuilder.attr("href", ctx.stageXmlLink(stage.getIdentifier()))));
    });
    builder.cdataNode("approvedBy", instance.getApprovedBy());
    return builder.build();
}
Also used : Document(org.dom4j.Document) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) ElementBuilder(com.thoughtworks.go.server.domain.xml.builder.ElementBuilder) DocumentBuilder(com.thoughtworks.go.server.domain.xml.builder.DocumentBuilder) NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) XmlRepresentable(com.thoughtworks.go.domain.XmlRepresentable) MaterialXmlRepresenter(com.thoughtworks.go.server.domain.xml.materials.MaterialXmlRepresenter) NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) DocumentBuilder(com.thoughtworks.go.server.domain.xml.builder.DocumentBuilder) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry)

Aggregations

NullStageHistoryItem (com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem)9 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)7 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)6 Test (org.junit.Test)6 PipelineModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineModel)5 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)3 PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)2 Document (org.dom4j.Document)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1 XmlRepresentable (com.thoughtworks.go.domain.XmlRepresentable)1 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 EmptyPipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel)1 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)1 StageInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)1 DocumentBuilder (com.thoughtworks.go.server.domain.xml.builder.DocumentBuilder)1 ElementBuilder (com.thoughtworks.go.server.domain.xml.builder.ElementBuilder)1 MaterialXmlRepresenter (com.thoughtworks.go.server.domain.xml.materials.MaterialXmlRepresenter)1