View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.api.common.attribute;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21  import org.kuali.rice.core.api.mo.ModelBuilder;
22  import org.kuali.rice.kim.api.type.KimType;
23  import org.w3c.dom.Element;
24  
25  import javax.xml.bind.annotation.XmlAccessType;
26  import javax.xml.bind.annotation.XmlAccessorType;
27  import javax.xml.bind.annotation.XmlAnyElement;
28  import javax.xml.bind.annotation.XmlElement;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  import java.io.Serializable;
32  import java.util.Collection;
33  
34  
35  @XmlRootElement(name = KimAttributeData.Constants.ROOT_ELEMENT_NAME)
36  @XmlAccessorType(XmlAccessType.NONE)
37  @XmlType(name = KimAttributeData.Constants.TYPE_NAME, propOrder = {
38          KimAttributeData.Elements.ID,
39          KimAttributeData.Elements.ASSIGNED_TO_ID,
40          KimAttributeData.Elements.KIM_TYPE_ID,
41          KimAttributeData.Elements.KIM_TYPE,
42          KimAttributeData.Elements.KIM_ATTRIBUTE,
43          KimAttributeData.Elements.ATTRIBUTE_VALUE,
44          CoreConstants.CommonElements.VERSION_NUMBER,
45          CoreConstants.CommonElements.OBJECT_ID,
46          CoreConstants.CommonElements.FUTURE_ELEMENTS
47  })
48  public final class KimAttributeData extends AbstractDataTransferObject implements KimAttributeDataContract {
49      @XmlElement(name = Elements.ID, required = false)
50      private final String id;
51  
52      @XmlElement(name = Elements.ASSIGNED_TO_ID, required = false)
53      private final String assignedToId;
54  
55      @XmlElement(name = Elements.KIM_TYPE_ID, required = true)
56      private final String kimTypeId;
57  
58      @XmlElement(name = Elements.KIM_TYPE, required = false)
59      private final KimType kimType;
60  
61      @XmlElement(name = Elements.KIM_ATTRIBUTE, required = false)
62      private final KimAttribute kimAttribute;
63  
64      @XmlElement(name = Elements.ATTRIBUTE_VALUE, required = false)
65      private final String attributeValue;
66  
67      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
68      private final Long versionNumber;
69  
70      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
71      private final String objectId;
72  
73      @SuppressWarnings("unused")
74      @XmlAnyElement
75      private final Collection<Element> _futureElements = null;
76  
77      @SuppressWarnings("unused")
78      private KimAttributeData() {
79          this.id = null;
80          this.assignedToId = null;
81          this.kimTypeId = null;
82          this.kimType = null;
83          this.kimAttribute = null;
84          this.attributeValue = null;
85          this.versionNumber = null;
86          this.objectId = null;
87      }
88  
89      private KimAttributeData(Builder builder) {
90          this.id = builder.getId();
91          this.assignedToId = builder.getAssignedToId();
92          this.kimTypeId = builder.getKimTypeId();
93          this.kimType =
94                  builder.getKimType() != null ? builder.getKimType().build() : null;
95          this.kimAttribute =
96                  builder.getKimAttribute() != null ? builder.getKimAttribute().build() : null;
97          this.attributeValue = builder.getAttributeValue();
98          this.versionNumber = builder.getVersionNumber();
99          this.objectId = builder.getObjectId();
100     }
101 
102     @Override
103     public String getId() {
104         return id;
105     }
106 
107     @Override
108     public String getAssignedToId() {
109         return assignedToId;
110     }
111 
112     @Override
113     public String getKimTypeId() {
114         return kimTypeId;
115     }
116 
117     @Override
118     public KimType getKimType() {
119         return kimType;
120     }
121 
122     @Override
123     public KimAttribute getKimAttribute() {
124         return kimAttribute;
125     }
126 
127     @Override
128     public String getAttributeValue() {
129         return attributeValue;
130     }
131 
132     @Override
133     public Long getVersionNumber() {
134         return versionNumber;
135     }
136 
137     @Override
138     public String getObjectId() {
139         return objectId;
140     }
141 
142     public static final class Builder implements KimAttributeDataContract, ModelBuilder, Serializable {
143         private String id;
144         private String assignedToId;
145         private String kimTypeId;
146         private KimType.Builder kimType;
147         private KimAttribute.Builder kimAttribute;
148         private String attributeValue;
149         private Long versionNumber;
150         private String objectId;
151 
152         private Builder(String kimTypeId) {
153             setKimTypeId(kimTypeId);
154         }
155 
156         /**
157          * creates a Parameter with the required fields.
158          */
159         public static Builder create(String kimTypeId) {
160             return new Builder(kimTypeId);
161         }
162 
163         /**
164          * creates a KimAttributeData from an existing {@link org.kuali.rice.kim.api.common.attribute.KimAttributeContract}
165          */
166         public static Builder create(KimAttributeDataContract contract) {
167             Builder builder = new Builder(contract.getKimTypeId());
168             builder.setAssignedToId(contract.getAssignedToId());
169 
170             builder.setId(contract.getId());
171             if (contract.getKimAttribute() != null) {
172                 builder.setKimAttribute(KimAttribute.Builder.create(contract.getKimAttribute()));
173             }
174             if (contract.getKimType() != null) {
175                 builder.setKimType(KimType.Builder.create(contract.getKimType()));
176             }
177             builder.setValue(contract.getAttributeValue());
178             builder.setVersionNumber(contract.getVersionNumber());
179             builder.setObjectId(contract.getObjectId());
180             return builder;
181         }
182 
183         @Override
184         public String getId() {
185             return id;
186         }
187 
188         public void setId(final String id) {
189             if (StringUtils.isWhitespace(id)) {
190                 throw new IllegalArgumentException("id is whitespace");
191             }
192             this.id = id;
193         }
194 
195         @Override
196         public String getAssignedToId() {
197             return assignedToId;
198         }
199 
200         public void setAssignedToId(final String assignedToId) {
201             this.assignedToId = assignedToId;
202         }
203 
204         @Override
205         public String getKimTypeId(){
206             return kimTypeId;
207         }
208 
209         public void setKimTypeId(String kimTypeId) {
210             this.kimTypeId = kimTypeId;
211         }
212 
213         @Override
214         public KimType.Builder getKimType() {
215             return kimType;
216         }
217 
218         public void setKimType(final KimType.Builder kimType) {
219             this.kimType = kimType;
220         }
221 
222         @Override
223         public KimAttribute.Builder getKimAttribute() {
224             return kimAttribute;
225         }
226 
227         public void setKimAttribute(final KimAttribute.Builder kimAttribute) {
228             this.kimAttribute = kimAttribute;
229         }
230 
231         @Override
232         public String getAttributeValue() {
233             return attributeValue;
234         }
235 
236         public void setValue(final String attributeValue) {
237             this.attributeValue = attributeValue;
238         }
239 
240         @Override
241         public Long getVersionNumber() {
242             return versionNumber;
243         }
244 
245         public void setVersionNumber(Long versionNumber) {
246             this.versionNumber = versionNumber;
247         }
248 
249         @Override
250         public String getObjectId() {
251             return objectId;
252         }
253 
254         public void setObjectId(final String objectId) {
255             this.objectId = objectId;
256         }
257 
258         @Override
259         public KimAttributeData build() {
260             return new KimAttributeData(this);
261         }
262     }
263 
264     /**
265      * Defines some internal constants used on this class.
266      */
267     static class Constants {
268         final static String ROOT_ELEMENT_NAME = "kimAttributeData";
269         final static String TYPE_NAME = "KimAttributeDataType";
270     }
271 
272     /**
273      * A private class which exposes constants which define the XML element names to use
274      * when this object is marshalled to XML.
275      */
276     static class Elements {
277         final static String ID = "id";
278         final static String ASSIGNED_TO_ID = "assignedToId";
279         final static String KIM_TYPE_ID = "kimTypeId";
280         final static String KIM_TYPE = "kimType";
281         final static String KIM_ATTRIBUTE = "kimAttribute";
282         final static String ATTRIBUTE_VALUE = "attributeValue";
283     }
284 }