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.

FederationProposal.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.models;
  17. import java.io.Serializable;
  18. import java.util.Date;
  19. import java.util.Map;
  20. import com.gitblit.Constants.FederationToken;
  21. /**
  22. * Represents a proposal from a Gitblit instance to pull its repositories.
  23. */
  24. public class FederationProposal implements Serializable {
  25. private static final long serialVersionUID = 1L;
  26. public Date received;
  27. public String name;
  28. public String url;
  29. public FederationToken tokenType;
  30. public String token;
  31. public String message;
  32. public Map<String, RepositoryModel> repositories;
  33. /**
  34. * The constructor for a federation proposal.
  35. *
  36. * @param url
  37. * the url of the source Gitblit instance
  38. * @param tokenType
  39. * the type of token from the source Gitblit instance
  40. * @param token
  41. * the federation token from the source Gitblit instance
  42. * @param repositories
  43. * the map of repositories to be pulled from the source Gitblit
  44. * instance keyed by the repository clone url
  45. */
  46. public FederationProposal(String url, FederationToken tokenType, String token,
  47. Map<String, RepositoryModel> repositories) {
  48. this.received = new Date();
  49. this.url = url;
  50. this.tokenType = tokenType;
  51. this.token = token;
  52. this.message = "";
  53. this.repositories = repositories;
  54. try {
  55. // determine server name and set that as the proposal name
  56. name = url.substring(url.indexOf("//") + 2);
  57. if (name.contains("/")) {
  58. name = name.substring(0, name.indexOf('/'));
  59. }
  60. name = name.replace(".", "").replace(";", "").replace(":", "").replace("-", "");
  61. } catch (Exception e) {
  62. name = Long.toHexString(System.currentTimeMillis());
  63. }
  64. }
  65. @Override
  66. public String toString() {
  67. return "Federation Proposal (" + url + ")";
  68. }
  69. }