1 | |
package org.kuali.rice.krms.api.repository.type; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
|
6 | |
import javax.xml.bind.annotation.XmlAccessType; |
7 | |
import javax.xml.bind.annotation.XmlAccessorType; |
8 | |
import javax.xml.bind.annotation.XmlAnyElement; |
9 | |
import javax.xml.bind.annotation.XmlElement; |
10 | |
import javax.xml.bind.annotation.XmlRootElement; |
11 | |
import javax.xml.bind.annotation.XmlType; |
12 | |
|
13 | |
import org.apache.commons.lang.StringUtils; |
14 | |
import org.kuali.rice.core.api.CoreConstants; |
15 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
16 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | 1 | @XmlRootElement(name = KrmsTypeAttribute.Constants.ROOT_ELEMENT_NAME) |
25 | |
@XmlAccessorType(XmlAccessType.NONE) |
26 | |
@XmlType(name = KrmsTypeAttribute.Constants.TYPE_NAME, propOrder = { |
27 | |
KrmsTypeAttribute.Elements.ID, |
28 | |
KrmsTypeAttribute.Elements.TYPE_ID, |
29 | |
KrmsTypeAttribute.Elements.ATTR_DEFN_ID, |
30 | |
KrmsTypeAttribute.Elements.SEQ_NO, |
31 | |
KrmsTypeAttribute.Elements.ACTIVE, |
32 | |
KrmsTypeAttribute.Elements.ATTR_DEFN, |
33 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
34 | |
}) |
35 | 9 | public final class KrmsTypeAttribute extends AbstractDataTransferObject implements KrmsTypeAttributeContract { |
36 | |
private static final long serialVersionUID = -304265575559412478L; |
37 | |
|
38 | |
@XmlElement(name = Elements.ID, required=true) |
39 | |
private String id; |
40 | |
@XmlElement(name = Elements.TYPE_ID, required=true) |
41 | |
private String typeId; |
42 | |
@XmlElement(name = Elements.ATTR_DEFN_ID, required=true) |
43 | |
private String attributeDefinitionId; |
44 | |
@XmlElement(name = Elements.SEQ_NO, required=true) |
45 | |
private Integer sequenceNumber; |
46 | |
@XmlElement(name = Elements.ACTIVE, required=false) |
47 | |
private boolean active; |
48 | |
@XmlElement(name = Elements.ATTR_DEFN, required=false) |
49 | |
private KrmsAttributeDefinition attributeDefinition; |
50 | |
|
51 | 20 | @SuppressWarnings("unused") |
52 | |
@XmlAnyElement |
53 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 11 | private KrmsTypeAttribute() { |
59 | 11 | this.id = null; |
60 | 11 | this.typeId = null; |
61 | 11 | this.attributeDefinitionId = null; |
62 | 11 | this.sequenceNumber = null; |
63 | 11 | this.active = false; |
64 | 11 | this.attributeDefinition = null; |
65 | 11 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 9 | private KrmsTypeAttribute(Builder builder) { |
74 | 9 | this.id = builder.getId(); |
75 | 9 | this.typeId = builder.getTypeId(); |
76 | 9 | this.attributeDefinitionId = builder.getAttributeDefinitionId(); |
77 | 9 | this.sequenceNumber = builder.getSequenceNumber(); |
78 | 9 | this.active = builder.isActive(); |
79 | 9 | if (builder.getAttributeDefinition() != null) { |
80 | 2 | this.attributeDefinition = builder.getAttributeDefinition().build(); |
81 | |
} |
82 | 9 | } |
83 | |
|
84 | |
public String getId() { |
85 | 3 | return this.id; |
86 | |
} |
87 | |
|
88 | |
public String getTypeId() { |
89 | 3 | return this.typeId; |
90 | |
} |
91 | |
|
92 | |
public String getAttributeDefinitionId() { |
93 | 3 | return this.attributeDefinitionId; |
94 | |
} |
95 | |
|
96 | |
public Integer getSequenceNumber() { |
97 | 3 | return this.sequenceNumber; |
98 | |
} |
99 | |
|
100 | |
public boolean isActive() { |
101 | 4 | return this.active; |
102 | |
} |
103 | |
|
104 | |
public KrmsAttributeDefinition getAttributeDefinition() { |
105 | 1 | return this.attributeDefinition; |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | 5 | public static class Builder implements KrmsTypeAttributeContract, ModelBuilder, Serializable { |
112 | |
private static final long serialVersionUID = 2729964674427296346L; |
113 | |
|
114 | |
private String id; |
115 | |
private String typeId; |
116 | |
private String attributeDefinitionId; |
117 | |
private Integer sequenceNumber; |
118 | |
private boolean active; |
119 | |
private KrmsAttributeDefinition.Builder attributeDefinition; |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | 21 | private Builder(String id, String typeId, String attributeDefinitionId, Integer sequenceNumber) { |
125 | 21 | setId(id); |
126 | 19 | setTypeId(typeId); |
127 | 17 | setAttributeDefinitionId(attributeDefinitionId); |
128 | 13 | setSequenceNumber(sequenceNumber); |
129 | 12 | setActive(true); |
130 | 12 | } |
131 | |
|
132 | |
public Builder attributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition){ |
133 | 2 | setAttributeDefinition(attributeDefinition); |
134 | 2 | return this; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public static Builder create(String id, String typeId, String attributeDefinitionId, Integer sequenceNumber) { |
148 | 21 | return new Builder(id, typeId, attributeDefinitionId, sequenceNumber); |
149 | |
} |
150 | |
|
151 | |
public static Builder create(KrmsTypeAttributeContract contract){ |
152 | 0 | if (contract == null) { |
153 | 0 | throw new IllegalArgumentException("contract is null"); |
154 | |
} |
155 | 0 | Builder builder = new Builder(contract.getId(), |
156 | |
contract.getTypeId(), |
157 | |
contract.getAttributeDefinitionId(), |
158 | |
contract.getSequenceNumber()); |
159 | 0 | if (contract.getAttributeDefinition() != null){ |
160 | 0 | KrmsAttributeDefinition.Builder attrBuilder = |
161 | |
KrmsAttributeDefinition.Builder.create(contract.getAttributeDefinition()); |
162 | 0 | builder.setAttributeDefinition(attrBuilder); |
163 | |
} |
164 | 0 | return builder; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public void setId(String id) { |
174 | 21 | if (null != id && StringUtils.isBlank(id)) { |
175 | 2 | throw new IllegalArgumentException("id must be null or non-blank"); |
176 | |
} |
177 | 19 | this.id = id; |
178 | 19 | } |
179 | |
|
180 | |
public void setTypeId(String typeId) { |
181 | 19 | if (null != typeId && StringUtils.isBlank(typeId)) { |
182 | 2 | throw new IllegalArgumentException("typeId must be null or non-blank"); |
183 | |
} |
184 | 17 | this.typeId = typeId; |
185 | 17 | } |
186 | |
|
187 | |
public void setAttributeDefinitionId(String attributeDefinitionId) { |
188 | 17 | if (StringUtils.isBlank(attributeDefinitionId)) { |
189 | 4 | throw new IllegalArgumentException("the attribute definition id is blank"); |
190 | |
} |
191 | 13 | this.attributeDefinitionId = attributeDefinitionId; |
192 | 13 | } |
193 | |
|
194 | |
public void setSequenceNumber(Integer sequenceNumber) { |
195 | 13 | if (sequenceNumber == null){ |
196 | 1 | throw new IllegalArgumentException("the sequence number is null"); |
197 | |
} |
198 | 12 | this.sequenceNumber = sequenceNumber; |
199 | 12 | } |
200 | |
|
201 | |
public void setAttributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition) { |
202 | 2 | this.attributeDefinition = attributeDefinition; |
203 | |
|
204 | 2 | } |
205 | |
|
206 | |
public void setActive(boolean active) { |
207 | 12 | this.active = active; |
208 | 12 | } |
209 | |
|
210 | |
public String getId() { |
211 | 9 | return id; |
212 | |
} |
213 | |
|
214 | |
public String getTypeId() { |
215 | 9 | return typeId; |
216 | |
} |
217 | |
|
218 | |
public String getAttributeDefinitionId() { |
219 | 9 | return attributeDefinitionId; |
220 | |
} |
221 | |
|
222 | |
public Integer getSequenceNumber() { |
223 | 9 | return sequenceNumber; |
224 | |
} |
225 | |
|
226 | |
public KrmsAttributeDefinition.Builder getAttributeDefinition() { |
227 | 11 | return attributeDefinition; |
228 | |
} |
229 | |
|
230 | |
|
231 | |
public boolean isActive() { |
232 | 9 | return active; |
233 | |
} |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
@Override |
241 | |
public KrmsTypeAttribute build() { |
242 | 9 | return new KrmsTypeAttribute(this); |
243 | |
} |
244 | |
|
245 | |
} |
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | 0 | static class Constants { |
251 | |
final static String ROOT_ELEMENT_NAME = "KrmsTypeAttribute"; |
252 | |
final static String TYPE_NAME = "KrmsTypeAttributeType"; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | 0 | public static class Elements { |
260 | |
final static String ID = "id"; |
261 | |
final static String TYPE_ID = "typeId"; |
262 | |
final static String ATTR_DEFN_ID = "attributeDefinitionId"; |
263 | |
final static String SEQ_NO = "sequenceNumber"; |
264 | |
final static String ACTIVE = "active"; |
265 | |
final static String ATTR_DEFN = "attributeDefinition"; |
266 | |
} |
267 | |
} |