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