|
| 1 | +package org.gitlab4j.api; |
| 2 | + |
| 3 | +import java.util.Date; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import javax.ws.rs.core.GenericType; |
| 7 | +import javax.ws.rs.core.Response; |
| 8 | + |
| 9 | +import org.gitlab4j.api.models.Event; |
| 10 | + |
| 11 | +/** |
| 12 | + * This class implements the client side API for the GitLab events calls. |
| 13 | + */ |
| 14 | +public class EventsApi extends AbstractApi { |
| 15 | + |
| 16 | + public EventsApi(GitLabApi gitLabApi) { |
| 17 | + super(gitLabApi); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * Get a list of events for the authenticated user. |
| 22 | + * |
| 23 | + * GET /events |
| 24 | + * |
| 25 | + * @param action include only events of a particular action type, optional |
| 26 | + * @param targetType include only events of a particular target type, optional |
| 27 | + * @param before include only events created before a particular date, optional |
| 28 | + * @param after include only events created after a particular date, optional |
| 29 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 30 | + * @return a list of events for the authenticated user and matching the supplied parameters |
| 31 | + * @throws GitLabApiException if any exception occurs |
| 32 | + */ |
| 33 | + public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, |
| 34 | + Date before, Date after, SortOrder sortOrder) throws GitLabApiException { |
| 35 | + return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, 1, getDefaultPerPage())); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Get a list of events for the authenticated user and in the specified page range. |
| 40 | + * |
| 41 | + * GET /events |
| 42 | + * |
| 43 | + * @param action include only events of a particular action type, optional |
| 44 | + * @param targetType include only events of a particular target type, optional |
| 45 | + * @param before include only events created before a particular date, optional |
| 46 | + * @param after include only events created after a particular date, optional |
| 47 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 48 | + * @param page the page to get |
| 49 | + * @param perPage the number of projects per page |
| 50 | + * @return a list of events for the authenticated user and matching the supplied parameters |
| 51 | + * @throws GitLabApiException if any exception occurs |
| 52 | + */ |
| 53 | + public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, |
| 54 | + Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException { |
| 55 | + |
| 56 | + GitLabApiForm formData = new GitLabApiForm() |
| 57 | + .withParam("action", action) |
| 58 | + .withParam("target_type", targetType) |
| 59 | + .withParam("before", before) |
| 60 | + .withParam("after", after) |
| 61 | + .withParam("sort", sortOrder) |
| 62 | + .withParam(PAGE_PARAM, page) |
| 63 | + .withParam(PER_PAGE_PARAM, perPage); |
| 64 | + |
| 65 | + Response response = get(Response.Status.OK, formData.asMap(), "events"); |
| 66 | + return (response.readEntity(new GenericType<List<Event>>() {})); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Get a list of events for the authenticated user and in the specified page range. |
| 71 | + * |
| 72 | + * GET /events |
| 73 | + * |
| 74 | + * @param action include only events of a particular action type, optional |
| 75 | + * @param targetType include only events of a particular target type, optional |
| 76 | + * @param before include only events created before a particular date, optional |
| 77 | + * @param after include only events created after a particular date, optional |
| 78 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 79 | + * @param itemsPerPage the number of Event instances that will be fetched per page |
| 80 | + * @return a Pager of events for the authenticated user and matching the supplied parameters |
| 81 | + * @throws GitLabApiException if any exception occurs |
| 82 | + */ |
| 83 | + public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after, |
| 84 | + SortOrder sortOrder, int itemsPerPage) throws GitLabApiException { |
| 85 | + |
| 86 | + GitLabApiForm formData = new GitLabApiForm() |
| 87 | + .withParam("action", action) |
| 88 | + .withParam("target_type", targetType) |
| 89 | + .withParam("before", before) |
| 90 | + .withParam("after", after) |
| 91 | + .withParam("sort", sortOrder); |
| 92 | + |
| 93 | + return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "events")); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Get a list of events for the specified user. |
| 98 | + * |
| 99 | + * GET /users/:userId/events |
| 100 | + * |
| 101 | + * @param userId the user ID to get the events for, required |
| 102 | + * @param action include only events of a particular action type, optional |
| 103 | + * @param targetType include only events of a particular target type, optional |
| 104 | + * @param before include only events created before a particular date, optional |
| 105 | + * @param after include only events created after a particular date, optional |
| 106 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 107 | + * @return a list of events for the specified user and matching the supplied parameters |
| 108 | + * @throws GitLabApiException if any exception occurs |
| 109 | + */ |
| 110 | + public List<Event> getUserEvents(Integer userId, ActionType action, TargetType targetType, |
| 111 | + Date before, Date after, SortOrder sortOrder) throws GitLabApiException { |
| 112 | + return (getUserEvents(userId, action, targetType, before, after, sortOrder, 1, getDefaultPerPage())); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Get a list of events for the specified user and in the specified page range. |
| 117 | + * |
| 118 | + * GET /users/:userId/events |
| 119 | + * |
| 120 | + * @param userId the user ID to get the events for, required |
| 121 | + * @param action include only events of a particular action type, optional |
| 122 | + * @param targetType include only events of a particular target type, optional |
| 123 | + * @param before include only events created before a particular date, optional |
| 124 | + * @param after include only events created after a particular date, optional |
| 125 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 126 | + * @param page the page to get |
| 127 | + * @param perPage the number of projects per page |
| 128 | + * @return a list of events for the specified user and matching the supplied parameters |
| 129 | + * @throws GitLabApiException if any exception occurs |
| 130 | + */ |
| 131 | + public List<Event> getUserEvents(Integer userId, ActionType action, TargetType targetType, |
| 132 | + Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException { |
| 133 | + |
| 134 | + if (userId == null) { |
| 135 | + throw new RuntimeException("user ID cannot be null"); |
| 136 | + } |
| 137 | + |
| 138 | + GitLabApiForm formData = new GitLabApiForm() |
| 139 | + .withParam("action", action) |
| 140 | + .withParam("target_type", targetType) |
| 141 | + .withParam("before", before) |
| 142 | + .withParam("after", after) |
| 143 | + .withParam("sort", sortOrder) |
| 144 | + .withParam(PAGE_PARAM, page) |
| 145 | + .withParam(PER_PAGE_PARAM, perPage); |
| 146 | + |
| 147 | + Response response = get(Response.Status.OK, formData.asMap(), "users", userId, "events"); |
| 148 | + return (response.readEntity(new GenericType<List<Event>>() {})); |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Get a list of events for the specified user and in the specified page range. |
| 153 | + * |
| 154 | + * GET /users/:userId/events |
| 155 | + * |
| 156 | + * @param userId the user ID to get the events for, required |
| 157 | + * @param action include only events of a particular action type, optional |
| 158 | + * @param targetType include only events of a particular target type, optional |
| 159 | + * @param before include only events created before a particular date, optional |
| 160 | + * @param after include only events created after a particular date, optional |
| 161 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 162 | + * @param itemsPerPage the number of Event instances that will be fetched per page |
| 163 | + * @return a Pager of events for the specified user and matching the supplied parameters |
| 164 | + * @throws GitLabApiException if any exception occurs |
| 165 | + */ |
| 166 | + public Pager<Event> getUserEvents(Integer userId, ActionType action, TargetType targetType, Date before, Date after, |
| 167 | + SortOrder sortOrder, int itemsPerPage) throws GitLabApiException { |
| 168 | + |
| 169 | + if (userId == null) { |
| 170 | + throw new RuntimeException("user ID cannot be null"); |
| 171 | + } |
| 172 | + |
| 173 | + GitLabApiForm formData = new GitLabApiForm() |
| 174 | + .withParam("action", action) |
| 175 | + .withParam("target_type", targetType) |
| 176 | + .withParam("before", before) |
| 177 | + .withParam("after", after) |
| 178 | + .withParam("sort", sortOrder); |
| 179 | + |
| 180 | + return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "users", userId, "events")); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Get a list of events for the specified project. |
| 185 | + * |
| 186 | + * GET /:projectId/events |
| 187 | + * |
| 188 | + * @param projectId the project ID to get the events for, required |
| 189 | + * @param action include only events of a particular action type, optional |
| 190 | + * @param targetType include only events of a particular target type, optional |
| 191 | + * @param before include only events created before a particular date, optional |
| 192 | + * @param after include only events created after a particular date, optional |
| 193 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 194 | + * @return a list of events for the specified project and matching the supplied parameters |
| 195 | + * @throws GitLabApiException if any exception occurs |
| 196 | + */ |
| 197 | + public List<Event> getProjectEvents(Integer projectId, ActionType action, TargetType targetType, |
| 198 | + Date before, Date after, SortOrder sortOrder) throws GitLabApiException { |
| 199 | + return (getProjectEvents(projectId, action, targetType, before, after, sortOrder, 1, getDefaultPerPage())); |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Get a list of events for the specified project and in the specified page range. |
| 204 | + * |
| 205 | + * GET /projects/:projectId/events |
| 206 | + * |
| 207 | + * @param projectId the project ID to get the events for, required |
| 208 | + * @param action include only events of a particular action type, optional |
| 209 | + * @param targetType include only events of a particular target type, optional |
| 210 | + * @param before include only events created before a particular date, optional |
| 211 | + * @param after include only events created after a particular date, optional |
| 212 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 213 | + * @param page the page to get |
| 214 | + * @param perPage the number of projects per page |
| 215 | + * @return a list of events for the specified project and matching the supplied parameters |
| 216 | + * @throws GitLabApiException if any exception occurs |
| 217 | + */ |
| 218 | + public List<Event> getProjectEvents(Integer projectId, ActionType action, TargetType targetType, |
| 219 | + Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException { |
| 220 | + |
| 221 | + if (projectId == null) { |
| 222 | + throw new RuntimeException("project ID cannot be null"); |
| 223 | + } |
| 224 | + |
| 225 | + GitLabApiForm formData = new GitLabApiForm() |
| 226 | + .withParam("action", action) |
| 227 | + .withParam("target_type", targetType) |
| 228 | + .withParam("before", before) |
| 229 | + .withParam("after", after) |
| 230 | + .withParam("sort", sortOrder) |
| 231 | + .withParam(PAGE_PARAM, page) |
| 232 | + .withParam(PER_PAGE_PARAM, perPage); |
| 233 | + |
| 234 | + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "events"); |
| 235 | + return (response.readEntity(new GenericType<List<Event>>() {})); |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * Get a list of events for the specified project and in the specified page range. |
| 240 | + * |
| 241 | + * GET /projects/:projectId/events |
| 242 | + * |
| 243 | + * @param projectId the project ID to get the events for, required |
| 244 | + * @param action include only events of a particular action type, optional |
| 245 | + * @param targetType include only events of a particular target type, optional |
| 246 | + * @param before include only events created before a particular date, optional |
| 247 | + * @param after include only events created after a particular date, optional |
| 248 | + * @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional |
| 249 | + * @param itemsPerPage the number of Event instances that will be fetched per page |
| 250 | + * @return a Pager of events for the specified project and matching the supplied parameters |
| 251 | + * @throws GitLabApiException if any exception occurs |
| 252 | + */ |
| 253 | + public Pager<Event> getProjectEvents(Integer projectId, ActionType action, TargetType targetType, Date before, Date after, |
| 254 | + SortOrder sortOrder, int itemsPerPage) throws GitLabApiException { |
| 255 | + |
| 256 | + if (projectId == null) { |
| 257 | + throw new RuntimeException("project ID cannot be null"); |
| 258 | + } |
| 259 | + |
| 260 | + GitLabApiForm formData = new GitLabApiForm() |
| 261 | + .withParam("action", action) |
| 262 | + .withParam("target_type", targetType) |
| 263 | + .withParam("before", before) |
| 264 | + .withParam("after", after) |
| 265 | + .withParam("sort", sortOrder); |
| 266 | + |
| 267 | + return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "projects", projectId, "events")); |
| 268 | + } |
| 269 | +} |
0 commit comments