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.

ProjectModel.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2012 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.Collection;
  19. import java.util.Date;
  20. import java.util.HashSet;
  21. import java.util.Set;
  22. import com.gitblit.utils.StringUtils;
  23. /**
  24. * ProjectModel is a serializable model class.
  25. *
  26. * @author James Moger
  27. *
  28. */
  29. public class ProjectModel implements Serializable, Comparable<ProjectModel> {
  30. private static final long serialVersionUID = 1L;
  31. // field names are reflectively mapped in EditProject page
  32. public final String name;
  33. public String title;
  34. public String description;
  35. public final Set<String> repositories = new HashSet<String>();
  36. public Date lastChange;
  37. public final boolean isRoot;
  38. public ProjectModel(String name) {
  39. this(name, false);
  40. }
  41. public ProjectModel(String name, boolean isRoot) {
  42. this.name = name;
  43. this.isRoot = isRoot;
  44. this.lastChange = new Date(0);
  45. this.title = "";
  46. this.description = "";
  47. }
  48. public boolean isUserProject() {
  49. return name.charAt(0) == '~';
  50. }
  51. public boolean hasRepository(String name) {
  52. return repositories.contains(name.toLowerCase());
  53. }
  54. public void addRepository(String name) {
  55. repositories.add(name.toLowerCase());
  56. }
  57. public void addRepository(RepositoryModel model) {
  58. repositories.add(model.name.toLowerCase());
  59. if (lastChange.before(model.lastChange)) {
  60. lastChange = model.lastChange;
  61. }
  62. }
  63. public void addRepositories(Collection<String> names) {
  64. for (String name:names) {
  65. repositories.add(name.toLowerCase());
  66. }
  67. }
  68. public void removeRepository(String name) {
  69. repositories.remove(name.toLowerCase());
  70. }
  71. public String getDisplayName() {
  72. return StringUtils.isEmpty(title) ? name : title;
  73. }
  74. @Override
  75. public String toString() {
  76. return name;
  77. }
  78. @Override
  79. public int compareTo(ProjectModel o) {
  80. return name.compareTo(o.name);
  81. }
  82. }