Skip to content

Commit 68416b5

Browse files
committed
Add methods to create child epics
1 parent 3cd0ab9 commit 68416b5

File tree

9 files changed

+554
-279
lines changed

9 files changed

+554
-279
lines changed

src/main/java/org/gitlab4j/api/EpicsApi.java

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import javax.ws.rs.core.GenericType;
1010
import javax.ws.rs.core.Response;
1111

12+
import org.gitlab4j.api.models.ChildEpic;
13+
import org.gitlab4j.api.models.CreatedChildEpic;
1214
import org.gitlab4j.api.models.Epic;
1315
import org.gitlab4j.api.models.EpicIssue;
1416
import org.gitlab4j.api.models.EpicIssueLink;
@@ -458,4 +460,125 @@ public List<EpicIssue> updateIssue(Object groupIdOrPath, Long epicIid, Long epic
458460
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues", epicIssueId);
459461
return response.readEntity(new GenericType<List<EpicIssue>>() {});
460462
}
463+
464+
465+
/**
466+
* Gets all child epics of an epic and the authenticated user has access to.
467+
*
468+
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/epics</code></pre>
469+
*
470+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
471+
* @param epicIid the IID of the epic to get child epics for
472+
* @return a list of all child epics of the specified epic
473+
* @throws GitLabApiException if any exception occurs
474+
*/
475+
public List<ChildEpic> getChildEpics(Object groupIdOrPath, Long epicIid) throws GitLabApiException {
476+
return (getChildEpics(groupIdOrPath, epicIid, getDefaultPerPage()).all());
477+
}
478+
479+
/**
480+
* Get a Pager of all child epics of an epic and the authenticated user has access to.
481+
*
482+
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/epics</code></pre>
483+
*
484+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
485+
* @param epicIid the IID of the epic to get child epics for
486+
* @param itemsPerPage the number of child epics per page
487+
* @return the Pager of all child epics of the specified epic
488+
* @throws GitLabApiException if any exception occurs
489+
*/
490+
public Pager<ChildEpic> getChildEpics(Object groupIdOrPath, Long epicIid, int itemsPerPage) throws GitLabApiException {
491+
return (new Pager<ChildEpic>(this, ChildEpic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "epics"));
492+
}
493+
494+
/**
495+
* Gets all child epics of an epic and the authenticated user has access to as a Stream.
496+
*
497+
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/epics</code></pre>
498+
*
499+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
500+
* @param epicIid the IID of the epic to get child epics for
501+
* @return a Stream of all child epics of the specified epic
502+
* @throws GitLabApiException if any exception occurs
503+
*/
504+
public Stream<ChildEpic> getChildEpicsStream(Object groupIdOrPath, Long epicIid) throws GitLabApiException {
505+
return (getChildEpics(groupIdOrPath, epicIid, getDefaultPerPage()).stream());
506+
}
507+
508+
/**
509+
* Creates an association between two epics, designating one as the parent epic and the other as the child epic. A parent epic can have multiple child epics. If the new child epic already belonged to another epic, it is unassigned from that previous parent.
510+
*
511+
* <pre><code>GitLab Endpoint: POST /groups/:id/epics/:epic_iid/epics/:child_epic_id</code></pre>
512+
*
513+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
514+
* @param epicIid the Epic IID to assign the child epic to
515+
* @param childEpicId the global ID of the child epic. Epic IID can’t be used because they can conflict with epics from other groups.
516+
* @return an ChildEpic instance containing info on the newly assigned child epic
517+
* @throws GitLabApiException if any exception occurs
518+
*/
519+
public ChildEpic assignChildEpic(Object groupIdOrPath, Long epicIid, Long childEpicId) throws GitLabApiException {
520+
Response response = post(Response.Status.CREATED, (Form)null,
521+
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "epics", childEpicId);
522+
return (response.readEntity(ChildEpic.class));
523+
}
524+
525+
/**
526+
* Creates a new epic and associates it with provided parent epic.
527+
*
528+
* <pre><code>GitLab Endpoint: POST /groups/:id/epics/:epic_iid/epics</code></pre>
529+
*
530+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
531+
* @param epicIid the Epic IID to assign the child epic to (of the future parent epic)
532+
* @param title the title of a newly created epic
533+
* @param confidential whether the epic should be confidential (optional)
534+
* @return an ChildEpic instance containing info on the newly created and assigned child epic
535+
* @throws GitLabApiException if any exception occurs
536+
*/
537+
public CreatedChildEpic createAndAssignChildEpic(Object groupIdOrPath, Long epicIid, String title, Boolean confidential) throws GitLabApiException {
538+
Form formData = new GitLabApiForm()
539+
.withParam("title", title, true)
540+
.withParam("confidential", confidential);
541+
Response response = post(Response.Status.CREATED, formData.asMap(),
542+
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "epics");
543+
return (response.readEntity(CreatedChildEpic.class));
544+
}
545+
546+
/**
547+
* Re-order a child epic
548+
*
549+
* <pre><code>GitLab Endpoint: PUT /groups/:id/epics/:epic_iid/epics/:child_epic_id</code></pre>
550+
*
551+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
552+
* @param epicIid the Epic IID that the child epic is assigned to
553+
* @param childEpicId the ID of the child epic. Epic IID can’t be used because they can conflict with epics from other groups.
554+
* @param moveBeforeId the ID of a sibling epic that should be placed before the child epic (optional)
555+
* @param moveAfterId the ID of a sibling epic that should be placed after the child epic (optional)
556+
* @return a list of all child epics of the specified epic
557+
* @throws GitLabApiException if any exception occurs
558+
*/
559+
public List<ChildEpic> reOrderChildEpic(Object groupIdOrPath, Long epicIid, Long childEpicId, Long moveBeforeId, Long moveAfterId) throws GitLabApiException {
560+
GitLabApiForm form = new GitLabApiForm()
561+
.withParam("move_before_id", moveBeforeId)
562+
.withParam("move_after_id", moveAfterId);
563+
Response response = put(Response.Status.OK, form.asMap(),
564+
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "epics", childEpicId);
565+
return response.readEntity(new GenericType<List<ChildEpic>>() {});
566+
}
567+
568+
/**
569+
* Unassigns a child epic from a parent epic.
570+
*
571+
* <pre><code>GitLab Endpoint: DELETE /groups/:id/epics/:epic_iid/epics/:child_epic_id</code></pre>
572+
*
573+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
574+
* @param epicIid the Epic IID to remove the child epic from
575+
* @param childEpicId the ID of the child epic. Epic IID can’t be used because they can conflict with epics from other groups.
576+
* @return an ChildEpic instance containing info on the removed child epic
577+
* @throws GitLabApiException if any exception occurs
578+
*/
579+
public ChildEpic unassignChildEpic(Object groupIdOrPath, Long epicIid, Long childEpicId) throws GitLabApiException {
580+
Response response = delete(Response.Status.OK, null,
581+
"groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "epics", childEpicId);
582+
return (response.readEntity(ChildEpic.class));
583+
}
461584
}
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.util.Date;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
8+
import org.gitlab4j.api.utils.JacksonJson;
9+
10+
import com.fasterxml.jackson.annotation.JsonCreator;
11+
import com.fasterxml.jackson.annotation.JsonIgnore;
12+
import com.fasterxml.jackson.annotation.JsonProperty;
13+
import com.fasterxml.jackson.annotation.JsonValue;
14+
15+
public class AbstractEpic<E extends AbstractEpic<E>> extends AbstractMinimalEpic<E> {
16+
17+
public enum EpicState {
18+
OPENED, CLOSED, ALL;
19+
20+
private static JacksonJsonEnumHelper<EpicState> enumHelper = new JacksonJsonEnumHelper<>(EpicState.class);
21+
22+
@JsonCreator
23+
public static EpicState forValue(String value) {
24+
return enumHelper.forValue(value);
25+
}
26+
27+
@JsonValue
28+
public String toValue() {
29+
return (enumHelper.toString(this));
30+
}
31+
32+
public String toString() {
33+
return (enumHelper.toString(this));
34+
}
35+
}
36+
37+
private Long parentIid;
38+
private String description;
39+
private EpicState state;
40+
private String webUrl;
41+
private References references;
42+
private Author author;
43+
private List<String> labels;
44+
private Date startDate;
45+
private Date dueDate;
46+
private Date endDate;
47+
private Date createdAt;
48+
private Date updatedAt;
49+
private Date closedAt;
50+
private Integer downvotes;
51+
private Integer upvotes;
52+
private String color;
53+
@JsonProperty("_links")
54+
private Map<String, String> links;
55+
56+
public Long getParentIid() {
57+
return parentIid;
58+
}
59+
60+
public void setParentIid(Long parentIid) {
61+
this.parentIid = parentIid;
62+
}
63+
64+
public String getDescription() {
65+
return description;
66+
}
67+
68+
public void setDescription(String description) {
69+
this.description = description;
70+
}
71+
72+
@SuppressWarnings("unchecked")
73+
public E withDescription(String description) {
74+
this.description = description;
75+
return (E) (this);
76+
}
77+
78+
public EpicState getState() {
79+
return state;
80+
}
81+
82+
public void setState(EpicState state) {
83+
this.state = state;
84+
}
85+
86+
public String getWebUrl() {
87+
return webUrl;
88+
}
89+
90+
public void setWebUrl(String webUrl) {
91+
this.webUrl = webUrl;
92+
}
93+
94+
public References getReferences() {
95+
return references;
96+
}
97+
98+
public void setReferences(References references) {
99+
this.references = references;
100+
}
101+
102+
public Author getAuthor() {
103+
return author;
104+
}
105+
106+
public void setAuthor(Author author) {
107+
this.author = author;
108+
}
109+
110+
@SuppressWarnings("unchecked")
111+
public E withAuthor(Author author) {
112+
this.author = author;
113+
return (E) (this);
114+
}
115+
116+
public List<String> getLabels() {
117+
return labels;
118+
}
119+
120+
public void setLabels(List<String> labels) {
121+
this.labels = labels;
122+
}
123+
124+
@SuppressWarnings("unchecked")
125+
public E withLabels(List<String> labels) {
126+
this.labels = labels;
127+
return (E) (this);
128+
}
129+
130+
public Date getStartDate() {
131+
return startDate;
132+
}
133+
134+
public void setStartDate(Date startDate) {
135+
this.startDate = startDate;
136+
}
137+
138+
@SuppressWarnings("unchecked")
139+
public E withStartDate(Date startDate) {
140+
this.startDate = startDate;
141+
return (E) (this);
142+
}
143+
144+
public Date getDueDate() {
145+
return dueDate;
146+
}
147+
148+
public void setDueDate(Date dueDate) {
149+
this.dueDate = dueDate;
150+
}
151+
152+
public Date getEndDate() {
153+
return endDate;
154+
}
155+
156+
public void setEndDate(Date endDate) {
157+
this.endDate = endDate;
158+
}
159+
160+
@SuppressWarnings("unchecked")
161+
public E withEndDate(Date endDate) {
162+
this.endDate = endDate;
163+
return (E) (this);
164+
}
165+
166+
public Date getCreatedAt() {
167+
return createdAt;
168+
}
169+
170+
public void setCreatedAt(Date createdAt) {
171+
this.createdAt = createdAt;
172+
}
173+
174+
public Date getUpdatedAt() {
175+
return updatedAt;
176+
}
177+
178+
public void setUpdatedAt(Date updatedAt) {
179+
this.updatedAt = updatedAt;
180+
}
181+
182+
public Date getClosedAt() {
183+
return closedAt;
184+
}
185+
186+
public void setClosedAt(Date closedAt) {
187+
this.closedAt = closedAt;
188+
}
189+
190+
public Integer getDownvotes() {
191+
return downvotes;
192+
}
193+
194+
public void setDownvotes(Integer downvotes) {
195+
this.downvotes = downvotes;
196+
}
197+
198+
public Integer getUpvotes() {
199+
return upvotes;
200+
}
201+
202+
public void setUpvotes(Integer upvotes) {
203+
this.upvotes = upvotes;
204+
}
205+
206+
public String getColor() {
207+
return color;
208+
}
209+
210+
public void setColor(String color) {
211+
this.color = color;
212+
}
213+
214+
public Map<String, String> getLinks() {
215+
return links;
216+
}
217+
218+
public void setLinks(Map<String, String> links) {
219+
this.links = links;
220+
}
221+
222+
@JsonIgnore
223+
public String getLinkByName(String name) {
224+
if (links == null || links.isEmpty()) {
225+
return (null);
226+
}
227+
228+
return (links.get(name));
229+
}
230+
231+
public String toString() {
232+
return (JacksonJson.toJsonString(this));
233+
}
234+
}

0 commit comments

Comments
 (0)