|
| 1 | +package org.gitlab4j.api; |
| 2 | + |
| 3 | +import org.gitlab4j.api.models.Issue; |
| 4 | +import org.gitlab4j.api.models.MergeRequest; |
| 5 | +import org.gitlab4j.api.models.Milestone; |
| 6 | + |
| 7 | +import javax.ws.rs.core.Form; |
| 8 | +import javax.ws.rs.core.GenericType; |
| 9 | +import javax.ws.rs.core.Response; |
| 10 | +import java.util.Date; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +/** |
| 14 | + * This class implements the client side API for the GitLab groups calls. |
| 15 | + */ |
| 16 | +public class MileStonesApi extends AbstractApi { |
| 17 | + |
| 18 | + public MileStonesApi(GitLabApi gitLabApi) { |
| 19 | + super(gitLabApi); |
| 20 | + } |
| 21 | + |
| 22 | + public List<Milestone> getMilestones(Integer projectId) throws GitLabApiException { |
| 23 | + if (projectId == null) { |
| 24 | + throw new RuntimeException("projectId cannot be null"); |
| 25 | + } |
| 26 | + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones"); |
| 27 | + return (response.readEntity(new GenericType<List<Milestone>>() { |
| 28 | + })); |
| 29 | + } |
| 30 | + |
| 31 | + public List<Milestone> getMilestones(Integer projectId, int page, int perPage) throws GitLabApiException { |
| 32 | + if (projectId == null) { |
| 33 | + throw new RuntimeException("projectId cannot be null"); |
| 34 | + } |
| 35 | + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "milestones"); |
| 36 | + return (response.readEntity(new GenericType<List<Milestone>>() { |
| 37 | + })); |
| 38 | + } |
| 39 | + |
| 40 | + public List<Milestone> getMilestones(Integer projectId, MilestoneState state) throws GitLabApiException { |
| 41 | + if (projectId == null) { |
| 42 | + throw new RuntimeException("projectId cannot be null"); |
| 43 | + } |
| 44 | + Form formData = new GitLabApiForm().withParam("state", state).withParam(PER_PAGE_PARAM, getDefaultPerPage()); |
| 45 | + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones"); |
| 46 | + return (response.readEntity(new GenericType<List<Milestone>>() { |
| 47 | + })); |
| 48 | + } |
| 49 | + |
| 50 | + public List<Milestone> getMilestones(Integer projectId, String search) throws GitLabApiException { |
| 51 | + if (projectId == null) { |
| 52 | + throw new RuntimeException("projectId cannot be null"); |
| 53 | + } |
| 54 | + Form formData = new GitLabApiForm().withParam("search", search).withParam(PER_PAGE_PARAM, getDefaultPerPage()); |
| 55 | + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones"); |
| 56 | + return (response.readEntity(new GenericType<List<Milestone>>() { |
| 57 | + })); |
| 58 | + } |
| 59 | + |
| 60 | + public List<Milestone> getMilestones(Integer projectId, MilestoneState state, String search) throws GitLabApiException { |
| 61 | + if (projectId == null) { |
| 62 | + throw new RuntimeException("projectId cannot be null"); |
| 63 | + } |
| 64 | + Form formData = new GitLabApiForm().withParam("state", state).withParam("search", search).withParam(PER_PAGE_PARAM, getDefaultPerPage()); |
| 65 | + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones"); |
| 66 | + return (response.readEntity(new GenericType<List<Milestone>>() { |
| 67 | + })); |
| 68 | + } |
| 69 | + |
| 70 | + public Milestone getMilestone(Integer projectId, int milestoneId) throws GitLabApiException { |
| 71 | + if (projectId == null) { |
| 72 | + throw new RuntimeException("projectId cannot be null"); |
| 73 | + } |
| 74 | + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId); |
| 75 | + return (response.readEntity(Milestone.class)); |
| 76 | + } |
| 77 | + |
| 78 | + public List<Issue> getIssues(Integer projectId, Integer milestoneId) throws GitLabApiException { |
| 79 | + if (projectId == null) { |
| 80 | + throw new RuntimeException("projectId cannot be null"); |
| 81 | + } |
| 82 | + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId, "issues"); |
| 83 | + return (response.readEntity(new GenericType<List<Issue>>() { |
| 84 | + })); |
| 85 | + } |
| 86 | + |
| 87 | + public List<MergeRequest> getMergeRequest(Integer projectId, Integer milestoneId) throws GitLabApiException { |
| 88 | + if (projectId == null) { |
| 89 | + throw new RuntimeException("projectId cannot be null"); |
| 90 | + } |
| 91 | + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId, "merge_requests"); |
| 92 | + return (response.readEntity(new GenericType<List<MergeRequest>>() { |
| 93 | + })); |
| 94 | + } |
| 95 | + |
| 96 | + public Milestone createMilestone(Integer projectId, String title, String description, Date dueDate, Date startDate) throws GitLabApiException { |
| 97 | + if (projectId == null) { |
| 98 | + throw new RuntimeException("projectId cannot be null"); |
| 99 | + } |
| 100 | + GitLabApiForm formData = new GitLabApiForm() |
| 101 | + .withParam("title", title, true) |
| 102 | + .withParam("description", description) |
| 103 | + .withParam("due_date", dueDate) |
| 104 | + .withParam("start_date", startDate); |
| 105 | + Response response = post(Response.Status.CREATED, formData, "projects", projectId, "milestones"); |
| 106 | + return (response.readEntity(Milestone.class)); |
| 107 | + } |
| 108 | + |
| 109 | + public Milestone closeMilestone(Integer projectId, Integer milestoneId) throws GitLabApiException { |
| 110 | + if (projectId == null) { |
| 111 | + throw new RuntimeException("projectId cannot be null"); |
| 112 | + } |
| 113 | + if (milestoneId == null) { |
| 114 | + throw new RuntimeException("milestoneId cannot be null"); |
| 115 | + } |
| 116 | + GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.CLOSE); |
| 117 | + Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId); |
| 118 | + return (response.readEntity(Milestone.class)); |
| 119 | + } |
| 120 | + |
| 121 | + public Milestone activateMilestone(Integer projectId, Integer milestoneId) throws GitLabApiException { |
| 122 | + if (projectId == null) { |
| 123 | + throw new RuntimeException("projectId cannot be null"); |
| 124 | + } |
| 125 | + if (milestoneId == null) { |
| 126 | + throw new RuntimeException("milestoneId cannot be null"); |
| 127 | + } |
| 128 | + GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.ACTIVATE); |
| 129 | + Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId); |
| 130 | + return (response.readEntity(Milestone.class)); |
| 131 | + } |
| 132 | + |
| 133 | + public Milestone updateMilestone(Integer projectId, Integer milestoneId, String title, String description, Date dueDate, Date startDate, MilestoneState milestoneState) throws GitLabApiException { |
| 134 | + if (projectId == null) { |
| 135 | + throw new RuntimeException("projectId cannot be null"); |
| 136 | + } |
| 137 | + if (milestoneId == null) { |
| 138 | + throw new RuntimeException("milestoneId cannot be null"); |
| 139 | + } |
| 140 | + GitLabApiForm formData = new GitLabApiForm() |
| 141 | + .withParam("title", title, true) |
| 142 | + .withParam("description", description) |
| 143 | + .withParam("due_date", dueDate) |
| 144 | + .withParam("start_date", startDate) |
| 145 | + .withParam("state_event", milestoneState); |
| 146 | + Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId); |
| 147 | + return (response.readEntity(Milestone.class)); |
| 148 | + } |
| 149 | +} |
0 commit comments