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.core.resources.ITrackerResources;
23
24 /**
25 * A relation between issues.
26 *
27 * @author ready
28 */
29 public class IssueRelation extends AbstractEntity {
30
31 /**
32 *
33 */
34 private static final long serialVersionUID = 1L;
35
36 private Issue issue;
37
38 private Issue relatedIssue;
39
40 /**
41 * Indicates the kind of relation that exists between the 2 issues.
42 */
43 private Type type;
44
45 private Integer matchingRelationId;
46
47 /**
48 * Default constructor (required by Hibernate).
49 * <p/>
50 * <p>
51 * PENDING: should be <code>private</code> so that it can only be used by
52 * Hibernate, to ensure that the fields which form an instance's identity
53 * are always initialized/never <tt>null</tt>.
54 * </p>
55 */
56 public IssueRelation() {
57 }
58
59 public IssueRelation(Issueef="../../../org/itracker/model/Issue.html#Issue">Issue issue, Issue relatedIssue, Type relationType) {
60 setIssue(issue);
61 setRelatedIssue(relatedIssue);
62 setRelationType(relationType);
63 }
64
65 public Issue getIssue() {
66 return issue;
67 }
68
69 public void setIssue(Issue issue) {
70 if (issue == null) {
71 throw new IllegalArgumentException("null issue");
72 }
73 this.issue = issue;
74 }
75
76 public Issue getRelatedIssue() {
77 return relatedIssue;
78 }
79
80 public void setRelatedIssue(Issue relatedIssue) {
81 if (relatedIssue == null) {
82 throw new IllegalArgumentException("null relatedIssue");
83 }
84 this.relatedIssue = relatedIssue;
85 }
86
87 public Type getRelationType() {
88 return type;
89 }
90
91 public void setRelationType(Type type) {
92 this.type = type;
93 }
94
95 public Integer getMatchingRelationId() {
96 return matchingRelationId;
97 }
98
99 public void setMatchingRelationId(Integer matchingRelationId) {
100 this.matchingRelationId = matchingRelationId;
101 }
102
103
104 @Override
105 public String toString() {
106 return new ToStringBuilder(this).append("id", getId())
107 .append("issue", getIssue()).append("relatedIssue", getRelatedIssue())
108 .append("type", getRelationType()).toString();
109 }
110
111 public static enum Type implements IntCodeEnum<Type> {
112
113 /**
114 * Defines a related issue. Sample text: related to
115 */
116 RELATED_P(1),
117
118 /**
119 * Defines a related issue. Sample text: related to
120 */
121 RELATED_C(2),
122
123 /**
124 * Defines a duplicate issue. Sample text: duplicates
125 */
126 DUPLICATE_P(3),
127
128 /**
129 * Defines a duplicate issue. Sample text: duplicate of
130 */
131 DUPLICATE_C(4),
132
133 /**
134 * Defines a cloned issue. Sample text: cloned to
135 */
136 CLONED_P(5),
137
138 /**
139 * Defines a cloned issue. Sample text: cloned from
140 */
141 CLONED_C(6),
142
143 /**
144 * Defines a split issue. Sample text: split to
145 */
146 SPLIT_P(7),
147
148 /**
149 * Defines a split issue. Sample text: split from
150 */
151 SPLIT_C(8),
152
153 /**
154 * Defines a dependent issue. Sample text: dependents
155 */
156 DEPENDENT_P(9),
157
158 /**
159 * Defines a dependent issue. Sample text: depends on
160 */
161 DEPENDENT_C(10);
162
163
164
165 private final Integer code;
166
167 private Type(Integer code) {
168 this.code = code;
169 }
170
171 public Integer getCode() {
172 return code;
173 }
174
175 public Type fromCode(Integer code) {
176 return Type.valueOf(code);
177 }
178
179 public static Type valueOf(Integer code) {
180 for (Type val: values()) {
181 if (val.code.compareTo(code) == 0) {
182 return val;
183 }
184 }
185 throw new IllegalArgumentException("Unknown code : " + code);
186 }
187 /**
188 * Returns the key for a particular issue relation type.
189 *
190 * @return the key for the item
191 */
192 public String getLanguageKeyCode() {
193 String key = ITrackerResources.KEY_BASE_ISSUE_RELATION + getCode();
194 return key;
195 }
196
197
198 }
199
200 }