View Javadoc

1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.model;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.Comparator;
24  import java.util.List;
25  import java.util.Set;
26  import java.util.TreeSet;
27  
28  import org.apache.commons.lang.builder.CompareToBuilder;
29  import org.apache.commons.lang.builder.ToStringBuilder;
30  
31  /**
32   * This is a POJO Business Domain Object modelling a project.
33   * 
34   * <p>
35   * Hibernate Bean.
36   * </p>
37   * 
38   * @author ready
39   */
40  public class Project extends AbstractEntity implements Comparable<Entity> {
41  
42  	public static final ProjectComparator PROJECT_COMPARATOR = new ProjectComparator();
43  	/**
44  	 * 
45  	 */
46  	private static final long serialVersionUID = 1L;
47  
48  	private String name;
49  
50  	private String description;
51  
52  	/**
53  	 * Project's current status.
54  	 * 
55  	 * <p>
56  	 * Invariant : never <tt>null</tt>.
57  	 * </p>
58  	 */
59  	private Status status;
60  
61  	private int options;
62  
63  	/**
64  	 * The list of Components that belong to this project.
65  	 * 
66  	 * <p>
67  	 * Project - Component is a 1-N relationship.
68  	 * </p>
69  	 */
70  	private List<Component> components = new ArrayList<Component>();
71  
72  	/**
73  	 * The list of Versions of this Project.
74  	 * 
75  	 * <p>
76  	 * Project - Version is a 1-N relationship.
77  	 * </p>
78  	 */
79  	private List<Version> versions = new ArrayList<Version>();
80  
81  	/**
82  	 * The Permissions of all Users on this Project.
83  	 * 
84  	 * <p>
85  	 * Project - Permission is a 1-N relationship.
86  	 * </p>
87  	 * 
88  	 * PENDING: Does this relationship need to be navigatable ?
89  	 */
90  	// TODO: it would be a Set, not list
91  	private Set<Permission> permissions = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);
92  
93  	/**
94  	 * The Users who are responsible for this Project.
95  	 * 
96  	 * Project - User (owners) is a M-N relationship.
97  	 */
98  	private List<User> owners = new ArrayList<User>();
99  
100 	/**
101 	 * The custom fields associated to this Project.
102 	 * 
103 	 * <p>
104 	 * Project - CustomField is a M-N relationship.
105 	 * </p>
106 	 * 
107 	 * <p>
108 	 * All Issues of this Project will have these custom fields.
109 	 * </p>
110 	 */
111 	private List<CustomField> customFields = new ArrayList<CustomField>();
112 
113 	/**
114 	 * Project - ProjectScript is a 1-N relationship.
115 	 */
116 	private List<ProjectScript> scripts = new ArrayList<ProjectScript>();
117 
118 	/*
119 	 * This class used to have a <code>issues</code> attribute, which was a
120 	 * Collection<Issue>. This has been removed because the association Project -
121 	 * Issue doesn't need to be navigatable in this direction.
122 	 */
123 
124 	/**
125 	 * Default constructor (required by Hibernate).
126 	 * 
127 	 * <p>
128 	 * PENDING: should be <code>private</code> so that it can only be used by
129 	 * Hibernate, to ensure that the fields which form an instance's identity
130 	 * are always initialized/never <tt>null</tt>.
131 	 * </p>
132 	 */
133 	public Project() {
134 	}
135 
136 	public Project(String name) {
137 		setName(name);
138 		this.status = Status.ACTIVE;
139 	}
140 
141 	public String getName() {
142 		return name;
143 	}
144 
145 	public void setName(String name) {
146 		if (name == null) {
147 			throw new IllegalArgumentException("null name");
148 		}
149 		this.name = name;
150 	}
151 
152 	public String getDescription() {
153 		return description;
154 	}
155 
156 	public void setDescription(String description) {
157 		this.description = description;
158 	}
159 
160 	/**
161 	 * @return project's current status
162 	 */
163 	public Status getStatus() {
164 		return status;
165 	}
166 
167 	/**
168 	 * 
169 	 * @param status
170 	 * @throws IllegalArgumentException
171 	 *             status is <tt>null</tt>
172 	 */
173 	public void setStatus(Status status) {
174 		if (status == null) {
175 			throw new IllegalArgumentException("null status");
176 		}
177 		this.status = status;
178 	}
179 
180 	public int getOptions() {
181 		return options;
182 	}
183 
184 	public void setOptions(int options) {
185 		this.options = options;
186 	}
187 
188 	public List<Component> getComponents() {
189 		return components;
190 	}
191 
192 	public void setComponents(List<Component> getComponents) {
193 		this.components = getComponents;
194 	}
195 
196 	public List<Version> getVersions() {
197 		return versions;
198 	}
199 
200 	public void setVersions(List<Version> getVersions) {
201 		this.versions = getVersions;
202 	}
203 
204 	public List<CustomField> getCustomFields() {
205 		return customFields;
206 	}
207 
208 	public void setCustomFields(List<CustomField> getCustomFields) {
209 		this.customFields = getCustomFields;
210 	}
211 
212 	public List<User> getOwners() {
213 		return owners;
214 	}
215 
216 	public void setOwners(List<User> getOwners) {
217 		this.owners = getOwners;
218 	}
219 
220 	public Set<Permission> getPermissions() {
221 		return permissions;
222 	}
223 
224 	public void setPermissions(Set<Permission> getPermissions) {
225 		this.permissions = getPermissions;
226 	}
227 
228 	public List<ProjectScript> getScripts() {
229 		return scripts;
230 	}
231 
232 	public void setScripts(List<ProjectScript> getScripts) {
233 		this.scripts = getScripts;
234 	}
235 
236 	/**
237 	 * @return <tt>Project [id=id, name=name]</tt>
238 	 */
239 	@Override
240 	public String toString() {
241 
242 		return new ToStringBuilder(this).append("id", this.getId()).append("name",
243 				this.getName()).append("description", getDescription()).append("owners", getOwners()).toString();
244 	}
245 
246 	/**
247 	 * Comparator for comparing projects by name
248 	 */
249 	public static final class ProjectComparator implements Comparator<Project>, Serializable {
250 		/**
251 		 * 
252 		 */
253 		private static final long serialVersionUID = 1L;
254 		public int compare(Project o1, Project o2) {
255 			return new CompareToBuilder().append(o1.getName(), o2.getName()).append(
256 					o1.getId(), o2.getId()).toComparison();
257 		}
258 	}
259 }