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 | 0 | 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 | 0 | @SuppressWarnings("unused") |
81 | |
@XmlAnyElement |
82 | |
private final Collection<Element> _futureElements = null; |
83 | |
|
84 | 0 | private DocumentUpdate() { |
85 | 0 | this.title = null; |
86 | 0 | this.applicationDocumentId = null; |
87 | 0 | this.applicationDocumentStatus = null; |
88 | 0 | this.variables = null; |
89 | 0 | } |
90 | |
|
91 | 0 | private DocumentUpdate(Builder builder) { |
92 | 0 | this.title = builder.getTitle(); |
93 | 0 | this.applicationDocumentId = builder.getApplicationDocumentId(); |
94 | 0 | this.applicationDocumentStatus = builder.getApplicationDocumentStatus(); |
95 | 0 | this.variables = builder.getVariables(); |
96 | 0 | } |
97 | |
|
98 | |
public String getTitle() { |
99 | 0 | return title; |
100 | |
} |
101 | |
|
102 | |
public String getApplicationDocumentId() { |
103 | 0 | return applicationDocumentId; |
104 | |
} |
105 | |
|
106 | |
public String getApplicationDocumentStatus() { |
107 | 0 | return applicationDocumentStatus; |
108 | |
} |
109 | |
|
110 | |
public Map<String, String> getVariables() { |
111 | 0 | if (variables == null) { |
112 | 0 | return Collections.emptyMap(); |
113 | |
} |
114 | 0 | return Collections.unmodifiableMap(variables); |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public int hashCode() { |
119 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public boolean equals(Object object) { |
124 | 0 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
125 | |
} |
126 | |
|
127 | |
@Override |
128 | |
public String toString() { |
129 | 0 | return ToStringBuilder.reflectionToString(this); |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 0 | 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 | 0 | private Builder() { |
146 | 0 | this.title = ""; |
147 | 0 | this.variables = new HashMap<String, String>(); |
148 | 0 | } |
149 | |
|
150 | |
public static Builder create() { |
151 | 0 | return new Builder(); |
152 | |
} |
153 | |
|
154 | |
public static Builder create(Document document) { |
155 | 0 | if (document == null) { |
156 | 0 | throw new IllegalArgumentException("document was null"); |
157 | |
} |
158 | 0 | Builder builder = create(); |
159 | 0 | builder.setTitle(document.getTitle()); |
160 | 0 | builder.setApplicationDocumentId(document.getApplicationDocumentId()); |
161 | 0 | builder.setApplicationDocumentStatus(document.getApplicationDocumentStatus()); |
162 | 0 | builder.setVariables(document.getVariables()); |
163 | 0 | return builder; |
164 | |
} |
165 | |
|
166 | |
public DocumentUpdate build() { |
167 | 0 | return new DocumentUpdate(this); |
168 | |
} |
169 | |
|
170 | |
public String getTitle() { |
171 | 0 | return title; |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public void setTitle(String title) { |
178 | 0 | if (title == null) { |
179 | 0 | title = ""; |
180 | |
} |
181 | 0 | if (title.length() > KewApiConstants.TITLE_MAX_LENGTH) { |
182 | 0 | title = title.substring(0, KewApiConstants.TITLE_MAX_LENGTH); |
183 | |
} |
184 | 0 | this.title = title; |
185 | 0 | } |
186 | |
|
187 | |
public String getApplicationDocumentId() { |
188 | 0 | return applicationDocumentId; |
189 | |
} |
190 | |
|
191 | |
public void setApplicationDocumentId(String applicationDocumentId) { |
192 | 0 | this.applicationDocumentId = applicationDocumentId; |
193 | 0 | } |
194 | |
|
195 | |
public String getApplicationDocumentStatus() { |
196 | 0 | return applicationDocumentStatus; |
197 | |
} |
198 | |
|
199 | |
public void setApplicationDocumentStatus(String applicationDocumentStatus) { |
200 | 0 | this.applicationDocumentStatus = applicationDocumentStatus; |
201 | 0 | } |
202 | |
|
203 | |
public void setVariables(Map<String, String> variables) { |
204 | 0 | if (variables == null) { |
205 | 0 | this.variables = new HashMap<String, String>(); |
206 | |
} else { |
207 | 0 | this.variables = new HashMap<String, String>(variables); |
208 | |
} |
209 | 0 | } |
210 | |
|
211 | |
public Map<String, String> getVariables() { |
212 | 0 | return variables; |
213 | |
} |
214 | |
|
215 | |
public String getVariableValue(String name) { |
216 | 0 | return variables.get(name); |
217 | |
} |
218 | |
|
219 | |
public void setVariable(String name, String value) { |
220 | 0 | if (StringUtils.isBlank(name)) { |
221 | 0 | throw new IllegalArgumentException("name was null or blank"); |
222 | |
} |
223 | 0 | variables.put(name, value); |
224 | 0 | } |
225 | |
|
226 | |
} |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | 0 | static class Constants { |
232 | |
final static String ROOT_ELEMENT_NAME = "documentUpdate"; |
233 | |
final static String TYPE_NAME = "DocumentUpdateType"; |
234 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
235 | |
} |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | 0 | 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 | |
} |