View Javadoc
1   package org.kuali.ole.deliver.api;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.api.jaxb.DateAdapter;
5   import org.kuali.rice.core.api.CoreConstants;
6   import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
7   import org.kuali.rice.core.api.mo.ModelBuilder;
8   import org.kuali.rice.kim.api.KimConstants;
9   import org.kuali.rice.kim.api.identity.address.EntityAddress;
10  import org.w3c.dom.Element;
11  
12  import javax.xml.bind.annotation.*;
13  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
14  import java.io.Serializable;
15  import java.util.Collection;
16  import java.util.Date;
17  
18  /**
19   * Created with IntelliJ IDEA.
20   * User: ?
21   * Date: 5/24/12
22   * Time: 8:26 PM
23   * To change this template use File | Settings | File Templates.
24   */
25  @XmlRootElement(name = org.kuali.ole.deliver.api.OleAddressDefinition.Constants.ROOT_ELEMENT_NAME)
26  @XmlAccessorType(XmlAccessType.NONE)
27  @XmlType(name = org.kuali.ole.deliver.api.OleAddressDefinition.Constants.TYPE_NAME, propOrder = {
28          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.OLE_ADDRESS_ID,
29          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.OLE_PTRN_ID,
30          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ID,
31          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_VERIFIED,
32          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_VALID_FROM,
33          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_VALID_TO,
34          //OleAddressDefinition.Elements.ENTITY_ADDRESS,
35          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_SOURCE,
36          org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_SOURCE_BO,
37          //OlePatronDefinition.Elements.OLE_BORROWER_TYPE,
38          //OlePatronDefinition.Elements.ENTITY,
39  
40          CoreConstants.CommonElements.VERSION_NUMBER,
41          //CoreConstants.CommonElements.OBJECT_ID,
42          CoreConstants.CommonElements.FUTURE_ELEMENTS
43  })
44  public class OleAddressDefinition extends AbstractDataTransferObject implements OleAddressContract {
45  
46      private static final long serialVersionUID = 1L;
47  
48      @XmlElement(name = Elements.OLE_ADDRESS_ID, required = false)
49      private final String oleAddressId;
50  
51      @XmlElement(name = Elements.OLE_PTRN_ID, required = false)
52      private final String olePatronId;
53  
54      @XmlElement(name = Elements.ID, required = false)
55      private final String id;
56  
57      @XmlElement(name = Elements.ADDRESS_VALID_FROM, required = false)
58      @XmlJavaTypeAdapter(value = DateAdapter.class, type = Date.class)
59      private final Date addressValidFrom;
60  
61      @XmlElement(name = Elements.ADDRESS_VALID_TO, required = false)
62      @XmlJavaTypeAdapter(value = DateAdapter.class, type = Date.class)
63      private final Date addressValidTo;
64  
65      @XmlElement(name = Elements.ADDRESS_VERIFIED, required = false)
66      private final boolean addressVerified;
67  
68     /* @XmlElement(name = Elements.ENTITY_ADDRESS, required = false)
69      private final EntityAddress entityAddress;*/
70  
71      @XmlElement(name = Elements.ADDRESS_SOURCE, required = false)
72      private final String addressSource;
73  
74      @XmlElement(name = Elements.ADDRESS_SOURCE_BO, required = false)
75      private final OleAddressSourceDefinition addressSourceBo;
76  
77      /* @XmlElement(name = Elements.EXPIRATION_DATE, required = false)
78   @XmlJavaTypeAdapter(value=DateAdapter.class, type=Date.class)
79   private final Date expirationDate;*/
80  
81      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
82      private final Long versionNumber;
83  
84      /*@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
85      private final String objectId;*/
86      @SuppressWarnings("unused")
87      @XmlAnyElement
88      private final Collection<Element> _futureElements = null;
89  
90      public OleAddressDefinition() {
91          this.oleAddressId = null;
92          this.addressVerified = false;
93          this.olePatronId = null;
94          this.id = null;
95          this.addressValidFrom = null;
96          this.addressValidTo = null;
97          // this.entityAddress = null;
98          this.addressSource = null;
99          this.addressSourceBo = null;
100         this.versionNumber = null;
101 
102         //this.objectId = null;
103     }
104 
105 
106     private OleAddressDefinition(Builder builder) {
107         this.oleAddressId = builder.getOleAddressId();
108         this.addressVerified = builder.isAddressVerified();
109         this.olePatronId = builder.getOlePatronId();
110         this.id = builder.getId();
111         this.addressValidFrom = builder.getAddressValidFrom();
112         this.addressValidTo = builder.getAddressValidTo();
113         // this.entityAddress = builder.getEntityAddress().build();
114         this.addressSource = builder.getAddressSource();
115         if (builder.getAddressSourceBo() != null)
116             this.addressSourceBo = builder.getAddressSourceBo().build();
117         else
118             this.addressSourceBo = new OleAddressSourceDefinition();
119         this.versionNumber = builder.getVersionNumber();
120         //this.objectId = builder.getObjectId();
121     }
122 
123     @Override
124     public String getOleAddressId() {
125         return oleAddressId;
126     }
127 
128     @Override
129     public boolean isAddressVerified() {
130         return addressVerified;
131     }
132 
133     public static long getSerialVersionUID() {
134         return serialVersionUID;
135     }
136 
137     public String getOlePatronId() {
138         return olePatronId;
139     }
140 
141     public Date getAddressValidFrom() {
142         return addressValidFrom;
143     }
144 
145     public Date getAddressValidTo() {
146         return addressValidTo;
147     }
148 
149    /* public EntityAddress getEntityAddress() {
150         return entityAddress;
151     }*/
152 
153     public String getAddressSource() {
154         return addressSource;
155     }
156 
157     public OleAddressSourceDefinition getAddressSourceBo() {
158         return addressSourceBo;
159     }
160     /* @Override
161     public boolean isActive() {
162         return this.activeIndicator;
163     }*/
164 
165     @Override
166     public Long getVersionNumber() {
167         return this.versionNumber;
168     }
169 
170     @Override
171     public String getId() {
172         return this.id;
173     }
174 
175 
176     //@Override
177     /*public OleBorrowerTypeDefinition getOleBorrowerType() {
178         return this.oleBorrowerType;
179     }*/
180 
181     public static class Builder
182             implements Serializable, ModelBuilder, OleAddressContract {
183         private String oleAddressId;
184         private String olePatronId;
185         private String id;
186         private boolean addressVerified;
187         private Date addressValidFrom;
188         private Date addressValidTo;
189         private String addressSource;
190         private OleAddressSourceDefinition.Builder addressSourceBo;
191         private EntityAddress.Builder entityAddress;
192         private Long versionNumber;
193         private String objectId;
194 
195         private Builder() {
196         }
197 
198         public static Builder create() {
199             return new Builder();
200         }
201 
202         public static Builder create(OleAddressContract contract) {
203             if (contract == null) {
204                 throw new IllegalArgumentException("contract was null");
205             }
206             Builder builder = create();
207             if (contract.getOleAddressId() != null) {
208                 builder.setOleAddressId(contract.getOleAddressId());
209             }
210             if (contract.isAddressVerified()) {
211                 builder.setAddressVerified(contract.isAddressVerified());
212             }
213             if (contract.getAddressValidFrom() != null) {
214                 builder.setAddressValidFrom(contract.getAddressValidFrom());
215             }
216             if (contract.getAddressValidTo() != null) {
217                 builder.setAddressValidTo(contract.getAddressValidTo());
218             }
219             if (contract.getOlePatronId() != null) {
220                 builder.setOlePatronId(contract.getOlePatronId());
221             }
222             if (contract.getId() != null) {
223                 builder.setId(contract.getId());
224             }
225             if (contract.getAddressSource() != null) {
226                 builder.setAddressSource(contract.getAddressSource());
227             }
228             if (contract.getAddressSourceBo() != null) {
229                 builder.setAddressSourceBo(OleAddressSourceDefinition.Builder.create(contract.getAddressSourceBo()));
230             }
231            /* if (contract.getEntityAddress() != null) {
232                 builder.setEntityAddress(EntityAddress.Builder.create(contract.getEntityAddress()));
233             }*/
234             builder.setVersionNumber(contract.getVersionNumber());
235             /*builder.setObjectId(contract.getObjectId());
236             builder.setActive(contract.isActive());*/
237             builder.setId(contract.getId());
238             return builder;
239         }
240 
241 
242         public org.kuali.ole.deliver.api.OleAddressDefinition build() {
243             return new org.kuali.ole.deliver.api.OleAddressDefinition(this);
244         }
245 
246         public String getOleAddressId() {
247             return oleAddressId;
248         }
249 
250         public void setOleAddressId(String oleAddressId) {
251             this.oleAddressId = oleAddressId;
252         }
253 
254         public String getOlePatronId() {
255             return olePatronId;
256         }
257 
258         public void setOlePatronId(String olePatronId) {
259             this.olePatronId = olePatronId;
260         }
261 
262         public Date getAddressValidFrom() {
263             return addressValidFrom;
264         }
265 
266         public void setAddressValidFrom(Date addressValidFrom) {
267             this.addressValidFrom = addressValidFrom;
268         }
269 
270         public Date getAddressValidTo() {
271             return addressValidTo;
272         }
273 
274         public void setAddressValidTo(Date addressValidTo) {
275             this.addressValidTo = addressValidTo;
276         }
277 
278         public boolean isAddressVerified() {
279             return addressVerified;
280         }
281 
282         public void setAddressVerified(boolean addressVerified) {
283             this.addressVerified = addressVerified;
284         }
285 
286         public EntityAddress.Builder getEntityAddress() {
287             return entityAddress;
288         }
289 
290         public void setEntityAddress(EntityAddress.Builder entityAddress) {
291             this.entityAddress = entityAddress;
292         }
293 
294         public String getAddressSource() {
295             return addressSource;
296         }
297 
298         public void setAddressSource(String addressSource) {
299             this.addressSource = addressSource;
300         }
301 
302         public OleAddressSourceDefinition.Builder getAddressSourceBo() {
303             return addressSourceBo;
304         }
305 
306         public void setAddressSourceBo(OleAddressSourceDefinition.Builder addressSourceBo) {
307             this.addressSourceBo = addressSourceBo;
308         }
309 
310         @Override
311         public Long getVersionNumber() {
312             return versionNumber;
313         }
314 
315         public void setVersionNumber(Long versionNumber) {
316             this.versionNumber = versionNumber;
317         }
318 
319         /*@Override
320         public String getObjectId() {
321             return objectId;
322         }*/
323 
324         public void setObjectId(String objectId) {
325             this.objectId = objectId;
326         }
327 
328         @Override
329         public String getId() {
330             return this.id;
331         }
332 
333 
334         public void setId(String id) {
335             if (StringUtils.isWhitespace(id)) {
336                 throw new IllegalArgumentException("id is blank");
337             }
338             this.id = id;
339         }
340     }
341 
342     static class Constants {
343 
344         final static String ROOT_ELEMENT_NAME = "oleAddress";
345         final static String TYPE_NAME = "OleAddressType";
346         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[]{CoreConstants.CommonElements.FUTURE_ELEMENTS};
347     }
348 
349     static class Elements {
350         final static String OLE_ADDRESS_ID = "oleAddressId";
351         //final static String ENTITY_ID = "entityId";
352         final static String OLE_PTRN_ID = "olePatronId";
353         final static String ID = "id";
354         final static String ADDRESS_VERIFIED = "addressVerified";
355         final static String ADDRESS_VALID_FROM = "addressValidFrom";
356         final static String ADDRESS_VALID_TO = "addressValidTo";
357         final static String ADDRESS_SOURCE = "addressSource";
358         //final static String ENTITY_ADDRESS = "entityAddress";
359         final static String ADDRESS_SOURCE_BO = "addressSourceBo";
360     }
361 
362     public static class Cache {
363         public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + Constants.TYPE_NAME;
364     }
365 }