1 package org.rundeck.api.parser;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.dom4j.Node;
5 import org.rundeck.api.domain.*;
6
7 import java.util.HashMap;
8 import java.util.HashSet;
9 import java.util.List;
10
11
12
13
14 public class ExecutionStateParser extends BaseXpathParser<RundeckExecutionState> {
15
16
17 public ExecutionStateParser(final String xpath) {
18 super(xpath);
19 }
20
21 @Override
22 public RundeckExecutionState parse(Node targetNode) {
23 RundeckExecutionState rundeckExecutionState = new RundeckExecutionState();
24 rundeckExecutionState.setExecutionId(Long.valueOf(targetNode.valueOf("@id")));
25
26 WorkflowStateParser.parseWorkflowState(targetNode, rundeckExecutionState);
27
28
29 final List<RundeckNode> rundeckNodes =
30 new ListParser<RundeckNode>(new NodeParser(), "allNodes/nodes/node").parseXmlNode(targetNode);
31 rundeckExecutionState.setAllNodes(new HashSet<RundeckNodeIdentity>(rundeckNodes));
32
33
34
35 HashMap<String, List<WorkflowStepContextState>> nodeStates = new HashMap<String, List<WorkflowStepContextState>>();
36
37 for (Object o : targetNode.selectNodes("nodes/node")) {
38 final Node nodeStateNode = (Node) o;
39 final String nodeName = StringUtils.trimToNull(nodeStateNode.valueOf("@name"));
40 if (null != nodeName) {
41 ListParser<WorkflowStepContextState> workflowStepStateListParser
42 = new ListParser<WorkflowStepContextState>(new IndexedWorkflowStepStateParser(rundeckExecutionState, nodeName)
43 , "steps/step");
44 nodeStates.put(nodeName, workflowStepStateListParser.parseXmlNode(nodeStateNode));
45 }
46 }
47 rundeckExecutionState.setNodeStates(nodeStates);
48
49 return rundeckExecutionState;
50 }
51 }