1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.api.repository.term; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.Collection; |
20 | |
|
21 | |
import javax.xml.bind.annotation.XmlAccessType; |
22 | |
import javax.xml.bind.annotation.XmlAccessorType; |
23 | |
import javax.xml.bind.annotation.XmlAnyElement; |
24 | |
import javax.xml.bind.annotation.XmlElement; |
25 | |
import javax.xml.bind.annotation.XmlRootElement; |
26 | |
import javax.xml.bind.annotation.XmlType; |
27 | |
|
28 | |
import org.apache.commons.lang.StringUtils; |
29 | |
import org.kuali.rice.core.api.CoreConstants; |
30 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
31 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
32 | |
import org.kuali.rice.krms.api.repository.BuilderUtils.Transformer; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
@XmlRootElement(name = TermParameterDefinition.Constants.ROOT_ELEMENT_NAME) |
42 | |
@XmlAccessorType(XmlAccessType.NONE) |
43 | |
@XmlType(name = TermParameterDefinition.Constants.TYPE_NAME, propOrder = { |
44 | |
TermParameterDefinition.Elements.ID, |
45 | |
TermParameterDefinition.Elements.NAME, |
46 | |
TermParameterDefinition.Elements.VALUE, |
47 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
48 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
49 | |
}) |
50 | 1 | public final class TermParameterDefinition extends AbstractDataTransferObject implements TermParameterDefinitionContract { |
51 | |
|
52 | |
private static final long serialVersionUID = 1L; |
53 | |
|
54 | |
@XmlElement(name = Elements.ID, required=true) |
55 | |
private final String id; |
56 | |
|
57 | |
private final String termId; |
58 | |
|
59 | |
@XmlElement(name = Elements.NAME, required=true) |
60 | |
private final String name; |
61 | |
|
62 | |
@XmlElement(name = Elements.VALUE) |
63 | |
private final String value; |
64 | |
|
65 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
66 | |
private final Long versionNumber; |
67 | |
|
68 | 3 | @SuppressWarnings("unused") |
69 | |
@XmlAnyElement |
70 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
71 | |
|
72 | |
|
73 | 2 | private TermParameterDefinition() { |
74 | 2 | id = null; |
75 | 2 | termId = null; |
76 | 2 | name = null; |
77 | 2 | value = null; |
78 | 2 | versionNumber = null; |
79 | 2 | } |
80 | |
|
81 | 1 | private TermParameterDefinition(Builder builder) { |
82 | 1 | id = builder.getId(); |
83 | 1 | termId = builder.getTermId(); |
84 | 1 | name = builder.getName(); |
85 | 1 | value = builder.getValue(); |
86 | 1 | versionNumber = builder.getVersionNumber(); |
87 | 1 | } |
88 | |
|
89 | 1 | public static class Builder implements TermParameterDefinitionContract, ModelBuilder, Serializable { |
90 | |
|
91 | |
private static final long serialVersionUID = 1L; |
92 | |
|
93 | |
private String id; |
94 | |
private String termId; |
95 | |
private String name; |
96 | |
private String value; |
97 | |
private Long versionNumber; |
98 | |
|
99 | |
private static final String NON_NULL_NON_EMPTY_ERROR = |
100 | |
" must be non-null and must contain non-whitespace chars"; |
101 | |
|
102 | 1 | public static final Transformer<TermParameterDefinitionContract, TermParameterDefinition.Builder> toBuilder = |
103 | 1 | new Transformer<TermParameterDefinitionContract, TermParameterDefinition.Builder>() { |
104 | |
public Builder transform(TermParameterDefinitionContract input) { |
105 | 0 | return Builder.create(input); |
106 | |
}; |
107 | |
}; |
108 | |
|
109 | 1 | private Builder(String id, String termId, String name, String value) { |
110 | 1 | setId(id); |
111 | 1 | setTermId(termId); |
112 | 1 | setName(name); |
113 | 1 | setValue(value); |
114 | 1 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public static Builder create(String id, String termId, String name, String value) { |
125 | 1 | return new Builder(id, termId, name, value); |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public static Builder create(TermParameterDefinitionContract termParameterDefinition) { |
134 | 0 | Builder builder = new Builder(termParameterDefinition.getId(), |
135 | |
termParameterDefinition.getTermId(), |
136 | |
termParameterDefinition.getName(), |
137 | |
termParameterDefinition.getValue()); |
138 | 0 | builder.setVersionNumber(termParameterDefinition.getVersionNumber()); |
139 | 0 | return builder; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
public void setId(String id) { |
150 | 1 | if (id != null && StringUtils.isBlank(id)) { |
151 | 0 | throw new IllegalArgumentException("id must contain non-whitespace chars"); |
152 | |
} |
153 | 1 | this.id = id; |
154 | 1 | } |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void setTermId(String termId) { |
160 | 1 | if (termId != null && StringUtils.isBlank(termId)) { |
161 | 0 | throw new IllegalArgumentException("termId must contain non-whitespace chars"); |
162 | |
} |
163 | 1 | this.termId = termId; |
164 | 1 | } |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public void setName(String name) { |
171 | 1 | if (StringUtils.isBlank(name)) { |
172 | 0 | throw new IllegalArgumentException("name" + NON_NULL_NON_EMPTY_ERROR); |
173 | |
} |
174 | 1 | this.name = name; |
175 | 1 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public void setValue(String value) { |
181 | 1 | this.value = value; |
182 | 1 | } |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
public void setVersionNumber(Long versionNumber){ |
188 | 0 | this.versionNumber = versionNumber; |
189 | 0 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
@Override |
197 | |
public String getId() { |
198 | 1 | return this.id; |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
@Override |
205 | |
public String getTermId() { |
206 | 1 | return this.termId; |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
@Override |
213 | |
public String getName() { |
214 | 1 | return this.name; |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
@Override |
221 | |
public String getValue() { |
222 | 1 | return this.value; |
223 | |
} |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
@Override |
229 | |
public Long getVersionNumber() { |
230 | 1 | return this.versionNumber; |
231 | |
} |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
@Override |
238 | |
public TermParameterDefinition build() { |
239 | 1 | return new TermParameterDefinition(this); |
240 | |
} |
241 | |
|
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
@Override |
249 | |
public String getId() { |
250 | 0 | return this.id; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
@Override |
256 | |
public String getTermId() { |
257 | 0 | return termId; |
258 | |
} |
259 | |
|
260 | |
|
261 | |
|
262 | |
@Override |
263 | |
public String getName() { |
264 | 0 | return this.name; |
265 | |
} |
266 | |
|
267 | |
|
268 | |
|
269 | |
@Override |
270 | |
public String getValue() { |
271 | 0 | return this.value; |
272 | |
} |
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
@Override |
278 | |
public Long getVersionNumber() { |
279 | 0 | return versionNumber; |
280 | |
} |
281 | |
|
282 | 0 | public static class Constants { |
283 | |
public static final String ROOT_ELEMENT_NAME = "TermParameterDefinition"; |
284 | |
public static final String TYPE_NAME = "TermParameterDefinitionType"; |
285 | |
} |
286 | |
|
287 | 0 | public static class Elements { |
288 | |
public static final String ID = "id"; |
289 | |
public static final String TERM_ID = "termId"; |
290 | |
public static final String NAME = "name"; |
291 | |
public static final String VALUE = "value"; |
292 | |
} |
293 | |
} |