|
| 1 | +package org.gitlab4j.api; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.Optional; |
| 5 | +import java.util.stream.Stream; |
| 6 | + |
| 7 | +import javax.ws.rs.core.GenericType; |
| 8 | +import javax.ws.rs.core.Response; |
| 9 | + |
| 10 | +import org.gitlab4j.api.models.Board; |
| 11 | +import org.gitlab4j.api.models.BoardList; |
| 12 | + |
| 13 | +/** |
| 14 | + * This class implements the client side API for the GitLab Issue Boards API calls. |
| 15 | + * |
| 16 | + * NOTE: If a user is not a member of a group and the group is private, |
| 17 | + * a GET request on that group will result to a 404 status code. |
| 18 | + * |
| 19 | + * @see <a href="https://docs.gitlab.com/ce/api/boards.html">GitLab Issue Boards API Documentaion</a> |
| 20 | + */ |
| 21 | +public class BoardsApi extends AbstractApi { |
| 22 | + |
| 23 | + public BoardsApi(GitLabApi gitLabApi) { |
| 24 | + super(gitLabApi); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Lists Issue Boards in the given project. |
| 29 | + * |
| 30 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards</code></pre> |
| 31 | + * |
| 32 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 33 | + * @return a list of project's issue boards |
| 34 | + * @throws GitLabApiException if any exception occurs |
| 35 | + */ |
| 36 | + public List<Board> getBoards(Object projectIdOrPath) throws GitLabApiException { |
| 37 | + return (getBoards(projectIdOrPath, getDefaultPerPage()).all()); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Get all issue boards for the specified project using the specified page and per page setting |
| 42 | + * |
| 43 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards</code></pre> |
| 44 | + * |
| 45 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 46 | + * @param page the page to get |
| 47 | + * @param perPage the number of items per page |
| 48 | + * @return a list of project's Boards in the specified range |
| 49 | + * @throws GitLabApiException if any exception occurs |
| 50 | + */ |
| 51 | + public List<Board> getBoards(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { |
| 52 | + Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), |
| 53 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards"); |
| 54 | + return (response.readEntity(new GenericType<List<Board>>() {})); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Get a Pager of all issue boards for the specified project. |
| 59 | + * |
| 60 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards</code></pre> |
| 61 | + * |
| 62 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 63 | + * @param itemsPerPage the number of items per page |
| 64 | + * @return a Pager of project's issue boards |
| 65 | + * @throws GitLabApiException if any exception occurs |
| 66 | + */ |
| 67 | + public Pager<Board> getBoards(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { |
| 68 | + return (new Pager<Board>(this, Board.class, itemsPerPage, null, |
| 69 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards")); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Get a Stream of all issue boards for the specified project. |
| 74 | + * |
| 75 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards</code></pre> |
| 76 | + * |
| 77 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 78 | + * @return a Stream of project's issue boards |
| 79 | + * @throws GitLabApiException if any exception occurs |
| 80 | + */ |
| 81 | + public Stream<Board> getBoardsStream(Object projectIdOrPath) throws GitLabApiException { |
| 82 | + return (getBoards(projectIdOrPath, getDefaultPerPage()).stream()); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Get a single issue board. |
| 87 | + * |
| 88 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id</code></pre> |
| 89 | + * |
| 90 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 91 | + * @param boardId the ID of the board |
| 92 | + * @return a Board instance for the specified board ID |
| 93 | + * @throws GitLabApiException if any exception occurs |
| 94 | + */ |
| 95 | + public Board getBoard(Object projectIdOrPath, Integer boardId) throws GitLabApiException { |
| 96 | + Response response = get(Response.Status.OK, null, |
| 97 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId); |
| 98 | + return (response.readEntity(Board.class)); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Get an issue board as an Optional instance. |
| 103 | + * |
| 104 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id</code></pre> |
| 105 | + * |
| 106 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 107 | + * @param boardId the ID of the board |
| 108 | + * @return the Board instance for the specified board ID as an Optional instance |
| 109 | + */ |
| 110 | + public Optional<Board> getOptionalBoard(Object projectIdOrPath, Integer boardId) { |
| 111 | + try { |
| 112 | + return (Optional.ofNullable(getBoard(projectIdOrPath, boardId))); |
| 113 | + } catch (GitLabApiException glae) { |
| 114 | + return (GitLabApi.createOptionalFromException(glae)); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Get a list of the board’s lists. Does not include open and closed lists. |
| 120 | + * |
| 121 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id/lists</code></pre> |
| 122 | + * |
| 123 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 124 | + * @param boardId the ID of the board |
| 125 | + * @return a list of the issue board's lists |
| 126 | + * @throws GitLabApiException if any exception occurs |
| 127 | + */ |
| 128 | + public List<BoardList> getBoardLists(Object projectIdOrPath, Integer boardId) throws GitLabApiException { |
| 129 | + return (getBoardLists(projectIdOrPath, boardId, getDefaultPerPage()).all()); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Get a list of the board’s lists for the specified project to using the specified page and per page setting. |
| 134 | + * Does not include open and closed lists. |
| 135 | + * |
| 136 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id/lists</code></pre> |
| 137 | + * |
| 138 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 139 | + * @param boardId the ID of the board |
| 140 | + * @param page the page to get |
| 141 | + * @param perPage the number of Boards per page |
| 142 | + * @return a list of the issue board's lists in the specified range |
| 143 | + * @throws GitLabApiException if any exception occurs |
| 144 | + */ |
| 145 | + public List<BoardList> getBoardLists(Object projectIdOrPath, Integer boardId, int page, int perPage) throws GitLabApiException { |
| 146 | + Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), |
| 147 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId, "lists"); |
| 148 | + return (response.readEntity(new GenericType<List<BoardList>>() {})); |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Get a Pager of the board’s lists. Does not include open and closed lists. |
| 153 | + * |
| 154 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id/lists</code></pre> |
| 155 | + * |
| 156 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 157 | + * @param boardId the ID of the board |
| 158 | + * @param itemsPerPage the number of Board instances that will be fetched per page |
| 159 | + * @return a Pager of the issue board's lists |
| 160 | + * @throws GitLabApiException if any exception occurs |
| 161 | + */ |
| 162 | + public Pager<BoardList> getBoardLists(Object projectIdOrPath, Integer boardId, int itemsPerPage) throws GitLabApiException { |
| 163 | + return (new Pager<BoardList>(this, BoardList.class, itemsPerPage, null, |
| 164 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId, "lists")); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Get a Stream of the board’s lists. Does not include open and closed lists. |
| 169 | + * |
| 170 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id/lists</code></pre> |
| 171 | + * |
| 172 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 173 | + * @param boardId the ID of the board |
| 174 | + * @return a Stream of the issue board's lists |
| 175 | + * @throws GitLabApiException if any exception occurs |
| 176 | + */ |
| 177 | + public Stream<BoardList> getBoardsListsStream(Object projectIdOrPath, Integer boardId) throws GitLabApiException { |
| 178 | + return (getBoardLists(projectIdOrPath, boardId, getDefaultPerPage()).stream()); |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Get a single issue board list. |
| 183 | + * |
| 184 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id/lists/:list_id</code></pre> |
| 185 | + * |
| 186 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 187 | + * @param boardId the ID of the board |
| 188 | + * @param listId the ID of the board lists to get |
| 189 | + * @return a BoardList instance for the specified board ID and list ID |
| 190 | + * @throws GitLabApiException if any exception occurs |
| 191 | + */ |
| 192 | + public BoardList getBoardList(Object projectIdOrPath, Integer boardId, Integer listId) throws GitLabApiException { |
| 193 | + Response response = get(Response.Status.OK, null, |
| 194 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId, "lists", listId); |
| 195 | + return (response.readEntity(BoardList.class)); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Get a single issue board list as an Optional instance. |
| 200 | + * |
| 201 | + * <pre><code>GitLab Endpoint: GET /projects/:id/boards/:board_id/lists/:list_id</code></pre> |
| 202 | + * |
| 203 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 204 | + * @param boardId the ID of the board |
| 205 | + * @param listId the ID of the board lists to get |
| 206 | + * @return a BoardList instance for the specified board ID and list ID as an Optional instance |
| 207 | + */ |
| 208 | + public Optional<BoardList> getOptionalBoardList(Object projectIdOrPath, Integer boardId, Integer listId) { |
| 209 | + try { |
| 210 | + return (Optional.ofNullable(getBoardList(projectIdOrPath, boardId, listId))); |
| 211 | + } catch (GitLabApiException glae) { |
| 212 | + return (GitLabApi.createOptionalFromException(glae)); |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Creates a new Issue Board list. |
| 218 | + * |
| 219 | + * <pre><code>GitLab Endpoint: POST /projects/:id/boards/:board_id/lists</code></pre> |
| 220 | + * |
| 221 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 222 | + * @param boardId the ID of the board |
| 223 | + * @param labelId the ID of the label |
| 224 | + * @return the created BoardList instance |
| 225 | + * @throws GitLabApiException if any exception occurs |
| 226 | + */ |
| 227 | + public BoardList createBoardList(Object projectIdOrPath, Integer boardId, Integer labelId) throws GitLabApiException { |
| 228 | + GitLabApiForm formData = new GitLabApiForm() |
| 229 | + .withParam("label_id", labelId, true); |
| 230 | + Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId, "lists"); |
| 231 | + return (response.readEntity(BoardList.class)); |
| 232 | + } |
| 233 | + |
| 234 | + /** |
| 235 | + * Updates an existing Issue Board list. This call is used to change list position. |
| 236 | + * |
| 237 | + * <pre><code>GitLab Endpoint: PUT /projects/:id/boards/:board_id/lists/:list_id</code></pre> |
| 238 | + * |
| 239 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 240 | + * @param boardId the ID of the board |
| 241 | + * @param listId the ID of the list |
| 242 | + * @param position the new position for the list |
| 243 | + * @return the updated BoardList instance |
| 244 | + * @throws GitLabApiException if any exception occurs |
| 245 | + */ |
| 246 | + public BoardList updateBoardList(Object projectIdOrPath, Integer boardId, Integer listId, Integer position) throws GitLabApiException { |
| 247 | + GitLabApiForm formData = new GitLabApiForm().withParam("position", position, true); |
| 248 | + Response response = putWithFormData(Response.Status.OK, formData, |
| 249 | + "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId, "lists", listId); |
| 250 | + return (response.readEntity(BoardList.class)); |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * Soft deletes an existing Issue Board list. Only for admins and project owners. |
| 255 | + * |
| 256 | + * <pre><code>GitLab Endpoint: DELETE /projects/:id/boards/:board_id/lists/:list_id</code></pre> |
| 257 | + * |
| 258 | + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance |
| 259 | + * @param boardId the ID of the board |
| 260 | + * @param listId the ID of the list |
| 261 | + * @throws GitLabApiException if any exception occurs |
| 262 | + */ |
| 263 | + public void deleteBoardList(Object projectIdOrPath, Integer boardId, Integer listId) throws GitLabApiException { |
| 264 | + delete(Response.Status.NO_CONTENT, null, "projects", getProjectIdOrPath(projectIdOrPath), "boards", boardId, "lists", listId); |
| 265 | + } |
| 266 | +} |
0 commit comments