View Javadoc

1   /*
2    * Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
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   */
17  
18  /*
19  * BulkDeleteParser.java
20  * 
21  * User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
22  * Created: 10/1/12 3:55 PM
23  * 
24  */
25  package org.rundeck.api.parser;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.dom4j.Node;
29  import org.rundeck.api.domain.RundeckJobDelete;
30  import org.rundeck.api.domain.RundeckJobDeleteBulk;
31  
32  import java.util.*;
33  
34  
35  /**
36   * BulkDeleteParser is ...
37   *
38   * @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
39   */
40  public class BulkDeleteParser extends BaseXpathParser<RundeckJobDeleteBulk> {
41  
42  
43      public BulkDeleteParser(final String xpath) {
44          super(xpath);
45      }
46  
47      @Override
48      public RundeckJobDeleteBulk parse(Node subnode) {
49          final ArrayList<RundeckJobDelete> deletes = new ArrayList<RundeckJobDelete>();
50          final List results = subnode.selectNodes("(succeeded|failed)/deleteJobResult");
51          final DeleteParser parser = new DeleteParser();
52          if (null != results && results.size() > 0) {
53              for (final Object o : results) {
54                  deletes.add(parser.parseXmlNode((Node) o));
55              }
56          }
57  
58          final String requestcount = StringUtils.trimToNull(subnode.valueOf("@requestCount"));
59          final String allsuccessString = StringUtils.trimToNull(subnode.valueOf("@allsuccessful"));
60          int count = 0;
61          boolean allsuccess = false;
62          if (null != requestcount) {
63              try {
64                  count = Integer.parseInt(requestcount);
65              } catch (NumberFormatException e) {
66  
67              }
68          }
69          if (null != allsuccessString) {
70              allsuccess = Boolean.parseBoolean(allsuccessString);
71          }
72  
73          return new RundeckJobDeleteBulk(deletes, count, allsuccess);
74      }
75  }