You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RpcUtils.java 22KB

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