James Moger
2014-06-13 9793855caf01d4ce9740dd99971e771cca6715a6
commit | author | age
15a51d 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.client;
17
18 import java.io.IOException;
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Collections;
17820f 22 import java.util.Date;
4cac0d 23 import java.util.HashSet;
97d3af 24 import java.util.LinkedHashSet;
15a51d 25 import java.util.List;
JM 26 import java.util.Map;
4cac0d 27 import java.util.Set;
97d3af 28 import java.util.TreeSet;
15a51d 29
9119cf 30 import com.gitblit.Constants;
87f6c3 31 import com.gitblit.Constants.AccessPermission;
94dcbd 32 import com.gitblit.Constants.AccessRestrictionType;
6adf56 33 import com.gitblit.Constants.AuthorizationControl;
ba6150 34 import com.gitblit.Constants.PermissionType;
JM 35 import com.gitblit.Constants.RegistrantType;
15a51d 36 import com.gitblit.GitBlitException.ForbiddenException;
8b7636 37 import com.gitblit.GitBlitException.NotAllowedException;
5ae0b7 38 import com.gitblit.GitBlitException.UnauthorizedException;
8b7636 39 import com.gitblit.GitBlitException.UnknownRequestException;
15a51d 40 import com.gitblit.Keys;
JM 41 import com.gitblit.models.FederationModel;
e493cf 42 import com.gitblit.models.FeedEntryModel;
17820f 43 import com.gitblit.models.FeedModel;
87f6c3 44 import com.gitblit.models.RegistrantAccessPermission;
15a51d 45 import com.gitblit.models.RepositoryModel;
84c1d5 46 import com.gitblit.models.ServerSettings;
b75734 47 import com.gitblit.models.ServerStatus;
f08aab 48 import com.gitblit.models.TeamModel;
15a51d 49 import com.gitblit.models.UserModel;
0db5c4 50 import com.gitblit.utils.ArrayUtils;
15a51d 51 import com.gitblit.utils.RpcUtils;
ec5a88 52 import com.gitblit.utils.StringUtils;
4cac0d 53 import com.gitblit.utils.SyndicationUtils;
15a51d 54
84c1d5 55 /**
JM 56  * GitblitClient is a object that retrieves data from a Gitblit server, caches
57  * it for local operations, and allows updating or creating Gitblit objects.
699e71 58  *
84c1d5 59  * @author James Moger
699e71 60  *
84c1d5 61  */
JM 62 public class GitblitClient implements Serializable {
15a51d 63
JM 64     private static final long serialVersionUID = 1L;
4cac0d 65
bab9c9 66     private static final Date NEVER = new Date(0);
JM 67
4cac0d 68     protected final GitblitRegistration reg;
15a51d 69
JM 70     public final String url;
71
72     public final String account;
73
74     private final char[] password;
2a99c3 75
f08aab 76     private volatile int protocolVersion;
JM 77
d03aff 78     private volatile boolean allowManagement;
15a51d 79
d03aff 80     private volatile boolean allowAdministration;
15a51d 81
84c1d5 82     private volatile ServerSettings settings;
15a51d 83
JM 84     private final List<RepositoryModel> allRepositories;
85
86     private final List<UserModel> allUsers;
f08aab 87
JM 88     private final List<TeamModel> allTeams;
15a51d 89
JM 90     private final List<FederationModel> federationRegistrations;
b75734 91
17820f 92     private final List<FeedModel> availableFeeds;
JM 93
ee458f 94     private final List<FeedEntryModel> syndicatedEntries;
17820f 95
JM 96     private final Set<String> subscribedRepositories;
4cac0d 97
b75734 98     private ServerStatus status;
15a51d 99
4cac0d 100     public GitblitClient(GitblitRegistration reg) {
JM 101         this.reg = reg;
102         this.url = reg.url;
103         this.account = reg.account;
104         this.password = reg.password;
15a51d 105
JM 106         this.allUsers = new ArrayList<UserModel>();
f08aab 107         this.allTeams = new ArrayList<TeamModel>();
15a51d 108         this.allRepositories = new ArrayList<RepositoryModel>();
JM 109         this.federationRegistrations = new ArrayList<FederationModel>();
17820f 110         this.availableFeeds = new ArrayList<FeedModel>();
ee458f 111         this.syndicatedEntries = new ArrayList<FeedEntryModel>();
17820f 112         this.subscribedRepositories = new HashSet<String>();
15a51d 113     }
JM 114
115     public void login() throws IOException {
f08aab 116         protocolVersion = RpcUtils.getProtocolVersion(url, account, password);
ec5a88 117         refreshSettings();
17820f 118         refreshAvailableFeeds();
15a51d 119         refreshRepositories();
e33b91 120         refreshSubscribedFeeds(0);
17820f 121
4cac0d 122         try {
JM 123             // credentials may not have administrator access
124             // or server may have disabled rpc management
15a51d 125             refreshUsers();
f08aab 126             if (protocolVersion > 1) {
JM 127                 refreshTeams();
128             }
d03aff 129             allowManagement = true;
5ae0b7 130         } catch (UnauthorizedException e) {
15a51d 131         } catch (ForbiddenException e) {
8b7636 132         } catch (NotAllowedException e) {
JM 133         } catch (UnknownRequestException e) {
15a51d 134         } catch (IOException e) {
8b7636 135             e.printStackTrace();
15a51d 136         }
d03aff 137
JM 138         try {
4cac0d 139             // credentials may not have administrator access
JM 140             // or server may have disabled rpc administration
486ee1 141             refreshStatus();
d03aff 142             allowAdministration = true;
JM 143         } catch (UnauthorizedException e) {
144         } catch (ForbiddenException e) {
8b7636 145         } catch (NotAllowedException e) {
JM 146         } catch (UnknownRequestException e) {
d03aff 147         } catch (IOException e) {
8b7636 148             e.printStackTrace();
d03aff 149         }
f08aab 150     }
JM 151
152     public int getProtocolVersion() {
153         return protocolVersion;
15a51d 154     }
JM 155
d03aff 156     public boolean allowManagement() {
JM 157         return allowManagement;
158     }
2a99c3 159
d03aff 160     public boolean allowAdministration() {
JM 161         return allowAdministration;
15a51d 162     }
JM 163
164     public boolean isOwner(RepositoryModel model) {
661db6 165         return model.isOwner(account);
15a51d 166     }
JM 167
ec5a88 168     public String getURL(String action, String repository, String objectId) {
JM 169         boolean mounted = settings.get(Keys.web.mountParameters).getBoolean(true);
170         StringBuilder sb = new StringBuilder();
171         sb.append(url);
172         sb.append('/');
173         sb.append(action);
174         sb.append('/');
175         if (mounted) {
176             // mounted url/action/repository/objectId
177             sb.append(StringUtils.encodeURL(repository));
178             if (!StringUtils.isEmpty(objectId)) {
179                 sb.append('/');
180                 sb.append(objectId);
181             }
182             return sb.toString();
183         } else {
184             // parameterized url/action/&r=repository&h=objectId
185             sb.append("?r=");
186             sb.append(repository);
187             if (!StringUtils.isEmpty(objectId)) {
188                 sb.append("&h=");
189                 sb.append(objectId);
190             }
191             return sb.toString();
192         }
193     }
699e71 194
94dcbd 195     public AccessRestrictionType getDefaultAccessRestriction() {
b32502 196         String restriction = "PUSH";
94dcbd 197         if (settings.hasKey(Keys.git.defaultAccessRestriction)) {
JM 198             restriction = settings.get(Keys.git.defaultAccessRestriction).currentValue;
199         }
200         return AccessRestrictionType.fromName(restriction);
201     }
ec5a88 202
6adf56 203     public AuthorizationControl getDefaultAuthorizationControl() {
JM 204         String authorization = null;
205         if (settings.hasKey(Keys.git.defaultAuthorizationControl)) {
206             authorization = settings.get(Keys.git.defaultAuthorizationControl).currentValue;
207         }
208         return AuthorizationControl.fromName(authorization);
209     }
210
97d3af 211     /**
JM 212      * Returns the list of pre-receive scripts the repository inherited from the
213      * global settings and team affiliations.
699e71 214      *
97d3af 215      * @param repository
JM 216      *            if null only the globally specified scripts are returned
217      * @return a list of scripts
218      */
219     public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) {
220         Set<String> scripts = new LinkedHashSet<String>();
221         // Globals
222         for (String script : settings.get(Keys.groovy.preReceiveScripts).getStrings()) {
223             if (script.endsWith(".groovy")) {
224                 scripts.add(script.substring(0, script.lastIndexOf('.')));
225             } else {
226                 scripts.add(script);
227             }
4bd203 228         }
97d3af 229
JM 230         // Team Scripts
231         if (repository != null) {
232             for (String teamname : getPermittedTeamnames(repository)) {
233                 TeamModel team = getTeamModel(teamname);
0db5c4 234                 if (!ArrayUtils.isEmpty(team.preReceiveScripts)) {
JM 235                     scripts.addAll(team.preReceiveScripts);
236                 }
97d3af 237             }
JM 238         }
239         return new ArrayList<String>(scripts);
240     }
241
242     /**
243      * Returns the list of all available Groovy pre-receive push hook scripts
244      * that are not already inherited by the repository. Script files must have
245      * .groovy extension
699e71 246      *
97d3af 247      * @param repository
JM 248      *            optional parameter
249      * @return list of available hook scripts
250      */
251     public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) {
252         Set<String> inherited = new TreeSet<String>(getPreReceiveScriptsInherited(repository));
253
254         // create list of available scripts by excluding inherited scripts
255         List<String> scripts = new ArrayList<String>();
979385 256         if (!ArrayUtils.isEmpty(settings.pushScripts)) {
JM 257             for (String script : settings.pushScripts) {
258                 if (!inherited.contains(script)) {
259                     scripts.add(script);
260                 }
97d3af 261             }
JM 262         }
263         return scripts;
264     }
265
266     /**
267      * Returns the list of post-receive scripts the repository inherited from
268      * the global settings and team affiliations.
699e71 269      *
97d3af 270      * @param repository
JM 271      *            if null only the globally specified scripts are returned
272      * @return a list of scripts
273      */
274     public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {
275         Set<String> scripts = new LinkedHashSet<String>();
276         // Global Scripts
277         for (String script : settings.get(Keys.groovy.postReceiveScripts).getStrings()) {
278             if (script.endsWith(".groovy")) {
279                 scripts.add(script.substring(0, script.lastIndexOf('.')));
280             } else {
281                 scripts.add(script);
282             }
283         }
284         // Team Scripts
285         if (repository != null) {
286             for (String teamname : getPermittedTeamnames(repository)) {
287                 TeamModel team = getTeamModel(teamname);
0db5c4 288                 if (!ArrayUtils.isEmpty(team.postReceiveScripts)) {
JM 289                     scripts.addAll(team.postReceiveScripts);
290                 }
97d3af 291             }
JM 292         }
293         return new ArrayList<String>(scripts);
294     }
295
296     /**
297      * Returns the list of unused Groovy post-receive push hook scripts that are
298      * not already inherited by the repository. Script files must have .groovy
299      * extension
699e71 300      *
97d3af 301      * @param repository
JM 302      *            optional parameter
303      * @return list of available hook scripts
304      */
305     public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {
306         Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));
307
308         // create list of available scripts by excluding inherited scripts
309         List<String> scripts = new ArrayList<String>();
699e71 310         if (!ArrayUtils.isEmpty(settings.pushScripts)) {
0db5c4 311             for (String script : settings.pushScripts) {
JM 312                 if (!inherited.contains(script)) {
313                     scripts.add(script);
314                 }
97d3af 315             }
JM 316         }
317         return scripts;
4bd203 318     }
JM 319
84c1d5 320     public ServerSettings getSettings() {
15a51d 321         return settings;
b75734 322     }
JM 323
84c1d5 324     public ServerStatus getStatus() {
JM 325         return status;
326     }
327
b75734 328     public String getSettingDescription(String key) {
JM 329         return settings.get(key).description;
15a51d 330     }
JM 331
332     public List<RepositoryModel> refreshRepositories() throws IOException {
333         Map<String, RepositoryModel> repositories = RpcUtils
334                 .getRepositories(url, account, password);
335         allRepositories.clear();
336         allRepositories.addAll(repositories.values());
337         Collections.sort(allRepositories);
17820f 338         markSubscribedFeeds();
15a51d 339         return allRepositories;
JM 340     }
341
342     public List<UserModel> refreshUsers() throws IOException {
343         List<UserModel> users = RpcUtils.getUsers(url, account, password);
344         allUsers.clear();
345         allUsers.addAll(users);
092f0a 346         Collections.sort(users);
15a51d 347         return allUsers;
JM 348     }
2a99c3 349
f08aab 350     public List<TeamModel> refreshTeams() throws IOException {
JM 351         List<TeamModel> teams = RpcUtils.getTeams(url, account, password);
352         allTeams.clear();
353         allTeams.addAll(teams);
092f0a 354         Collections.sort(teams);
f08aab 355         return allTeams;
JM 356     }
357
f306ef 358     public ServerSettings refreshSettings() throws IOException {
JM 359         settings = RpcUtils.getSettings(url, account, password);
360         return settings;
361     }
8b7636 362
486ee1 363     public ServerStatus refreshStatus() throws IOException {
JM 364         status = RpcUtils.getStatus(url, account, password);
365         return status;
366     }
15a51d 367
9119cf 368     public List<String> getBranches(String repository) {
JM 369         List<FeedModel> feeds = getAvailableFeeds(repository);
370         List<String> branches = new ArrayList<String>();
371         for (FeedModel feed : feeds) {
372             branches.add(feed.branch);
373         }
374         Collections.sort(branches);
375         return branches;
376     }
377
17820f 378     public List<FeedModel> getAvailableFeeds() {
JM 379         return availableFeeds;
380     }
381
382     public List<FeedModel> getAvailableFeeds(RepositoryModel repository) {
9119cf 383         return getAvailableFeeds(repository.name);
JM 384     }
385
386     public List<FeedModel> getAvailableFeeds(String repository) {
17820f 387         List<FeedModel> repositoryFeeds = new ArrayList<FeedModel>();
JM 388         if (repository == null) {
389             return repositoryFeeds;
390         }
391         for (FeedModel feed : availableFeeds) {
9119cf 392             if (feed.repository.equalsIgnoreCase(repository)) {
17820f 393                 repositoryFeeds.add(feed);
JM 394             }
395         }
396         return repositoryFeeds;
397     }
398
399     public List<FeedModel> refreshAvailableFeeds() throws IOException {
400         List<FeedModel> feeds = RpcUtils.getBranchFeeds(url, account, password);
401         availableFeeds.clear();
402         availableFeeds.addAll(feeds);
403         markSubscribedFeeds();
404         return availableFeeds;
405     }
406
ee458f 407     public List<FeedEntryModel> refreshSubscribedFeeds(int page) throws IOException {
JM 408         Set<FeedEntryModel> allEntries = new HashSet<FeedEntryModel>();
17820f 409         if (reg.feeds.size() > 0) {
JM 410             for (FeedModel feed : reg.feeds) {
bab9c9 411                 feed.lastRefreshDate = feed.currentRefreshDate;
JM 412                 feed.currentRefreshDate = new Date();
f08aab 413                 List<FeedEntryModel> entries = SyndicationUtils.readFeed(url, feed.repository,
JM 414                         feed.branch, -1, page, account, password);
17820f 415                 allEntries.addAll(entries);
4cac0d 416             }
JM 417         }
bab9c9 418         reg.cacheFeeds();
4cac0d 419         syndicatedEntries.clear();
17820f 420         syndicatedEntries.addAll(allEntries);
4cac0d 421         Collections.sort(syndicatedEntries);
JM 422         return syndicatedEntries;
423     }
424
17820f 425     public void updateSubscribedFeeds(List<FeedModel> list) {
JM 426         reg.updateSubscribedFeeds(list);
427         markSubscribedFeeds();
428     }
429
430     private void markSubscribedFeeds() {
431         subscribedRepositories.clear();
432         for (FeedModel feed : availableFeeds) {
433             // mark feed in the available list as subscribed
434             feed.subscribed = reg.feeds.contains(feed);
435             if (feed.subscribed) {
436                 subscribedRepositories.add(feed.repository.toLowerCase());
4cac0d 437             }
JM 438         }
17820f 439     }
JM 440
bab9c9 441     public Date getLastFeedRefresh(String repository, String branch) {
JM 442         FeedModel feed = new FeedModel();
443         feed.repository = repository;
444         feed.branch = branch;
445         if (reg.feeds.contains(feed)) {
446             int idx = reg.feeds.indexOf(feed);
447             feed = reg.feeds.get(idx);
448             return feed.lastRefreshDate;
449         }
450         return NEVER;
451     }
452
17820f 453     public boolean isSubscribed(RepositoryModel repository) {
JM 454         return subscribedRepositories.contains(repository.name.toLowerCase());
4cac0d 455     }
JM 456
ee458f 457     public List<FeedEntryModel> getSyndicatedEntries() {
4cac0d 458         return syndicatedEntries;
JM 459     }
460
f08aab 461     public List<FeedEntryModel> log(String repository, String branch, int numberOfEntries, int page)
JM 462             throws IOException {
ee458f 463         return SyndicationUtils.readFeed(url, repository, branch, numberOfEntries, page, account,
JM 464                 password);
465     }
466
467     public List<FeedEntryModel> search(String repository, String branch, String fragment,
e33b91 468             Constants.SearchType type, int numberOfEntries, int page) throws IOException {
9119cf 469         return SyndicationUtils.readSearchFeed(url, repository, branch, fragment, type,
e33b91 470                 numberOfEntries, page, account, password);
9119cf 471     }
JM 472
15a51d 473     public List<FederationModel> refreshFederationRegistrations() throws IOException {
JM 474         List<FederationModel> list = RpcUtils.getFederationRegistrations(url, account, password);
475         federationRegistrations.clear();
476         federationRegistrations.addAll(list);
477         return federationRegistrations;
478     }
479
480     public List<UserModel> getUsers() {
481         return allUsers;
482     }
699e71 483
092f0a 484     public UserModel getUser(String username) {
JM 485         for (UserModel user : getUsers()) {
486             if (user.username.equalsIgnoreCase(username)) {
487                 return user;
488             }
489         }
490         return null;
491     }
15a51d 492
JM 493     public List<String> getUsernames() {
494         List<String> usernames = new ArrayList<String>();
495         for (UserModel user : this.allUsers) {
496             usernames.add(user.username);
497         }
498         Collections.sort(usernames);
499         return usernames;
500     }
501
502     public List<String> getPermittedUsernames(RepositoryModel repository) {
503         List<String> usernames = new ArrayList<String>();
504         for (UserModel user : this.allUsers) {
822dfe 505             if (user.hasRepositoryPermission(repository.name)) {
15a51d 506                 usernames.add(user.username);
JM 507             }
508         }
509         return usernames;
822dfe 510     }
699e71 511
ba6150 512     /**
JM 513      * Returns the effective list of permissions for this user, taking into account
514      * team memberships, ownerships.
699e71 515      *
ba6150 516      * @param user
JM 517      * @return the effective list of permissions for the user
518      */
519     public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
520         Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>();
521         set.addAll(user.getRepositoryPermissions());
522         // Flag missing repositories
523         for (RegistrantAccessPermission permission : set) {
524             if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
525                 RepositoryModel rm = getRepository(permission.registrant);
526                 if (rm == null) {
527                     permission.permissionType = PermissionType.MISSING;
528                     permission.mutable = false;
529                     continue;
530                 }
531             }
532         }
533
534         // TODO reconsider ownership as a user property
535         // manually specify personal repository ownerships
536         for (RepositoryModel rm : allRepositories) {
661db6 537             if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
ba6150 538                 RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,
JM 539                         PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
540                 // user may be owner of a repository to which they've inherited
541                 // a team permission, replace any existing perm with owner perm
542                 set.remove(rp);
543                 set.add(rp);
544             }
545         }
699e71 546
ba6150 547         List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(set);
JM 548         Collections.sort(list);
549         return list;
550     }
699e71 551
5e8826 552     public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
ba6150 553         List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
JM 554         if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
555             // no permissions needed, REWIND for everyone!
556             return list;
557         }
558         if (AuthorizationControl.AUTHENTICATED.equals(repository.authorizationControl)) {
559             // no permissions needed, REWIND for authenticated!
560             return list;
561         }
562         // NAMED users and teams
563         for (UserModel user : allUsers) {
644bdd 564             RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
JM 565             if (ap.permission.exceeds(AccessPermission.NONE)) {
566                 list.add(ap);
092f0a 567             }
JM 568         }
644bdd 569         return list;
822dfe 570     }
JM 571
572     public boolean setUserAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {
573         return RpcUtils.setRepositoryMemberPermissions(repository, permissions, url, account, password);
15a51d 574     }
JM 575
f08aab 576     public List<TeamModel> getTeams() {
JM 577         return allTeams;
578     }
579
580     public List<String> getTeamnames() {
581         List<String> teamnames = new ArrayList<String>();
582         for (TeamModel team : this.allTeams) {
583             teamnames.add(team.name);
584         }
585         Collections.sort(teamnames);
586         return teamnames;
587     }
588
589     public List<String> getPermittedTeamnames(RepositoryModel repository) {
590         List<String> teamnames = new ArrayList<String>();
591         for (TeamModel team : this.allTeams) {
822dfe 592             if (team.hasRepositoryPermission(repository.name)) {
f08aab 593                 teamnames.add(team.name);
JM 594             }
595         }
596         return teamnames;
822dfe 597     }
699e71 598
5e8826 599     public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
JM 600         List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
601         for (TeamModel team : allTeams) {
644bdd 602             RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
JM 603             if (ap.permission.exceeds(AccessPermission.NONE)) {
604                 list.add(ap);
5e8826 605             }
JM 606         }
092f0a 607         Collections.sort(list);
5e8826 608         return list;
822dfe 609     }
JM 610
611     public boolean setTeamAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {
612         return RpcUtils.setRepositoryTeamPermissions(repository, permissions, url, account, password);
f08aab 613     }
0db5c4 614
97d3af 615     public TeamModel getTeamModel(String name) {
JM 616         for (TeamModel team : allTeams) {
617             if (team.name.equalsIgnoreCase(name)) {
618                 return team;
619             }
620         }
621         return null;
622     }
f08aab 623
15a51d 624     public List<String> getFederationSets() {
b75734 625         return settings.get(Keys.federation.sets).getStrings();
15a51d 626     }
JM 627
628     public List<RepositoryModel> getRepositories() {
629         return allRepositories;
630     }
699e71 631
092f0a 632     public RepositoryModel getRepository(String name) {
JM 633         for (RepositoryModel repository : allRepositories) {
634             if (repository.name.equalsIgnoreCase(name)) {
635                 return repository;
636             }
637         }
638         return null;
639     }
15a51d 640
822dfe 641     public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions)
15a51d 642             throws IOException {
822dfe 643         return createRepository(repository, userPermissions, null);
f08aab 644     }
JM 645
822dfe 646     public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions,
JM 647             List<RegistrantAccessPermission> teamPermissions) throws IOException {
15a51d 648         boolean success = true;
c25a1d 649         success &= RpcUtils.createRepository(repository, url, account, password);
822dfe 650         if (userPermissions != null && userPermissions.size() > 0) {
15a51d 651             // if new repository has named members, set them
822dfe 652             success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,
f08aab 653                     password);
JM 654         }
822dfe 655         if (teamPermissions != null && teamPermissions.size() > 0) {
f08aab 656             // if new repository has named teams, set them
822dfe 657             success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,
15a51d 658                     password);
JM 659         }
660         return success;
661     }
662
663     public boolean updateRepository(String name, RepositoryModel repository,
822dfe 664             List<RegistrantAccessPermission> userPermissions) throws IOException {
JM 665         return updateRepository(name, repository, userPermissions, null);
f08aab 666     }
JM 667
668     public boolean updateRepository(String name, RepositoryModel repository,
822dfe 669             List<RegistrantAccessPermission> userPermissions,    List<RegistrantAccessPermission> teamPermissions) throws IOException {
15a51d 670         boolean success = true;
JM 671         success &= RpcUtils.updateRepository(name, repository, url, account, password);
f08aab 672         // set the repository members
822dfe 673         if (userPermissions != null) {
JM 674             success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,
f08aab 675                     password);
JM 676         }
822dfe 677         if (teamPermissions != null) {
JM 678             success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,
f08aab 679                     password);
JM 680         }
15a51d 681         return success;
JM 682     }
683
684     public boolean deleteRepository(RepositoryModel repository) throws IOException {
685         return RpcUtils.deleteRepository(repository, url, account, password);
686     }
699e71 687
fee060 688     public boolean clearRepositoryCache() throws IOException {
JM 689         return RpcUtils.clearRepositoryCache(url, account, password);
690     }
15a51d 691
JM 692     public boolean createUser(UserModel user) throws IOException {
693         return RpcUtils.createUser(user, url, account, password);
694     }
695
696     public boolean updateUser(String name, UserModel user) throws IOException {
697         return RpcUtils.updateUser(name, user, url, account, password);
698     }
699
700     public boolean deleteUser(UserModel user) throws IOException {
701         return RpcUtils.deleteUser(user, url, account, password);
702     }
2a99c3 703
f08aab 704     public boolean createTeam(TeamModel team) throws IOException {
JM 705         return RpcUtils.createTeam(team, url, account, password);
706     }
707
708     public boolean updateTeam(String name, TeamModel team) throws IOException {
709         return RpcUtils.updateTeam(name, team, url, account, password);
710     }
711
712     public boolean deleteTeam(TeamModel team) throws IOException {
713         return RpcUtils.deleteTeam(team, url, account, password);
714     }
715
2a99c3 716     public boolean updateSettings(Map<String, String> newSettings) throws IOException {
JM 717         return RpcUtils.updateSettings(newSettings, url, account, password);
718     }
15a51d 719 }