1 package org.itracker.persistence.dao;
2
3 import java.util.Date;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.Set;
7
8 import org.itracker.model.Issue;
9 import org.itracker.model.IssueSearchQuery;
10 import org.itracker.model.PermissionType;
11 import org.itracker.model.User;
12
13 /**
14 * Issue Data Access Object interface.
15 */
16 public interface IssueDAO extends BaseDAO<Issue> {
17
18 /**
19 * Finds the issue with the given ID.
20 *
21 * <p>PENDING: should this method throw a NoSuchEntityException
22 * instead of returning null if the issue doesn't exist ? </p>
23 *
24 * @param issueId ID of the issue to retrieve
25 * @return issue with the given ID or <tt>null</tt> if none exits
26 */
27 Issue findByPrimaryKey(Integer issueId);
28
29 /**
30 * Finds all issues in all projects.
31 *
32 * <p>PENDING: do we really need to retrieve all issues at once ?
33 * It can cause OutOfMemoryError depending on the DB size!
34 * Consider scrolling through an issues result set in case we really do.
35 * </p>
36 *
37 * @return list of exiting issues, in an unspecified order
38 * @deprecated don't use due to expensive memory use.
39 */
40 List<Issue> findAll();
41
42 /**
43 * Finds all issues in the given status in all projects.
44 *
45 * @param status status of the issues to return
46 * @return list of issues matching the above filter, in an unspecified order
47 */
48 List<Issue> findByStatus(int status);
49
50 /**
51 * Finds all issues with a status less than the given one in all projects.
52 *
53 * @param maxExclusiveStatus all issues under this status will be returned
54 * @return list of issues matching the above filter, in an unspecified order
55 */
56 List<Issue> findByStatusLessThan(int maxExclusiveStatus);
57
58 /**
59 * Finds all issues with a status less than or equal to the given status
60 * in all projects.
61 *
62 * @param maxStatus all issues less that or equal to this status will be returned
63 * @return list of issues matching the above filter, in an unspecified order
64 */
65 List<Issue> findByStatusLessThanEqualTo(int maxStatus);
66
67 /**
68 * Finds all issues with a status less than or equal to the given status
69 * in active and viewable projects.
70 *
71 * @param maxStatus all issues less that or equal to this status will be returned
72 * @return list of issues matching the above filter, in an unspecified order
73 */
74 List<Issue> findByStatusLessThanEqualToInAvailableProjects(int maxStatus);
75
76 /**
77 * Finds all issues with the given severity in all projects.
78 *
79 * @param severity severity of the issues to return
80 * @return list of issues matching the above filter, in an unspecified order
81 */
82 List<Issue> findBySeverity(int severity);
83
84 /**
85 * Finds all issues of the given project.
86 *
87 * @param projectId ID of the project of which to retrieve all issues
88 * @return list of issues in no particular order
89 */
90 List<Issue> findByProject(Integer projectId);
91
92 /**
93 * Counts the number of issues of the given project.
94 *
95 * @param projectId ID of the project of which to count issues
96 * @return number of issues
97 */
98 Long countByProject(Integer projectId);
99
100 /**
101 * Finds all issues of the given project with a status lower than
102 * the given one.
103 *
104 * @param projectId ID of the project of which to retrieve the issues
105 * @param maxExclusiveStatus all issues under this status will be returned
106 * @return list of issues matching the above filter, in an unspecified order
107 */
108 List<Issue> findByProjectAndLowerStatus(Integer projectId,
109 int maxExclusiveStatus);
110
111 /**
112 * Counts the number of issues of the given project with a status
113 * lower than the given one.
114 *
115 * @param projectId ID of the project of which to count issues
116 * @param maxExclusiveStatus all issues under this status will be counted
117 * @return number of issues
118 */
119 Long countByProjectAndLowerStatus(Integer projectId,
120 int maxExclusiveStatus);
121
122 /**
123 * Finds all issues of the given project with a status higher than
124 * or equal to the given one.
125 *
126 * @param projectId ID of the project of which to retrieve the issues
127 * @param minStatus all issues with this status or above will be returned
128 * @return list of issues matching the above filter, in an unspecified order
129 */
130 List<Issue> findByProjectAndHigherStatus(Integer projectId,
131 int minStatus);
132
133 /**
134 * Counts the number of issues of the given project with a status
135 * higher than or equal to the given one.
136 *
137 * @param projectId ID of the project of which to count issues
138 * @param minStatus all issues with this status or above will be counted
139 * @return number of issues
140 */
141 Long countByProjectAndHigherStatus(Integer projectId, int minStatus);
142
143 /**
144 * Finds all issues owned by the given user in all projects
145 * and with a status lower than the given one.
146 *
147 * @param ownerId ID of the user who owns the issues to return
148 * @param maxExclusiveStatus status under which to return issues
149 * @return list of issues matching the above filter, in an unspecified order
150 */
151 List<Issue> findByOwner(Integer ownerId, int maxExclusiveStatus);
152
153 /**
154 * Finds all issues owned by the given user in all active and viewable
155 * projects and with a status less than the given one.
156 *
157 * @param ownerId ID of the user who owns the issues to return
158 * @param maxExclusiveStatus status under which to return issues
159 * @return list of issues matching the above filter, in an unspecified order
160 */
161 List<Issue> findByOwnerInAvailableProjects(Integer ownerId,
162 int maxExclusiveStatus);
163
164 /**
165 * Finds all issues without owner with a status less than
166 * or equal to the given one in all projects.
167 *
168 * @param maxStatus maximum status allowed for the issues to return
169 * @return list of issues matching the above filter, in an unspecified order
170 */
171 List<Issue> findUnassignedIssues(int maxStatus);
172
173 /**
174 * Finds all issues created by the given user in all projects
175 * and with a status less than the given one.
176 *
177 * @param userId ID of the user who created the issues to return
178 * @param maxExclusiveStatus all issues under this status will be returned
179 * @return list of issues matching the above filter, in an unspecified order
180 */
181 List<Issue> findByCreator(Integer creatorId, int maxExclusiveStatus);
182
183 /**
184 * Finds all issues created by the given user in all active and viewable
185 * projects and with a status less than the given one.
186 *
187 * @param userId ID of the user who created the issues to return
188 * @param maxExclusiveStatus all issues under this status will be returned
189 * @return list of issues matching the above filter, in an unspecified order
190 */
191 List<Issue> findByCreatorInAvailableProjects(Integer creatorId,
192 int maxExclusiveStatus);
193
194 /**
195 * Finds all issues with notifications for the given user in all projects
196 * and with a status less than the given one.
197 *
198 * <p>Only 1 instance of every issue is returned, even if multiple
199 * notifications exist for an issue. </p>
200 *
201 * @param userId ID of the user with notifications for the issues to return
202 * @param maxExclusiveStatus all issues under this status will be returned
203 * @return list of issues matching the above filter, in an unspecified order
204 */
205 List<Issue> findByNotification(Integer userId, int maxExclusiveStatus);
206
207 /**
208 * Finds all issues with notifications for the given user in active
209 * and viewable projects.
210 *
211 * <p>Only 1 instance of every issue is returned, even if multiple
212 * notifications exist for an issue. </p>
213 *
214 * @param userId ID of the user with notifications for the issues to return
215 * @param maxExclusiveStatus all issues under this status will be returned
216 * @return list of issues matching the above filter, in an unspecified order
217 */
218 List<Issue> findByNotificationInAvailableProjects(Integer userId,
219 int maxExclusiveStatus);
220
221 /**
222 * Finds all issues of the component with the given ID.
223 *
224 * @param componentId ID of the component of which to retrieve all issues
225 * @return list of issues in no particular order
226 */
227 List<Issue> findByComponent(Integer componentId);
228
229 /**
230 * Count all Issues in database
231 *
232 * @return
233 */
234 Long countAllIssues();
235
236 /**
237 * Counts the number of issues attached to a component.
238 *
239 * @param componentId ID of the component
240 * @return number of issues
241 */
242 Long countByComponent(Integer componentId);
243
244 /**
245 * Finds all issues of the version with the given ID.
246 *
247 * @param versionId ID of the version of which to retrieve all issues
248 * @return list of issues in no particular order
249 */
250 List<Issue> findByVersion(Integer versionId);
251
252 /**
253 * Counts the number of issues attached to a version.
254 *
255 * @param versionId ID of the version
256 * @return number of issues
257 */
258 Long countByVersion(Integer versionId);
259
260 /**
261 * Returns the modification date of the latest modified issue
262 * in the project with the given id.
263 *
264 * @param projectId ID of the project of which to retrieve the issues
265 * @return date of the most recent issue modification for the project.
266 * <tt>null</tt> if no issue exists in the project
267 */
268 Date latestModificationDate(Integer projectId);
269
270 /**
271 * Query the list of issues that satisfies the search criteria
272 * specified in <code>queryModel</code>.
273 *
274 * @param queryModel The search criteria.
275 * @param user The currently logged-in user.
276 * @param userPermissions Permissions currently inforced. TODO: We could look this up instead of passing this as parameter.
277 * @return
278 */
279 List<Issue> query(IssueSearchQuery queryModel, User user, Map<Integer, Set<PermissionType>> userPermissions);
280
281 /**
282 * Delete all issues targeted for the specified version.
283 * @param versionId the version ID.
284 */
285 List<Issue> findByTargetVersion(Integer versionId);
286
287
288 }