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.ToStringBuilder;
22  import org.itracker.model.util.IssueUtilities;
23  
24  /**
25   * An issue history entry.
26   * <p/>
27   * <p>
28   * An IssueHistory can only belong to 1 Issue (composition).
29   * </p>
30   * <p/>
31   * <p>
32   * PENDING : what's the difference with an IssueActivity ?
33   * </p>
34   *
35   * @author ready
36   */
37  public class IssueHistory extends AbstractEntity {
38  
39      /**
40       *
41       */
42      private static final long serialVersionUID = 1L;
43  
44      private Issue issue;
45  
46      private String description;
47  
48      private int status;
49  
50      /**
51       * The User who generated this history entry.
52       */
53      private User creator;
54  
55      /**
56       * Default constructor (required by Hibernate).
57       * <p/>
58       * <p>
59       * PENDING: should be <code>private</code> so that it can only be used by
60       * Hibernate, to ensure that the fields which form an instance's identity
61       * are always initialized/never <tt>null</tt>.
62       * </p>
63       */
64      public IssueHistory() {
65      }
66  
67      public IssueHistory(Issue issue, User creator) {
68          setIssue(issue);
69          setUser(creator);
70          setStatus(IssueUtilities.HISTORY_STATUS_AVAILABLE);
71      }
72  
73      public IssueHistory(Issue issue, User creator, String description,
74                          int status) {
75          setIssue(issue);
76          setUser(creator);
77          setDescription(description);
78          setStatus(status);
79      }
80  
81      public Issue getIssue() {
82          return issue;
83      }
84  
85      public void setIssue(Issue issue) {
86          if (issue == null) {
87              throw new IllegalArgumentException("null issue");
88          }
89          this.issue = issue;
90      }
91  
92      public User getUser() {
93          return creator;
94      }
95  
96      public void setUser(User creator) {
97          if (creator == null) {
98              throw new IllegalArgumentException("null creator");
99          }
100         this.creator = creator;
101     }
102 
103     public int getStatus() {
104         return status;
105     }
106 
107     public void setStatus(int status) {
108         this.status = status;
109     }
110 
111     public String getDescription() {
112         return description;
113     }
114 
115     public void setDescription(String description) {
116         this.description = description;
117     }
118 
119 
120     @Override
121     public String toString() {
122         return new ToStringBuilder(this).append("id", getId())
123                 .append("issue", issue).append("creator", getUser()).append(
124                         "createDate", getCreateDate()).toString();
125     }
126 
127     public static enum Status {
128 
129         STATUS_REMOVED(-1),
130 
131         STATUS_AVAILABLE(1);
132 
133         @SuppressWarnings("unused")
134         private final int code;
135 
136         private Status(int code) {
137             this.code = code;
138         }
139 
140     }
141 
142 }