package eu.smartlm.abs.portal.view.data; import java.util.Calendar; import java.util.Date; import java.util.HashSet; import java.util.Set; import eu.smartlm.abs.portal.security.login.controller.LoginController; import eu.smartlm.abs.portal.util.StringUtil; /** * Class that represents the Accounting and Billing Query that the user does with the portlet * @author David García Pérez - CESGA * */ public class ABSQuery { //The different options public static int NUMBER_OF_OPTIONS = 6; public static String DATE_FORMAT = "yyyy/MM/dd"; public static String PRODUCT = "Product"; public static String USER = "User"; public static String ACCOUNTINGGROUP = "AccountingGroup"; public static String PROJECT = "Project"; public static String HOST = "Host"; public static String SUBMITHOST = "SubmitHost"; // Number of options private int numberOptions = NUMBER_OF_OPTIONS; // Possible form fields private boolean products = true; private boolean users = true; private boolean accountingGroups = true; private boolean projects = true; private boolean hosts = true; private boolean submithosts = true; // Possible Queries private Set queryProducts = new HashSet(); private Set queryUsers = new HashSet(); private Set queryAccountingGroups = new HashSet(); private Set queryOrganizations = new HashSet(); private Set queryProjects = new HashSet(); private Set queryHosts = new HashSet(); private Set querySubmitHosts = new HashSet(); // Possible Security Filters private Set securityUserFilter = new HashSet(); private Set securityAccountingGroupFilter = new HashSet(); // Dates to search for Usage Records private String startDate = ""; private String endDate = ""; private String firstOption = ""; private String secondOption = ""; //List of options to show in the forms private Set options = new HashSet(); private int loginStatus = LoginController.LOGGED_OUT; public ABSQuery() { prepareOptions(); } private void prepareOptions() { options.clear(); options.add(PRODUCT); options.add(USER); options.add(ACCOUNTINGGROUP); options.add(PROJECT); options.add(HOST); options.add(SUBMITHOST); } /** * It resets all the variables to its default values */ public void reset() { products = true; projects = true; users = true; accountingGroups = true; hosts = true; submithosts = true; numberOptions = NUMBER_OF_OPTIONS; // We empty the already constructed query queryAccountingGroups.clear(); queryHosts.clear(); queryOrganizations.clear(); queryProducts.clear(); queryProjects.clear(); querySubmitHosts.clear(); queryUsers.clear(); // We make all the options available again prepareOptions(); // We reset the date fields Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(today); calendar.add(Calendar.DATE, -7); Date oneweekago = calendar.getTime(); startDate = StringUtil.dateToString(oneweekago); endDate = StringUtil.dateToString(today); firstOption = ""; secondOption = ""; } @Override public String toString() { String string = ""; for(String option : options) { string = string + " " + option; } string = string + " FIRST: " + firstOption + " Second: " + secondOption; return string; } /** * @return the products */ public boolean isProducts() { return products; } /** * @param products the products to set */ public void setProducts(boolean products) { if(products) options.add(PRODUCT); else options.remove(PRODUCT); this.products = products; } /** * @return the users */ public boolean isUsers() { return users; } /** * @param users the users to set */ public void setUsers(boolean users) { if(users) options.add(USER); else options.remove(USER); this.users = users; } /** * @return the AccountingGroups */ public boolean isAccountingGroups() { return accountingGroups; } /** * @param departments the departments to set */ public void setAccountingGroups(boolean accountingGroups) { if(accountingGroups) options.add(ACCOUNTINGGROUP); else options.remove(ACCOUNTINGGROUP); this.accountingGroups = accountingGroups; } /** * @return the project */ public boolean isProjects() { return projects; } /** * @param project the project to set */ public void setProjects(boolean project) { if(project) options.add(PROJECT); else options.remove(PROJECT); this.projects = project; } /** * @return the hosts */ public boolean isHosts() { return hosts; } /** * @param hosts the hosts to set */ public void setHosts(boolean hosts) { if(hosts) options.add(HOST); else options.remove(HOST); this.hosts = hosts; } /** * @return the submithosts */ public boolean isSubmithosts() { return submithosts; } /** * @param submithosts the submithosts to set */ public void setSubmithosts(boolean submithosts) { if(submithosts) options.add(SUBMITHOST); else options.remove(SUBMITHOST); this.submithosts = submithosts; } /** * This method returns a list of options currently available for the form * @return options to be returned */ public Set getOptions() { return options; } /** * @param numberOptions the numberOptions to set */ public void setNumberOptions(int numberOptions) { this.numberOptions = numberOptions; } /** * @return the numberOptions */ public int getNumberOptions() { return numberOptions; } /** * @return the queryProducts */ public Set getQueryProducts() { return queryProducts; } /** * @param queryProducts the queryProducts to set */ public void setQueryProducts(Set queryProducts) { this.queryProducts = queryProducts; } /** * @return the queryUsers */ public Set getQueryUsers() { return queryUsers; } /** * @param queryUsers the queryUsers to set */ public void setQueryUsers(Set queryUsers) { this.queryUsers = queryUsers; } /** * @return the queryDepartments */ public Set getQueryAccountingGroups() { return queryAccountingGroups; } /** * @param queryDepartments the queryAccountingGroups to set */ public void setQueryAccountingGroups(Set queryAccountingGroups) { this.queryAccountingGroups = queryAccountingGroups; } /** * @return the queryOrganizations */ public Set getQueryOrganizations() { return queryOrganizations; } /** * @param queryOrganizations the queryOrganizations to set */ public void setQueryOrganizations(Set queryOrganizations) { this.queryOrganizations = queryOrganizations; } /** * @return the queryProjects */ public Set getQueryProjects() { return queryProjects; } /** * @param queryProjects the queryProjects to set */ public void setQueryProjects(Set queryProjects) { this.queryProjects = queryProjects; } /** * @return the queryHosts */ public Set getQueryHosts() { return queryHosts; } /** * @param queryHosts the queryHosts to set */ public void setQueryHosts(Set queryHosts) { this.queryHosts = queryHosts; } /** * @return the querySubmitHosts */ public Set getQuerySubmitHosts() { return querySubmitHosts; } /** * @param querySubmitHosts the querySubmitHosts to set */ public void setQuerySubmitHosts(Set querySubmitHosts) { this.querySubmitHosts = querySubmitHosts; } /** * @param startDate the startDate to set */ public void setStartDate(String startDate) { this.startDate = startDate; } /** * @return the startDate */ public String getStartDate() { return startDate; } /** * @param endDate the endDate to set */ public void setEndDate(String endDate) { this.endDate = endDate; } /** * @return the endDate */ public String getEndDate() { return endDate; } /** * @param firstOption the firstOption to set */ public void setFirstOption(String firstOption) { this.firstOption = firstOption; } /** * @return the firstOption */ public String getFirstOption() { return firstOption; } /** * @param secondOption the secondOption to set */ public void setSecondOption(String secondOption) { this.secondOption = secondOption; } /** * @return the secondOption */ public String getSecondOption() { return secondOption; } public void setSecurityUserFilter(Set securityUserFilter) { this.securityUserFilter = securityUserFilter; } public Set getSecurityUserFilter() { return securityUserFilter; } public void setSecurityAccountingGroupFilter( Set securityAccountingGroupFilter) { this.securityAccountingGroupFilter = securityAccountingGroupFilter; } public Set getSecurityAccountingGroupFilter() { return securityAccountingGroupFilter; } public void setLoginStatus(int loginStatus) { this.loginStatus = loginStatus; } public int getLoginStatus() { return loginStatus; } }