View Javadoc

1   /*
2    * Copyright 2011 Vincent Behar
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rundeck.api.parser;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.dom4j.Node;
22  import org.rundeck.api.domain.RundeckJob;
23  import org.rundeck.api.domain.RundeckJobsImportResult;
24  
25  /**
26   * Parser for a single {@link RundeckJobsImportResult}
27   *
28   * @author Vincent Behar
29   */
30  public class JobsImportResultParser extends BaseXpathParser<RundeckJobsImportResult> {
31  
32  
33      public JobsImportResultParser(final String xpath) {
34          super(xpath);
35      }
36  
37      @Override
38      public RundeckJobsImportResult parse(Node resultNode) {
39  
40          RundeckJobsImportResult result = new RundeckJobsImportResult();
41  
42          @SuppressWarnings("unchecked")
43          List<Node> succeededJobsNodes = resultNode.selectNodes("succeeded/job");
44          if (succeededJobsNodes != null) {
45              for (Node succeededJobNode : succeededJobsNodes) {
46                  RundeckJob job = new JobParser().parseXmlNode(succeededJobNode);
47                  result.addSucceededJob(job);
48              }
49          }
50  
51          @SuppressWarnings("unchecked")
52          List<Node> skippedJobsNodes = resultNode.selectNodes("skipped/job");
53          if (skippedJobsNodes != null) {
54              for (Node skippedJobNode : skippedJobsNodes) {
55                  RundeckJob job = new JobParser().parseXmlNode(skippedJobNode);
56                  result.addSkippedJob(job);
57              }
58          }
59  
60          @SuppressWarnings("unchecked")
61          List<Node> failedJobsNodes = resultNode.selectNodes("failed/job");
62          if (failedJobsNodes != null) {
63              for (Node failedJobNode : failedJobsNodes) {
64                  RundeckJob job = new JobParser().parseXmlNode(failedJobNode);
65                  result.addFailedJob(job, failedJobNode.valueOf("error"));
66              }
67          }
68  
69          return result;
70      }
71  
72  }