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.

TeamModel.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.ArrayList;
  19. import java.util.Collection;
  20. import java.util.HashSet;
  21. import java.util.List;
  22. import java.util.Set;
  23. /**
  24. * TeamModel is a serializable model class that represents a group of users and
  25. * a list of accessible repositories.
  26. *
  27. * @author James Moger
  28. *
  29. */
  30. public class TeamModel implements Serializable, Comparable<TeamModel> {
  31. private static final long serialVersionUID = 1L;
  32. // field names are reflectively mapped in EditTeam page
  33. public String name;
  34. public final Set<String> users = new HashSet<String>();
  35. public final Set<String> repositories = new HashSet<String>();
  36. public final Set<String> mailingLists = new HashSet<String>();
  37. public final List<String> preReceiveScripts = new ArrayList<String>();
  38. public final List<String> postReceiveScripts = new ArrayList<String>();
  39. public TeamModel(String name) {
  40. this.name = name;
  41. }
  42. public boolean hasRepository(String name) {
  43. return repositories.contains(name.toLowerCase());
  44. }
  45. public void addRepository(String name) {
  46. repositories.add(name.toLowerCase());
  47. }
  48. public void addRepositories(Collection<String> names) {
  49. for (String name:names) {
  50. repositories.add(name.toLowerCase());
  51. }
  52. }
  53. public void removeRepository(String name) {
  54. repositories.remove(name.toLowerCase());
  55. }
  56. public boolean hasUser(String name) {
  57. return users.contains(name.toLowerCase());
  58. }
  59. public void addUser(String name) {
  60. users.add(name.toLowerCase());
  61. }
  62. public void addUsers(Collection<String> names) {
  63. for (String name:names) {
  64. users.add(name.toLowerCase());
  65. }
  66. }
  67. public void removeUser(String name) {
  68. users.remove(name.toLowerCase());
  69. }
  70. public void addMailingLists(Collection<String> addresses) {
  71. for (String address:addresses) {
  72. mailingLists.add(address.toLowerCase());
  73. }
  74. }
  75. @Override
  76. public String toString() {
  77. return name;
  78. }
  79. @Override
  80. public int compareTo(TeamModel o) {
  81. return name.compareTo(o.name);
  82. }
  83. }