001/**
002 * Copyright 2005-2017 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 */
016package org.kuali.rice.kim.api.identity.affiliation;
017
018import java.io.Serializable;
019import java.util.Collection;
020import javax.xml.bind.annotation.XmlAccessType;
021import javax.xml.bind.annotation.XmlAccessorType;
022import javax.xml.bind.annotation.XmlAnyElement;
023import javax.xml.bind.annotation.XmlElement;
024import javax.xml.bind.annotation.XmlRootElement;
025import javax.xml.bind.annotation.XmlType;
026
027import org.apache.commons.lang.StringUtils;
028import org.kuali.rice.core.api.CoreConstants;
029import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
030import org.kuali.rice.core.api.mo.ModelBuilder;
031import org.w3c.dom.Element;
032
033@XmlRootElement(name = EntityAffiliationType.Constants.ROOT_ELEMENT_NAME)
034@XmlAccessorType(XmlAccessType.NONE)
035@XmlType(name = EntityAffiliationType.Constants.TYPE_NAME, propOrder = {
036    EntityAffiliationType.Elements.CODE,
037    EntityAffiliationType.Elements.NAME,
038    EntityAffiliationType.Elements.SORT_CODE,
039    EntityAffiliationType.Elements.ACTIVE,
040    EntityAffiliationType.Elements.EMPLOYMENT_AFFILIATION_TYPE,
041    CoreConstants.CommonElements.VERSION_NUMBER,
042    CoreConstants.CommonElements.OBJECT_ID,
043    CoreConstants.CommonElements.FUTURE_ELEMENTS
044})
045public final class EntityAffiliationType extends AbstractDataTransferObject
046    implements EntityAffiliationTypeContract
047{
048    @XmlElement(name = Elements.CODE, required = true)
049    private final String code;
050    @XmlElement(name = Elements.NAME, required = false)
051    private final String name;
052    @XmlElement(name = Elements.SORT_CODE, required = false)
053    private final String sortCode;
054    @XmlElement(name = Elements.EMPLOYMENT_AFFILIATION_TYPE, required = false)
055    private final boolean employmentAffiliationType;
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.ACTIVE, required = false)
061    private final boolean active;
062    @SuppressWarnings("unused")
063    @XmlAnyElement
064    private final Collection<Element> _futureElements = null;
065
066    /**
067     * Private constructor used only by JAXB.
068     * 
069     */
070    private EntityAffiliationType() {
071        this.name = null;
072        this.code = null;
073        this.sortCode = null;
074        this.versionNumber = null;
075        this.objectId = null;
076        this.active = false;
077        this.employmentAffiliationType = false;
078    }
079
080    private EntityAffiliationType(Builder builder) {
081        this.name = builder.getName();
082        this.code = builder.getCode();
083        this.sortCode = builder.getSortCode();
084        this.employmentAffiliationType = builder.isEmploymentAffiliationType();
085        this.versionNumber = builder.getVersionNumber();
086        this.objectId = builder.getObjectId();
087        this.active = builder.isActive();
088    }
089
090    @Override
091    public String getName() {
092        return this.name;
093    }
094
095    @Override
096    public String getCode() {
097        return this.code;
098    }
099
100    @Override
101    public String getSortCode() {
102        return this.sortCode;
103    }
104
105    @Override
106    public boolean isEmploymentAffiliationType() {
107        return this.employmentAffiliationType;
108    }
109
110    @Override
111    public Long getVersionNumber() {
112        return this.versionNumber;
113    }
114
115    @Override
116    public String getObjectId() {
117        return this.objectId;
118    }
119
120    @Override
121    public boolean isActive() {
122        return this.active;
123    }
124
125    /**
126     * A builder which can be used to construct {@link CodedAttribute} instances.  Enforces the constraints of the {@link CodedAttributeContract}.
127     * 
128     */
129    public final static class Builder
130        implements Serializable, ModelBuilder, EntityAffiliationTypeContract
131    {
132
133        private String name;
134        private String code;
135        private String sortCode;
136        private boolean employmentAffiliationType;
137        private Long versionNumber;
138        private String objectId;
139        private boolean active;
140
141        private Builder(String code) {
142            setCode(code);
143        }
144
145        public static Builder create(String code) {
146            return new Builder(code);
147        }
148
149        public static Builder create(EntityAffiliationTypeContract contract) {
150            if (contract == null) {
151                throw new IllegalArgumentException("contract was null");
152            }
153            // TODO if create() is modified to accept required parameters, this will need to be modified
154            Builder builder = create(contract.getCode());
155            builder.setName(contract.getName());
156            builder.setSortCode(contract.getSortCode());
157            builder.setEmploymentAffiliationType(contract.isEmploymentAffiliationType());
158            builder.setVersionNumber(contract.getVersionNumber());
159            builder.setObjectId(contract.getObjectId());
160            builder.setActive(contract.isActive());
161            return builder;
162        }
163
164        public EntityAffiliationType build() {
165            return new EntityAffiliationType(this);
166        }
167
168        @Override
169        public String getName() {
170            return this.name;
171        }
172
173        @Override
174        public String getCode() {
175            return this.code;
176        }
177
178        @Override
179        public String getSortCode() {
180            return this.sortCode;
181        }
182
183        @Override
184        public boolean isEmploymentAffiliationType() {
185            return this.employmentAffiliationType;
186        }
187
188        @Override
189        public Long getVersionNumber() {
190            return this.versionNumber;
191        }
192
193        @Override
194        public String getObjectId() {
195            return this.objectId;
196        }
197
198        @Override
199        public boolean isActive() {
200            return this.active;
201        }
202
203        public void setName(String name) {
204            this.name = name;
205        }
206
207        public void setCode(String code) {
208            if (StringUtils.isWhitespace(code)) {
209                throw new IllegalArgumentException("code is empty");
210            }
211            this.code = code;
212        }
213
214        public void setSortCode(String sortCode) {
215            this.sortCode = sortCode;
216        }
217
218        public void setEmploymentAffiliationType(boolean employmentAffiliationType) {
219            this.employmentAffiliationType = employmentAffiliationType;
220        }
221
222        public void setVersionNumber(Long versionNumber) {
223            this.versionNumber = versionNumber;
224        }
225
226        public void setObjectId(String objectId) {
227            this.objectId = objectId;
228        }
229
230        public void setActive(boolean active) {
231            this.active = active;
232        }
233
234    }
235
236
237    /**
238     * Defines some internal constants used on this class.
239     * 
240     */
241    static class Constants {
242        final static String ROOT_ELEMENT_NAME = "entityAffiliationType";
243        final static String TYPE_NAME = "entityAffiliationTypeType";
244    }
245
246
247    /**
248     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
249     * 
250     */
251    static class Elements {
252
253        final static String NAME = "name";
254        final static String CODE = "code";
255        final static String SORT_CODE = "sortCode";
256        final static String ACTIVE = "active";
257        final static String EMPLOYMENT_AFFILIATION_TYPE = "employmentAffiliationType";
258
259    }
260
261}