View Javadoc

1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.model;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.apache.commons.collections.CollectionUtils;
28  import org.apache.commons.collections.Transformer;
29  import org.apache.commons.lang.builder.ToStringBuilder;
30  import org.itracker.persistence.dao.ProjectDAO;
31  
32  public class IssueSearchQuery implements Serializable {
33  
34  	/**
35  	 * 
36  	 */
37  	private static final long serialVersionUID = 1L;
38  	public static final Integer TYPE_FULL = 1;
39  	public static final Integer TYPE_PROJECT = 2;
40  
41  	private List<Project> availableProjects = new ArrayList<Project>();
42  
43  	private List<Integer> projects = new ArrayList<Integer>();
44  	private List<Integer> statuses = new ArrayList<Integer>();
45  	private List<Integer> severities = new ArrayList<Integer>();
46  	private List<Integer> components = new ArrayList<Integer>();
47  	private List<Integer> versions = new ArrayList<Integer>();
48  	private Integer targetVersion = null;
49  	private User owner = null;
50  	private User creator = null;
51  	private String text = null;
52  	private String resolution = null;
53  
54  	private String orderBy = null;
55  
56  	private Integer type = -1;
57  	private Project project = null;
58  	private Integer projectId = -1;
59  	private String projectName = "";
60  
61  	private List<Issue> results = null;
62  
63  	public IssueSearchQuery() {
64  	}
65  
66  	public List<Project> getAvailableProjects() {
67  		return availableProjects;
68  	}
69  
70  	public void setAvailableProjects(List<Project> value) {
71  		if (null != value) {
72  			availableProjects = Collections.unmodifiableList(value);
73  		} else {
74  			availableProjects = Collections.EMPTY_LIST;
75  		}
76  	}
77  
78  	public Project getProject() {
79  		return project;
80  	}
81  
82  	public void setProject(Project value) {
83  		project = value;
84  	}
85  
86  	public Integer getProjectId() {
87  		return (project == null ? projectId : project.getId());
88  	}
89  
90  	public void setProjectId(Integer value) {
91  		projectId = value;
92  
93  	}
94  
95  	public String getProjectName() {
96  		return (project == null ? projectName : project.getName());
97  	}
98  
99  	public void setProjectName(String value) {
100 		projectName = value;
101 	}
102 
103 	public List<Integer> getProjects() {
104 		return projects;
105 	}
106 
107 	public void setProjects(List<Integer> value) {
108 		if (value != null) {
109 			projects = Collections.unmodifiableList(value);
110 		} else {
111 			projects = Collections.EMPTY_LIST;
112 		}
113 	}
114 
115 	public List<Integer> getSeverities() {
116 		return severities;
117 	}
118 
119 	public void setSeverities(List<Integer> value) {
120 		if (value != null) {
121 			severities = Collections.unmodifiableList(value);
122 		} else {
123 			severities = Collections.EMPTY_LIST;
124 		}
125 	}
126 
127 	public List<Integer> getStatuses() {
128 		return statuses;
129 	}
130 
131 	public void setStatuses(List<Integer> value) {
132 		if (value != null) {
133 			statuses = Collections.unmodifiableList(value);
134 		} else {
135 			statuses = Collections.EMPTY_LIST;
136 		}
137 	}
138 
139 	public List<Integer> getComponents() {
140 		return components;
141 	}
142 
143 	public void setComponents(List<Integer> value) {
144 		
145 		if (value != null) {
146 			components = Collections.unmodifiableList(value);
147 		} else {
148 			components = Collections.EMPTY_LIST;
149 		}
150 	}
151 
152 	public List<Integer> getVersions() {
153 		return versions;
154 	}
155 
156 	public void setVersions(List<Integer> value) {
157 		if (value != null) {
158 			versions = Collections.unmodifiableList(value);
159 		} else {
160 			versions = Collections.EMPTY_LIST;
161 		}
162 	}
163 
164 	public Integer getTargetVersion() {
165 		return targetVersion;
166 	}
167 
168 	public void setTargetVersion(Integer value) {
169 		targetVersion = value;
170 	}
171 
172 	public User getOwner() {
173 		return owner;
174 	}
175 
176 	public void setOwner(User value) {
177 		owner = value;
178 	}
179 
180 	public User getCreator() {
181 		return creator;
182 	}
183 
184 	public void setCreator(User value) {
185 		creator = value;
186 	}
187 
188 	public String getText() {
189 		return text;
190 	}
191 
192 	public void setText(String value) {
193 		text = value;
194 	}
195 
196 	public String getResolution() {
197 		return resolution;
198 	}
199 
200 	public void setResolution(String value) {
201 		resolution = value;
202 	}
203 
204 	public String getOrderBy() {
205 		return orderBy;
206 	}
207 
208 	public void setOrderBy(String value) {
209 		orderBy = value;
210 	}
211 
212 	public Integer getType() {
213 		return type;
214 	}
215 
216 	public void setType(Integer value) {
217 		type = value;
218 	}
219 
220 	public List<Issue> getResults() {
221 		return results;
222 	}
223 
224 	public void setResults(List<Issue> value) {
225 		results = value;
226 	}
227 
228 	@Override
229 	public String toString() {
230 		return new ToStringBuilder(this).append("type", this.type).append(
231 				"severities", severities).append("text", text).append(
232 				"resoution", resolution).append("results", results).toString();
233 	}
234 
235 	/*
236 	 * this class is coded to keep integer ids, instead of objects the following
237 	 * methods exist to temporarily work around this.
238 	 * 
239 	 * the proper fix would be to always keep objects
240 	 */
241 
242 	// from the list of project ids this objects has, return a list of
243 	// projects
244 	public Collection<?> getProjectsObjects(final ProjectDAO projectDAO) {
245 		return CollectionUtils.collect(getProjects(), new Transformer() {
246 			public Object transform(Object arg0) {
247 				return projectDAO.findByPrimaryKey((Integer) arg0);
248 			}
249 		});
250 	}
251 }