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