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  * ExecutionQuery.java
20  * 
21  * User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
22  * Created: 9/13/12 3:18 PM
23  * 
24  */
25  package org.rundeck.api.query;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.rundeck.api.domain.RundeckExecution;
29  
30  import java.util.*;
31  
32  
33  /**
34   * ExecutionQuery contains the query parameters for the /executions api, build one with the {@link Builder} class, e.g.
35   * using the {@link #builder()} method.
36   *
37   * @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
38   */
39  public class ExecutionQuery  {
40      private RundeckExecution.ExecutionStatus status;
41      private String abortedby;
42      private List<String> jobList;
43      private List<String> jobIdList;
44      private List<String> excludeJobList;
45      private List<String> excludeJobIdList;
46      private Date begin;
47      private Date end;
48      private String recent;
49      private String job;
50      private String jobExact;
51      private String excludeJob;
52      private String excludeJobExact;
53      private String project;
54      private String groupPath;
55      private String groupPathExact;
56      private String excludeGroupPath;
57      private String excludeGroupPathExact;
58      private String user;
59      private String description;
60      private Boolean adhoc;
61  
62      private ExecutionQuery() {
63      }
64  
65      private ExecutionQuery(ExecutionQuery query) {
66          this.status = query.getStatus();
67          this.abortedby = query.getAbortedby();
68          this.jobList = query.getJobList();
69          this.jobIdList = query.getJobIdList();
70          this.excludeJobList = query.getExcludeJobList();
71          this.excludeJobIdList = query.getExcludeJobIdList();
72          this.begin = query.getBegin();
73          this.end = query.getEnd();
74          this.recent = query.getRecent();
75          this.job = query.getJob();
76          this.jobExact = query.getJobExact();
77          this.excludeJob = query.getExcludeJob();
78          this.excludeJobExact = query.getExcludeJobExact();
79          this.project = query.getProject();
80          this.groupPath = query.getGroupPath();
81          this.groupPathExact = query.getGroupPathExact();
82          this.excludeGroupPath = query.getExcludeGroupPath();
83          this.excludeGroupPathExact = query.getExcludeGroupPathExact();
84          this.description = query.getDescription();
85          this.user = query.getUser();
86          this.adhoc = query.getAdhoc();
87      }
88  
89      /**
90       * Return true if some parameter is set
91       */
92      public boolean notBlank() {
93          return null!=status ||
94                 !StringUtils.isBlank(abortedby) ||
95                 !StringUtils.isBlank(recent) ||
96                 !StringUtils.isBlank(job) ||
97                 !StringUtils.isBlank(jobExact) ||
98                 !StringUtils.isBlank(excludeJob) ||
99                 !StringUtils.isBlank(excludeJobExact) ||
100                !StringUtils.isBlank(groupPath) ||
101                !StringUtils.isBlank(groupPathExact) ||
102                !StringUtils.isBlank(excludeGroupPath) ||
103                !StringUtils.isBlank(excludeGroupPathExact) ||
104                !StringUtils.isBlank(description) ||
105                //boolean
106                (null!=adhoc) ||
107                //lists
108                (null != jobList && jobList.size() > 0) ||
109                (null != jobIdList && jobIdList.size() > 0) ||
110                (null != excludeJobList && excludeJobList.size() > 0) ||
111                (null != excludeJobIdList && excludeJobIdList.size() > 0) ||
112                //dates
113                (null != begin ) ||
114                (null != end )
115             ;
116     }
117 
118     public RundeckExecution.ExecutionStatus getStatus() {
119         return status;
120     }
121 
122     public String getAbortedby() {
123         return abortedby;
124     }
125 
126     public List<String> getJobList() {
127         return jobList;
128     }
129 
130     public List<String> getExcludeJobList() {
131         return excludeJobList;
132     }
133 
134     public List<String> getExcludeJobIdList() {
135         return excludeJobIdList;
136     }
137 
138     public Date getBegin() {
139         return begin;
140     }
141 
142     public Date getEnd() {
143         return end;
144     }
145 
146     public String getRecent() {
147         return recent;
148     }
149 
150     public String getJob() {
151         return job;
152     }
153 
154     public String getJobExact() {
155         return jobExact;
156     }
157 
158     public String getProject() {
159         return project;
160     }
161 
162     public String getGroupPath() {
163         return groupPath;
164     }
165 
166     public String getGroupPathExact() {
167         return groupPathExact;
168     }
169 
170     public String getDescription() {
171         return description;
172     }
173 
174     public List<String> getJobIdList() {
175         return jobIdList;
176     }
177 
178     /**
179      * Create a Builder for an ExecutionQuery
180      */
181     public static Builder builder() {
182         return new Builder();
183     }
184 
185     public String getUser() {
186         return user;
187     }
188 
189     public Boolean getAdhoc() {
190         return adhoc;
191     }
192 
193     public String getExcludeJob() {
194         return excludeJob;
195     }
196 
197     public String getExcludeJobExact() {
198         return excludeJobExact;
199     }
200 
201     public String getExcludeGroupPath() {
202         return excludeGroupPath;
203     }
204 
205     public String getExcludeGroupPathExact() {
206         return excludeGroupPathExact;
207     }
208 
209 
210     /**
211      * Builder for ExecutionQueries
212      */
213     public static class Builder {
214         ExecutionQuery query;
215 
216         public Builder() {
217             query = new ExecutionQuery();
218         }
219 
220         /**
221          * Execution status to query
222          */
223         public Builder status(RundeckExecution.ExecutionStatus status) {
224             query.status = status;
225             return this;
226         }
227 
228         /**
229          * Username
230          */
231         public Builder abortedby(String abortedby) {
232             query.abortedby = abortedby;
233             return this;
234         }
235 
236         /**
237          * List of job "group/name" to query
238          */
239         public Builder jobList(List<String> list) {
240             query.jobList = list;
241             return this;
242         }
243         /**
244          * List of job IDs to query
245          */
246         public Builder jobIdList(List<String> list) {
247             query.jobIdList = list;
248             return this;
249         }
250 
251         /**
252          * List of job "group/name" to exclude from query
253          */
254         public Builder excludeJobList(List<String> list) {
255             query.excludeJobList = list;
256             return this;
257         }
258 
259         /**
260          * List of job IDs to exclude from query
261          */
262         public Builder excludeJobIdList(List<String> list) {
263             query.excludeJobIdList = list;
264             return this;
265         }
266 
267         /**
268          * Start date/time for execution completion time
269          */
270         public Builder begin(Date begin) {
271             query.begin = begin;
272             return this;
273         }
274 
275         /**
276          * End date/time for execution completion time
277          */
278         public Builder end(Date end) {
279             query.end = end;
280             return this;
281         }
282 
283         /**
284          * Recent time filter, in the for "XY", where X is a number, and Y
285          * is one of: "h" (hour), "d" (day), "w" (week), "m" (month), "y" (year)
286          */
287         public Builder recent(String recent) {
288             query.recent = recent;
289             return this;
290         }
291 
292         /**
293          * Job name filter, which can match any part of the name
294          */
295         public Builder job(String job) {
296             query.job = job;
297             return this;
298         }
299 
300         /**
301          * Job exact name filter, much match exactly
302          */
303         public Builder jobExact(String exact) {
304             query.jobExact = exact;
305             return this;
306         }
307         /**
308          * Job name filter to exclude, which can match any part of the name
309          */
310         public Builder excludeJob(String job) {
311             query.excludeJob = job;
312             return this;
313         }
314 
315         /**
316          * Job exact name filter to exclude, much match exactly
317          */
318         public Builder excludeJobExact(String exact) {
319             query.excludeJobExact = exact;
320             return this;
321         }
322 
323         /**
324          * Project name
325          */
326         public Builder project(String project) {
327             query.project = project;
328             return this;
329         }
330 
331         /**
332          * Group path or super path, which will include any jobs within the subtree.
333          */
334         public Builder groupPath(String path) {
335             query.groupPath = path;
336             return this;
337         }
338 
339         /**
340          * Exact group path to include
341          */
342         public Builder groupPathExact(String exact) {
343             query.groupPathExact = exact;
344             return this;
345         }
346         /**
347          * Group path or super path, which will exclude any jobs within the subtree.
348          */
349         public Builder excludeGroupPath(String excludeGroupPath) {
350             query.excludeGroupPath = excludeGroupPath;
351             return this;
352         }
353 
354         /**
355          * Exact group path to exclude
356          */
357         public Builder excludeGroupPathExact(String excludeGroupPathExact) {
358             query.excludeGroupPathExact = excludeGroupPathExact;
359             return this;
360         }
361 
362         /**
363          * Job description match
364          */
365         public Builder description(String description) {
366             query.description = description;
367             return this;
368         }
369 
370         /**
371          * Name of username that started the execution
372          */
373         public Builder user(String user) {
374             query.user = user;
375             return this;
376         }
377 
378         /**
379          * True to query only adhoc executions, false to query only Job executions, null for both
380          */
381         public Builder adhoc(Boolean adhoc) {
382             query.adhoc = adhoc;
383             return this;
384         }
385 
386         /**
387          * Build the query
388          */
389         public ExecutionQuery build() {
390             return new ExecutionQuery(query);
391         }
392     }
393 }