From 13a3f5bc3e2d25fc76850f86070dc34efe60d77a Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 7 Sep 2012 22:06:15 -0400 Subject: Draft project pages, project metadata, and RSS feeds This is an in-progress feature to offer an interface for grouped repositories. This may help installations with large numbers of repositories stay organized. It also will be part of a future, more advanced security model. --- src/com/gitblit/models/ProjectModel.java | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/com/gitblit/models/ProjectModel.java (limited to 'src/com/gitblit/models') diff --git a/src/com/gitblit/models/ProjectModel.java b/src/com/gitblit/models/ProjectModel.java new file mode 100644 index 00000000..bc359037 --- /dev/null +++ b/src/com/gitblit/models/ProjectModel.java @@ -0,0 +1,95 @@ +/* + * Copyright 2012 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.models; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import com.gitblit.utils.StringUtils; + +/** + * ProjectModel is a serializable model class. + * + * @author James Moger + * + */ +public class ProjectModel implements Serializable, Comparable { + + private static final long serialVersionUID = 1L; + + // field names are reflectively mapped in EditProject page + public final String name; + public String title; + public String description; + public final Set repositories = new HashSet(); + + public Date lastChange; + public final boolean isRoot; + + public ProjectModel(String name) { + this(name, false); + } + + public ProjectModel(String name, boolean isRoot) { + this.name = name; + this.isRoot = isRoot; + this.lastChange = new Date(0); + this.title = ""; + this.description = ""; + } + + public boolean hasRepository(String name) { + return repositories.contains(name.toLowerCase()); + } + + public void addRepository(String name) { + repositories.add(name.toLowerCase()); + } + + public void addRepository(RepositoryModel model) { + repositories.add(model.name.toLowerCase()); + if (lastChange.before(model.lastChange)) { + lastChange = model.lastChange; + } + } + + public void addRepositories(Collection names) { + for (String name:names) { + repositories.add(name.toLowerCase()); + } + } + + public void removeRepository(String name) { + repositories.remove(name.toLowerCase()); + } + + public String getDisplayName() { + return StringUtils.isEmpty(title) ? name : title; + } + + @Override + public String toString() { + return name; + } + + @Override + public int compareTo(ProjectModel o) { + return name.compareTo(o.name); + } +} -- cgit v1.2.3