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.privacy;
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.kuali.rice.kim.api.KimConstants;
032import org.w3c.dom.Element;
033
034@XmlRootElement(name = EntityPrivacyPreferences.Constants.ROOT_ELEMENT_NAME)
035@XmlAccessorType(XmlAccessType.NONE)
036@XmlType(name = EntityPrivacyPreferences.Constants.TYPE_NAME, propOrder = {
037    EntityPrivacyPreferences.Elements.ENTITY_ID,
038    EntityPrivacyPreferences.Elements.SUPPRESS_NAME,
039    EntityPrivacyPreferences.Elements.SUPPRESS_ADDRESS,
040    EntityPrivacyPreferences.Elements.SUPPRESS_EMAIL,
041    EntityPrivacyPreferences.Elements.SUPPRESS_PHONE,
042    EntityPrivacyPreferences.Elements.SUPPRESS_PERSONAL,
043    CoreConstants.CommonElements.VERSION_NUMBER,
044    CoreConstants.CommonElements.OBJECT_ID,
045    CoreConstants.CommonElements.FUTURE_ELEMENTS
046})
047public final class EntityPrivacyPreferences extends AbstractDataTransferObject
048    implements EntityPrivacyPreferencesContract
049{
050
051    @XmlElement(name = Elements.ENTITY_ID, required = false)
052    private final String entityId;
053    @XmlElement(name = Elements.SUPPRESS_NAME, required = false)
054    private final boolean suppressName;
055    @XmlElement(name = Elements.SUPPRESS_ADDRESS, required = false)
056    private final boolean suppressAddress;
057    @XmlElement(name = Elements.SUPPRESS_EMAIL, required = false)
058    private final boolean suppressEmail;
059    @XmlElement(name = Elements.SUPPRESS_PHONE, required = false)
060    private final boolean suppressPhone;
061    @XmlElement(name = Elements.SUPPRESS_PERSONAL, required = false)
062    private final boolean suppressPersonal;
063    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
064    private final Long versionNumber;
065    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
066    private final String objectId;
067    @SuppressWarnings("unused")
068    @XmlAnyElement
069    private final Collection<Element> _futureElements = null;
070
071    /**
072     * Private constructor used only by JAXB.
073     */
074    private EntityPrivacyPreferences() {
075        this.entityId = null;
076        this.suppressName = false;
077        this.suppressAddress = false;
078        this.suppressEmail = false;
079        this.suppressPhone = false;
080        this.suppressPersonal = false;
081        this.versionNumber = null;
082        this.objectId = null;
083    }
084
085    private EntityPrivacyPreferences(Builder builder) {
086        this.entityId = builder.getEntityId();
087        this.suppressName = builder.isSuppressName();
088        this.suppressAddress = builder.isSuppressAddress();
089        this.suppressEmail = builder.isSuppressEmail();
090        this.suppressPhone = builder.isSuppressPhone();
091        this.suppressPersonal = builder.isSuppressPersonal();
092        this.versionNumber = builder.getVersionNumber();
093        this.objectId = builder.getObjectId();
094    }
095
096    @Override
097    public String getEntityId() {
098        return this.entityId;
099    }
100
101    @Override
102    public boolean isSuppressName() {
103        return this.suppressName;
104    }
105
106    @Override
107    public boolean isSuppressAddress() {
108        return this.suppressAddress;
109    }
110
111    @Override
112    public boolean isSuppressEmail() {
113        return this.suppressEmail;
114    }
115
116    @Override
117    public boolean isSuppressPhone() {
118        return this.suppressPhone;
119    }
120
121    @Override
122    public boolean isSuppressPersonal() {
123        return this.suppressPersonal;
124    }
125
126    @Override
127    public Long getVersionNumber() {
128        return this.versionNumber;
129    }
130
131    @Override
132    public String getObjectId() {
133        return this.objectId;
134    }
135
136
137    /**
138     * A builder which can be used to construct {@link EntityPrivacyPreferences} instances.  Enforces the constraints of the {@link EntityPrivacyPreferencesContract}.
139     * 
140     */
141    public final static class Builder
142        implements Serializable, ModelBuilder, EntityPrivacyPreferencesContract
143    {
144
145        private String entityId;
146        private boolean suppressName;
147        private boolean suppressAddress;
148        private boolean suppressEmail;
149        private boolean suppressPhone;
150        private boolean suppressPersonal;
151        private Long versionNumber;
152        private String objectId;
153
154        private Builder(String entityId) {
155            setEntityId(entityId);
156        }
157
158        public static Builder create(String entityId) {
159            return new Builder(entityId);
160        }
161
162        public static Builder create(EntityPrivacyPreferencesContract contract) {
163            if (contract == null) {
164                throw new IllegalArgumentException("contract was null");
165            }
166            Builder builder = create(contract.getEntityId());
167            builder.setSuppressName(contract.isSuppressName());
168            builder.setSuppressAddress(contract.isSuppressAddress());
169            builder.setSuppressEmail(contract.isSuppressEmail());
170            builder.setSuppressPhone(contract.isSuppressPhone());
171            builder.setSuppressPersonal(contract.isSuppressPersonal());
172            builder.setVersionNumber(contract.getVersionNumber());
173            builder.setObjectId(contract.getObjectId());
174            return builder;
175        }
176
177        public EntityPrivacyPreferences build() {
178            return new EntityPrivacyPreferences(this);
179        }
180
181        @Override
182        public String getEntityId() {
183            return this.entityId;
184        }
185
186        @Override
187        public boolean isSuppressName() {
188            return this.suppressName;
189        }
190
191        @Override
192        public boolean isSuppressAddress() {
193            return this.suppressAddress;
194        }
195
196        @Override
197        public boolean isSuppressEmail() {
198            return this.suppressEmail;
199        }
200
201        @Override
202        public boolean isSuppressPhone() {
203            return this.suppressPhone;
204        }
205
206        @Override
207        public boolean isSuppressPersonal() {
208            return this.suppressPersonal;
209        }
210
211        @Override
212        public Long getVersionNumber() {
213            return this.versionNumber;
214        }
215
216        @Override
217        public String getObjectId() {
218            return this.objectId;
219        }
220
221        public void setEntityId(String entityId) {
222            if (StringUtils.isEmpty(entityId)) {
223                throw new IllegalArgumentException("entityId is empty");
224            }
225            this.entityId = entityId;
226        }
227
228        public void setSuppressName(boolean suppressName) {
229            // TODO add validation of input value if required and throw IllegalArgumentException if needed
230            this.suppressName = suppressName;
231        }
232
233        public void setSuppressAddress(boolean suppressAddress) {
234            // TODO add validation of input value if required and throw IllegalArgumentException if needed
235            this.suppressAddress = suppressAddress;
236        }
237
238        public void setSuppressEmail(boolean suppressEmail) {
239            // TODO add validation of input value if required and throw IllegalArgumentException if needed
240            this.suppressEmail = suppressEmail;
241        }
242
243        public void setSuppressPhone(boolean suppressPhone) {
244            // TODO add validation of input value if required and throw IllegalArgumentException if needed
245            this.suppressPhone = suppressPhone;
246        }
247
248        public void setSuppressPersonal(boolean suppressPersonal) {
249            // TODO add validation of input value if required and throw IllegalArgumentException if needed
250            this.suppressPersonal = suppressPersonal;
251        }
252
253        public void setVersionNumber(Long versionNumber) {
254            // TODO add validation of input value if required and throw IllegalArgumentException if needed
255            this.versionNumber = versionNumber;
256        }
257
258        public void setObjectId(String objectId) {
259            // TODO add validation of input value if required and throw IllegalArgumentException if needed
260            this.objectId = objectId;
261        }
262
263    }
264
265
266    /**
267     * Defines some internal constants used on this class.
268     * 
269     */
270    static class Constants {
271
272        final static String ROOT_ELEMENT_NAME = "entityPrivacyPreferences";
273        final static String TYPE_NAME = "EntityPrivacyPreferencesType";
274
275    }
276
277
278    /**
279     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
280     * 
281     */
282    static class Elements {
283
284        final static String ENTITY_ID = "entityId";
285        final static String SUPPRESS_NAME = "suppressName";
286        final static String SUPPRESS_ADDRESS = "suppressAddress";
287        final static String SUPPRESS_EMAIL = "suppressEmail";
288        final static String SUPPRESS_PHONE = "suppressPhone";
289        final static String SUPPRESS_PERSONAL = "suppressPersonal";
290
291    }
292
293    public static class Cache {
294        public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + EntityPrivacyPreferences.Constants.TYPE_NAME;
295    }
296
297}