1 package org.rundeck.api.parser;
2
3 import org.dom4j.Node;
4 import org.rundeck.api.domain.DeleteExecutionsResponse;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9
10
11
12
13
14
15 public class DeleteExecutionsResponseParser extends BaseXpathParser<DeleteExecutionsResponse> {
16
17 public DeleteExecutionsResponseParser(final String xpath) {
18 super(xpath);
19 }
20
21 @Override public DeleteExecutionsResponse parse(final Node baseNode) {
22
23 final DeleteExecutionsResponse response = new DeleteExecutionsResponse();
24 response.setAllsuccessful(Boolean.parseBoolean(baseNode.valueOf("@allsuccessful")));
25 response.setRequestCount(Integer.parseInt(baseNode.valueOf("@requestCount")));
26 response.setSuccessCount(Integer.parseInt(baseNode.valueOf("successful/@count")));
27
28 final Node failedNode = baseNode.selectSingleNode("failed");
29
30 final List<DeleteExecutionsResponse.DeleteFailure> failures = new ArrayList
31 <DeleteExecutionsResponse.DeleteFailure>();
32 int failedCount = 0;
33 if (null != failedNode) {
34 failedCount = Integer.parseInt(baseNode.valueOf("failed/@count"));
35 final List list = baseNode.selectNodes("failed/execution");
36
37 for (final Object o : list) {
38 final Node execNode = (Node) o;
39 final DeleteExecutionsResponse.DeleteFailure deleteFailure =
40 new DeleteExecutionsResponse.DeleteFailure();
41 deleteFailure.setExecutionId(Long.parseLong(execNode.valueOf("@id")));
42 deleteFailure.setMessage(execNode.valueOf("@message"));
43 failures.add(deleteFailure);
44 }
45 }
46 response.setFailedCount(failedCount);
47 response.setFailures(failures);
48 return response;
49 }
50 }