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