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