Project.java

  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. package org.itracker.model;

  19. import org.apache.commons.lang.builder.CompareToBuilder;
  20. import org.apache.commons.lang.builder.ToStringBuilder;

  21. import java.io.Serializable;
  22. import java.util.*;

  23. /**
  24.  * This is a POJO Business Domain Object modelling a project.
  25.  * <p/>
  26.  * <p>
  27.  * Hibernate Bean.
  28.  * </p>
  29.  *
  30.  * @author ready
  31.  */
  32. public class Project extends AbstractEntity implements Comparable<Entity> {

  33.     public static final ProjectComparator PROJECT_COMPARATOR = new ProjectComparator();
  34.     /**
  35.      *
  36.      */
  37.     private static final long serialVersionUID = 1L;

  38.     private String name;

  39.     private String description;

  40.     /**
  41.      * Project's current status.
  42.      * <p/>
  43.      * <p>
  44.      * Invariant : never <tt>null</tt>.
  45.      * </p>
  46.      */
  47.     private Status status;

  48.     private int options;

  49.     /**
  50.      * The list of Components that belong to this project.
  51.      * <p/>
  52.      * <p>
  53.      * Project - Component is a 1-N relationship.
  54.      * </p>
  55.      */
  56.     private List<Component> components = new ArrayList<Component>();

  57.     /**
  58.      * The list of Versions of this Project.
  59.      * <p/>
  60.      * <p>
  61.      * Project - Version is a 1-N relationship.
  62.      * </p>
  63.      */
  64.     private List<Version> versions = new ArrayList<Version>();

  65.     /**
  66.      * The Permissions of all Users on this Project.
  67.      * <p/>
  68.      * <p>
  69.      * Project - Permission is a 1-N relationship.
  70.      * </p>
  71.      * <p/>
  72.      * PENDING: Does this relationship need to be navigatable ?
  73.      */
  74.     // TODO: it would be a Set, not list
  75.     private Set<Permission> permissions = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);

  76.     /**
  77.      * The Users who are responsible for this Project.
  78.      * <p/>
  79.      * Project - User (owners) is a M-N relationship.
  80.      */
  81.     private List<User> owners = new ArrayList<User>();

  82.     /**
  83.      * The custom fields associated to this Project.
  84.      * <p/>
  85.      * <p>
  86.      * Project - CustomField is a M-N relationship.
  87.      * </p>
  88.      * <p/>
  89.      * <p>
  90.      * All Issues of this Project will have these custom fields.
  91.      * </p>
  92.      */
  93.     private List<CustomField> customFields = new ArrayList<CustomField>();

  94.     /**
  95.      * Project - ProjectScript is a 1-N relationship.
  96.      */
  97.     private List<ProjectScript> scripts = new ArrayList<ProjectScript>();

  98.     /*
  99.       * This class used to have a <code>issues</code> attribute, which was a
  100.       * Collection<Issue>. This has been removed because the association Project -
  101.       * Issue doesn't need to be navigatable in this direction.
  102.       */

  103.     /**
  104.      * Default constructor (required by Hibernate).
  105.      * <p/>
  106.      * <p>
  107.      * PENDING: should be <code>private</code> so that it can only be used by
  108.      * Hibernate, to ensure that the fields which form an instance's identity
  109.      * are always initialized/never <tt>null</tt>.
  110.      * </p>
  111.      */
  112.     public Project() {
  113.     }

  114.     public Project(String name) {
  115.         setName(name);
  116.         this.status = Status.ACTIVE;
  117.     }

  118.     public String getName() {
  119.         return name;
  120.     }

  121.     public void setName(String name) {
  122.         if (name == null) {
  123.             throw new IllegalArgumentException("null name");
  124.         }
  125.         this.name = name;
  126.     }

  127.     public String getDescription() {
  128.         return description;
  129.     }

  130.     public void setDescription(String description) {
  131.         this.description = description;
  132.     }

  133.     /**
  134.      * @return project's current status
  135.      */
  136.     public Status getStatus() {
  137.         return status;
  138.     }

  139.     /**
  140.      * @throws IllegalArgumentException status is <tt>null</tt>
  141.      */
  142.     public void setStatus(Status status) {
  143.         if (status == null) {
  144.             throw new IllegalArgumentException("null status");
  145.         }
  146.         this.status = status;
  147.     }

  148.     public int getOptions() {
  149.         return options;
  150.     }

  151.     public void setOptions(int options) {
  152.         this.options = options;
  153.     }

  154.     public List<Component> getComponents() {
  155.         return components;
  156.     }

  157.     public void setComponents(List<Component> getComponents) {
  158.         this.components = getComponents;
  159.     }

  160.     public List<Version> getVersions() {
  161.         return versions;
  162.     }

  163.     public void setVersions(List<Version> getVersions) {
  164.         this.versions = getVersions;
  165.     }

  166.     public List<CustomField> getCustomFields() {
  167.         return customFields;
  168.     }

  169.     public void setCustomFields(List<CustomField> getCustomFields) {
  170.         this.customFields = getCustomFields;
  171.     }

  172.     public List<User> getOwners() {
  173.         return owners;
  174.     }

  175.     public void setOwners(List<User> getOwners) {
  176.         this.owners = getOwners;
  177.     }

  178.     public Set<Permission> getPermissions() {
  179.         return permissions;
  180.     }

  181.     public void setPermissions(Set<Permission> getPermissions) {
  182.         this.permissions = getPermissions;
  183.     }

  184.     public List<ProjectScript> getScripts() {
  185.         return scripts;
  186.     }

  187.     public void setScripts(List<ProjectScript> getScripts) {
  188.         this.scripts = getScripts;
  189.     }

  190.     /**
  191.      * @return <tt>Project [id=id, name=name]</tt>
  192.      */
  193.     @Override
  194.     public String toString() {

  195.         return new ToStringBuilder(this).append("id", this.getId()).append("name",
  196.                 this.getName()).append("description", getDescription()).append("owners", getOwners()).toString();
  197.     }

  198.     /**
  199.      * Comparator for comparing projects by name
  200.      */
  201.     public static final class ProjectComparator implements Comparator<Project>, Serializable {
  202.         /**
  203.          *
  204.          */
  205.         private static final long serialVersionUID = 1L;

  206.         public int compare(Project o1, Project o2) {
  207.             return new CompareToBuilder().append(o1.getName(), o2.getName()).append(
  208.                     o1.getId(), o2.getId()).toComparison();
  209.         }
  210.     }
  211. }