001/**
002 * Copyright 2005-2016 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.ken.api.notification;
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;
026import org.kuali.rice.core.api.CoreConstants;
027import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
028import org.kuali.rice.core.api.mo.ModelBuilder;
029import org.w3c.dom.Element;
030
031@XmlRootElement(name = NotificationListRecipient.Constants.ROOT_ELEMENT_NAME)
032@XmlAccessorType(XmlAccessType.NONE)
033@XmlType(name = NotificationListRecipient.Constants.TYPE_NAME, propOrder = {
034        NotificationListRecipient.Elements.CHANNEL,
035        NotificationListRecipient.Elements.RECIPIENT_ID,
036        NotificationListRecipient.Elements.RECIPIENT_TYPE,
037        NotificationListRecipient.Elements.ID,
038        CoreConstants.CommonElements.VERSION_NUMBER,
039        CoreConstants.CommonElements.OBJECT_ID,
040        CoreConstants.CommonElements.FUTURE_ELEMENTS
041})
042public final class NotificationListRecipient
043        extends AbstractDataTransferObject
044        implements NotificationListRecipientContract
045{
046
047    @XmlElement(name = Elements.CHANNEL, required = false)
048    private final NotificationChannel channel;
049    @XmlElement(name = Elements.RECIPIENT_ID, required = false)
050    private final String recipientId;
051    @XmlElement(name = Elements.RECIPIENT_TYPE, required = false)
052    private final String recipientType;
053    @XmlElement(name = Elements.ID, required = false)
054    private final Long id;
055    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
056    private final Long versionNumber;
057    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
058    private final String objectId;
059    @SuppressWarnings("unused")
060    @XmlAnyElement
061    private final Collection<Element> _futureElements = null;
062
063    /**
064     * Private constructor used only by JAXB.
065     *
066     */
067    private NotificationListRecipient() {
068        this.channel = null;
069        this.recipientId = null;
070        this.recipientType = null;
071        this.id = null;
072        this.versionNumber = null;
073        this.objectId = null;
074    }
075
076    private NotificationListRecipient(Builder builder) {
077        this.channel = builder.getChannel() == null ? null : builder.getChannel().build();
078        this.recipientId = builder.getRecipientId();
079        this.recipientType = builder.getRecipientType();
080        this.id = builder.getId();
081        this.versionNumber = builder.getVersionNumber();
082        this.objectId = builder.getObjectId();
083    }
084
085    @Override
086    public NotificationChannel getChannel() {
087        return this.channel;
088    }
089
090    @Override
091    public String getRecipientId() {
092        return this.recipientId;
093    }
094
095    @Override
096    public String getRecipientType() {
097        return this.recipientType;
098    }
099
100    @Override
101    public Long getId() {
102        return this.id;
103    }
104
105    @Override
106    public Long getVersionNumber() {
107        return this.versionNumber;
108    }
109
110    @Override
111    public String getObjectId() {
112        return this.objectId;
113    }
114
115
116    /**
117     * A builder which can be used to construct {@link NotificationListRecipient} instances.  Enforces the constraints of the {@link NotificationListRecipientContract}.
118     *
119     */
120    public final static class Builder
121            implements Serializable, ModelBuilder, NotificationListRecipientContract
122    {
123
124        private NotificationChannel.Builder channel;
125        private String recipientId;
126        private String recipientType;
127        private Long id;
128        private Long versionNumber;
129        private String objectId;
130
131        private Builder() {
132        }
133
134        public static Builder create() {
135            return new Builder();
136        }
137
138        public static Builder create(NotificationListRecipientContract contract) {
139            if (contract == null) {
140                throw new IllegalArgumentException("contract was null");
141            }
142            // TODO if create() is modified to accept required parameters, this will need to be modified
143            Builder builder = create();
144            builder.setChannel(contract.getChannel() != null ? NotificationChannel.Builder.create(contract.getChannel()) : null);
145            builder.setRecipientId(contract.getRecipientId());
146            builder.setRecipientType(contract.getRecipientType());
147            builder.setId(contract.getId());
148            builder.setVersionNumber(contract.getVersionNumber());
149            builder.setObjectId(contract.getObjectId());
150            return builder;
151        }
152
153        public NotificationListRecipient build() {
154            return new NotificationListRecipient(this);
155        }
156
157        @Override
158        public NotificationChannel.Builder getChannel() {
159            return this.channel;
160        }
161
162        @Override
163        public String getRecipientId() {
164            return this.recipientId;
165        }
166
167        @Override
168        public String getRecipientType() {
169            return this.recipientType;
170        }
171
172        @Override
173        public Long getId() {
174            return this.id;
175        }
176
177        @Override
178        public Long getVersionNumber() {
179            return this.versionNumber;
180        }
181
182        @Override
183        public String getObjectId() {
184            return this.objectId;
185        }
186
187        public void setChannel(NotificationChannel.Builder channel) {
188            this.channel = channel;
189        }
190
191        public void setRecipientId(String recipientId) {
192            this.recipientId = recipientId;
193        }
194
195        public void setRecipientType(String recipientType) {
196            this.recipientType = recipientType;
197        }
198
199        public void setId(Long id) {
200            // TODO add validation of input value if required and throw IllegalArgumentException if needed
201            this.id = id;
202        }
203
204        public void setVersionNumber(Long versionNumber) {
205            // TODO add validation of input value if required and throw IllegalArgumentException if needed
206            this.versionNumber = versionNumber;
207        }
208
209        public void setObjectId(String objectId) {
210            // TODO add validation of input value if required and throw IllegalArgumentException if needed
211            this.objectId = objectId;
212        }
213
214    }
215
216
217    /**
218     * Defines some internal constants used on this class.
219     *
220     */
221    static class Constants {
222
223        final static String ROOT_ELEMENT_NAME = "notificationListRecipient";
224        final static String TYPE_NAME = "NotificationListRecipientType";
225
226    }
227
228
229    /**
230     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
231     *
232     */
233    static class Elements {
234
235        final static String CHANNEL = "channel";
236        final static String RECIPIENT_ID = "recipientId";
237        final static String RECIPIENT_TYPE = "recipientType";
238        final static String ID = "id";
239
240    }
241
242}