View Javadoc

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