Search in sources :

Example 1 with DOMElement

use of org.dom4j.dom.DOMElement in project gocd by gocd.

the class StageXmlViewModel method toXml.

public Document toXml(XmlWriterContext writerContext) {
    DOMElement root = new DOMElement("stage");
    root.addAttribute("name", stage.getName()).addAttribute("counter", String.valueOf(stage.getCounter()));
    Document document = new DOMDocument(root);
    root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl()));
    StageIdentifier stageId = stage.getIdentifier();
    root.addElement("id").addCDATA(stageId.asURN());
    String pipelineName = stageId.getPipelineName();
    root.addElement("pipeline").addAttribute("name", pipelineName).addAttribute("counter", String.valueOf(stageId.getPipelineCounter())).addAttribute("label", stageId.getPipelineLabel()).addAttribute("href", writerContext.getBaseUrl() + "/api/pipelines/" + pipelineName + "/" + stage.getPipelineId() + ".xml");
    root.addElement("updated").addText(DateUtils.formatISO8601(stage.latestTransitionDate()));
    root.addElement("result").addText(stage.getResult().toString());
    root.addElement("state").addText(stage.status());
    root.addElement("approvedBy").addCDATA(stage.getApprovedBy());
    Element jobs = root.addElement("jobs");
    for (JobInstance jobInstance : stage.getJobInstances()) {
        jobs.addElement("job").addAttribute("href", writerContext.getBaseUrl() + "/api/jobs/" + jobInstance.getId() + ".xml");
    }
    return document;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) JobInstance(com.thoughtworks.go.domain.JobInstance) 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)

Example 2 with DOMElement

use of org.dom4j.dom.DOMElement in project gocd by gocd.

the class JobPlanXmlViewModel method getXmlForJobPlan.

private DOMElement getXmlForJobPlan(XmlWriterContext writerContext, WaitingJobPlan waitingJobPlan) {
    JobPlan jobPlan = waitingJobPlan.jobPlan();
    DOMElement root = new DOMElement("job");
    root.addAttribute("name", jobPlan.getName()).addAttribute("id", String.valueOf(jobPlan.getJobId()));
    root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrlFor(writerContext.getBaseUrl(), jobPlan.getIdentifier()));
    root.addElement("buildLocator").addText(jobPlan.getIdentifier().buildLocator());
    if (!StringUtil.isBlank(waitingJobPlan.envName())) {
        root.addElement("environment").addText(waitingJobPlan.envName());
    }
    if (!jobPlan.getResources().isEmpty()) {
        DOMElement resources = new DOMElement("resources");
        for (Resource resource : jobPlan.getResources()) {
            resources.addElement("resource").addCDATA(resource.getName());
        }
        root.add(resources);
    }
    if (!jobPlan.getVariables().isEmpty()) {
        DOMElement envVars = new DOMElement("environmentVariables");
        for (EnvironmentVariableConfig environmentVariableConfig : jobPlan.getVariables()) {
            envVars.addElement("variable").addAttribute("name", environmentVariableConfig.getName()).addText(environmentVariableConfig.getDisplayValue());
        }
        root.add(envVars);
    }
    return root;
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) JobPlan(com.thoughtworks.go.domain.JobPlan) WaitingJobPlan(com.thoughtworks.go.domain.WaitingJobPlan) Resource(com.thoughtworks.go.config.Resource) DOMElement(org.dom4j.dom.DOMElement)

Example 3 with DOMElement

use of org.dom4j.dom.DOMElement in project gocd by gocd.

the class JobPlanXmlViewModel method toXml.

public Document toXml(XmlWriterContext writerContext) throws DocumentException, IOException {
    DOMElement root = new DOMElement("scheduledJobs");
    for (WaitingJobPlan jobPlan : jobPlans) {
        DOMElement jobElement = getXmlForJobPlan(writerContext, jobPlan);
        root.add(jobElement);
    }
    DOMDocument domDocument = new DOMDocument(root);
    return domDocument;
}
Also used : DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement) WaitingJobPlan(com.thoughtworks.go.domain.WaitingJobPlan)

Example 4 with DOMElement

use of org.dom4j.dom.DOMElement in project gocd by gocd.

the class JobXmlViewModel method toXml.

public Document toXml(XmlWriterContext writerContext) throws DocumentException, IOException {
    DOMElement root = new DOMElement("job");
    root.addAttribute("name", jobInstance.getName());
    Document document = new DOMDocument(root);
    root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl()));
    JobIdentifier identifier = jobInstance.getIdentifier();
    root.addElement("id").addCDATA(identifier.asURN());
    String pipelineName = identifier.getPipelineName();
    StageIdentifier stageId = identifier.getStageIdentifier();
    root.addElement("pipeline").addAttribute("name", pipelineName).addAttribute("counter", String.valueOf(stageId.getPipelineCounter())).addAttribute("label", stageId.getPipelineLabel());
    root.addElement("stage").addAttribute("name", stageId.getStageName()).addAttribute("counter", stageId.getStageCounter()).addAttribute("href", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), jobInstance.getStageId()));
    root.addElement("result").addText(jobInstance.getResult().toString());
    root.addElement("state").addText(jobInstance.getState().toString());
    Element properties = root.addElement("properties");
    for (Property property : writerContext.propertiesForJob(jobInstance.getId())) {
        properties.addElement("property").addAttribute("name", property.getKey()).addCDATA(property.getValue());
    }
    root.addElement("agent").addAttribute("uuid", jobInstance.getAgentUuid());
    Element artifacts = root.addElement("artifacts");
    artifacts.addAttribute("baseUri", writerContext.artifactBaseUrl(identifier)).addAttribute("pathFromArtifactRoot", writerContext.artifactRootPath(identifier));
    JobPlan jobPlan = writerContext.planFor(identifier);
    for (ArtifactPlan artifactPlan : jobPlan.getArtifactPlans()) {
        artifacts.addElement("artifact").addAttribute("src", artifactPlan.getSrc()).addAttribute("dest", artifactPlan.getDest()).addAttribute("type", artifactPlan.getArtifactType().toString());
    }
    Element resources = root.addElement("resources");
    for (Resource resource : jobPlan.getResources()) {
        resources.addElement("resource").addText(resource.getName());
    }
    Element envVars = root.addElement("environmentvariables");
    for (EnvironmentVariableConfig environmentVariableConfig : jobPlan.getVariables()) {
        envVars.addElement("variable").addAttribute("name", environmentVariableConfig.getName()).addCDATA(environmentVariableConfig.getDisplayValue());
    }
    return document;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) ArtifactPlan(com.thoughtworks.go.config.ArtifactPlan) JobPlan(com.thoughtworks.go.domain.JobPlan) Element(org.dom4j.Element) DOMElement(org.dom4j.dom.DOMElement) DOMDocument(org.dom4j.dom.DOMDocument) Resource(com.thoughtworks.go.config.Resource) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DOMElement(org.dom4j.dom.DOMElement) Document(org.dom4j.Document) DOMDocument(org.dom4j.dom.DOMDocument) Property(com.thoughtworks.go.domain.Property)

Example 5 with DOMElement

use of org.dom4j.dom.DOMElement in project gocd by gocd.

the class PipelineXmlViewModel method toXml.

public Document toXml(XmlWriterContext writerContext) throws DocumentException, IOException {
    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) DOMElement(org.dom4j.dom.DOMElement) Element(org.dom4j.Element) 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)

Aggregations

DOMElement (org.dom4j.dom.DOMElement)5 DOMDocument (org.dom4j.dom.DOMDocument)4 Document (org.dom4j.Document)3 Element (org.dom4j.Element)3 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 Resource (com.thoughtworks.go.config.Resource)2 JobPlan (com.thoughtworks.go.domain.JobPlan)2 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)2 WaitingJobPlan (com.thoughtworks.go.domain.WaitingJobPlan)2 ArtifactPlan (com.thoughtworks.go.config.ArtifactPlan)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)1 Property (com.thoughtworks.go.domain.Property)1 NullStageHistoryItem (com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem)1 StageInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)1