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.6KB

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