org.rundeck.api.parser.ExecutionStateParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rundeck-api-java-client Show documentation
Show all versions of rundeck-api-java-client Show documentation
Java client for the Rundeck REST API
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;
}
}