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