001/**
002 * Copyright 2005-2018 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.citizenship;
017
018import org.apache.commons.lang.StringUtils;
019import org.joda.time.DateTime;
020import org.kuali.rice.core.api.CoreConstants;
021import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
022import org.kuali.rice.core.api.mo.ModelBuilder;
023import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
024import org.kuali.rice.kim.api.identity.CodedAttribute;
025import org.w3c.dom.Element;
026
027import javax.xml.bind.annotation.XmlAccessType;
028import javax.xml.bind.annotation.XmlAccessorType;
029import javax.xml.bind.annotation.XmlAnyElement;
030import javax.xml.bind.annotation.XmlElement;
031import javax.xml.bind.annotation.XmlRootElement;
032import javax.xml.bind.annotation.XmlType;
033import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
034import java.io.Serializable;
035import java.util.Collection;
036
037@XmlRootElement(name = EntityCitizenship.Constants.ROOT_ELEMENT_NAME)
038@XmlAccessorType(XmlAccessType.NONE)
039@XmlType(name = EntityCitizenship.Constants.TYPE_NAME, propOrder = {
040    EntityCitizenship.Elements.ID,
041    EntityCitizenship.Elements.ENTITY_ID,
042    EntityCitizenship.Elements.STATUS,
043    EntityCitizenship.Elements.COUNTRY_CODE,
044    EntityCitizenship.Elements.START_DATE,
045    EntityCitizenship.Elements.END_DATE,
046    CoreConstants.CommonElements.VERSION_NUMBER,
047    CoreConstants.CommonElements.OBJECT_ID,
048    EntityCitizenship.Elements.ACTIVE,
049    CoreConstants.CommonElements.FUTURE_ELEMENTS
050})
051public final class EntityCitizenship extends AbstractDataTransferObject
052    implements EntityCitizenshipContract
053{
054    @XmlElement(name = Elements.ID, required = false)
055    private final String id;
056    @XmlElement(name = Elements.ENTITY_ID, required = false)
057    private final String entityId;
058    @XmlElement(name = Elements.STATUS, required = false)
059    private final CodedAttribute status;
060    @XmlElement(name = Elements.COUNTRY_CODE, required = false)
061    private final String countryCode;
062    @XmlJavaTypeAdapter(DateTimeAdapter.class)
063    @XmlElement(name = Elements.START_DATE, required = false)
064    private final DateTime startDate;
065    @XmlJavaTypeAdapter(DateTimeAdapter.class)
066    @XmlElement(name = Elements.END_DATE, required = false)
067    private final DateTime endDate;
068    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
069    private final Long versionNumber;
070    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
071    private final String objectId;
072    @XmlElement(name = Elements.ACTIVE, required = false)
073    private final boolean active;
074    @SuppressWarnings("unused")
075    @XmlAnyElement
076    private final Collection<Element> _futureElements = null;
077
078    /**
079     * Private constructor used only by JAXB.
080     * 
081     */
082    private EntityCitizenship() {
083        this.status = null;
084        this.countryCode = null;
085        this.startDate = null;
086        this.endDate = null;
087        this.versionNumber = null;
088        this.objectId = null;
089        this.active = false;
090        this.id = null;
091        this.entityId = null;
092    }
093
094    private EntityCitizenship(Builder builder) {
095        this.status = builder.getStatus() != null ? builder.getStatus().build() : null;
096        this.countryCode = builder.getCountryCode();
097        this.startDate = builder.getStartDate();
098        this.endDate = builder.getEndDate();
099        this.versionNumber = builder.getVersionNumber();
100        this.objectId = builder.getObjectId();
101        this.active = builder.isActive();
102        this.id = builder.getId();
103        this.entityId = builder.getEntityId();
104    }
105
106    @Override
107    public String getEntityId() {
108        return this.entityId;
109    }
110
111    @Override
112    public CodedAttribute getStatus() {
113        return this.status;
114    }
115
116    @Override
117    public String getCountryCode() {
118        return this.countryCode;
119    }
120
121    @Override
122    public DateTime getStartDate() {
123        return this.startDate;
124    }
125
126    @Override
127    public DateTime getEndDate() {
128        return this.endDate;
129    }
130
131    @Override
132    public Long getVersionNumber() {
133        return this.versionNumber;
134    }
135
136    @Override
137    public String getObjectId() {
138        return this.objectId;
139    }
140
141    @Override
142    public boolean isActive() {
143        return this.active;
144    }
145
146    @Override
147    public String getId() {
148        return this.id;
149    }
150
151    /**
152     * A builder which can be used to construct {@link EntityCitizenship} instances.  Enforces the constraints of the {@link EntityCitizenshipContract}.
153     * 
154     */
155    public final static class Builder
156        implements Serializable, ModelBuilder, EntityCitizenshipContract
157    {
158        private String entityId;
159        private CodedAttribute.Builder status;
160        private String countryCode;
161        private DateTime startDate;
162        private DateTime endDate;
163        private Long versionNumber;
164        private String objectId;
165        private boolean active;
166        private String id;
167
168        private Builder() {
169        }
170
171        public static Builder create() {
172            return new Builder();
173        }
174
175        public static Builder create(EntityCitizenshipContract contract) {
176            if (contract == null) {
177                throw new IllegalArgumentException("contract was null");
178            }
179            Builder builder = create();
180            builder.setEntityId(contract.getEntityId());
181            if (contract.getStatus() != null) {
182                builder.setStatus(CodedAttribute.Builder.create(contract.getStatus()));
183            }
184            builder.setCountryCode(contract.getCountryCode());
185            builder.setStartDate(contract.getStartDate());
186            builder.setEndDate(contract.getEndDate());
187            builder.setVersionNumber(contract.getVersionNumber());
188            builder.setObjectId(contract.getObjectId());
189            builder.setActive(contract.isActive());
190            builder.setId(contract.getId());
191            return builder;
192        }
193
194        public EntityCitizenship build() {
195            return new EntityCitizenship(this);
196        }
197
198        @Override
199        public String getEntityId() {
200            return this.entityId;
201        }
202
203        @Override
204        public CodedAttribute.Builder getStatus() {
205            return this.status;
206        }
207
208        @Override
209        public String getCountryCode() {
210            return this.countryCode;
211        }
212
213        @Override
214        public DateTime getStartDate() {
215            return this.startDate;
216        }
217
218        @Override
219        public DateTime getEndDate() {
220            return this.endDate;
221        }
222
223        @Override
224        public Long getVersionNumber() {
225            return this.versionNumber;
226        }
227
228        @Override
229        public String getObjectId() {
230            return this.objectId;
231        }
232
233        @Override
234        public boolean isActive() {
235            return this.active;
236        }
237
238        @Override
239        public String getId() {
240            return this.id;
241        }
242
243        public void setEntityId(String entityId) {
244            this.entityId = entityId;
245        }
246        public void setStatus(CodedAttribute.Builder status) {
247            this.status = status;
248        }
249
250        public void setCountryCode(String countryCode) {
251            this.countryCode = countryCode;
252        }
253
254        public void setStartDate(DateTime startDate) {
255            this.startDate = startDate;
256        }
257
258        public void setEndDate(DateTime endDate) {
259            this.endDate = endDate;
260        }
261
262        public void setVersionNumber(Long versionNumber) {
263            this.versionNumber = versionNumber;
264        }
265
266        public void setObjectId(String objectId) {
267            this.objectId = objectId;
268        }
269
270        public void setActive(boolean active) {
271            this.active = active;
272        }
273
274        public void setId(String id) {
275            if (StringUtils.isWhitespace(id)) {
276                throw new IllegalArgumentException("id is blank");
277            }
278            this.id = id;
279        }
280
281        }
282
283
284    /**
285     * Defines some internal constants used on this class.
286     * 
287     */
288    static class Constants {
289
290        final static String ROOT_ELEMENT_NAME = "entityCitizenship";
291        final static String TYPE_NAME = "EntityCitizenshipType";
292    }
293
294
295    /**
296     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
297     * 
298     */
299    static class Elements {
300        final static String ENTITY_ID = "entityId";
301        final static String STATUS = "status";
302        final static String COUNTRY_CODE = "countryCode";
303        final static String START_DATE = "startDate";
304        final static String END_DATE = "endDate";
305        final static String ACTIVE = "active";
306        final static String ID = "id";
307
308    }
309
310}