|
| 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 | +} |
0 commit comments