All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rundeck.api.parser.ExecutionStateParser Maven / Gradle / Ivy

The newest version!
package org.rundeck.api.parser;

import org.apache.commons.lang.StringUtils;
import org.dom4j.Node;
import org.rundeck.api.domain.*;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/**
 * $INTERFACE is ... User: greg Date: 1/16/14 Time: 5:42 PM
 */
public class ExecutionStateParser extends BaseXpathParser {


    public ExecutionStateParser(final String xpath) {
        super(xpath);
    }

    @Override
    public RundeckExecutionState parse(Node targetNode) {
        RundeckExecutionState rundeckExecutionState = new RundeckExecutionState();
        rundeckExecutionState.setExecutionId(Long.valueOf(targetNode.valueOf("@id")));

        WorkflowStateParser.parseWorkflowState(targetNode, rundeckExecutionState);


        final List rundeckNodes =
                new ListParser(new NodeParser(), "allNodes/nodes/node").parseXmlNode(targetNode);
        rundeckExecutionState.setAllNodes(new HashSet(rundeckNodes));


        //node states
        HashMap> nodeStates = new HashMap>();

        for (Object o : targetNode.selectNodes("nodes/node")) {
            final Node nodeStateNode = (Node) o;
            final String nodeName = StringUtils.trimToNull(nodeStateNode.valueOf("@name"));
            if (null != nodeName) {
                ListParser workflowStepStateListParser
                        = new ListParser(new IndexedWorkflowStepStateParser(rundeckExecutionState, nodeName)
                        , "steps/step");
                nodeStates.put(nodeName, workflowStepStateListParser.parseXmlNode(nodeStateNode));
            }
        }
        rundeckExecutionState.setNodeStates(nodeStates);

        return rundeckExecutionState;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy