1 package org.itracker.persistence.dao; 2 3 import org.itracker.model.Issue; 4 import org.itracker.model.IssueSearchQuery; 5 import org.itracker.model.PermissionType; 6 import org.itracker.model.User; 7 8 import java.util.Date; 9 import java.util.List; 10 import java.util.Map; 11 import java.util.Set; 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 * <p/> 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 * <p/> 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 * <p/> 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 * <p/> 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 * Get the next issues in the project based on ID. 231 * @param issueId the issue ID 232 * @return List of next issues in the project. 233 */ 234 List<Issue> findNextIssues(Integer issueId); 235 236 /** 237 * Get the next issues in the project based on ID. 238 * @param issueId the issue ID 239 * @return List of next issues in the project. 240 */ 241 List<Issue> findPreviousIssues(Integer issueId); 242 243 /** 244 * Count all Issues in database 245 */ 246 Long countAllIssues(); 247 248 /** 249 * Counts the number of issues attached to a component. 250 * 251 * @param componentId ID of the component 252 * @return number of issues 253 */ 254 Long countByComponent(Integer componentId); 255 256 /** 257 * Finds all issues of the version with the given ID. 258 * 259 * @param versionId ID of the version of which to retrieve all issues 260 * @return list of issues in no particular order 261 */ 262 List<Issue> findByVersion(Integer versionId); 263 264 /** 265 * Counts the number of issues attached to a version. 266 * 267 * @param versionId ID of the version 268 * @return number of issues 269 */ 270 Long countByVersion(Integer versionId); 271 272 /** 273 * Returns the modification date of the latest modified issue 274 * in the project with the given id. 275 * 276 * @param projectId ID of the project of which to retrieve the issues 277 * @return date of the most recent issue modification for the project. 278 * <tt>null</tt> if no issue exists in the project 279 */ 280 Date latestModificationDate(Integer projectId); 281 282 /** 283 * Query the list of issues that satisfies the search criteria 284 * specified in <code>queryModel</code>. 285 * 286 * @param queryModel The search criteria. 287 * @param user The currently logged-in user. 288 * @param userPermissions Permissions currently inforced. TODO: We could look this up instead of passing this as parameter. 289 */ 290 List<Issue> query(IssueSearchQuery queryModel, User user, Map<Integer, Set<PermissionType>> userPermissions); 291 292 /** 293 * Delete all issues targeted for the specified version. 294 * 295 * @param versionId the version ID. 296 */ 297 List<Issue> findByTargetVersion(Integer versionId); 298 299 300 }