Skip to content

Commit 0e6a72a

Browse files
committed
Initial commit (#143).
1 parent 40a846f commit 0e6a72a

File tree

4 files changed

+473
-0
lines changed

4 files changed

+473
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package org.gitlab4j.api;
2+
3+
import javax.ws.rs.core.Response;
4+
5+
import org.gitlab4j.api.models.NotificationSettings;
6+
import org.gitlab4j.api.models.NotificationSettings.Events;
7+
8+
public class NotificationSettingsApi extends AbstractApi {
9+
10+
public NotificationSettingsApi(GitLabApi gitLabApi) {
11+
super(gitLabApi);
12+
}
13+
14+
/**
15+
* Get the global notification settings.
16+
*
17+
* GET /notification_settings
18+
*
19+
* @return a NotificationSettings instance containing the global notification settings
20+
* @throws GitLabApiException if any exception occurs
21+
*/
22+
public NotificationSettings getGlobalNotificationSettings() throws GitLabApiException {
23+
Response response = get(Response.Status.OK, null, "notification_settings");
24+
return (response.readEntity(NotificationSettings.class));
25+
}
26+
27+
/**
28+
* Update the global notification settings.
29+
*
30+
* PUT /notification_settings
31+
*
32+
* @param settings a NotificationSettings instance with the new settings
33+
* @return a NotificationSettings instance containing the updated global notification settings
34+
* @throws GitLabApiException if any exception occurs
35+
*/
36+
public NotificationSettings updateGlobalNotificationSettings(NotificationSettings settings) throws GitLabApiException {
37+
38+
GitLabApiForm formData = new GitLabApiForm()
39+
.withParam("level", settings.getLevel())
40+
.withParam("email", settings.getEmail());
41+
42+
Events events = settings.getEvents();
43+
if (events != null) {
44+
formData.withParam("new_note", events.getNewNote())
45+
.withParam("new_issuee", events.getNewIssue())
46+
.withParam("reopen_issuee", events.getReopenIssue())
47+
.withParam("close_issuee", events.getCloseIssue())
48+
.withParam("reassign_issuee", events.getReassignIssue())
49+
.withParam("new_merge_requeste", events.getNewMergeRequest())
50+
.withParam("reopen_merge_requeste", events.getReopenMergeRequest())
51+
.withParam("close_merge_requeste", events.getCloseMergeRequest())
52+
.withParam("reassign_merge_requeste", events.getReassignMergeRequest())
53+
.withParam("merge_merge_requeste", events.getMergeMergeRequest())
54+
.withParam("failed_pipelinee", events.getFailedPipeline())
55+
.withParam("success_pipelinee", events.getSuccessPipeline());
56+
}
57+
58+
Response response = put(Response.Status.OK, formData.asMap(), "notification_settings");
59+
return (response.readEntity(NotificationSettings.class));
60+
}
61+
62+
/**
63+
* Get the notification settings for a group.
64+
*
65+
* GET /groups/:id/notification_settings
66+
*
67+
* @param groupId the group ID to get the notification settings for
68+
* @return a NotificationSettings instance containing the specified group's notification settings
69+
* @throws GitLabApiException if any exception occurs
70+
*/
71+
public NotificationSettings getGroupNotificationSettings(int groupId) throws GitLabApiException {
72+
Response response = get(Response.Status.OK, null, "groups", groupId, "notification_settings");
73+
return (response.readEntity(NotificationSettings.class));
74+
}
75+
76+
/**
77+
* Update the notification settings for a group
78+
*
79+
* PUT /groups/:id/notification_settings
80+
*
81+
* @param groupId the group ID to update the notification settings for
82+
* @param settings a NotificationSettings instance with the new settings
83+
* @return a NotificationSettings instance containing the updated group notification settings
84+
* @throws GitLabApiException if any exception occurs
85+
*/
86+
public NotificationSettings updateGroupNotificationSettings(int groupId, NotificationSettings settings) throws GitLabApiException {
87+
88+
GitLabApiForm formData = new GitLabApiForm()
89+
.withParam("level", settings.getLevel())
90+
.withParam("email", settings.getEmail());
91+
92+
Events events = settings.getEvents();
93+
if (events != null) {
94+
formData.withParam("new_note", events.getNewNote())
95+
.withParam("new_issuee", events.getNewIssue())
96+
.withParam("reopen_issuee", events.getReopenIssue())
97+
.withParam("close_issuee", events.getCloseIssue())
98+
.withParam("reassign_issuee", events.getReassignIssue())
99+
.withParam("new_merge_requeste", events.getNewMergeRequest())
100+
.withParam("reopen_merge_requeste", events.getReopenMergeRequest())
101+
.withParam("close_merge_requeste", events.getCloseMergeRequest())
102+
.withParam("reassign_merge_requeste", events.getReassignMergeRequest())
103+
.withParam("merge_merge_requeste", events.getMergeMergeRequest())
104+
.withParam("failed_pipelinee", events.getFailedPipeline())
105+
.withParam("success_pipelinee", events.getSuccessPipeline());
106+
}
107+
108+
Response response = put(Response.Status.OK, formData.asMap(), "groups", groupId, "notification_settings");
109+
return (response.readEntity(NotificationSettings.class));
110+
}
111+
112+
/**
113+
* Get the notification settings for a project.
114+
*
115+
* GET /projects/:id/notification_settings
116+
*
117+
* @param projectId the project ID to get the notification settings for
118+
* @return a NotificationSettings instance containing the specified project's notification settings
119+
* @throws GitLabApiException if any exception occurs
120+
*/
121+
public NotificationSettings getProjectNotificationSettings(int projectId) throws GitLabApiException {
122+
Response response = get(Response.Status.OK, null, "projects", projectId, "notification_settings");
123+
return (response.readEntity(NotificationSettings.class));
124+
}
125+
126+
/**
127+
* Update the notification settings for a project
128+
*
129+
* PUT /projects/:id/notification_settings
130+
*
131+
* @param projectId the project ID to update the notification settings for
132+
* @param settings a NotificationSettings instance with the new settings
133+
* @return a NotificationSettings instance containing the updated project notification settings
134+
* @throws GitLabApiException if any exception occurs
135+
*/
136+
public NotificationSettings updateProjectNotificationSettings(int projectId, NotificationSettings settings) throws GitLabApiException {
137+
138+
GitLabApiForm formData = new GitLabApiForm()
139+
.withParam("level", settings.getLevel())
140+
.withParam("email", settings.getEmail());
141+
142+
Events events = settings.getEvents();
143+
if (events != null) {
144+
formData.withParam("new_note", events.getNewNote())
145+
.withParam("new_issuee", events.getNewIssue())
146+
.withParam("reopen_issuee", events.getReopenIssue())
147+
.withParam("close_issuee", events.getCloseIssue())
148+
.withParam("reassign_issuee", events.getReassignIssue())
149+
.withParam("new_merge_requeste", events.getNewMergeRequest())
150+
.withParam("reopen_merge_requeste", events.getReopenMergeRequest())
151+
.withParam("close_merge_requeste", events.getCloseMergeRequest())
152+
.withParam("reassign_merge_requeste", events.getReassignMergeRequest())
153+
.withParam("merge_merge_requeste", events.getMergeMergeRequest())
154+
.withParam("failed_pipelinee", events.getFailedPipeline())
155+
.withParam("success_pipelinee", events.getSuccessPipeline());
156+
}
157+
158+
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "notification_settings");
159+
return (response.readEntity(NotificationSettings.class));
160+
}
161+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package org.gitlab4j.api.models;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlRootElement;
6+
7+
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
8+
9+
import com.fasterxml.jackson.annotation.JsonCreator;
10+
import com.fasterxml.jackson.annotation.JsonValue;
11+
12+
@XmlRootElement
13+
@XmlAccessorType(XmlAccessType.FIELD)
14+
public class NotificationSettings {
15+
16+
/** Notification level */
17+
public static enum Level {
18+
19+
DISABLED, PARTICIPATING, WATCH, GLOBAL, MENTION, CUSTOM;
20+
21+
private static JacksonJsonEnumHelper<Level> enumHelper = new JacksonJsonEnumHelper<>(Level.class);
22+
23+
@JsonCreator
24+
public static Level forValue(String value) {
25+
return enumHelper.forValue(value);
26+
}
27+
28+
@JsonValue
29+
public String toValue() {
30+
return (enumHelper.toString(this));
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return (enumHelper.toString(this));
36+
}
37+
}
38+
39+
public static class Events {
40+
41+
private Boolean newNote;
42+
private Boolean newIssue;
43+
private Boolean reopenIssue;
44+
private Boolean closeIssue;
45+
private Boolean reassignIssue;
46+
private Boolean newMergeRequest;
47+
private Boolean reopenMergeRequest;
48+
private Boolean closeMergeRequest;
49+
private Boolean reassignMergeRequest;
50+
private Boolean mergeMergeRequest;
51+
private Boolean failedPipeline;
52+
private Boolean successPipeline;
53+
54+
public Boolean getNewNote() {
55+
return newNote;
56+
}
57+
58+
public void setNewNote(Boolean newNote) {
59+
this.newNote = newNote;
60+
}
61+
62+
public Boolean getNewIssue() {
63+
return newIssue;
64+
}
65+
66+
public void setNewIssue(Boolean newIssue) {
67+
this.newIssue = newIssue;
68+
}
69+
70+
public Boolean getReopenIssue() {
71+
return reopenIssue;
72+
}
73+
74+
public void setReopenIssue(Boolean reopenIssue) {
75+
this.reopenIssue = reopenIssue;
76+
}
77+
78+
public Boolean getCloseIssue() {
79+
return closeIssue;
80+
}
81+
82+
public void setCloseIssue(Boolean closeIssue) {
83+
this.closeIssue = closeIssue;
84+
}
85+
86+
public Boolean getReassignIssue() {
87+
return reassignIssue;
88+
}
89+
90+
public void setReassignIssue(Boolean reassignIssue) {
91+
this.reassignIssue = reassignIssue;
92+
}
93+
94+
public Boolean getNewMergeRequest() {
95+
return newMergeRequest;
96+
}
97+
98+
public void setNewMergeRequest(Boolean newMergeRequest) {
99+
this.newMergeRequest = newMergeRequest;
100+
}
101+
102+
public Boolean getReopenMergeRequest() {
103+
return reopenMergeRequest;
104+
}
105+
106+
public void setReopenMergeRequest(Boolean reopenMergeRequest) {
107+
this.reopenMergeRequest = reopenMergeRequest;
108+
}
109+
110+
public Boolean getCloseMergeRequest() {
111+
return closeMergeRequest;
112+
}
113+
114+
public void setCloseMergeRequest(Boolean closeMergeRequest) {
115+
this.closeMergeRequest = closeMergeRequest;
116+
}
117+
118+
public Boolean getReassignMergeRequest() {
119+
return reassignMergeRequest;
120+
}
121+
122+
public void setReassignMergeRequest(Boolean reassignMergeRequest) {
123+
this.reassignMergeRequest = reassignMergeRequest;
124+
}
125+
126+
public Boolean getMergeMergeRequest() {
127+
return mergeMergeRequest;
128+
}
129+
130+
public void setMergeMergeRequest(Boolean mergeMergeRequest) {
131+
this.mergeMergeRequest = mergeMergeRequest;
132+
}
133+
134+
public Boolean getFailedPipeline() {
135+
return failedPipeline;
136+
}
137+
138+
public void setFailedPipeline(Boolean failedPipeline) {
139+
this.failedPipeline = failedPipeline;
140+
}
141+
142+
public Boolean getSuccessPipeline() {
143+
return successPipeline;
144+
}
145+
146+
public void setSuccessPipeline(Boolean successPipeline) {
147+
this.successPipeline = successPipeline;
148+
}
149+
}
150+
151+
private Level level;
152+
private String email;
153+
private Events events;
154+
155+
public Level getLevel() {
156+
return level;
157+
}
158+
159+
public void setLevel(Level level) {
160+
this.level = level;
161+
}
162+
163+
public String getEmail() {
164+
return email;
165+
}
166+
167+
public void setEmail(String email) {
168+
this.email = email;
169+
}
170+
171+
public Events getEvents() {
172+
return events;
173+
}
174+
175+
public void setEvents(Events events) {
176+
this.events = events;
177+
}
178+
}

0 commit comments

Comments
 (0)