001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kim.api.identity.affiliation;
017    
018    import java.io.Serializable;
019    import java.util.Collection;
020    import javax.xml.bind.annotation.XmlAccessType;
021    import javax.xml.bind.annotation.XmlAccessorType;
022    import javax.xml.bind.annotation.XmlAnyElement;
023    import javax.xml.bind.annotation.XmlElement;
024    import javax.xml.bind.annotation.XmlRootElement;
025    import javax.xml.bind.annotation.XmlType;
026    
027    import org.apache.commons.lang.StringUtils;
028    import org.kuali.rice.core.api.CoreConstants;
029    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
030    import org.kuali.rice.core.api.mo.ModelBuilder;
031    import org.w3c.dom.Element;
032    
033    @XmlRootElement(name = EntityAffiliation.Constants.ROOT_ELEMENT_NAME)
034    @XmlAccessorType(XmlAccessType.NONE)
035    @XmlType(name = EntityAffiliation.Constants.TYPE_NAME, propOrder = {
036        EntityAffiliation.Elements.ID,
037        EntityAffiliation.Elements.ENTITY_ID,
038        EntityAffiliation.Elements.AFFILIATION_TYPE,
039        EntityAffiliation.Elements.CAMPUS_CODE,
040        EntityAffiliation.Elements.DEFAULT_VALUE,
041        EntityAffiliation.Elements.ACTIVE,
042        CoreConstants.CommonElements.VERSION_NUMBER,
043        CoreConstants.CommonElements.OBJECT_ID,
044        CoreConstants.CommonElements.FUTURE_ELEMENTS
045    })
046    public final class EntityAffiliation extends AbstractDataTransferObject
047        implements EntityAffiliationContract
048    {
049    
050        @XmlElement(name = Elements.ENTITY_ID, required = false)
051        private final String entityId;
052        @XmlElement(name = Elements.AFFILIATION_TYPE, required = false)
053        private final EntityAffiliationType affiliationType;
054        @XmlElement(name = Elements.CAMPUS_CODE, required = false)
055        private final String campusCode;
056        @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
057        private final Long versionNumber;
058        @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
059        private final String objectId;
060        @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
061        private final boolean defaultValue;
062        @XmlElement(name = Elements.ACTIVE, required = false)
063        private final boolean active;
064        @XmlElement(name = Elements.ID, required = false)
065        private final String id;
066        @SuppressWarnings("unused")
067        @XmlAnyElement
068        private final Collection<Element> _futureElements = null;
069    
070        /**
071         * Private constructor used only by JAXB.
072         * 
073         */
074        private EntityAffiliation() {
075            this.entityId = null;
076            this.affiliationType = null;
077            this.campusCode = null;
078            this.versionNumber = null;
079            this.objectId = null;
080            this.defaultValue = false;
081            this.active = false;
082            this.id = null;
083        }
084    
085        private EntityAffiliation(Builder builder) {
086            this.entityId = builder.getEntityId();
087            this.affiliationType = builder.getAffiliationType() != null ? builder.getAffiliationType().build() : null;
088            this.campusCode = builder.getCampusCode();
089            this.versionNumber = builder.getVersionNumber();
090            this.objectId = builder.getObjectId();
091            this.defaultValue = builder.isDefaultValue();
092            this.active = builder.isActive();
093            this.id = builder.getId();
094        }
095    
096        @Override
097        public String getEntityId() {
098            return this.entityId;
099        }
100    
101        @Override
102        public EntityAffiliationType getAffiliationType() {
103            return this.affiliationType;
104        }
105    
106        @Override
107        public String getCampusCode() {
108            return this.campusCode;
109        }
110    
111        @Override
112        public Long getVersionNumber() {
113            return this.versionNumber;
114        }
115    
116        @Override
117        public String getObjectId() {
118            return this.objectId;
119        }
120    
121        @Override
122        public boolean isDefaultValue() {
123            return this.defaultValue;
124        }
125    
126        @Override
127        public boolean isActive() {
128            return this.active;
129        }
130    
131        @Override
132        public String getId() {
133            return this.id;
134        }
135    
136        /**
137         * A builder which can be used to construct {@link EntityAffiliation} instances.  Enforces the constraints of the {@link EntityAffiliationContract}.
138         * 
139         */
140        public final static class Builder
141            implements Serializable, ModelBuilder, EntityAffiliationContract
142        {
143    
144            private String entityId;
145            private EntityAffiliationType.Builder affiliationType;
146            private String campusCode;
147            private Long versionNumber;
148            private String objectId;
149            private boolean defaultValue;
150            private boolean active;
151            private String id;
152    
153            private Builder() { }
154    
155            public static Builder create() {
156                return new Builder();
157            }
158    
159            public static Builder create(EntityAffiliationContract contract) {
160                if (contract == null) {
161                    throw new IllegalArgumentException("contract was null");
162                }
163                Builder builder = create();
164                builder.setEntityId(contract.getEntityId());
165                if (contract.getAffiliationType() != null) {
166                    builder.setAffiliationType(EntityAffiliationType.Builder.create(contract.getAffiliationType()));
167                }
168                builder.setCampusCode(contract.getCampusCode());
169                builder.setVersionNumber(contract.getVersionNumber());
170                builder.setObjectId(contract.getObjectId());
171                builder.setDefaultValue(contract.isDefaultValue());
172                builder.setActive(contract.isActive());
173                builder.setId(contract.getId());
174                return builder;
175            }
176    
177            public EntityAffiliation build() {
178                return new EntityAffiliation(this);
179            }
180    
181            @Override
182            public String getEntityId() {
183                return this.entityId;
184            }
185    
186            @Override
187            public EntityAffiliationType.Builder getAffiliationType() {
188                return this.affiliationType;
189            }
190    
191            @Override
192            public String getCampusCode() {
193                return this.campusCode;
194            }
195    
196            @Override
197            public Long getVersionNumber() {
198                return this.versionNumber;
199            }
200    
201            @Override
202            public String getObjectId() {
203                return this.objectId;
204            }
205    
206            @Override
207            public boolean isDefaultValue() {
208                return this.defaultValue;
209            }
210    
211            @Override
212            public boolean isActive() {
213                return this.active;
214            }
215    
216            @Override
217            public String getId() {
218                return this.id;
219            }
220    
221            public void setEntityId(String entityId) {
222                this.entityId = entityId;
223            }
224    
225            public void setAffiliationType(EntityAffiliationType.Builder affiliationType) {
226                this.affiliationType = affiliationType;
227            }
228    
229            public void setCampusCode(String campusCode) {
230                this.campusCode = campusCode;
231            }
232    
233            public void setVersionNumber(Long versionNumber) {
234                this.versionNumber = versionNumber;
235            }
236    
237            public void setObjectId(String objectId) {
238                this.objectId = objectId;
239            }
240    
241            public void setDefaultValue(boolean defaultValue) {
242                this.defaultValue = defaultValue;
243            }
244    
245            public void setActive(boolean active) {
246                this.active = active;
247            }
248    
249            public void setId(String id) {
250                if (StringUtils.isWhitespace(id)) {
251                    throw new IllegalArgumentException("id is blank");
252                }
253                this.id = id;
254            }
255    
256        }
257    
258    
259        /**
260         * Defines some internal constants used on this class.
261         * 
262         */
263        static class Constants {
264    
265            final static String ROOT_ELEMENT_NAME = "entityAffiliation";
266            final static String TYPE_NAME = "EntityAffiliationType";
267        }
268    
269    
270        /**
271         * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
272         * 
273         */
274        static class Elements {
275    
276            final static String ENTITY_ID = "entityId";
277            final static String AFFILIATION_TYPE = "affiliationType";
278            final static String CAMPUS_CODE = "campusCode";
279            final static String DEFAULT_VALUE = "defaultValue";
280            final static String ACTIVE = "active";
281            final static String ID = "id";
282    
283        }
284    
285    }