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