James Moger
2014-05-08 d99277724206102f25e7c5c569d2e7fdc891e4a0
commit | author | age
93f0b1 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.utils;
17
31abc2 18 import java.io.IOException;
93f0b1 19 import java.lang.reflect.Type;
31abc2 20 import java.util.ArrayList;
93f0b1 21 import java.util.Collection;
31abc2 22 import java.util.List;
93f0b1 23 import java.util.Map;
JM 24
25 import com.gitblit.Constants;
26 import com.gitblit.Constants.RpcRequest;
f08aab 27 import com.gitblit.GitBlitException.UnknownRequestException;
813a1f 28 import com.gitblit.models.FederationModel;
JM 29 import com.gitblit.models.FederationProposal;
30 import com.gitblit.models.FederationSet;
31 import com.gitblit.models.FeedModel;
32 import com.gitblit.models.RegistrantAccessPermission;
33 import com.gitblit.models.RepositoryModel;
34 import com.gitblit.models.ServerSettings;
35 import com.gitblit.models.ServerStatus;
36 import com.gitblit.models.TeamModel;
37 import com.gitblit.models.UserModel;
93f0b1 38 import com.google.gson.reflect.TypeToken;
JM 39
40 /**
41  * Utility methods for rpc calls.
699e71 42  *
93f0b1 43  * @author James Moger
699e71 44  *
93f0b1 45  */
JM 46 public class RpcUtils {
47
31abc2 48     public static final Type NAMES_TYPE = new TypeToken<Collection<String>>() {
d03aff 49     }.getType();
JM 50
97a20e 51     public static final Type SETTINGS_TYPE = new TypeToken<Map<String, String>>() {
93f0b1 52     }.getType();
JM 53
31abc2 54     private static final Type REPOSITORIES_TYPE = new TypeToken<Map<String, RepositoryModel>>() {
JM 55     }.getType();
56
57     private static final Type USERS_TYPE = new TypeToken<Collection<UserModel>>() {
f08aab 58     }.getType();
JM 59
60     private static final Type TEAMS_TYPE = new TypeToken<Collection<TeamModel>>() {
31abc2 61     }.getType();
JM 62
63     private static final Type REGISTRATIONS_TYPE = new TypeToken<Collection<FederationModel>>() {
64     }.getType();
65
66     private static final Type PROPOSALS_TYPE = new TypeToken<Collection<FederationProposal>>() {
67     }.getType();
68
69     private static final Type SETS_TYPE = new TypeToken<Collection<FederationSet>>() {
93f0b1 70     }.getType();
JM 71
c75304 72     private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() {
822dfe 73     }.getType();
JM 74
75     public static final Type REGISTRANT_PERMISSIONS_TYPE = new TypeToken<Collection<RegistrantAccessPermission>>() {
c75304 76     }.getType();
JM 77
93f0b1 78     /**
699e71 79      *
93f0b1 80      * @param remoteURL
JM 81      *            the url of the remote gitblit instance
82      * @param req
83      *            the rpc request type
84      * @return
85      */
86     public static String asLink(String remoteURL, RpcRequest req) {
31abc2 87         return asLink(remoteURL, req, null);
JM 88     }
89
90     /**
699e71 91      *
31abc2 92      * @param remoteURL
JM 93      *            the url of the remote gitblit instance
94      * @param req
95      *            the rpc request type
96      * @param name
97      *            the name of the actionable object
98      * @return
99      */
100     public static String asLink(String remoteURL, RpcRequest req, String name) {
93f0b1 101         if (remoteURL.length() > 0 && remoteURL.charAt(remoteURL.length() - 1) == '/') {
JM 102             remoteURL = remoteURL.substring(0, remoteURL.length() - 1);
103         }
104         if (req == null) {
105             req = RpcRequest.LIST_REPOSITORIES;
106         }
31abc2 107         return remoteURL + Constants.RPC_PATH + "?req=" + req.name().toLowerCase()
f08aab 108                 + (name == null ? "" : ("&name=" + StringUtils.encodeURL(name)));
JM 109     }
110
111     /**
112      * Returns the version of the RPC protocol on the server.
699e71 113      *
f08aab 114      * @param serverUrl
JM 115      * @param account
116      * @param password
117      * @return the protocol version
118      * @throws IOException
119      */
120     public static int getProtocolVersion(String serverUrl, String account, char[] password)
121             throws IOException {
122         String url = asLink(serverUrl, RpcRequest.GET_PROTOCOL);
123         int protocol = 1;
124         try {
125             protocol = JsonUtils.retrieveJson(url, Integer.class, account, password);
126         } catch (UnknownRequestException e) {
699e71 127             // v0.7.0 (protocol 1) did not have this request type
f08aab 128         }
JM 129         return protocol;
93f0b1 130     }
31abc2 131
93f0b1 132     /**
JM 133      * Retrieves a map of the repositories at the remote gitblit instance keyed
134      * by the repository clone url.
699e71 135      *
93f0b1 136      * @param serverUrl
31abc2 137      * @param account
JM 138      * @param password
93f0b1 139      * @return a map of cloneable repositories
31abc2 140      * @throws IOException
93f0b1 141      */
31abc2 142     public static Map<String, RepositoryModel> getRepositories(String serverUrl, String account,
JM 143             char[] password) throws IOException {
93f0b1 144         String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORIES);
31abc2 145         Map<String, RepositoryModel> models = JsonUtils.retrieveJson(url, REPOSITORIES_TYPE,
JM 146                 account, password);
93f0b1 147         return models;
JM 148     }
149
150     /**
151      * Tries to pull the gitblit user accounts from the remote gitblit instance.
699e71 152      *
93f0b1 153      * @param serverUrl
31abc2 154      * @param account
JM 155      * @param password
93f0b1 156      * @return a collection of UserModel objects
31abc2 157      * @throws IOException
93f0b1 158      */
31abc2 159     public static List<UserModel> getUsers(String serverUrl, String account, char[] password)
JM 160             throws IOException {
93f0b1 161         String url = asLink(serverUrl, RpcRequest.LIST_USERS);
31abc2 162         Collection<UserModel> models = JsonUtils.retrieveJson(url, USERS_TYPE, account, password);
JM 163         List<UserModel> list = new ArrayList<UserModel>(models);
f08aab 164         return list;
JM 165     }
166
167     /**
168      * Tries to pull the gitblit team definitions from the remote gitblit
169      * instance.
699e71 170      *
f08aab 171      * @param serverUrl
JM 172      * @param account
173      * @param password
174      * @return a collection of UserModel objects
175      * @throws IOException
176      */
177     public static List<TeamModel> getTeams(String serverUrl, String account, char[] password)
178             throws IOException {
179         String url = asLink(serverUrl, RpcRequest.LIST_TEAMS);
180         Collection<TeamModel> models = JsonUtils.retrieveJson(url, TEAMS_TYPE, account, password);
181         List<TeamModel> list = new ArrayList<TeamModel>(models);
31abc2 182         return list;
JM 183     }
184
185     /**
186      * Create a repository on the Gitblit server.
699e71 187      *
31abc2 188      * @param repository
JM 189      * @param serverUrl
190      * @param account
191      * @param password
192      * @return true if the action succeeded
193      * @throws IOException
194      */
195     public static boolean createRepository(RepositoryModel repository, String serverUrl,
196             String account, char[] password) throws IOException {
773bb6 197         // ensure repository name ends with .git
JM 198         if (!repository.name.endsWith(".git")) {
199             repository.name += ".git";
200         }
31abc2 201         return doAction(RpcRequest.CREATE_REPOSITORY, null, repository, serverUrl, account,
JM 202                 password);
203
204     }
205
03d5ee 206     /**
813a1f 207      * Create a fork of a repository.
03d5ee 208      *
M 209      * @param repository
210
211      * @return true if the action succeeded
212      * @throws IOException
213      */
813a1f 214     public static boolean forkRepository(RepositoryModel repository, String serverUrl,
03d5ee 215                                         String account, char[] password) throws IOException {
813a1f 216         return doAction(RpcRequest.FORK_REPOSITORY, repository.name, null, serverUrl, account, password);
03d5ee 217     }
M 218
219
220     /**
31abc2 221      * Send a revised version of the repository model to the Gitblit server.
699e71 222      *
31abc2 223      * @param repository
JM 224      * @param serverUrl
225      * @param account
226      * @param password
227      * @return true if the action succeeded
228      * @throws IOException
229      */
230     public static boolean updateRepository(String repositoryName, RepositoryModel repository,
231             String serverUrl, String account, char[] password) throws IOException {
232         return doAction(RpcRequest.EDIT_REPOSITORY, repositoryName, repository, serverUrl, account,
233                 password);
234     }
235
236     /**
237      * Delete a repository from the Gitblit server.
699e71 238      *
31abc2 239      * @param repository
JM 240      * @param serverUrl
241      * @param account
242      * @param password
243      * @return true if the action succeeded
244      * @throws IOException
245      */
246     public static boolean deleteRepository(RepositoryModel repository, String serverUrl,
247             String account, char[] password) throws IOException {
248         return doAction(RpcRequest.DELETE_REPOSITORY, null, repository, serverUrl, account,
249                 password);
250
251     }
699e71 252
fee060 253     /**
JM 254      * Clears the repository cache on the Gitblit server.
699e71 255      *
fee060 256      * @param serverUrl
JM 257      * @param account
258      * @param password
259      * @return true if the action succeeded
260      * @throws IOException
261      */
699e71 262     public static boolean clearRepositoryCache(String serverUrl, String account,
fee060 263             char[] password) throws IOException {
JM 264         return doAction(RpcRequest.CLEAR_REPOSITORY_CACHE, null, null, serverUrl, account,
265                 password);
266     }
31abc2 267
JM 268     /**
88693e 269      * Reindex all tickets on the Gitblit server.
JM 270      *
271      * @param serverUrl
272      * @param account
273      * @param password
274      * @return true if the action succeeded
275      * @throws IOException
276      */
277     public static boolean reindexTickets(String serverUrl, String account,
278             char[] password) throws IOException {
279         return doAction(RpcRequest.REINDEX_TICKETS, null, null, serverUrl, account,
280                 password);
281     }
282
283     /**
284      * Reindex tickets for the specified repository on the Gitblit server.
285      *
286      * @param serverUrl
287      * @param repositoryName
288      * @param account
289      * @param password
290      * @return true if the action succeeded
291      * @throws IOException
292      */
293     public static boolean reindexTickets(String serverUrl, String repositoryName,
294             String account, char[] password) throws IOException {
295         return doAction(RpcRequest.REINDEX_TICKETS, repositoryName, null, serverUrl,
296                 account, password);
297     }
298
299     /**
31abc2 300      * Create a user on the Gitblit server.
699e71 301      *
31abc2 302      * @param user
JM 303      * @param serverUrl
304      * @param account
305      * @param password
306      * @return true if the action succeeded
307      * @throws IOException
308      */
309     public static boolean createUser(UserModel user, String serverUrl, String account,
310             char[] password) throws IOException {
311         return doAction(RpcRequest.CREATE_USER, null, user, serverUrl, account, password);
312
313     }
314
315     /**
316      * Send a revised version of the user model to the Gitblit server.
699e71 317      *
31abc2 318      * @param user
JM 319      * @param serverUrl
320      * @param account
321      * @param password
322      * @return true if the action succeeded
323      * @throws IOException
324      */
325     public static boolean updateUser(String username, UserModel user, String serverUrl,
326             String account, char[] password) throws IOException {
327         return doAction(RpcRequest.EDIT_USER, username, user, serverUrl, account, password);
328
329     }
330
331     /**
332      * Deletes a user from the Gitblit server.
699e71 333      *
31abc2 334      * @param user
JM 335      * @param serverUrl
336      * @param account
337      * @param password
338      * @return true if the action succeeded
339      * @throws IOException
340      */
341     public static boolean deleteUser(UserModel user, String serverUrl, String account,
342             char[] password) throws IOException {
343         return doAction(RpcRequest.DELETE_USER, null, user, serverUrl, account, password);
344     }
699e71 345
a5ae3d 346     /**
JM 347      * Tries to get the specified gitblit user account from the remote gitblit instance.
348      * If the username is null or empty, the current user is returned.
699e71 349      *
a5ae3d 350      * @param username
JM 351      * @param serverUrl
352      * @param account
353      * @param password
354      * @return a UserModel or null
355      * @throws IOException
356      */
357     public static UserModel getUser(String username, String serverUrl, String account, char[] password)
358             throws IOException {
359         String url = asLink(serverUrl, RpcRequest.GET_USER);
360         UserModel model = JsonUtils.retrieveJson(url, UserModel.class, account, password);
361         return model;
362     }
31abc2 363
JM 364     /**
f08aab 365      * Create a team on the Gitblit server.
699e71 366      *
f08aab 367      * @param team
JM 368      * @param serverUrl
369      * @param account
370      * @param password
371      * @return true if the action succeeded
372      * @throws IOException
373      */
374     public static boolean createTeam(TeamModel team, String serverUrl, String account,
375             char[] password) throws IOException {
376         return doAction(RpcRequest.CREATE_TEAM, null, team, serverUrl, account, password);
377
378     }
379
380     /**
381      * Send a revised version of the team model to the Gitblit server.
699e71 382      *
f08aab 383      * @param team
JM 384      * @param serverUrl
385      * @param account
386      * @param password
387      * @return true if the action succeeded
388      * @throws IOException
389      */
390     public static boolean updateTeam(String teamname, TeamModel team, String serverUrl,
391             String account, char[] password) throws IOException {
392         return doAction(RpcRequest.EDIT_TEAM, teamname, team, serverUrl, account, password);
393
394     }
395
396     /**
397      * Deletes a team from the Gitblit server.
699e71 398      *
f08aab 399      * @param team
JM 400      * @param serverUrl
401      * @param account
402      * @param password
403      * @return true if the action succeeded
404      * @throws IOException
405      */
406     public static boolean deleteTeam(TeamModel team, String serverUrl, String account,
407             char[] password) throws IOException {
408         return doAction(RpcRequest.DELETE_TEAM, null, team, serverUrl, account, password);
409     }
410
411     /**
31abc2 412      * Retrieves the list of users that can access the specified repository.
699e71 413      *
31abc2 414      * @param repository
JM 415      * @param serverUrl
416      * @param account
417      * @param password
418      * @return list of members
419      * @throws IOException
420      */
421     public static List<String> getRepositoryMembers(RepositoryModel repository, String serverUrl,
422             String account, char[] password) throws IOException {
423         String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_MEMBERS, repository.name);
424         Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);
425         return new ArrayList<String>(list);
426     }
699e71 427
31abc2 428     /**
822dfe 429      * Retrieves the list of user access permissions for the specified repository.
699e71 430      *
31abc2 431      * @param repository
822dfe 432      * @param serverUrl
JM 433      * @param account
434      * @param password
435      * @return list of User-AccessPermission tuples
436      * @throws IOException
437      */
699e71 438     public static List<RegistrantAccessPermission> getRepositoryMemberPermissions(RepositoryModel repository,
822dfe 439             String serverUrl, String account, char [] password) throws IOException {
JM 440         String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS, repository.name);
441         Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password);
442         return new ArrayList<RegistrantAccessPermission>(list);
443     }
444
445     /**
446      * Sets the repository user access permissions
699e71 447      *
822dfe 448      * @param repository
JM 449      * @param permissions
31abc2 450      * @param serverUrl
JM 451      * @param account
452      * @param password
453      * @return true if the action succeeded
454      * @throws IOException
455      */
822dfe 456     public static boolean setRepositoryMemberPermissions(RepositoryModel repository,
JM 457             List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password)
31abc2 458             throws IOException {
822dfe 459         return doAction(RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS, repository.name, permissions, serverUrl,
31abc2 460                 account, password);
JM 461     }
699e71 462
31abc2 463     /**
f08aab 464      * Retrieves the list of teams that can access the specified repository.
699e71 465      *
f08aab 466      * @param repository
JM 467      * @param serverUrl
468      * @param account
469      * @param password
470      * @return list of teams
471      * @throws IOException
472      */
473     public static List<String> getRepositoryTeams(RepositoryModel repository, String serverUrl,
474             String account, char[] password) throws IOException {
475         String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_TEAMS, repository.name);
476         Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);
477         return new ArrayList<String>(list);
478     }
699e71 479
f08aab 480     /**
822dfe 481      * Retrieves the list of team access permissions for the specified repository.
699e71 482      *
f08aab 483      * @param repository
822dfe 484      * @param serverUrl
JM 485      * @param account
486      * @param password
487      * @return list of Team-AccessPermission tuples
488      * @throws IOException
489      */
699e71 490     public static List<RegistrantAccessPermission> getRepositoryTeamPermissions(RepositoryModel repository,
822dfe 491             String serverUrl, String account, char [] password) throws IOException {
JM 492         String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS, repository.name);
493         Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password);
494         return new ArrayList<RegistrantAccessPermission>(list);
495     }
496
497     /**
498      * Sets the repository team access permissions
699e71 499      *
822dfe 500      * @param repository
JM 501      * @param permissions
f08aab 502      * @param serverUrl
JM 503      * @param account
504      * @param password
505      * @return true if the action succeeded
506      * @throws IOException
507      */
822dfe 508     public static boolean setRepositoryTeamPermissions(RepositoryModel repository,
JM 509             List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password)
f08aab 510             throws IOException {
822dfe 511         return doAction(RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS, repository.name, permissions, serverUrl,
f08aab 512                 account, password);
JM 513     }
699e71 514
f08aab 515     /**
31abc2 516      * Retrieves the list of federation registrations. These are the list of
JM 517      * registrations that this Gitblit instance is pulling from.
699e71 518      *
31abc2 519      * @param serverUrl
JM 520      * @param account
521      * @param password
522      * @return a collection of FederationRegistration objects
523      * @throws IOException
524      */
525     public static List<FederationModel> getFederationRegistrations(String serverUrl,
526             String account, char[] password) throws IOException {
527         String url = asLink(serverUrl, RpcRequest.LIST_FEDERATION_REGISTRATIONS);
528         Collection<FederationModel> registrations = JsonUtils.retrieveJson(url, REGISTRATIONS_TYPE,
529                 account, password);
530         List<FederationModel> list = new ArrayList<FederationModel>(registrations);
531         return list;
532     }
533
534     /**
535      * Retrieves the list of federation result registrations. These are the
536      * results reported back to this Gitblit instance from a federation client.
699e71 537      *
31abc2 538      * @param serverUrl
JM 539      * @param account
540      * @param password
541      * @return a collection of FederationRegistration objects
542      * @throws IOException
543      */
544     public static List<FederationModel> getFederationResultRegistrations(String serverUrl,
545             String account, char[] password) throws IOException {
546         String url = asLink(serverUrl, RpcRequest.LIST_FEDERATION_RESULTS);
547         Collection<FederationModel> registrations = JsonUtils.retrieveJson(url, REGISTRATIONS_TYPE,
548                 account, password);
549         List<FederationModel> list = new ArrayList<FederationModel>(registrations);
550         return list;
551     }
da0269 552
31abc2 553     /**
JM 554      * Retrieves the list of federation proposals.
699e71 555      *
31abc2 556      * @param serverUrl
JM 557      * @param account
558      * @param password
559      * @return a collection of FederationProposal objects
560      * @throws IOException
561      */
da0269 562     public static List<FederationProposal> getFederationProposals(String serverUrl, String account,
JM 563             char[] password) throws IOException {
31abc2 564         String url = asLink(serverUrl, RpcRequest.LIST_FEDERATION_PROPOSALS);
JM 565         Collection<FederationProposal> proposals = JsonUtils.retrieveJson(url, PROPOSALS_TYPE,
566                 account, password);
567         List<FederationProposal> list = new ArrayList<FederationProposal>(proposals);
568         return list;
569     }
da0269 570
31abc2 571     /**
JM 572      * Retrieves the list of federation repository sets.
699e71 573      *
31abc2 574      * @param serverUrl
JM 575      * @param account
576      * @param password
577      * @return a collection of FederationSet objects
578      * @throws IOException
579      */
da0269 580     public static List<FederationSet> getFederationSets(String serverUrl, String account,
JM 581             char[] password) throws IOException {
31abc2 582         String url = asLink(serverUrl, RpcRequest.LIST_FEDERATION_SETS);
da0269 583         Collection<FederationSet> sets = JsonUtils.retrieveJson(url, SETS_TYPE, account, password);
31abc2 584         List<FederationSet> list = new ArrayList<FederationSet>(sets);
JM 585         return list;
da0269 586     }
JM 587
588     /**
589      * Retrieves the settings of the Gitblit server.
699e71 590      *
da0269 591      * @param serverUrl
JM 592      * @param account
593      * @param password
84c1d5 594      * @return an Settings object
da0269 595      * @throws IOException
JM 596      */
84c1d5 597     public static ServerSettings getSettings(String serverUrl, String account, char[] password)
JM 598             throws IOException {
da0269 599         String url = asLink(serverUrl, RpcRequest.LIST_SETTINGS);
d03aff 600         ServerSettings settings = JsonUtils.retrieveJson(url, ServerSettings.class, account,
JM 601                 password);
da0269 602         return settings;
b75734 603     }
JM 604
605     /**
d03aff 606      * Update the settings on the Gitblit server.
699e71 607      *
d03aff 608      * @param settings
JM 609      *            the settings to update
610      * @param serverUrl
611      * @param account
612      * @param password
613      * @return true if the action succeeded
614      * @throws IOException
615      */
616     public static boolean updateSettings(Map<String, String> settings, String serverUrl,
617             String account, char[] password) throws IOException {
618         return doAction(RpcRequest.EDIT_SETTINGS, null, settings, serverUrl, account, password);
619
620     }
621
622     /**
b75734 623      * Retrieves the server status object.
699e71 624      *
b75734 625      * @param serverUrl
JM 626      * @param account
627      * @param password
628      * @return an ServerStatus object
629      * @throws IOException
630      */
631     public static ServerStatus getStatus(String serverUrl, String account, char[] password)
632             throws IOException {
84c1d5 633         String url = asLink(serverUrl, RpcRequest.LIST_STATUS);
b75734 634         ServerStatus status = JsonUtils.retrieveJson(url, ServerStatus.class, account, password);
JM 635         return status;
31abc2 636     }
JM 637
638     /**
17820f 639      * Retrieves a map of local branches in the Gitblit server keyed by
c75304 640      * repository.
699e71 641      *
c75304 642      * @param serverUrl
JM 643      * @param account
644      * @param password
645      * @return
646      * @throws IOException
647      */
17820f 648     public static Map<String, Collection<String>> getBranches(String serverUrl, String account,
JM 649             char[] password) throws IOException {
c75304 650         String url = asLink(serverUrl, RpcRequest.LIST_BRANCHES);
17820f 651         Map<String, Collection<String>> branches = JsonUtils.retrieveJson(url, BRANCHES_TYPE,
JM 652                 account, password);
653         return branches;
654     }
655
656     /**
657      * Retrieves a list of available branch feeds in the Gitblit server.
699e71 658      *
17820f 659      * @param serverUrl
JM 660      * @param account
661      * @param password
662      * @return
663      * @throws IOException
664      */
665     public static List<FeedModel> getBranchFeeds(String serverUrl, String account, char[] password)
666             throws IOException {
667         List<FeedModel> feeds = new ArrayList<FeedModel>();
668         Map<String, Collection<String>> allBranches = getBranches(serverUrl, account, password);
669         for (Map.Entry<String, Collection<String>> entry : allBranches.entrySet()) {
670             for (String branch : entry.getValue()) {
671                 FeedModel feed = new FeedModel();
672                 feed.repository = entry.getKey();
673                 feed.branch = branch;
674                 feeds.add(feed);
675             }
676         }
677         return feeds;
c75304 678     }
JM 679
680     /**
31abc2 681      * Do the specified administrative action on the Gitblit server.
699e71 682      *
31abc2 683      * @param request
JM 684      * @param name
685      *            the name of the object (may be null)
686      * @param object
687      * @param serverUrl
688      * @param account
689      * @param password
690      * @return true if the action succeeded
691      * @throws IOException
692      */
693     protected static boolean doAction(RpcRequest request, String name, Object object,
694             String serverUrl, String account, char[] password) throws IOException {
695         String url = asLink(serverUrl, request, name);
696         String json = JsonUtils.toJsonString(object);
697         int resultCode = JsonUtils.sendJsonString(url, json, account, password);
698         return resultCode == 200;
da0269 699     }
93f0b1 700 }