Line data Source code
1 : // Copyright (C) 2015 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.extensions.api.groups; 16 : 17 : import com.google.gerrit.extensions.common.AccountInfo; 18 : import com.google.gerrit.extensions.common.GroupAuditEventInfo; 19 : import com.google.gerrit.extensions.common.GroupInfo; 20 : import com.google.gerrit.extensions.common.GroupOptionsInfo; 21 : import com.google.gerrit.extensions.restapi.NotImplementedException; 22 : import com.google.gerrit.extensions.restapi.RestApiException; 23 : import java.util.Arrays; 24 : import java.util.List; 25 : 26 : public interface GroupApi { 27 : /** Returns group info with no {@code ListGroupsOption}s set. */ 28 : GroupInfo get() throws RestApiException; 29 : 30 : /** Returns group info with all {@code ListGroupsOption}s set. */ 31 : GroupInfo detail() throws RestApiException; 32 : 33 : /** Returns group name. */ 34 : String name() throws RestApiException; 35 : 36 : /** 37 : * Set group name. 38 : * 39 : * @param name new name. 40 : */ 41 : void name(String name) throws RestApiException; 42 : 43 : /** Returns owning group info. */ 44 : GroupInfo owner() throws RestApiException; 45 : 46 : /** 47 : * Set group owner. 48 : * 49 : * @param owner identifier of new group owner. 50 : */ 51 : void owner(String owner) throws RestApiException; 52 : 53 : /** Returns group description. */ 54 : String description() throws RestApiException; 55 : 56 : /** 57 : * Set group decsription. 58 : * 59 : * @param description new description. 60 : */ 61 : void description(String description) throws RestApiException; 62 : 63 : /** Returns group options. */ 64 : GroupOptionsInfo options() throws RestApiException; 65 : 66 : /** 67 : * Set group options. 68 : * 69 : * @param options new options. 70 : */ 71 : void options(GroupOptionsInfo options) throws RestApiException; 72 : 73 : /** 74 : * List group members, non-recursively. 75 : * 76 : * @return group members. 77 : */ 78 : List<AccountInfo> members() throws RestApiException; 79 : 80 : /** 81 : * List group members. 82 : * 83 : * @param recursive whether to recursively included groups. 84 : * @return group members. 85 : */ 86 : List<AccountInfo> members(boolean recursive) throws RestApiException; 87 : 88 : /** 89 : * Add members to a group. 90 : * 91 : * @param members list of member identifiers, in any format accepted by {@link 92 : * com.google.gerrit.extensions.api.accounts.Accounts#id(String)} 93 : */ 94 : void addMembers(List<String> members) throws RestApiException; 95 : 96 : /** 97 : * Add members to a group. 98 : * 99 : * @param members list of member identifiers, in any format accepted by {@link 100 : * com.google.gerrit.extensions.api.accounts.Accounts#id(String)} 101 : */ 102 : default void addMembers(String... members) throws RestApiException { 103 12 : addMembers(Arrays.asList(members)); 104 12 : } 105 : 106 : /** 107 : * Remove members from a group. 108 : * 109 : * @param members list of member identifiers, in any format accepted by {@link 110 : * com.google.gerrit.extensions.api.accounts.Accounts#id(String)} 111 : */ 112 : void removeMembers(List<String> members) throws RestApiException; 113 : 114 : /** 115 : * Remove members from a group. 116 : * 117 : * @param members list of member identifiers, in any format accepted by {@link 118 : * com.google.gerrit.extensions.api.accounts.Accounts#id(String)} 119 : */ 120 : default void removeMembers(String... members) throws RestApiException { 121 5 : removeMembers(Arrays.asList(members)); 122 5 : } 123 : 124 : /** 125 : * Lists the subgroups of this group. 126 : * 127 : * @return the found subgroups 128 : */ 129 : List<GroupInfo> includedGroups() throws RestApiException; 130 : 131 : /** 132 : * Adds subgroups to this group. 133 : * 134 : * @param groups list of group identifiers, in any format accepted by {@link Groups#id(String)} 135 : */ 136 : void addGroups(List<String> groups) throws RestApiException; 137 : 138 : /** 139 : * Adds subgroups to this group. 140 : * 141 : * @param groups list of group identifiers, in any format accepted by {@link Groups#id(String)} 142 : */ 143 : default void addGroups(String... groups) throws RestApiException { 144 4 : addGroups(Arrays.asList(groups)); 145 4 : } 146 : 147 : /** 148 : * Removes subgroups from this group. 149 : * 150 : * @param groups list of group identifiers, in any format accepted by {@link Groups#id(String)} 151 : */ 152 : void removeGroups(List<String> groups) throws RestApiException; 153 : 154 : /** 155 : * Removes subgroups from this group. 156 : * 157 : * @param groups list of group identifiers, in any format accepted by {@link Groups#id(String)} 158 : */ 159 : default void removeGroups(String... groups) throws RestApiException { 160 3 : removeGroups(Arrays.asList(groups)); 161 3 : } 162 : 163 : /** 164 : * Returns the audit log of the group. 165 : * 166 : * @return list of audit events of the group. 167 : */ 168 : List<? extends GroupAuditEventInfo> auditLog() throws RestApiException; 169 : 170 : /** 171 : * Reindexes the group. 172 : * 173 : * <p>Only supported for internal groups. 174 : */ 175 : void index() throws RestApiException; 176 : 177 : /** 178 : * A default implementation which allows source compatibility when adding new methods to the 179 : * interface. 180 : */ 181 0 : class NotImplemented implements GroupApi { 182 : @Override 183 : public GroupInfo get() throws RestApiException { 184 0 : throw new NotImplementedException(); 185 : } 186 : 187 : @Override 188 : public GroupInfo detail() throws RestApiException { 189 0 : throw new NotImplementedException(); 190 : } 191 : 192 : @Override 193 : public String name() throws RestApiException { 194 0 : throw new NotImplementedException(); 195 : } 196 : 197 : @Override 198 : public void name(String name) throws RestApiException { 199 0 : throw new NotImplementedException(); 200 : } 201 : 202 : @Override 203 : public GroupInfo owner() throws RestApiException { 204 0 : throw new NotImplementedException(); 205 : } 206 : 207 : @Override 208 : public void owner(String owner) throws RestApiException { 209 0 : throw new NotImplementedException(); 210 : } 211 : 212 : @Override 213 : public String description() throws RestApiException { 214 0 : throw new NotImplementedException(); 215 : } 216 : 217 : @Override 218 : public void description(String description) throws RestApiException { 219 0 : throw new NotImplementedException(); 220 : } 221 : 222 : @Override 223 : public GroupOptionsInfo options() throws RestApiException { 224 0 : throw new NotImplementedException(); 225 : } 226 : 227 : @Override 228 : public void options(GroupOptionsInfo options) throws RestApiException { 229 0 : throw new NotImplementedException(); 230 : } 231 : 232 : @Override 233 : public List<AccountInfo> members() throws RestApiException { 234 0 : throw new NotImplementedException(); 235 : } 236 : 237 : @Override 238 : public List<AccountInfo> members(boolean recursive) throws RestApiException { 239 0 : throw new NotImplementedException(); 240 : } 241 : 242 : @Override 243 : public void addMembers(List<String> members) throws RestApiException { 244 0 : throw new NotImplementedException(); 245 : } 246 : 247 : @Override 248 : public void removeMembers(List<String> members) throws RestApiException { 249 0 : throw new NotImplementedException(); 250 : } 251 : 252 : @Override 253 : public List<GroupInfo> includedGroups() throws RestApiException { 254 0 : throw new NotImplementedException(); 255 : } 256 : 257 : @Override 258 : public void addGroups(List<String> groups) throws RestApiException { 259 0 : throw new NotImplementedException(); 260 : } 261 : 262 : @Override 263 : public void removeGroups(List<String> groups) throws RestApiException { 264 0 : throw new NotImplementedException(); 265 : } 266 : 267 : @Override 268 : public List<? extends GroupAuditEventInfo> auditLog() throws RestApiException { 269 0 : throw new NotImplementedException(); 270 : } 271 : 272 : @Override 273 : public void index() throws RestApiException { 274 0 : throw new NotImplementedException(); 275 : } 276 : } 277 : }