001package org.kuali.ole.deliver.api; 002 003import org.apache.commons.lang.StringUtils; 004import org.kuali.api.jaxb.DateAdapter; 005import org.kuali.rice.core.api.CoreConstants; 006import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 007import org.kuali.rice.core.api.mo.ModelBuilder; 008import org.kuali.rice.kim.api.KimConstants; 009import org.kuali.rice.kim.api.identity.address.EntityAddress; 010import org.w3c.dom.Element; 011 012import javax.xml.bind.annotation.*; 013import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 014import java.io.Serializable; 015import java.util.Collection; 016import java.util.Date; 017 018/** 019 * Created with IntelliJ IDEA. 020 * User: ? 021 * Date: 5/24/12 022 * Time: 8:26 PM 023 * To change this template use File | Settings | File Templates. 024 */ 025@XmlRootElement(name = org.kuali.ole.deliver.api.OleAddressDefinition.Constants.ROOT_ELEMENT_NAME) 026@XmlAccessorType(XmlAccessType.NONE) 027@XmlType(name = org.kuali.ole.deliver.api.OleAddressDefinition.Constants.TYPE_NAME, propOrder = { 028 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.OLE_ADDRESS_ID, 029 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.OLE_PTRN_ID, 030 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ID, 031 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_VERIFIED, 032 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_VALID_FROM, 033 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_VALID_TO, 034 //OleAddressDefinition.Elements.ENTITY_ADDRESS, 035 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_SOURCE, 036 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.ADDRESS_SOURCE_BO, 037 org.kuali.ole.deliver.api.OleAddressDefinition.Elements.DELIVER_ADDRESS, 038 //OlePatronDefinition.Elements.OLE_BORROWER_TYPE, 039 //OlePatronDefinition.Elements.ENTITY, 040 041 CoreConstants.CommonElements.VERSION_NUMBER, 042 //CoreConstants.CommonElements.OBJECT_ID, 043 CoreConstants.CommonElements.FUTURE_ELEMENTS 044}) 045public class OleAddressDefinition extends AbstractDataTransferObject implements OleAddressContract { 046 047 private static final long serialVersionUID = 1L; 048 049 @XmlElement(name = Elements.OLE_ADDRESS_ID, required = false) 050 private final String oleAddressId; 051 052 @XmlElement(name = Elements.OLE_PTRN_ID, required = false) 053 private final String olePatronId; 054 055 @XmlElement(name = Elements.ID, required = false) 056 private final String id; 057 058 @XmlElement(name = Elements.ADDRESS_VALID_FROM, required = false) 059 @XmlJavaTypeAdapter(value = DateAdapter.class, type = Date.class) 060 private final Date addressValidFrom; 061 062 @XmlElement(name = Elements.ADDRESS_VALID_TO, required = false) 063 @XmlJavaTypeAdapter(value = DateAdapter.class, type = Date.class) 064 private final Date addressValidTo; 065 066 @XmlElement(name = Elements.ADDRESS_VERIFIED, required = false) 067 private final boolean addressVerified; 068 069 /* @XmlElement(name = Elements.ENTITY_ADDRESS, required = false) 070 private final EntityAddress entityAddress;*/ 071 072 @XmlElement(name = Elements.ADDRESS_SOURCE, required = false) 073 private final String addressSource; 074 075 @XmlElement(name = Elements.ADDRESS_SOURCE_BO, required = false) 076 private final OleAddressSourceDefinition addressSourceBo; 077 078 /* @XmlElement(name = Elements.EXPIRATION_DATE, required = false) 079 @XmlJavaTypeAdapter(value=DateAdapter.class, type=Date.class) 080 private final Date expirationDate;*/ 081 082 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 083 private final Long versionNumber; 084 085 @XmlElement(name = Elements.DELIVER_ADDRESS, required = false) 086 private final boolean deliverAddress; 087 088 089 090 /*@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) 091 private final String objectId;*/ 092 @SuppressWarnings("unused") 093 @XmlAnyElement 094 private final Collection<Element> _futureElements = null; 095 096 public OleAddressDefinition() { 097 this.oleAddressId = null; 098 this.addressVerified = false; 099 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}