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.external;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.CoreConstants;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.kuali.rice.core.api.mo.ModelBuilder;
022import org.w3c.dom.Element;
023
024import javax.xml.bind.annotation.XmlAccessType;
025import javax.xml.bind.annotation.XmlAccessorType;
026import javax.xml.bind.annotation.XmlAnyElement;
027import javax.xml.bind.annotation.XmlElement;
028import javax.xml.bind.annotation.XmlRootElement;
029import javax.xml.bind.annotation.XmlType;
030import java.io.Serializable;
031import java.util.Collection;
032
033@XmlRootElement(name = EntityExternalIdentifierType.Constants.ROOT_ELEMENT_NAME)
034@XmlAccessorType(XmlAccessType.NONE)
035@XmlType(name = EntityExternalIdentifierType.Constants.TYPE_NAME, propOrder = {
036    EntityExternalIdentifierType.Elements.CODE,
037    EntityExternalIdentifierType.Elements.NAME,
038    EntityExternalIdentifierType.Elements.SORT_CODE,
039    EntityExternalIdentifierType.Elements.ACTIVE,
040    EntityExternalIdentifierType.Elements.ENCRYPTION_REQUIRED,
041    CoreConstants.CommonElements.VERSION_NUMBER,
042    CoreConstants.CommonElements.OBJECT_ID,
043    CoreConstants.CommonElements.FUTURE_ELEMENTS
044})
045public final class EntityExternalIdentifierType extends AbstractDataTransferObject
046    implements EntityExternalIdentifierTypeContract
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.ENCRYPTION_REQUIRED, required = false)
055    private final boolean encryptionRequired;
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 EntityExternalIdentifierType() {
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.encryptionRequired = false;
078    }
079
080    private EntityExternalIdentifierType(Builder builder) {
081        this.name = builder.getName();
082        this.code = builder.getCode();
083        this.sortCode = builder.getSortCode();
084        this.encryptionRequired = builder.isEncryptionRequired();
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 isEncryptionRequired() {
107        return this.encryptionRequired;
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, EntityExternalIdentifierTypeContract
131    {
132
133        private String name;
134        private String code;
135        private String sortCode;
136        private boolean encryptionRequired;
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(EntityExternalIdentifierTypeContract contract) {
150            if (contract == null) {
151                throw new IllegalArgumentException("contract was null");
152            }
153            Builder builder = create(contract.getCode());
154            builder.setName(contract.getName());
155            builder.setSortCode(contract.getSortCode());
156            builder.setEncryptionRequired(contract.isEncryptionRequired());
157            builder.setVersionNumber(contract.getVersionNumber());
158            builder.setObjectId(contract.getObjectId());
159            builder.setActive(contract.isActive());
160            return builder;
161        }
162
163        public EntityExternalIdentifierType build() {
164            return new EntityExternalIdentifierType(this);
165        }
166
167        @Override
168        public String getName() {
169            return this.name;
170        }
171
172        @Override
173        public String getCode() {
174            return this.code;
175        }
176
177        @Override
178        public String getSortCode() {
179            return this.sortCode;
180        }
181
182        @Override
183        public boolean isEncryptionRequired() {
184            return this.encryptionRequired;
185        }
186
187        @Override
188        public Long getVersionNumber() {
189            return this.versionNumber;
190        }
191
192        @Override
193        public String getObjectId() {
194            return this.objectId;
195        }
196
197        @Override
198        public boolean isActive() {
199            return this.active;
200        }
201
202        public void setName(String name) {
203            this.name = name;
204        }
205
206        public void setCode(String code) {
207            if (StringUtils.isWhitespace(code)) {
208                throw new IllegalArgumentException("code is empty");
209            }
210            this.code = code;
211        }
212
213        public void setSortCode(String sortCode) {
214            this.sortCode = sortCode;
215        }
216
217        public void setEncryptionRequired(boolean encryptionRequired) {
218            this.encryptionRequired = encryptionRequired;
219        }
220
221        public void setVersionNumber(Long versionNumber) {
222            this.versionNumber = versionNumber;
223        }
224
225        public void setObjectId(String objectId) {
226            this.objectId = objectId;
227        }
228
229        public void setActive(boolean active) {
230            this.active = active;
231        }
232
233    }
234
235
236    /**
237     * Defines some internal constants used on this class.
238     * 
239     */
240    static class Constants {
241
242        final static String ROOT_ELEMENT_NAME = "entityExternalIdentifierType";
243        final static String TYPE_NAME = "entityExternalIdentifierTypeType";
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 ENCRYPTION_REQUIRED = "encryptionRequired";
258
259    }
260
261}