View Javadoc
1   package org.kuali.ole.deliver.api;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.commons.lang.StringUtils;
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.affiliation.EntityAffiliationType;
10  import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
11  import org.kuali.rice.kim.api.identity.employment.EntityEmploymentContract;
12  import org.w3c.dom.Element;
13  
14  import javax.xml.bind.annotation.*;
15  import java.io.Serializable;
16  import java.util.ArrayList;
17  import java.util.Collection;
18  import java.util.List;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: ?
23   * Date: 5/24/12
24   * Time: 8:26 PM
25   * To change this template use File | Settings | File Templates.
26   */
27  @XmlRootElement(name = org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Constants.ROOT_ELEMENT_NAME)
28  @XmlAccessorType(XmlAccessType.NONE)
29  @XmlType(name = org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Constants.TYPE_NAME, propOrder = {
30          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.ENTITY_AFFILIATION_ID,
31          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.ENTITY_ID,
32          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.AFFILIATION_TYPE_CODE,
33          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.AFFILIATION_TYPE,
34          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.CAMPUS_CODE,
35          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.EMPLOYMENTS,
36          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.DEFAULT_VALUE,
37          org.kuali.ole.deliver.api.OlePatronAffiliationDefinition.Elements.ACTIVE_INDICATOR,
38  
39          CoreConstants.CommonElements.VERSION_NUMBER,
40          CoreConstants.CommonElements.OBJECT_ID,
41          CoreConstants.CommonElements.FUTURE_ELEMENTS
42  })
43  public final class OlePatronAffiliationDefinition extends AbstractDataTransferObject implements OlePatronAffiliationContract {
44  
45      @XmlElement(name = Elements.ENTITY_AFFILIATION_ID, required = false)
46      private final String entityAffiliationId;
47  
48      @XmlElement(name = Elements.ENTITY_ID, required = false)
49      private final String entityId;
50  
51      @XmlElement(name = Elements.AFFILIATION_TYPE_CODE, required = false)
52      private final String affiliationTypeCode;
53  
54      @XmlElement(name = Elements.CAMPUS_CODE, required = false)
55      private final String campusCode;
56  
57      @XmlElement(name = Elements.AFFILIATION_TYPE, required = false)
58      private final EntityAffiliationType affiliationType;
59  
60  
61      @XmlElement(name = Elements.ACTIVE_INDICATOR, required = false)
62      private final boolean active;
63  
64      @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
65      private final boolean defaultValue;
66  
67      @XmlElementWrapper(name = Elements.EMPLOYMENTS, required = false)
68      @XmlElement(name = Elements.EMPLOYMENTS, required = false)
69      private final List<EntityEmployment> employments;
70  
71      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
72      private final Long versionNumber;
73  
74      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
75      private final String objectId;
76  
77      @SuppressWarnings("unused")
78      @XmlAnyElement
79      private final Collection<Element> _futureElements = null;
80  
81      public OlePatronAffiliationDefinition() {
82          this.entityAffiliationId = null;
83          this.entityId = null;
84          this.affiliationTypeCode = null;
85          this.campusCode = null;
86          this.affiliationType = null;
87          this.employments = null;
88          this.defaultValue = false;
89          this.active = false;
90  
91          this.versionNumber = null;
92          this.objectId = null;
93      }
94  
95  
96      private OlePatronAffiliationDefinition(Builder builder) {
97          this.entityAffiliationId = builder.getEntityAffiliationId();
98          this.affiliationTypeCode = builder.getAffiliationTypeCode();
99          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 }