1 package org.kuali.ole.deliver.api;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.rice.core.api.CoreConstants;
5 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
6 import org.kuali.rice.core.api.mo.ModelBuilder;
7 import org.kuali.rice.kim.api.KimConstants;
8 import org.kuali.rice.kim.api.identity.email.EntityEmail;
9 import org.w3c.dom.Element;
10
11 import javax.xml.bind.annotation.*;
12 import java.io.Serializable;
13 import java.util.Collection;
14
15
16
17
18 @XmlRootElement(name = OleEmailDefinition.Constants.ROOT_ELEMENT_NAME)
19 @XmlAccessorType(XmlAccessType.NONE)
20 @XmlType(name = OleEmailDefinition.Constants.TYPE_NAME, propOrder = {
21 OleEmailDefinition.Elements.OLE_EMAIL_ID,
22 OleEmailDefinition.Elements.OLE_PTRN_ID,
23 OleEmailDefinition.Elements.ID,
24 OleEmailDefinition.Elements.EMAIL_SOURCE,
25 OleEmailDefinition.Elements.OLE_EMAIL_SOURCE_BO,
26
27 CoreConstants.CommonElements.VERSION_NUMBER,
28 CoreConstants.CommonElements.FUTURE_ELEMENTS
29 })
30 public class OleEmailDefinition extends AbstractDataTransferObject implements OleEmailContract {
31
32 private static final long serialVersionUID = 1L;
33
34 @XmlElement(name = Elements.OLE_EMAIL_ID, required = false)
35 private final String oleEmailId;
36
37 @XmlElement(name = Elements.OLE_PTRN_ID, required = false)
38 private final String olePatronId;
39
40 @XmlElement(name = Elements.ID, required = false)
41 private final String id;
42
43 @XmlElement(name = Elements.EMAIL_SOURCE, required = false)
44 private final String emailSource;
45
46 @XmlElement(name = Elements.OLE_EMAIL_SOURCE_BO, required = false)
47 private final OleAddressSourceDefinition oleEmailSourceBo;
48
49 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
50 private final Long versionNumber;
51
52 @SuppressWarnings("unused")
53 @XmlAnyElement
54 private final Collection<Element> _futureElements = null;
55
56 public OleEmailDefinition() {
57 this.oleEmailId = null;
58 this.olePatronId = null;
59 this.id = null;
60 this.emailSource = null;
61 this.oleEmailSourceBo = null;
62 this.versionNumber = null;
63 }
64
65 private OleEmailDefinition(Builder builder) {
66 this.oleEmailId = builder.getOleEmailId();
67 this.olePatronId = builder.getOlePatronId();
68 this.id = builder.getId();
69 this.emailSource = builder.getEmailSource();
70 if (builder.getOleEmailSourceBo() != null)
71 this.oleEmailSourceBo = builder.getOleEmailSourceBo().build();
72 else
73 this.oleEmailSourceBo = new OleAddressSourceDefinition();
74 this.versionNumber = builder.getVersionNumber();
75 }
76
77 @Override
78 public String getOleEmailId() {
79 return oleEmailId;
80 }
81
82 @Override
83 public String getOlePatronId() {
84 return olePatronId;
85 }
86
87 @Override
88 public String getId() {
89 return this.id;
90 }
91
92 @Override
93 public String getEmailSource() {
94 return emailSource;
95 }
96
97 @Override
98 public OleAddressSourceDefinition getOleEmailSourceBo() {
99 return oleEmailSourceBo;
100 }
101
102 @Override
103 public Long getVersionNumber() {
104 return this.versionNumber;
105 }
106
107 public static class Builder
108 implements Serializable, ModelBuilder, OleEmailContract {
109 private String oleEmailId;
110 private String olePatronId;
111 private String id;
112 private String emailSource;
113 private OleAddressSourceDefinition.Builder oleEmailSourceBo;
114 private EntityEmail.Builder entityEmail;
115 private Long versionNumber;
116 private String objectId;
117
118 private Builder() {
119 }
120
121 public static Builder create() {
122 return new Builder();
123 }
124
125 public static Builder create(OleEmailContract contract) {
126 if (contract == null) {
127 throw new IllegalArgumentException("contract was null");
128 }
129 Builder builder = create();
130 if (contract.getOleEmailId() != null) {
131 builder.setOleEmailId(contract.getOleEmailId());
132 }
133 if (contract.getOlePatronId() != null) {
134 builder.setOlePatronId(contract.getOlePatronId());
135 }
136 if (contract.getId() != null) {
137 builder.setId(contract.getId());
138 }
139 if (contract.getEmailSource() != null) {
140 builder.setEmailSource(contract.getEmailSource());
141 }
142 if (contract.getOleEmailSourceBo() != null) {
143 builder.setOleEmailSourceBo(OleAddressSourceDefinition.Builder.create(contract.getOleEmailSourceBo()));
144 }
145 builder.setVersionNumber(contract.getVersionNumber());
146 builder.setId(contract.getId());
147 return builder;
148 }
149
150
151 public OleEmailDefinition build() {
152 return new OleEmailDefinition(this);
153 }
154
155 public String getOleEmailId() {
156 return oleEmailId;
157 }
158
159 public void setOleEmailId(String oleEmailId) {
160 this.oleEmailId = oleEmailId;
161 }
162
163 public String getOlePatronId() {
164 return olePatronId;
165 }
166
167 public void setOlePatronId(String olePatronId) {
168 this.olePatronId = olePatronId;
169 }
170
171 public String getEmailSource() {
172 return emailSource;
173 }
174
175 public void setEmailSource(String emailSource) {
176 this.emailSource = emailSource;
177 }
178
179 public OleAddressSourceDefinition.Builder getOleEmailSourceBo() {
180 return oleEmailSourceBo;
181 }
182
183 public void setOleEmailSourceBo(OleAddressSourceDefinition.Builder oleEmailSourceBo) {
184 this.oleEmailSourceBo = oleEmailSourceBo;
185 }
186
187 public EntityEmail.Builder getEntityEmail() {
188 return entityEmail;
189 }
190
191 public void setEntityEmail(EntityEmail.Builder entityEmail) {
192 this.entityEmail = entityEmail;
193 }
194
195 @Override
196 public Long getVersionNumber() {
197 return versionNumber;
198 }
199
200 public void setVersionNumber(Long versionNumber) {
201 this.versionNumber = versionNumber;
202 }
203
204 public void setObjectId(String objectId) {
205 this.objectId = objectId;
206 }
207
208 @Override
209 public String getId() {
210 return this.id;
211 }
212
213 public void setId(String id) {
214 if (StringUtils.isWhitespace(id)) {
215 throw new IllegalArgumentException("id is blank");
216 }
217 this.id = id;
218 }
219 }
220
221 static class Constants {
222
223 final static String ROOT_ELEMENT_NAME = "oleEmail";
224 final static String TYPE_NAME = "OleEmailType";
225 final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[]{CoreConstants.CommonElements.FUTURE_ELEMENTS};
226 }
227
228 static class Elements {
229 final static String OLE_EMAIL_ID = "oleEmailId";
230 final static String OLE_PTRN_ID = "olePatronId";
231 final static String ID = "id";
232 final static String EMAIL_SOURCE = "emailSource";
233 final static String OLE_EMAIL_SOURCE_BO = "oleEmailSourceBo";
234 }
235
236 public static class Cache {
237 public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + Constants.TYPE_NAME;
238 }
239 }