1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.rundeck.api.parser;
17
18 import java.util.Date;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.dom4j.Node;
22 import org.rundeck.api.domain.RundeckEvent;
23 import org.rundeck.api.domain.RundeckEvent.EventStatus;
24 import org.rundeck.api.domain.RundeckEvent.NodeSummary;
25
26
27
28
29
30
31 public class EventParser extends BaseXpathParser<RundeckEvent> {
32
33
34 public EventParser(final String xpath) {
35 super(xpath);
36 }
37
38 public EventParser() {
39 super();
40 }
41
42 @Override
43 public RundeckEvent parse(Node eventNode) {
44
45 RundeckEvent event = new RundeckEvent();
46
47 event.setTitle(StringUtils.trimToNull(eventNode.valueOf("title")));
48 try {
49 event.setStatus(EventStatus.valueOf(StringUtils.upperCase(eventNode.valueOf("status"))));
50 } catch (IllegalArgumentException e) {
51 event.setStatus(null);
52 }
53 event.setSummary(StringUtils.trimToNull(eventNode.valueOf("summary")));
54
55 NodeSummary nodeSummary = new NodeSummary();
56 nodeSummary.setSucceeded(Integer.valueOf(eventNode.valueOf("node-summary/@succeeded")));
57 nodeSummary.setFailed(Integer.valueOf(eventNode.valueOf("node-summary/@failed")));
58 nodeSummary.setTotal(Integer.valueOf(eventNode.valueOf("node-summary/@total")));
59 event.setNodeSummary(nodeSummary);
60
61 event.setUser(StringUtils.trimToNull(eventNode.valueOf("user")));
62 event.setProject(StringUtils.trimToNull(eventNode.valueOf("project")));
63 String startedAt = StringUtils.trimToNull(eventNode.valueOf("@starttime"));
64 if (startedAt != null) {
65 event.setStartedAt(new Date(Long.valueOf(startedAt)));
66 }
67 String endedAt = StringUtils.trimToNull(eventNode.valueOf("@endtime"));
68 if (endedAt != null) {
69 event.setEndedAt(new Date(Long.valueOf(endedAt)));
70 }
71 event.setAbortedBy(StringUtils.trimToNull(eventNode.valueOf("abortedby")));
72 try {
73 event.setExecutionId(Long.valueOf(eventNode.valueOf("execution/@id")));
74 } catch (NumberFormatException e) {
75 event.setExecutionId(null);
76 }
77 event.setJobId(StringUtils.trimToNull(eventNode.valueOf("job/@id")));
78
79 return event;
80 }
81
82 }