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