001 package org.kuali.rice.kew.api.action;
002
003 import java.io.Serializable;
004 import java.util.ArrayList;
005 import java.util.Collection;
006 import java.util.Collections;
007 import java.util.List;
008 import javax.xml.bind.annotation.XmlAccessType;
009 import javax.xml.bind.annotation.XmlAccessorType;
010 import javax.xml.bind.annotation.XmlAnyElement;
011 import javax.xml.bind.annotation.XmlElement;
012 import javax.xml.bind.annotation.XmlRootElement;
013 import javax.xml.bind.annotation.XmlType;
014
015 import org.kuali.rice.core.api.CoreConstants;
016 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
017 import org.kuali.rice.core.api.mo.ModelBuilder;
018 import org.w3c.dom.Element;
019
020 @XmlRootElement(name = RoutingReportCriteria.Constants.ROOT_ELEMENT_NAME)
021 @XmlAccessorType(XmlAccessType.NONE)
022 @XmlType(name = RoutingReportCriteria.Constants.TYPE_NAME, propOrder = {
023 RoutingReportCriteria.Elements.DOCUMENT_ID,
024 RoutingReportCriteria.Elements.TARGET_NODE_NAME,
025 RoutingReportCriteria.Elements.TARGET_PRINCIPAL_IDS,
026 RoutingReportCriteria.Elements.ROUTING_PRINCIPAL_ID,
027 RoutingReportCriteria.Elements.DOCUMENT_TYPE_NAME,
028 RoutingReportCriteria.Elements.XML_CONTENT,
029 RoutingReportCriteria.Elements.RULE_TEMPLATE_NAMES,
030 RoutingReportCriteria.Elements.NODE_NAMES,
031 RoutingReportCriteria.Elements.ACTIONS_TO_TAKE,
032 RoutingReportCriteria.Elements.ACTIVATE_REQUESTS,
033 RoutingReportCriteria.Elements.FLATTEN_NODES,
034 CoreConstants.CommonElements.FUTURE_ELEMENTS})
035 public final class RoutingReportCriteria extends AbstractDataTransferObject implements RoutingReportCriteriaContract {
036
037 @XmlElement(name = Elements.DOCUMENT_ID, required = false)
038 private final String documentId;
039 @XmlElement(name = Elements.TARGET_NODE_NAME, required = false)
040 private final String targetNodeName;
041 @XmlElement(name = Elements.TARGET_PRINCIPAL_IDS, required = false)
042 private final List<String> targetPrincipalIds;
043 @XmlElement(name = Elements.ROUTING_PRINCIPAL_ID, required = false)
044 private final String routingPrincipalId;
045 @XmlElement(name = Elements.DOCUMENT_TYPE_NAME, required = false)
046 private final String documentTypeName;
047 @XmlElement(name = Elements.XML_CONTENT, required = false)
048 private final String xmlContent;
049 @XmlElement(name = Elements.RULE_TEMPLATE_NAMES, required = false)
050 private final List<String> ruleTemplateNames;
051 @XmlElement(name = Elements.NODE_NAMES, required = false)
052 private final List<String> nodeNames;
053 @XmlElement(name = Elements.ACTIONS_TO_TAKE, required = false)
054 private final List<RoutingReportActionToTake> actionsToTake;
055 @XmlElement(name = Elements.ACTIVATE_REQUESTS, required = false)
056 private final boolean activateRequests;
057 @XmlElement(name = Elements.FLATTEN_NODES, required = false)
058 private final boolean flattenNodes;
059 @SuppressWarnings("unused")
060 @XmlAnyElement
061 private final Collection<Element> _futureElements = null;
062
063 /**
064 * Private constructor used only by JAXB.
065 */
066 private RoutingReportCriteria() {
067 this.documentId = null;
068 this.targetNodeName = null;
069 this.targetPrincipalIds = null;
070 this.routingPrincipalId = null;
071 this.documentTypeName = null;
072 this.xmlContent = null;
073 this.ruleTemplateNames = null;
074 this.nodeNames = null;
075 this.actionsToTake = null;
076 this.flattenNodes = false;
077 this.activateRequests = false;
078 }
079
080 private RoutingReportCriteria(Builder builder) {
081 this.documentId = builder.getDocumentId();
082 this.targetNodeName = builder.getTargetNodeName();
083 this.targetPrincipalIds = builder.getTargetPrincipalIds();
084 this.routingPrincipalId = builder.getRoutingPrincipalId();
085 this.documentTypeName = builder.getDocumentTypeName();
086 this.xmlContent = builder.getXmlContent();
087 this.ruleTemplateNames = builder.getRuleTemplateNames();
088 this.nodeNames = builder.getNodeNames();
089 if (builder.getActionsToTake() != null) {
090 List<RoutingReportActionToTake> actions = new ArrayList<RoutingReportActionToTake>();
091 for (RoutingReportActionToTake.Builder actionBuilder : builder.getActionsToTake()) {
092 actions.add(actionBuilder.build());
093 }
094 this.actionsToTake = actions;
095 } else {
096 this.actionsToTake = Collections.emptyList();
097 }
098 this.flattenNodes = builder.isFlattenNodes();
099 this.activateRequests = builder.isActivateRequests();
100 }
101
102 @Override
103 public String getDocumentId() {
104 return this.documentId;
105 }
106
107 @Override
108 public String getTargetNodeName() {
109 return this.targetNodeName;
110 }
111
112 @Override
113 public List<String> getTargetPrincipalIds() {
114 return this.targetPrincipalIds;
115 }
116
117 @Override
118 public String getRoutingPrincipalId() {
119 return this.routingPrincipalId;
120 }
121
122 @Override
123 public String getDocumentTypeName() {
124 return this.documentTypeName;
125 }
126
127 @Override
128 public String getXmlContent() {
129 return this.xmlContent;
130 }
131
132 @Override
133 public List<String> getRuleTemplateNames() {
134 return this.ruleTemplateNames;
135 }
136
137 @Override
138 public List<String> getNodeNames() {
139 return this.nodeNames;
140 }
141
142 @Override
143 public List<RoutingReportActionToTake> getActionsToTake() {
144 return this.actionsToTake;
145 }
146
147 @Override
148 public boolean isActivateRequests() {
149 return this.activateRequests;
150 }
151
152 @Override
153 public boolean isFlattenNodes() {
154 return this.flattenNodes;
155 }
156
157 /**
158 * A builder which can be used to construct {@link RoutingReportCriteria} instances. Enforces the constraints of
159 * the {@link RoutingReportCriteriaContract}.
160 */
161 public final static class Builder implements Serializable, ModelBuilder, RoutingReportCriteriaContract {
162
163 private String documentId;
164 private String targetNodeName;
165 private List<String> targetPrincipalIds;
166 private String routingPrincipalId;
167 private String documentTypeName;
168 private String xmlContent;
169 private List<String> ruleTemplateNames;
170 private List<String> nodeNames;
171 private List<RoutingReportActionToTake.Builder> actionsToTake;
172 private boolean activateRequests;
173 private boolean flattenNodes;
174
175 private Builder(String documentId, String targetNodeName) {
176 this.setDocumentId(documentId);
177 this.setTargetNodeName(targetNodeName);
178 }
179
180 private Builder(String documentTypeName) {
181 this.setDocumentTypeName(documentTypeName);
182 }
183
184 public static Builder createByDocumentTypeName(String documentTypeName) {
185 return new Builder(documentTypeName);
186 }
187
188 public static Builder createByDocumentId(String documentId) {
189 return new Builder(documentId, null);
190 }
191
192 public static Builder createByDocumentIdAndTargetNodeName(String documentId, String targetNodeName) {
193 return new Builder(documentId, targetNodeName);
194 }
195
196 public static Builder create(RoutingReportCriteriaContract contract) {
197 if (contract == null) {
198 throw new IllegalArgumentException("contract was null");
199 }
200 Builder builder =
201 createByDocumentIdAndTargetNodeName(contract.getDocumentId(), contract.getTargetNodeName());
202 builder.setDocumentId(contract.getDocumentId());
203 builder.setTargetNodeName(contract.getTargetNodeName());
204 builder.setTargetPrincipalIds(contract.getTargetPrincipalIds());
205 builder.setRoutingPrincipalId(contract.getRoutingPrincipalId());
206 builder.setDocumentTypeName(contract.getDocumentTypeName());
207 builder.setXmlContent(contract.getXmlContent());
208 builder.setRuleTemplateNames(contract.getRuleTemplateNames());
209 builder.setNodeNames(contract.getNodeNames());
210 if (contract.getActionsToTake() != null) {
211 List<RoutingReportActionToTake.Builder> actionsToTake = new ArrayList<RoutingReportActionToTake.Builder>();
212 for (RoutingReportActionToTakeContract action : contract.getActionsToTake()) {
213 actionsToTake.add(RoutingReportActionToTake.Builder.create(action));
214 }
215 builder.setActionsToTake(actionsToTake);
216 }
217 builder.setActivateRequests(contract.isActivateRequests());
218 builder.setFlattenNodes(contract.isFlattenNodes());
219
220 return builder;
221 }
222
223 public RoutingReportCriteria build() {
224 return new RoutingReportCriteria(this);
225 }
226
227 @Override
228 public String getDocumentId() {
229 return this.documentId;
230 }
231
232 @Override
233 public String getTargetNodeName() {
234 return this.targetNodeName;
235 }
236
237 @Override
238 public List<String> getTargetPrincipalIds() {
239 return this.targetPrincipalIds;
240 }
241
242 @Override
243 public String getRoutingPrincipalId() {
244 return this.routingPrincipalId;
245 }
246
247 @Override
248 public String getDocumentTypeName() {
249 return this.documentTypeName;
250 }
251
252 @Override
253 public String getXmlContent() {
254 return this.xmlContent;
255 }
256
257 @Override
258 public List<String> getRuleTemplateNames() {
259 return this.ruleTemplateNames;
260 }
261
262 @Override
263 public List<String> getNodeNames() {
264 return this.nodeNames;
265 }
266
267 @Override
268 public List<RoutingReportActionToTake.Builder> getActionsToTake() {
269 return this.actionsToTake;
270 }
271
272 @Override
273 public boolean isActivateRequests() {
274 return this.activateRequests;
275 }
276
277 @Override
278 public boolean isFlattenNodes() {
279 return this.flattenNodes;
280 }
281
282 public void setDocumentId(String documentId) {
283 // TODO add validation of input value if required and throw IllegalArgumentException if needed
284 this.documentId = documentId;
285 }
286
287 public void setTargetNodeName(String targetNodeName) {
288 // TODO add validation of input value if required and throw IllegalArgumentException if needed
289 this.targetNodeName = targetNodeName;
290 }
291
292 public void setTargetPrincipalIds(List<String> targetPrincipalIds) {
293 // TODO add validation of input value if required and throw IllegalArgumentException if needed
294 this.targetPrincipalIds = Collections.unmodifiableList(targetPrincipalIds);
295 }
296
297 public void setRoutingPrincipalId(String routingPrincipalId) {
298 // TODO add validation of input value if required and throw IllegalArgumentException if needed
299 this.routingPrincipalId = routingPrincipalId;
300 }
301
302 public void setDocumentTypeName(String documentTypeName) {
303 // TODO add validation of input value if required and throw IllegalArgumentException if needed
304 this.documentTypeName = documentTypeName;
305 }
306
307 public void setXmlContent(String xmlContent) {
308 // TODO add validation of input value if required and throw IllegalArgumentException if needed
309 this.xmlContent = xmlContent;
310 }
311
312 public void setRuleTemplateNames(List<String> ruleTemplateNames) {
313 // TODO add validation of input value if required and throw IllegalArgumentException if needed
314 this.ruleTemplateNames = Collections.unmodifiableList(ruleTemplateNames);
315 }
316
317 public void setNodeNames(List<String> nodeNames) {
318 // TODO add validation of input value if required and throw IllegalArgumentException if needed
319 this.nodeNames = Collections.unmodifiableList(nodeNames);
320 }
321
322 public void setActionsToTake(List<RoutingReportActionToTake.Builder> actionsToTake) {
323 // TODO add validation of input value if required and throw IllegalArgumentException if needed
324 this.actionsToTake = Collections.unmodifiableList(actionsToTake);
325 }
326
327 public void setActivateRequests(boolean activateRequests) {
328 // TODO add validation of input value if required and throw IllegalArgumentException if needed
329 this.activateRequests = activateRequests;
330 }
331
332 public void setFlattenNodes(boolean flattenNodes) {
333 // TODO add validation of input value if required and throw IllegalArgumentException if needed
334 this.flattenNodes = flattenNodes;
335 }
336 }
337
338 /**
339 * Defines some internal constants used on this class.
340 */
341 static class Constants {
342
343 final static String ROOT_ELEMENT_NAME = "routingReportCriteria";
344 final static String TYPE_NAME = "RoutingReportCriteriaType";
345 }
346
347 /**
348 * A private class which exposes constants which define the XML element names to use when this object is marshalled
349 * to XML.
350 */
351 static class Elements {
352
353 final static String DOCUMENT_ID = "documentId";
354 final static String TARGET_NODE_NAME = "targetNodeName";
355 final static String TARGET_PRINCIPAL_IDS = "targetPrincipalIds";
356 final static String ROUTING_PRINCIPAL_ID = "routingPrincipalId";
357 final static String DOCUMENT_TYPE_NAME = "documentTypeName";
358 final static String XML_CONTENT = "xmlContent";
359 final static String RULE_TEMPLATE_NAMES = "ruleTemplateNames";
360 final static String NODE_NAMES = "nodeNames";
361 final static String ACTIONS_TO_TAKE = "actionsToTake";
362 final static String ACTIVATE_REQUESTS = "activateRequests";
363 final static String FLATTEN_NODES = "flattenNodes";
364 }
365 }