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 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 @SuppressWarnings("unused")
78 @XmlAnyElement
79 private final Collection<Element> _futureElements = null;
80
81 private DocumentUpdate() {
82 this.title = null;
83 this.applicationDocumentId = null;
84 this.applicationDocumentStatus = null;
85 this.variables = null;
86 }
87
88 private DocumentUpdate(Builder builder) {
89 this.title = builder.getTitle();
90 this.applicationDocumentId = builder.getApplicationDocumentId();
91 this.applicationDocumentStatus = builder.getApplicationDocumentStatus();
92 this.variables = builder.getVariables();
93 }
94
95 public String getTitle() {
96 return title;
97 }
98
99 public String getApplicationDocumentId() {
100 return applicationDocumentId;
101 }
102
103 public String getApplicationDocumentStatus() {
104 return applicationDocumentStatus;
105 }
106
107 public Map<String, String> getVariables() {
108 if (variables == null) {
109 return Collections.emptyMap();
110 }
111 return Collections.unmodifiableMap(variables);
112 }
113
114
115
116
117 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 private Builder() {
128 this.title = "";
129 this.variables = new HashMap<String, String>();
130 }
131
132 public static Builder create() {
133 return new Builder();
134 }
135
136 public static Builder create(Document document) {
137 if (document == null) {
138 throw new IllegalArgumentException("document was null");
139 }
140 Builder builder = create();
141 builder.setTitle(document.getTitle());
142 builder.setApplicationDocumentId(document.getApplicationDocumentId());
143 builder.setApplicationDocumentStatus(document.getApplicationDocumentStatus());
144 builder.setVariables(document.getVariables());
145 return builder;
146 }
147
148 public DocumentUpdate build() {
149 return new DocumentUpdate(this);
150 }
151
152 public String getTitle() {
153 return title;
154 }
155
156
157
158
159 public void setTitle(String title) {
160 if (title == null) {
161 title = "";
162 }
163 if (title.length() > KewApiConstants.TITLE_MAX_LENGTH) {
164 title = title.substring(0, KewApiConstants.TITLE_MAX_LENGTH);
165 }
166 this.title = title;
167 }
168
169 public String getApplicationDocumentId() {
170 return applicationDocumentId;
171 }
172
173 public void setApplicationDocumentId(String applicationDocumentId) {
174 this.applicationDocumentId = applicationDocumentId;
175 }
176
177 public String getApplicationDocumentStatus() {
178 return applicationDocumentStatus;
179 }
180
181 public void setApplicationDocumentStatus(String applicationDocumentStatus) {
182 this.applicationDocumentStatus = applicationDocumentStatus;
183 }
184
185 public void setVariables(Map<String, String> variables) {
186 if (variables == null) {
187 this.variables = new HashMap<String, String>();
188 } else {
189 this.variables = new HashMap<String, String>(variables);
190 }
191 }
192
193 public Map<String, String> getVariables() {
194 return variables;
195 }
196
197 public String getVariableValue(String name) {
198 return variables.get(name);
199 }
200
201 public void setVariable(String name, String value) {
202 if (StringUtils.isBlank(name)) {
203 throw new IllegalArgumentException("name was null or blank");
204 }
205 variables.put(name, value);
206 }
207
208 }
209
210
211
212
213 static class Constants {
214 final static String ROOT_ELEMENT_NAME = "documentUpdate";
215 final static String TYPE_NAME = "DocumentUpdateType";
216 }
217
218
219
220
221 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 }