1 : |
dgarcia |
1 |
package eu.smartlm.abs.portal.view.data;
|
2 : |
|
|
|
3 : |
|
|
import java.util.Calendar;
|
4 : |
|
|
import java.util.Date;
|
5 : |
|
|
import java.util.HashSet;
|
6 : |
|
|
import java.util.Set;
|
7 : |
|
|
|
8 : |
|
|
import eu.smartlm.abs.portal.security.login.controller.LoginController;
|
9 : |
|
|
import eu.smartlm.abs.portal.util.StringUtil;
|
10 : |
|
|
|
11 : |
|
|
/**
|
12 : |
|
|
* Class that represents the Accounting and Billing Query that the user does with the portlet
|
13 : |
|
|
* @author David García Pérez - CESGA
|
14 : |
|
|
*
|
15 : |
|
|
*/
|
16 : |
|
|
public class ABSQuery {
|
17 : |
|
|
//The different options
|
18 : |
|
|
public static int NUMBER_OF_OPTIONS = 6;
|
19 : |
|
|
public static String DATE_FORMAT = "yyyy/MM/dd";
|
20 : |
|
|
public static String PRODUCT = "Product";
|
21 : |
|
|
public static String USER = "User";
|
22 : |
|
|
public static String ACCOUNTINGGROUP = "AccountingGroup";
|
23 : |
|
|
public static String PROJECT = "Project";
|
24 : |
|
|
public static String HOST = "Host";
|
25 : |
|
|
public static String SUBMITHOST = "SubmitHost";
|
26 : |
|
|
|
27 : |
|
|
// Number of options
|
28 : |
|
|
private int numberOptions = NUMBER_OF_OPTIONS;
|
29 : |
|
|
|
30 : |
|
|
// Possible form fields
|
31 : |
|
|
private boolean products = true;
|
32 : |
|
|
private boolean users = true;
|
33 : |
|
|
private boolean accountingGroups = true;
|
34 : |
|
|
private boolean projects = true;
|
35 : |
|
|
private boolean hosts = true;
|
36 : |
|
|
private boolean submithosts = true;
|
37 : |
|
|
|
38 : |
|
|
// Possible Queries
|
39 : |
|
|
private Set<String> queryProducts = new HashSet<String>();
|
40 : |
|
|
private Set<String> queryUsers = new HashSet<String>();
|
41 : |
|
|
private Set<String> queryAccountingGroups = new HashSet<String>();
|
42 : |
|
|
private Set<String> queryOrganizations = new HashSet<String>();
|
43 : |
|
|
private Set<String> queryProjects = new HashSet<String>();
|
44 : |
|
|
private Set<String> queryHosts = new HashSet<String>();
|
45 : |
|
|
private Set<String> querySubmitHosts = new HashSet<String>();
|
46 : |
|
|
|
47 : |
|
|
// Possible Security Filters
|
48 : |
|
|
private Set<String> securityUserFilter = new HashSet<String>();
|
49 : |
|
|
private Set<String> securityAccountingGroupFilter = new HashSet<String>();
|
50 : |
|
|
|
51 : |
|
|
// Dates to search for Usage Records
|
52 : |
|
|
private String startDate = "";
|
53 : |
|
|
private String endDate = "";
|
54 : |
|
|
private String firstOption = "";
|
55 : |
|
|
private String secondOption = "";
|
56 : |
|
|
|
57 : |
|
|
//List of options to show in the forms
|
58 : |
|
|
private Set<String> options = new HashSet<String>();
|
59 : |
|
|
|
60 : |
|
|
private int loginStatus = LoginController.LOGGED_OUT;
|
61 : |
|
|
|
62 : |
|
|
public ABSQuery() {
|
63 : |
|
|
prepareOptions();
|
64 : |
|
|
}
|
65 : |
|
|
|
66 : |
|
|
private void prepareOptions() {
|
67 : |
|
|
options.clear();
|
68 : |
|
|
|
69 : |
|
|
options.add(PRODUCT);
|
70 : |
|
|
options.add(USER);
|
71 : |
|
|
options.add(ACCOUNTINGGROUP);
|
72 : |
|
|
options.add(PROJECT);
|
73 : |
|
|
options.add(HOST);
|
74 : |
|
|
options.add(SUBMITHOST);
|
75 : |
|
|
}
|
76 : |
|
|
|
77 : |
|
|
/**
|
78 : |
|
|
* It resets all the variables to its default values
|
79 : |
|
|
*/
|
80 : |
|
|
public void reset() {
|
81 : |
|
|
products = true;
|
82 : |
|
|
projects = true;
|
83 : |
|
|
users = true;
|
84 : |
|
|
accountingGroups = true;
|
85 : |
|
|
hosts = true;
|
86 : |
|
|
submithosts = true;
|
87 : |
|
|
numberOptions = NUMBER_OF_OPTIONS;
|
88 : |
|
|
|
89 : |
|
|
// We empty the already constructed query
|
90 : |
|
|
queryAccountingGroups.clear();
|
91 : |
|
|
queryHosts.clear();
|
92 : |
|
|
queryOrganizations.clear();
|
93 : |
|
|
queryProducts.clear();
|
94 : |
|
|
queryProjects.clear();
|
95 : |
|
|
querySubmitHosts.clear();
|
96 : |
|
|
queryUsers.clear();
|
97 : |
|
|
|
98 : |
|
|
// We make all the options available again
|
99 : |
|
|
prepareOptions();
|
100 : |
|
|
|
101 : |
|
|
// We reset the date fields
|
102 : |
|
|
Date today = new Date();
|
103 : |
|
|
|
104 : |
|
|
Calendar calendar = Calendar.getInstance();
|
105 : |
|
|
calendar.setTime(today);
|
106 : |
|
|
calendar.add(Calendar.DATE, -7);
|
107 : |
|
|
Date oneweekago = calendar.getTime();
|
108 : |
|
|
|
109 : |
|
|
startDate = StringUtil.dateToString(oneweekago);
|
110 : |
|
|
endDate = StringUtil.dateToString(today);
|
111 : |
|
|
|
112 : |
|
|
firstOption = "";
|
113 : |
|
|
secondOption = "";
|
114 : |
|
|
}
|
115 : |
|
|
|
116 : |
|
|
@Override
|
117 : |
|
|
public String toString() {
|
118 : |
|
|
String string = "";
|
119 : |
|
|
for(String option : options) {
|
120 : |
|
|
string = string + " " + option;
|
121 : |
|
|
}
|
122 : |
|
|
|
123 : |
|
|
string = string + " FIRST: " + firstOption + " Second: " + secondOption;
|
124 : |
|
|
|
125 : |
|
|
return string;
|
126 : |
|
|
}
|
127 : |
|
|
/**
|
128 : |
|
|
* @return the products
|
129 : |
|
|
*/
|
130 : |
|
|
public boolean isProducts() {
|
131 : |
|
|
return products;
|
132 : |
|
|
}
|
133 : |
|
|
/**
|
134 : |
|
|
* @param products the products to set
|
135 : |
|
|
*/
|
136 : |
|
|
public void setProducts(boolean products) {
|
137 : |
|
|
if(products) options.add(PRODUCT);
|
138 : |
|
|
else options.remove(PRODUCT);
|
139 : |
|
|
|
140 : |
|
|
this.products = products;
|
141 : |
|
|
}
|
142 : |
|
|
/**
|
143 : |
|
|
* @return the users
|
144 : |
|
|
*/
|
145 : |
|
|
public boolean isUsers() {
|
146 : |
|
|
return users;
|
147 : |
|
|
}
|
148 : |
|
|
/**
|
149 : |
|
|
* @param users the users to set
|
150 : |
|
|
*/
|
151 : |
|
|
public void setUsers(boolean users) {
|
152 : |
|
|
if(users) options.add(USER);
|
153 : |
|
|
else options.remove(USER);
|
154 : |
|
|
|
155 : |
|
|
this.users = users;
|
156 : |
|
|
}
|
157 : |
|
|
/**
|
158 : |
|
|
* @return the AccountingGroups
|
159 : |
|
|
*/
|
160 : |
|
|
public boolean isAccountingGroups() {
|
161 : |
|
|
return accountingGroups;
|
162 : |
|
|
}
|
163 : |
|
|
/**
|
164 : |
|
|
* @param departments the departments to set
|
165 : |
|
|
*/
|
166 : |
|
|
public void setAccountingGroups(boolean accountingGroups) {
|
167 : |
|
|
if(accountingGroups) options.add(ACCOUNTINGGROUP);
|
168 : |
|
|
else options.remove(ACCOUNTINGGROUP);
|
169 : |
|
|
|
170 : |
|
|
this.accountingGroups = accountingGroups;
|
171 : |
|
|
}
|
172 : |
|
|
|
173 : |
|
|
/**
|
174 : |
|
|
* @return the project
|
175 : |
|
|
*/
|
176 : |
|
|
public boolean isProjects() {
|
177 : |
|
|
return projects;
|
178 : |
|
|
}
|
179 : |
|
|
/**
|
180 : |
|
|
* @param project the project to set
|
181 : |
|
|
*/
|
182 : |
|
|
public void setProjects(boolean project) {
|
183 : |
|
|
if(project) options.add(PROJECT);
|
184 : |
|
|
else options.remove(PROJECT);
|
185 : |
|
|
|
186 : |
|
|
this.projects = project;
|
187 : |
|
|
}
|
188 : |
|
|
/**
|
189 : |
|
|
* @return the hosts
|
190 : |
|
|
*/
|
191 : |
|
|
public boolean isHosts() {
|
192 : |
|
|
return hosts;
|
193 : |
|
|
}
|
194 : |
|
|
/**
|
195 : |
|
|
* @param hosts the hosts to set
|
196 : |
|
|
*/
|
197 : |
|
|
public void setHosts(boolean hosts) {
|
198 : |
|
|
if(hosts) options.add(HOST);
|
199 : |
|
|
else options.remove(HOST);
|
200 : |
|
|
|
201 : |
|
|
this.hosts = hosts;
|
202 : |
|
|
}
|
203 : |
|
|
/**
|
204 : |
|
|
* @return the submithosts
|
205 : |
|
|
*/
|
206 : |
|
|
public boolean isSubmithosts() {
|
207 : |
|
|
return submithosts;
|
208 : |
|
|
}
|
209 : |
|
|
/**
|
210 : |
|
|
* @param submithosts the submithosts to set
|
211 : |
|
|
*/
|
212 : |
|
|
public void setSubmithosts(boolean submithosts) {
|
213 : |
|
|
if(submithosts) options.add(SUBMITHOST);
|
214 : |
|
|
else options.remove(SUBMITHOST);
|
215 : |
|
|
|
216 : |
|
|
this.submithosts = submithosts;
|
217 : |
|
|
}
|
218 : |
|
|
|
219 : |
|
|
/**
|
220 : |
|
|
* This method returns a list of options currently available for the form
|
221 : |
|
|
* @return options to be returned
|
222 : |
|
|
*/
|
223 : |
|
|
public Set<String> getOptions() {
|
224 : |
|
|
return options;
|
225 : |
|
|
}
|
226 : |
|
|
|
227 : |
|
|
/**
|
228 : |
|
|
* @param numberOptions the numberOptions to set
|
229 : |
|
|
*/
|
230 : |
|
|
public void setNumberOptions(int numberOptions) {
|
231 : |
|
|
this.numberOptions = numberOptions;
|
232 : |
|
|
}
|
233 : |
|
|
|
234 : |
|
|
/**
|
235 : |
|
|
* @return the numberOptions
|
236 : |
|
|
*/
|
237 : |
|
|
public int getNumberOptions() {
|
238 : |
|
|
return numberOptions;
|
239 : |
|
|
}
|
240 : |
|
|
|
241 : |
|
|
/**
|
242 : |
|
|
* @return the queryProducts
|
243 : |
|
|
*/
|
244 : |
|
|
public Set<String> getQueryProducts() {
|
245 : |
|
|
return queryProducts;
|
246 : |
|
|
}
|
247 : |
|
|
|
248 : |
|
|
/**
|
249 : |
|
|
* @param queryProducts the queryProducts to set
|
250 : |
|
|
*/
|
251 : |
|
|
public void setQueryProducts(Set<String> queryProducts) {
|
252 : |
|
|
this.queryProducts = queryProducts;
|
253 : |
|
|
}
|
254 : |
|
|
|
255 : |
|
|
/**
|
256 : |
|
|
* @return the queryUsers
|
257 : |
|
|
*/
|
258 : |
|
|
public Set<String> getQueryUsers() {
|
259 : |
|
|
return queryUsers;
|
260 : |
|
|
}
|
261 : |
|
|
|
262 : |
|
|
/**
|
263 : |
|
|
* @param queryUsers the queryUsers to set
|
264 : |
|
|
*/
|
265 : |
|
|
public void setQueryUsers(Set<String> queryUsers) {
|
266 : |
|
|
this.queryUsers = queryUsers;
|
267 : |
|
|
}
|
268 : |
|
|
|
269 : |
|
|
/**
|
270 : |
|
|
* @return the queryDepartments
|
271 : |
|
|
*/
|
272 : |
|
|
public Set<String> getQueryAccountingGroups() {
|
273 : |
|
|
return queryAccountingGroups;
|
274 : |
|
|
}
|
275 : |
|
|
|
276 : |
|
|
/**
|
277 : |
|
|
* @param queryDepartments the queryAccountingGroups to set
|
278 : |
|
|
*/
|
279 : |
|
|
public void setQueryAccountingGroups(Set<String> queryAccountingGroups) {
|
280 : |
|
|
this.queryAccountingGroups = queryAccountingGroups;
|
281 : |
|
|
}
|
282 : |
|
|
|
283 : |
|
|
/**
|
284 : |
|
|
* @return the queryOrganizations
|
285 : |
|
|
*/
|
286 : |
|
|
public Set<String> getQueryOrganizations() {
|
287 : |
|
|
return queryOrganizations;
|
288 : |
|
|
}
|
289 : |
|
|
|
290 : |
|
|
/**
|
291 : |
|
|
* @param queryOrganizations the queryOrganizations to set
|
292 : |
|
|
*/
|
293 : |
|
|
public void setQueryOrganizations(Set<String> queryOrganizations) {
|
294 : |
|
|
this.queryOrganizations = queryOrganizations;
|
295 : |
|
|
}
|
296 : |
|
|
|
297 : |
|
|
/**
|
298 : |
|
|
* @return the queryProjects
|
299 : |
|
|
*/
|
300 : |
|
|
public Set<String> getQueryProjects() {
|
301 : |
|
|
return queryProjects;
|
302 : |
|
|
}
|
303 : |
|
|
|
304 : |
|
|
/**
|
305 : |
|
|
* @param queryProjects the queryProjects to set
|
306 : |
|
|
*/
|
307 : |
|
|
public void setQueryProjects(Set<String> queryProjects) {
|
308 : |
|
|
this.queryProjects = queryProjects;
|
309 : |
|
|
}
|
310 : |
|
|
|
311 : |
|
|
/**
|
312 : |
|
|
* @return the queryHosts
|
313 : |
|
|
*/
|
314 : |
|
|
public Set<String> getQueryHosts() {
|
315 : |
|
|
return queryHosts;
|
316 : |
|
|
}
|
317 : |
|
|
|
318 : |
|
|
/**
|
319 : |
|
|
* @param queryHosts the queryHosts to set
|
320 : |
|
|
*/
|
321 : |
|
|
public void setQueryHosts(Set<String> queryHosts) {
|
322 : |
|
|
this.queryHosts = queryHosts;
|
323 : |
|
|
}
|
324 : |
|
|
|
325 : |
|
|
/**
|
326 : |
|
|
* @return the querySubmitHosts
|
327 : |
|
|
*/
|
328 : |
|
|
public Set<String> getQuerySubmitHosts() {
|
329 : |
|
|
return querySubmitHosts;
|
330 : |
|
|
}
|
331 : |
|
|
|
332 : |
|
|
/**
|
333 : |
|
|
* @param querySubmitHosts the querySubmitHosts to set
|
334 : |
|
|
*/
|
335 : |
|
|
public void setQuerySubmitHosts(Set<String> querySubmitHosts) {
|
336 : |
|
|
this.querySubmitHosts = querySubmitHosts;
|
337 : |
|
|
}
|
338 : |
|
|
|
339 : |
|
|
/**
|
340 : |
|
|
* @param startDate the startDate to set
|
341 : |
|
|
*/
|
342 : |
|
|
public void setStartDate(String startDate) {
|
343 : |
|
|
this.startDate = startDate;
|
344 : |
|
|
}
|
345 : |
|
|
|
346 : |
|
|
/**
|
347 : |
|
|
* @return the startDate
|
348 : |
|
|
*/
|
349 : |
|
|
public String getStartDate() {
|
350 : |
|
|
return startDate;
|
351 : |
|
|
}
|
352 : |
|
|
|
353 : |
|
|
/**
|
354 : |
|
|
* @param endDate the endDate to set
|
355 : |
|
|
*/
|
356 : |
|
|
public void setEndDate(String endDate) {
|
357 : |
|
|
this.endDate = endDate;
|
358 : |
|
|
}
|
359 : |
|
|
|
360 : |
|
|
/**
|
361 : |
|
|
* @return the endDate
|
362 : |
|
|
*/
|
363 : |
|
|
public String getEndDate() {
|
364 : |
|
|
return endDate;
|
365 : |
|
|
}
|
366 : |
|
|
|
367 : |
|
|
/**
|
368 : |
|
|
* @param firstOption the firstOption to set
|
369 : |
|
|
*/
|
370 : |
|
|
public void setFirstOption(String firstOption) {
|
371 : |
|
|
this.firstOption = firstOption;
|
372 : |
|
|
}
|
373 : |
|
|
|
374 : |
|
|
/**
|
375 : |
|
|
* @return the firstOption
|
376 : |
|
|
*/
|
377 : |
|
|
public String getFirstOption() {
|
378 : |
|
|
return firstOption;
|
379 : |
|
|
}
|
380 : |
|
|
|
381 : |
|
|
/**
|
382 : |
|
|
* @param secondOption the secondOption to set
|
383 : |
|
|
*/
|
384 : |
|
|
public void setSecondOption(String secondOption) {
|
385 : |
|
|
this.secondOption = secondOption;
|
386 : |
|
|
}
|
387 : |
|
|
|
388 : |
|
|
/**
|
389 : |
|
|
* @return the secondOption
|
390 : |
|
|
*/
|
391 : |
|
|
public String getSecondOption() {
|
392 : |
|
|
return secondOption;
|
393 : |
|
|
}
|
394 : |
|
|
|
395 : |
|
|
public void setSecurityUserFilter(Set<String> securityUserFilter) {
|
396 : |
|
|
this.securityUserFilter = securityUserFilter;
|
397 : |
|
|
}
|
398 : |
|
|
|
399 : |
|
|
public Set<String> getSecurityUserFilter() {
|
400 : |
|
|
return securityUserFilter;
|
401 : |
|
|
}
|
402 : |
|
|
|
403 : |
|
|
public void setSecurityAccountingGroupFilter(
|
404 : |
|
|
Set<String> securityAccountingGroupFilter) {
|
405 : |
|
|
this.securityAccountingGroupFilter = securityAccountingGroupFilter;
|
406 : |
|
|
}
|
407 : |
|
|
|
408 : |
|
|
public Set<String> getSecurityAccountingGroupFilter() {
|
409 : |
|
|
return securityAccountingGroupFilter;
|
410 : |
|
|
}
|
411 : |
|
|
|
412 : |
|
|
public void setLoginStatus(int loginStatus) {
|
413 : |
|
|
this.loginStatus = loginStatus;
|
414 : |
|
|
}
|
415 : |
|
|
|
416 : |
|
|
public int getLoginStatus() {
|
417 : |
|
|
return loginStatus;
|
418 : |
|
|
}
|
419 : |
|
|
}
|