1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 import org.itracker.model.util.IssueUtilities;
24
25 import java.io.Serializable;
26 import java.util.Comparator;
27
28
29
30
31
32
33 public class Configuration extends AbstractEntity implements Comparable<Entity> {
34
35 public static enum Type implements IntCodeEnum<Type> {
36 initialized(-1, 0),
37 locale(1, 0),
38 status(2, IssueUtilities.FIELD_STATUS),
39 severity(3, IssueUtilities.FIELD_SEVERITY),
40 resolution(4, IssueUtilities.FIELD_RESOLUTION),
41 customfield(5, 0);
42
43
44 private final Integer code;
45 private final Integer legacyCode;
46
47 private Type(Integer code, Integer legacyCode) {
48 this.code = code;
49 this.legacyCode = legacyCode;
50 }
51
52 public Integer getCode() {
53 return code;
54 }
55
56 public Type fromCode(Integer code) {
57 return Type.valueOf(code);
58 }
59
60 public Integer getLegacyCode() {
61 return legacyCode;
62 }
63
64 public static Type valueOf(Integer code) {
65 for (Type val: values()) {
66 if (val.code.compareTo(code) == 0) {
67 return val;
68 }
69 }
70 throw new IllegalArgumentException("Unknown code : " + code);
71 }
72
73
74
75
76
77
78
79
80 public String getLanguageKey(final Configuration configuration) {
81 if (configuration != null) {
82 final Type type = configuration.getType();
83 String key = "itracker." + type.name() + ".";
84
85 if (type == Type.locale) {
86 key += "name.";
87 }
88
89 key += configuration.getValue();
90
91 if (type == Type.customfield) {
92 key += ".label";
93 }
94 return key;
95 }
96 return "";
97 }
98 public String getTypeLanguageKey() {
99 final String base = "itracker.web.attr.";
100
101 return base + name();
102 }
103
104
105
106 }
107
108 public static final ConfigurationOrderComparator CONFIGURATION_ORDER_COMPARATOR = new ConfigurationOrderComparator();
109
110
111
112 private static final long serialVersionUID = 1L;
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 private String name;
131
132
133
134
135 private String version;
136
137
138
139
140 private Type type;
141
142
143
144
145 private String value;
146
147
148
149
150
151
152
153
154 private int order;
155
156
157
158
159
160
161
162
163
164
165 public Configuration() {
166 }
167
168 public Configuration(Type type, String value) {
169 setType(type);
170 setValue(value);
171 }
172
173 public Configuration(Type type, NameValuePair pair) {
174 this(type, pair.getValue());
175 setName(pair.getName());
176 }
177
178 public Configuration(Type type, String value, String version) {
179 this(type, value);
180 setVersion(version);
181 }
182
183 public Configuration(Type type, String value, int order) {
184 this(type, value);
185 setOrder(order);
186 }
187
188 public Configuration(Type type, String value, String version, int order) {
189 this(type, value, version);
190 setOrder(order);
191 }
192
193 public String getName() {
194 return name;
195 }
196
197 public void setName(String name) {
198 this.name = name;
199 }
200
201 public int getOrder() {
202 return order;
203 }
204
205 public void setOrder(int order) {
206 this.order = order;
207 }
208
209 public Type getType() {
210 return type;
211 }
212
213 public void setType(Type type) {
214 this.type = type;
215 }
216
217 public String getValue() {
218 return value;
219 }
220
221 public void setValue(String value) {
222 if (value == null) {
223 throw new IllegalArgumentException("null value");
224 }
225 this.value = value;
226 }
227
228 public String getVersion() {
229 return version;
230 }
231
232 public void setVersion(String version) {
233 if (version == null) {
234 throw new IllegalArgumentException("null version");
235 }
236 this.version = version;
237 }
238
239
240
241
242 @Override
243 public String toString() {
244 return new ToStringBuilder(this).append("id", getId()).append("type", getType())
245 .append("name", getName()).append("version", getVersion()).append(
246 "value", getValue()).toString();
247
248 }
249
250 public static final class ConfigurationOrderComparator implements
251 Comparator<Configuration>, Serializable {
252
253
254
255 private static final long serialVersionUID = 1L;
256
257 public int compare(Configuration./../../org/itracker/model/Configuration.html#Configuration">Configuration o1, Configuration o2) {
258 return new CompareToBuilder().append(o1.getOrder(), o2.getOrder()).append(o1.getValue(), o2.getValue())
259 .toComparison();
260 }
261
262
263 }
264
265 }