1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.document;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlAnyElement;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlType;
30 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31
32 import org.apache.commons.lang.StringUtils;
33 import org.apache.commons.lang.builder.EqualsBuilder;
34 import org.apache.commons.lang.builder.HashCodeBuilder;
35 import org.apache.commons.lang.builder.ToStringBuilder;
36 import org.kuali.rice.core.api.CoreConstants;
37 import org.kuali.rice.core.api.mo.ModelBuilder;
38 import org.kuali.rice.core.util.jaxb.MapStringStringAdapter;
39 import org.kuali.rice.kew.api.KewApiConstants;
40 import org.w3c.dom.Element;
41
42
43
44
45
46
47
48
49
50
51
52
53
54 @XmlRootElement(name = DocumentUpdate.Constants.ROOT_ELEMENT_NAME)
55 @XmlAccessorType(XmlAccessType.NONE)
56 @XmlType(name = DocumentUpdate.Constants.TYPE_NAME, propOrder = {
57 DocumentUpdate.Elements.TITLE,
58 DocumentUpdate.Elements.APPLICATION_DOCUMENT_ID,
59 DocumentUpdate.Elements.APPLICATION_DOCUMENT_STATUS,
60 DocumentUpdate.Elements.VARIABLES,
61 CoreConstants.CommonElements.FUTURE_ELEMENTS
62 })
63 public final class DocumentUpdate implements Serializable {
64
65 private static final long serialVersionUID = 608839901744771499L;
66
67 @XmlElement(name = Elements.TITLE, required = false)
68 private final String title;
69
70 @XmlElement(name = Elements.APPLICATION_DOCUMENT_ID, required = false)
71 private final String applicationDocumentId;
72
73 @XmlElement(name = Elements.APPLICATION_DOCUMENT_STATUS, required = false)
74 private final String applicationDocumentStatus;
75
76 @XmlElement(name = Elements.VARIABLES, required = false)
77 @XmlJavaTypeAdapter(MapStringStringAdapter.class)
78 private final Map<String, String> variables;
79
80 @SuppressWarnings("unused")
81 @XmlAnyElement
82 private final Collection<Element> _futureElements = null;
83
84 private DocumentUpdate() {
85 this.title = null;
86 this.applicationDocumentId = null;
87 this.applicationDocumentStatus = null;
88 this.variables = null;
89 }
90
91 private DocumentUpdate(Builder builder) {
92 this.title = builder.getTitle();
93 this.applicationDocumentId = builder.getApplicationDocumentId();
94 this.applicationDocumentStatus = builder.getApplicationDocumentStatus();
95 this.variables = builder.getVariables();
96 }
97
98 public String getTitle() {
99 return title;
100 }
101
102 public String getApplicationDocumentId() {
103 return applicationDocumentId;
104 }
105
106 public String getApplicationDocumentStatus() {
107 return applicationDocumentStatus;
108 }
109
110 public Map<String, String> getVariables() {
111 if (variables == null) {
112 return Collections.emptyMap();
113 }
114 return Collections.unmodifiableMap(variables);
115 }
116
117 @Override
118 public int hashCode() {
119 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
120 }
121
122 @Override
123 public boolean equals(Object object) {
124 return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
125 }
126
127 @Override
128 public String toString() {
129 return ToStringBuilder.reflectionToString(this);
130 }
131
132
133
134
135 public final static class Builder implements Serializable, ModelBuilder {
136
137 private static final long serialVersionUID = 2220000561051177421L;
138
139 private String title;
140 private String applicationDocumentId;
141 private String applicationDocumentStatus;
142 private Map<String, String> variables;
143
144
145 private Builder() {
146 this.title = "";
147 this.variables = new HashMap<String, String>();
148 }
149
150 public static Builder create() {
151 return new Builder();
152 }
153
154 public static Builder create(Document document) {
155 if (document == null) {
156 throw new IllegalArgumentException("document was null");
157 }
158 Builder builder = create();
159 builder.setTitle(document.getTitle());
160 builder.setApplicationDocumentId(document.getApplicationDocumentId());
161 builder.setApplicationDocumentStatus(document.getApplicationDocumentStatus());
162 builder.setVariables(document.getVariables());
163 return builder;
164 }
165
166 public DocumentUpdate build() {
167 return new DocumentUpdate(this);
168 }
169
170 public String getTitle() {
171 return title;
172 }
173
174
175
176
177 public void setTitle(String title) {
178 if (title == null) {
179 title = "";
180 }
181 if (title.length() > KewApiConstants.TITLE_MAX_LENGTH) {
182 title = title.substring(0, KewApiConstants.TITLE_MAX_LENGTH);
183 }
184 this.title = title;
185 }
186
187 public String getApplicationDocumentId() {
188 return applicationDocumentId;
189 }
190
191 public void setApplicationDocumentId(String applicationDocumentId) {
192 this.applicationDocumentId = applicationDocumentId;
193 }
194
195 public String getApplicationDocumentStatus() {
196 return applicationDocumentStatus;
197 }
198
199 public void setApplicationDocumentStatus(String applicationDocumentStatus) {
200 this.applicationDocumentStatus = applicationDocumentStatus;
201 }
202
203 public void setVariables(Map<String, String> variables) {
204 if (variables == null) {
205 this.variables = new HashMap<String, String>();
206 } else {
207 this.variables = new HashMap<String, String>(variables);
208 }
209 }
210
211 public Map<String, String> getVariables() {
212 return variables;
213 }
214
215 public String getVariableValue(String name) {
216 return variables.get(name);
217 }
218
219 public void setVariable(String name, String value) {
220 if (StringUtils.isBlank(name)) {
221 throw new IllegalArgumentException("name was null or blank");
222 }
223 variables.put(name, value);
224 }
225
226 }
227
228
229
230
231 static class Constants {
232 final static String ROOT_ELEMENT_NAME = "documentUpdate";
233 final static String TYPE_NAME = "DocumentUpdateType";
234 final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] { CoreConstants.CommonElements.FUTURE_ELEMENTS };
235 }
236
237
238
239
240 static class Elements {
241 final static String TITLE = "title";
242 final static String APPLICATION_DOCUMENT_ID = "applicationDocumentId";
243 final static String APPLICATION_DOCUMENT_STATUS = "applicationDocumentStatus";
244 final static String VARIABLES = "variables";
245 }
246
247 }