001package org.kuali.ole.deliver.api; 002 003import org.apache.commons.collections.CollectionUtils; 004import org.apache.commons.lang.StringUtils; 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.affiliation.EntityAffiliationType; 010import org.kuali.rice.kim.api.identity.employment.EntityEmployment; 011import org.kuali.rice.kim.api.identity.employment.EntityEmploymentContract; 012import org.w3c.dom.Element; 013 014import javax.xml.bind.annotation.*; 015import java.io.Serializable; 016import java.util.ArrayList; 017import java.util.Collection; 018import java.util.List; 019 020/** 021 * Created with IntelliJ IDEA. 022 * User: ? 023 * Date: 5/24/12 024 * Time: 8:26 PM 025 * To change this template use File | Settings | File Templates. 026 */ 027@XmlRootElement(name = org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Constants.ROOT_ELEMENT_NAME) 028@XmlAccessorType(XmlAccessType.NONE) 029@XmlType(name = org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Constants.TYPE_NAME, propOrder = { 030 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.ENTITY_AFFILIATION_ID, 031 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.ENTITY_ID, 032 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.AFFILIATION_TYPE_CODE, 033 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.AFFILIATION_TYPE, 034 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.CAMPUS_CODE, 035 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.EMPLOYMENTS, 036 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.DEFAULT_VALUE, 037 org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.ACTIVE_INDICATOR, 038 039 CoreConstants.CommonElements.VERSION_NUMBER, 040 CoreConstants.CommonElements.OBJECT_ID, 041 CoreConstants.CommonElements.FUTURE_ELEMENTS 042}) 043public final class OlePatronAffiliationDefinition extends AbstractDataTransferObject implements OlePatronAffiliationContract { 044 045 @XmlElement(name = Elements.ENTITY_AFFILIATION_ID, required = false) 046 private final String entityAffiliationId; 047 048 @XmlElement(name = Elements.ENTITY_ID, required = false) 049 private final String entityId; 050 051 @XmlElement(name = Elements.AFFILIATION_TYPE_CODE, required = false) 052 private final String affiliationTypeCode; 053 054 @XmlElement(name = Elements.CAMPUS_CODE, required = false) 055 private final String campusCode; 056 057 @XmlElement(name = Elements.AFFILIATION_TYPE, required = false) 058 private final EntityAffiliationType affiliationType; 059 060 061 @XmlElement(name = Elements.ACTIVE_INDICATOR, required = false) 062 private final boolean active; 063 064 @XmlElement(name = Elements.DEFAULT_VALUE, required = false) 065 private final boolean defaultValue; 066 067 @XmlElementWrapper(name = Elements.EMPLOYMENTS, required = false) 068 @XmlElement(name = Elements.EMPLOYMENTS, required = false) 069 private final List<EntityEmployment> employments; 070 071 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 072 private final Long versionNumber; 073 074 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) 075 private final String objectId; 076 077 @SuppressWarnings("unused") 078 @XmlAnyElement 079 private final Collection<Element> _futureElements = null; 080 081 public OlePatronAffiliationDefinition() { 082 this.entityAffiliationId = null; 083 this.entityId = null; 084 this.affiliationTypeCode = null; 085 this.campusCode = null; 086 this.affiliationType = null; 087 this.employments = null; 088 this.defaultValue = false; 089 this.active = false; 090 091 this.versionNumber = null; 092 this.objectId = null; 093 } 094 095 096 private OlePatronAffiliationDefinition(Builder builder) { 097 this.entityAffiliationId = builder.getEntityAffiliationId(); 098 this.affiliationTypeCode = builder.getAffiliationTypeCode(); 099 this.campusCode = builder.getCampusCode(); 100 this.defaultValue = builder.isDefaultValue(); 101 this.active = builder.isActive(); 102 this.entityId = builder.getEntityId(); 103 104 105 this.employments = new ArrayList<EntityEmployment>(); 106 if (!CollectionUtils.isEmpty(builder.getEmployments())) { 107 for (EntityEmployment.Builder employment : builder.getEmployments()) { 108 this.employments.add(employment.build()); 109 } 110 } 111 112 this.affiliationType = builder.getAffiliationType().build(); 113 this.versionNumber = builder.getVersionNumber(); 114 this.objectId = builder.getObjectId(); 115 } 116 117 public String getEntityAffiliationId() { 118 return this.entityAffiliationId; 119 } 120 121 public String getAffiliationTypeCode() { 122 return this.affiliationTypeCode; 123 } 124 125 public String getCampusCode() { 126 return this.campusCode; 127 } 128 129 public boolean isDefaultValue() { 130 return this.defaultValue; 131 } 132 133 public EntityAffiliationType getAffiliationType() { 134 return this.affiliationType; 135 } 136 137 public List<EntityEmployment> getEmployments() { 138 return this.employments; 139 } 140 141 @Override 142 public boolean isActive() { 143 return this.active; 144 } 145 146 @Override 147 public Long getVersionNumber() { 148 return this.versionNumber; 149 } 150 151 @Override 152 public String getId() { 153 return this.getEntityAffiliationId(); 154 } 155 156 @Override 157 public String getObjectId() { 158 return this.objectId; 159 } 160 161 /*@Override 162 public EntityAffiliation getEntityAffliationBo() { 163 return null; //To change body of implemented methods use File | Settings | File Templates. 164 }*/ 165 166 @Override 167 public String getEntityId() { 168 return entityId; 169 } 170 171 //@Override 172 /*public OleBorrowerTypeDefinition getOleBorrowerType() { 173 return this.oleBorrowerType; 174 }*/ 175 176 public static class Builder 177 implements Serializable, ModelBuilder, OlePatronAffiliationContract { 178 private String entityAffiliationId; 179 private String affiliationTypeCode; 180 private String campusCode; 181 private boolean defaultValue; 182 private boolean active; 183 private EntityAffiliationType.Builder affiliationType; 184 private List<EntityEmployment.Builder> employments; 185 private String entityId; 186 187 private Long versionNumber; 188 private String objectId; 189 190 private Builder() { 191 } 192 193 public static Builder create() { 194 return new Builder(); 195 } 196 197 public static Builder create(OlePatronAffiliationContract contract) { 198 if (contract == null) { 199 throw new IllegalArgumentException("contract was null"); 200 } 201 Builder builder = create(); 202 if (contract.getEntityAffiliationId() != null) { 203 builder.setEntityAffiliationId(contract.getEntityAffiliationId()); 204 } 205 if (contract.getAffiliationTypeCode() != null) { 206 builder.setAffiliationTypeCode(contract.getAffiliationTypeCode()); 207 } 208 if (contract.getCampusCode() != null) { 209 builder.setCampusCode(contract.getCampusCode()); 210 } 211 if (contract.isActive()) { 212 builder.setActive(contract.isActive()); 213 } 214 if (contract.isDefaultValue()) { 215 builder.setDefaultValue(contract.isDefaultValue()); 216 } 217 218 builder.employments = new ArrayList<EntityEmployment.Builder>(); 219 if (!CollectionUtils.isEmpty(contract.getEmployments())) { 220 for (EntityEmploymentContract entityEmploymentContract : contract.getEmployments()) { 221 builder.employments.add(EntityEmployment.Builder.create(entityEmploymentContract)); 222 } 223 } 224 if (contract.getAffiliationType() != null) { 225 builder.setAffiliationType(EntityAffiliationType.Builder.create(contract.getAffiliationType())); 226 } 227 228 builder.setEntityId(contract.getEntityId()); 229 builder.setVersionNumber(contract.getVersionNumber()); 230 builder.setObjectId(contract.getObjectId()); 231 builder.setActive(contract.isActive()); 232 builder.setId(contract.getId()); 233 return builder; 234 } 235 236 237 public org.kuali.ole.deliver.api.OlePatronAffiliationDefinition build() { 238 return new org.kuali.ole.deliver.api.OlePatronAffiliationDefinition(this); 239 } 240 241 public String getEntityAffiliationId() { 242 return entityAffiliationId; 243 } 244 245 public void setEntityAffiliationId(String entityAffiliationId) { 246 this.entityAffiliationId = entityAffiliationId; 247 } 248 249 public String getAffiliationTypeCode() { 250 return affiliationTypeCode; 251 } 252 253 public void setAffiliationTypeCode(String affiliationTypeCode) { 254 this.affiliationTypeCode = affiliationTypeCode; 255 } 256 257 public String getCampusCode() { 258 return campusCode; 259 } 260 261 public void setCampusCode(String campusCode) { 262 this.campusCode = campusCode; 263 } 264 265 public boolean isDefaultValue() { 266 return defaultValue; 267 } 268 269 public void setDefaultValue(boolean defaultValue) { 270 this.defaultValue = defaultValue; 271 } 272 273 public EntityAffiliationType.Builder getAffiliationType() { 274 return affiliationType; 275 } 276 277 public void setAffiliationType(EntityAffiliationType.Builder affiliationType) { 278 this.affiliationType = affiliationType; 279 } 280 281 public List<EntityEmployment.Builder> getEmployments() { 282 return employments; 283 } 284 285 public void setEmployments(List<EntityEmployment.Builder> employments) { 286 this.employments = employments; 287 } 288 289 public boolean isActive() { 290 return active; 291 } 292 293 public void setActive(boolean active) { 294 this.active = active; 295 } 296 297 @Override 298 public Long getVersionNumber() { 299 return versionNumber; 300 } 301 302 public void setVersionNumber(Long versionNumber) { 303 this.versionNumber = versionNumber; 304 } 305 306 @Override 307 public String getObjectId() { 308 return objectId; 309 } 310 311 public void setObjectId(String objectId) { 312 this.objectId = objectId; 313 } 314 315 public void setId(String id) { 316 if (StringUtils.isWhitespace(id)) { 317 throw new IllegalArgumentException("id is blank"); 318 } 319 this.entityAffiliationId = id; 320 } 321 322 @Override 323 public String getId() { 324 return this.entityAffiliationId; 325 } 326 327 public String getEntityId() { 328 return entityId; 329 } 330 331 public void setEntityId(String entityId) { 332 this.entityId = entityId; 333 } 334 } 335 336 static class Constants { 337 338 final static String ROOT_ELEMENT_NAME = "olePatronAffiliation"; 339 final static String TYPE_NAME = "OlePatronAffiliationType"; 340 final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[]{CoreConstants.CommonElements.FUTURE_ELEMENTS}; 341 } 342 343 static class Elements { 344 final static String ENTITY_AFFILIATION_ID = "entityAffiliationId"; 345 //final static String ENTITY_ID = "entityId"; 346 final static String AFFILIATION_TYPE_CODE = "affiliationTypeCode"; 347 final static String CAMPUS_CODE = "campusCode"; 348 final static String AFFILIATION_TYPE = "affiliationType"; 349 final static String EMPLOYMENTS = "employments"; 350 final static String DEFAULT_VALUE = "defaultValue"; 351 final static String ACTIVE_INDICATOR = "active"; 352 final static String ENTITY_ID = "entityId"; 353 354 355 } 356 357 public static class Cache { 358 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + Constants.TYPE_NAME; 359 } 360}