| 1 | |
package org.kuali.rice.kim.api.identity.type; |
| 2 | |
|
| 3 | |
import org.apache.commons.collections.CollectionUtils; |
| 4 | |
import org.apache.commons.lang.StringUtils; |
| 5 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 6 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 7 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 8 | |
import org.kuali.rice.core.api.CoreConstants; |
| 9 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 10 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 11 | |
import org.kuali.rice.kim.api.identity.EntityUtils; |
| 12 | |
import org.kuali.rice.kim.api.identity.Type; |
| 13 | |
import org.kuali.rice.kim.api.identity.TypeContract; |
| 14 | |
import org.kuali.rice.kim.api.identity.address.EntityAddress; |
| 15 | |
import org.kuali.rice.kim.api.identity.address.EntityAddressContract; |
| 16 | |
import org.kuali.rice.kim.api.identity.email.EntityEmail; |
| 17 | |
import org.kuali.rice.kim.api.identity.email.EntityEmailContract; |
| 18 | |
import org.kuali.rice.kim.api.identity.phone.EntityPhone; |
| 19 | |
import org.kuali.rice.kim.api.identity.phone.EntityPhoneContract; |
| 20 | |
import org.w3c.dom.Element; |
| 21 | |
|
| 22 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 23 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 24 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 25 | |
import javax.xml.bind.annotation.XmlElement; |
| 26 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
| 27 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 28 | |
import javax.xml.bind.annotation.XmlType; |
| 29 | |
import java.io.Serializable; |
| 30 | |
import java.util.ArrayList; |
| 31 | |
import java.util.Collection; |
| 32 | |
import java.util.List; |
| 33 | |
|
| 34 | 0 | @XmlRootElement(name = EntityTypeData.Constants.ROOT_ELEMENT_NAME) |
| 35 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 36 | |
@XmlType(name = EntityTypeData.Constants.TYPE_NAME, propOrder = { |
| 37 | |
EntityTypeData.Elements.ENTITY_ID, |
| 38 | |
EntityTypeData.Elements.ENTITY_TYPE_CODE, |
| 39 | |
EntityTypeData.Elements.ENTITY_TYPE, |
| 40 | |
EntityTypeData.Elements.ADDRESSES, |
| 41 | |
EntityTypeData.Elements.EMAIL_ADDRESSES, |
| 42 | |
EntityTypeData.Elements.PHONE_NUMBERS, |
| 43 | |
EntityTypeData.Elements.DEFAULT_ADDRESS, |
| 44 | |
EntityTypeData.Elements.DEFAULT_EMAIL_ADDRESS, |
| 45 | |
EntityTypeData.Elements.DEFAULT_PHONE_NUMBER, |
| 46 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 47 | |
CoreConstants.CommonElements.OBJECT_ID, |
| 48 | |
EntityTypeData.Elements.ACTIVE, |
| 49 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 50 | |
}) |
| 51 | 6 | public final class EntityTypeData |
| 52 | |
implements ModelObjectComplete, EntityTypeDataContract |
| 53 | |
{ |
| 54 | |
|
| 55 | |
@XmlElement(name = Elements.ENTITY_ID, required = true) |
| 56 | |
private final String entityId; |
| 57 | |
@XmlElement(name = Elements.ENTITY_TYPE_CODE, required = true) |
| 58 | |
private final String entityTypeCode; |
| 59 | |
@XmlElement(name = Elements.ENTITY_TYPE, required = false) |
| 60 | |
private final Type entityType; |
| 61 | |
@XmlElementWrapper(name = Elements.ADDRESSES, required = false) |
| 62 | |
@XmlElement(name = Elements.ADDRESS, required = false) |
| 63 | |
private final List<EntityAddress> addresses; |
| 64 | |
@XmlElementWrapper(name = Elements.EMAIL_ADDRESSES, required = false) |
| 65 | |
@XmlElement(name = Elements.EMAIL_ADDRESS, required = false) |
| 66 | |
private final List<EntityEmail> emailAddresses; |
| 67 | |
@XmlElementWrapper(name = Elements.PHONE_NUMBERS, required = false) |
| 68 | |
@XmlElement(name = Elements.PHONE_NUMBER, required = false) |
| 69 | |
private final List<EntityPhone> phoneNumbers; |
| 70 | |
@XmlElement(name = Elements.DEFAULT_ADDRESS, required = false) |
| 71 | |
private final EntityAddress defaultAddress; |
| 72 | |
@XmlElement(name = Elements.DEFAULT_EMAIL_ADDRESS, required = false) |
| 73 | |
private final EntityEmail defaultEmailAddress; |
| 74 | |
@XmlElement(name = Elements.DEFAULT_PHONE_NUMBER, required = false) |
| 75 | |
private final EntityPhone defaultPhoneNumber; |
| 76 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 77 | |
private final Long versionNumber; |
| 78 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
| 79 | |
private final String objectId; |
| 80 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
| 81 | |
private final boolean active; |
| 82 | 10 | @SuppressWarnings("unused") |
| 83 | |
@XmlAnyElement |
| 84 | |
private final Collection<Element> _futureElements = null; |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | 4 | private EntityTypeData() { |
| 90 | 4 | this.entityId = null; |
| 91 | 4 | this.entityTypeCode = null; |
| 92 | 4 | this.entityType = null; |
| 93 | 4 | this.addresses = null; |
| 94 | 4 | this.emailAddresses = null; |
| 95 | 4 | this.phoneNumbers = null; |
| 96 | 4 | this.defaultAddress = null; |
| 97 | 4 | this.defaultEmailAddress = null; |
| 98 | 4 | this.defaultPhoneNumber = null; |
| 99 | 4 | this.versionNumber = null; |
| 100 | 4 | this.objectId = null; |
| 101 | 4 | this.active = false; |
| 102 | 4 | } |
| 103 | |
|
| 104 | 6 | private EntityTypeData(Builder builder) { |
| 105 | 6 | this.entityId = builder.getEntityId(); |
| 106 | 6 | this.entityTypeCode = builder.getEntityTypeCode(); |
| 107 | 6 | this.entityType = (builder.getEntityType() != null) ? builder.getEntityType().build() : null; |
| 108 | 6 | this.addresses = new ArrayList<EntityAddress>(); |
| 109 | 6 | if (!CollectionUtils.isEmpty(builder.getAddresses())) { |
| 110 | 4 | for (EntityAddress.Builder address : builder.getAddresses()) { |
| 111 | 4 | this.addresses.add(address.build()); |
| 112 | |
} |
| 113 | |
} |
| 114 | |
|
| 115 | 6 | this.emailAddresses = new ArrayList<EntityEmail>(); |
| 116 | 6 | if (!CollectionUtils.isEmpty(builder.getEmailAddresses())) { |
| 117 | 4 | for (EntityEmail.Builder email : builder.getEmailAddresses()) { |
| 118 | 4 | this.emailAddresses.add(email.build()); |
| 119 | |
} |
| 120 | |
} |
| 121 | 6 | this.phoneNumbers = new ArrayList<EntityPhone>(); |
| 122 | 6 | if (!CollectionUtils.isEmpty(builder.getPhoneNumbers())) { |
| 123 | 4 | for (EntityPhone.Builder phoneNumber : builder.getPhoneNumbers()) { |
| 124 | 4 | this.phoneNumbers.add(phoneNumber.build()); |
| 125 | |
} |
| 126 | |
} |
| 127 | 6 | this.defaultAddress = builder.getDefaultAddress() != null ? builder.getDefaultAddress().build() : null; |
| 128 | 6 | this.defaultEmailAddress = builder.getDefaultEmailAddress() != null ? builder.getDefaultEmailAddress().build() : null; |
| 129 | 6 | this.defaultPhoneNumber = builder.getDefaultPhoneNumber() != null ? builder.getDefaultPhoneNumber().build() : null; |
| 130 | 6 | this.versionNumber = builder.getVersionNumber(); |
| 131 | 6 | this.objectId = builder.getObjectId(); |
| 132 | 6 | this.active = builder.isActive(); |
| 133 | 6 | } |
| 134 | |
|
| 135 | |
@Override |
| 136 | |
public String getEntityId() { |
| 137 | 4 | return this.entityId; |
| 138 | |
} |
| 139 | |
|
| 140 | |
@Override |
| 141 | |
public String getEntityTypeCode() { |
| 142 | 4 | return this.entityTypeCode; |
| 143 | |
} |
| 144 | |
|
| 145 | |
@Override |
| 146 | |
public TypeContract getEntityType() { |
| 147 | 12 | return this.entityType; |
| 148 | |
} |
| 149 | |
|
| 150 | |
@Override |
| 151 | |
public List<EntityAddress> getAddresses() { |
| 152 | 61 | return this.addresses; |
| 153 | |
} |
| 154 | |
|
| 155 | |
@Override |
| 156 | |
public List<EntityEmail> getEmailAddresses() { |
| 157 | 37 | return this.emailAddresses; |
| 158 | |
} |
| 159 | |
|
| 160 | |
@Override |
| 161 | |
public List<EntityPhone> getPhoneNumbers() { |
| 162 | 49 | return this.phoneNumbers; |
| 163 | |
} |
| 164 | |
|
| 165 | |
@Override |
| 166 | |
public EntityAddressContract getDefaultAddress() { |
| 167 | 0 | return this.defaultAddress; |
| 168 | |
} |
| 169 | |
|
| 170 | |
@Override |
| 171 | |
public EntityEmail getDefaultEmailAddress() { |
| 172 | 0 | return this.defaultEmailAddress; |
| 173 | |
} |
| 174 | |
|
| 175 | |
@Override |
| 176 | |
public EntityPhoneContract getDefaultPhoneNumber() { |
| 177 | 0 | return this.defaultPhoneNumber; |
| 178 | |
} |
| 179 | |
|
| 180 | |
@Override |
| 181 | |
public Long getVersionNumber() { |
| 182 | 4 | return this.versionNumber; |
| 183 | |
} |
| 184 | |
|
| 185 | |
@Override |
| 186 | |
public String getObjectId() { |
| 187 | 4 | return this.objectId; |
| 188 | |
} |
| 189 | |
|
| 190 | |
@Override |
| 191 | |
public boolean isActive() { |
| 192 | 4 | return this.active; |
| 193 | |
} |
| 194 | |
|
| 195 | |
@Override |
| 196 | |
public int hashCode() { |
| 197 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 198 | |
} |
| 199 | |
|
| 200 | |
@Override |
| 201 | |
public boolean equals(Object object) { |
| 202 | 5 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 203 | |
} |
| 204 | |
|
| 205 | |
@Override |
| 206 | |
public String toString() { |
| 207 | 0 | return ToStringBuilder.reflectionToString(this); |
| 208 | |
} |
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | 4 | public final static class Builder |
| 216 | |
implements Serializable, ModelBuilder, EntityTypeDataContract |
| 217 | |
{ |
| 218 | |
private String entityId; |
| 219 | |
private String entityTypeCode; |
| 220 | |
private Type.Builder entityType; |
| 221 | |
private List<EntityAddress.Builder> addresses; |
| 222 | |
private List<EntityEmail.Builder> emailAddresses; |
| 223 | |
private List<EntityPhone.Builder> phoneNumbers; |
| 224 | |
private Long versionNumber; |
| 225 | |
private String objectId; |
| 226 | |
private boolean active; |
| 227 | |
|
| 228 | 11 | private Builder(String entityId, String entityTypeCode) { |
| 229 | 11 | setEntityId(entityId); |
| 230 | 9 | setEntityTypeCode(entityTypeCode); |
| 231 | 7 | setEntityType(Type.Builder.create(entityTypeCode)); |
| 232 | 7 | } |
| 233 | |
|
| 234 | |
public static Builder create(String entityId, String entityTypeCode) { |
| 235 | 11 | return new Builder(entityId, entityTypeCode); |
| 236 | |
} |
| 237 | |
|
| 238 | |
public static Builder create(EntityTypeDataContract contract) { |
| 239 | 5 | if (contract == null) { |
| 240 | 0 | throw new IllegalArgumentException("contract was null"); |
| 241 | |
} |
| 242 | 5 | Builder builder = create(contract.getEntityId(), contract.getEntityTypeCode()); |
| 243 | 5 | if (contract.getEntityType() != null) { |
| 244 | 5 | builder.setEntityType(Type.Builder.create(contract.getEntityType())); |
| 245 | |
} |
| 246 | 5 | builder.addresses = new ArrayList<EntityAddress.Builder>(); |
| 247 | 5 | if (!CollectionUtils.isEmpty(contract.getAddresses())) { |
| 248 | 4 | for (EntityAddressContract addressContract : contract.getAddresses()) { |
| 249 | 4 | builder.addresses.add(EntityAddress.Builder.create(addressContract)); |
| 250 | |
} |
| 251 | |
} |
| 252 | 5 | builder.emailAddresses = new ArrayList<EntityEmail.Builder>(); |
| 253 | 5 | if (!CollectionUtils.isEmpty(contract.getEmailAddresses())) { |
| 254 | 4 | for (EntityEmailContract emailContract : contract.getEmailAddresses()) { |
| 255 | 4 | builder.emailAddresses.add(EntityEmail.Builder.create(emailContract)); |
| 256 | |
} |
| 257 | |
} |
| 258 | 5 | builder.phoneNumbers = new ArrayList<EntityPhone.Builder>(); |
| 259 | 5 | if (!CollectionUtils.isEmpty(contract.getPhoneNumbers())) { |
| 260 | 4 | for (EntityPhoneContract phoneContract : contract.getPhoneNumbers()) { |
| 261 | 4 | builder.phoneNumbers.add(EntityPhone.Builder.create(phoneContract)); |
| 262 | |
} |
| 263 | |
} |
| 264 | 5 | builder.setVersionNumber(contract.getVersionNumber()); |
| 265 | 5 | builder.setObjectId(contract.getObjectId()); |
| 266 | 5 | builder.setActive(contract.isActive()); |
| 267 | 5 | return builder; |
| 268 | |
} |
| 269 | |
|
| 270 | |
public EntityTypeData build() { |
| 271 | 6 | return new EntityTypeData(this); |
| 272 | |
} |
| 273 | |
|
| 274 | |
@Override |
| 275 | |
public String getEntityId() { |
| 276 | 6 | return this.entityId; |
| 277 | |
} |
| 278 | |
|
| 279 | |
@Override |
| 280 | |
public String getEntityTypeCode() { |
| 281 | 6 | return this.entityTypeCode; |
| 282 | |
} |
| 283 | |
|
| 284 | |
@Override |
| 285 | |
public Type.Builder getEntityType() { |
| 286 | 12 | return this.entityType; |
| 287 | |
} |
| 288 | |
|
| 289 | |
@Override |
| 290 | |
public List<EntityAddress.Builder> getAddresses() { |
| 291 | 10 | return this.addresses; |
| 292 | |
} |
| 293 | |
|
| 294 | |
@Override |
| 295 | |
public List<EntityEmail.Builder> getEmailAddresses() { |
| 296 | 10 | return this.emailAddresses; |
| 297 | |
} |
| 298 | |
|
| 299 | |
@Override |
| 300 | |
public List<EntityPhone.Builder> getPhoneNumbers() { |
| 301 | 10 | return this.phoneNumbers; |
| 302 | |
} |
| 303 | |
|
| 304 | |
@Override |
| 305 | |
public EntityAddress.Builder getDefaultAddress() { |
| 306 | 10 | return EntityUtils.getDefaultItem(this.addresses); |
| 307 | |
} |
| 308 | |
|
| 309 | |
@Override |
| 310 | |
public EntityEmail.Builder getDefaultEmailAddress() { |
| 311 | 10 | return EntityUtils.getDefaultItem(this.emailAddresses); |
| 312 | |
} |
| 313 | |
|
| 314 | |
@Override |
| 315 | |
public EntityPhone.Builder getDefaultPhoneNumber() { |
| 316 | 10 | return EntityUtils.getDefaultItem(this.phoneNumbers); |
| 317 | |
} |
| 318 | |
|
| 319 | |
@Override |
| 320 | |
public Long getVersionNumber() { |
| 321 | 6 | return this.versionNumber; |
| 322 | |
} |
| 323 | |
|
| 324 | |
@Override |
| 325 | |
public String getObjectId() { |
| 326 | 6 | return this.objectId; |
| 327 | |
} |
| 328 | |
|
| 329 | |
@Override |
| 330 | |
public boolean isActive() { |
| 331 | 6 | return this.active; |
| 332 | |
} |
| 333 | |
|
| 334 | |
public void setEntityId(String entityId) { |
| 335 | 11 | if (StringUtils.isEmpty(entityId)) { |
| 336 | 2 | throw new IllegalArgumentException("entityId is empty"); |
| 337 | |
} |
| 338 | 9 | this.entityId = entityId; |
| 339 | 9 | } |
| 340 | |
|
| 341 | |
public void setEntityTypeCode(String entityTypeCode) { |
| 342 | 9 | if (StringUtils.isEmpty(entityTypeCode)) { |
| 343 | 2 | throw new IllegalArgumentException("entityTypeCode is empty"); |
| 344 | |
} |
| 345 | 7 | this.entityTypeCode = entityTypeCode; |
| 346 | 7 | } |
| 347 | |
|
| 348 | |
public void setEntityType(Type.Builder entityType) { |
| 349 | 12 | this.entityType = entityType; |
| 350 | 12 | } |
| 351 | |
|
| 352 | |
public void setAddresses(List addresses) { |
| 353 | 0 | this.addresses = addresses; |
| 354 | 0 | } |
| 355 | |
|
| 356 | |
public void setEmailAddresses(List emailAddresses) { |
| 357 | 0 | this.emailAddresses = emailAddresses; |
| 358 | 0 | } |
| 359 | |
|
| 360 | |
public void setPhoneNumbers(List phoneNumbers) { |
| 361 | 0 | this.phoneNumbers = phoneNumbers; |
| 362 | 0 | } |
| 363 | |
|
| 364 | |
public void setVersionNumber(Long versionNumber) { |
| 365 | 5 | this.versionNumber = versionNumber; |
| 366 | 5 | } |
| 367 | |
|
| 368 | |
public void setObjectId(String objectId) { |
| 369 | 5 | this.objectId = objectId; |
| 370 | 5 | } |
| 371 | |
|
| 372 | |
public void setActive(boolean active) { |
| 373 | 5 | this.active = active; |
| 374 | 5 | } |
| 375 | |
} |
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | 0 | static class Constants { |
| 383 | |
|
| 384 | |
final static String ROOT_ELEMENT_NAME = "entityTypeData"; |
| 385 | |
final static String TYPE_NAME = "EntityTypeDataType"; |
| 386 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
| 387 | |
|
| 388 | |
} |
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | 0 | static class Elements { |
| 396 | |
|
| 397 | |
final static String ENTITY_ID = "entityId"; |
| 398 | |
final static String ENTITY_TYPE_CODE = "entityTypeCode"; |
| 399 | |
final static String ENTITY_TYPE = "entityType"; |
| 400 | |
final static String ADDRESSES = "addresses"; |
| 401 | |
final static String ADDRESS = "address"; |
| 402 | |
final static String EMAIL_ADDRESSES = "emailAddresses"; |
| 403 | |
final static String EMAIL_ADDRESS = "emailAddress"; |
| 404 | |
final static String PHONE_NUMBERS = "phoneNumbers"; |
| 405 | |
final static String PHONE_NUMBER = "phoneNumber"; |
| 406 | |
final static String DEFAULT_ADDRESS = "defaultAddress"; |
| 407 | |
final static String DEFAULT_EMAIL_ADDRESS = "defaultEmailAddress"; |
| 408 | |
final static String DEFAULT_PHONE_NUMBER = "defaultPhoneNumber"; |
| 409 | |
final static String ACTIVE = "active"; |
| 410 | |
|
| 411 | |
} |
| 412 | |
|
| 413 | |
} |