View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.api.action;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.List;
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlAnyElement;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlElementWrapper;
28  import javax.xml.bind.annotation.XmlRootElement;
29  import javax.xml.bind.annotation.XmlType;
30  
31  import org.kuali.rice.core.api.CoreConstants;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.kuali.rice.core.api.mo.ModelBuilder;
34  import org.w3c.dom.Element;
35  
36  @XmlRootElement(name = RoutingReportCriteria.Constants.ROOT_ELEMENT_NAME)
37  @XmlAccessorType(XmlAccessType.NONE)
38  @XmlType(name = RoutingReportCriteria.Constants.TYPE_NAME, propOrder = {
39          RoutingReportCriteria.Elements.DOCUMENT_ID,
40          RoutingReportCriteria.Elements.TARGET_NODE_NAME,
41          RoutingReportCriteria.Elements.TARGET_PRINCIPAL_IDS,
42          RoutingReportCriteria.Elements.ROUTING_PRINCIPAL_ID,
43          RoutingReportCriteria.Elements.DOCUMENT_TYPE_NAME,
44          RoutingReportCriteria.Elements.XML_CONTENT,
45          RoutingReportCriteria.Elements.RULE_TEMPLATE_NAMES,
46          RoutingReportCriteria.Elements.NODE_NAMES,
47          RoutingReportCriteria.Elements.ACTIONS_TO_TAKE,
48          RoutingReportCriteria.Elements.ACTIVATE_REQUESTS,
49          RoutingReportCriteria.Elements.FLATTEN_NODES,
50          CoreConstants.CommonElements.FUTURE_ELEMENTS})
51  public final class RoutingReportCriteria extends AbstractDataTransferObject implements RoutingReportCriteriaContract {
52  
53      @XmlElement(name = Elements.DOCUMENT_ID, required = false)
54      private final String documentId;
55  
56      @XmlElement(name = Elements.TARGET_NODE_NAME, required = false)
57      private final String targetNodeName;
58  
59      @XmlElementWrapper(name = Elements.TARGET_PRINCIPAL_IDS, required = false)
60      @XmlElement(name = Elements.TARGET_PRINCIPAL_ID, required = false)
61      private final List<String> targetPrincipalIds;
62  
63      @XmlElement(name = Elements.ROUTING_PRINCIPAL_ID, required = false)
64      private final String routingPrincipalId;
65  
66      @XmlElement(name = Elements.DOCUMENT_TYPE_NAME, required = false)
67      private final String documentTypeName;
68  
69      @XmlElement(name = Elements.XML_CONTENT, required = false)
70      private final String xmlContent;
71  
72      @XmlElementWrapper(name = Elements.RULE_TEMPLATE_NAMES, required = false)
73      @XmlElement(name = Elements.RULE_TEMPLATE_NAME, required = false)
74      private final List<String> ruleTemplateNames;
75  
76      @XmlElementWrapper(name = Elements.NODE_NAMES, required = false)
77      @XmlElement(name = Elements.NODE_NAME, required = false)
78      private final List<String> nodeNames;
79  
80      @XmlElementWrapper(name = Elements.ACTIONS_TO_TAKE, required = false)
81      @XmlElement(name = Elements.ACTION_TO_TAKE, required = false)
82      private final List<RoutingReportActionToTake> actionsToTake;
83  
84      @XmlElement(name = Elements.ACTIVATE_REQUESTS, required = false)
85      private final boolean activateRequests;
86  
87      @XmlElement(name = Elements.FLATTEN_NODES, required = false)
88      private final boolean flattenNodes;
89  
90      @SuppressWarnings("unused")
91      @XmlAnyElement
92      private final Collection<Element> _futureElements = null;
93  
94      /**
95       * Private constructor used only by JAXB.
96       */
97      private RoutingReportCriteria() {
98          this.documentId = null;
99          this.targetNodeName = null;
100         this.targetPrincipalIds = null;
101         this.routingPrincipalId = null;
102         this.documentTypeName = null;
103         this.xmlContent = null;
104         this.ruleTemplateNames = null;
105         this.nodeNames = null;
106         this.actionsToTake = null;
107         this.flattenNodes = false;
108         this.activateRequests = false;
109     }
110 
111     private RoutingReportCriteria(Builder builder) {
112         this.documentId = builder.getDocumentId();
113         this.targetNodeName = builder.getTargetNodeName();
114         this.targetPrincipalIds = builder.getTargetPrincipalIds();
115         this.routingPrincipalId = builder.getRoutingPrincipalId();
116         this.documentTypeName = builder.getDocumentTypeName();
117         this.xmlContent = builder.getXmlContent();
118         this.ruleTemplateNames = builder.getRuleTemplateNames();
119         this.nodeNames = builder.getNodeNames();
120         if (builder.getActionsToTake() != null) {
121             List<RoutingReportActionToTake> actions = new ArrayList<RoutingReportActionToTake>();
122             for (RoutingReportActionToTake.Builder actionBuilder : builder.getActionsToTake()) {
123                 actions.add(actionBuilder.build());
124             }
125             this.actionsToTake = actions;
126         } else {
127             this.actionsToTake = Collections.emptyList();
128         }
129         this.flattenNodes = builder.isFlattenNodes();
130         this.activateRequests = builder.isActivateRequests();
131     }
132 
133     @Override
134     public String getDocumentId() {
135         return this.documentId;
136     }
137 
138     @Override
139     public String getTargetNodeName() {
140         return this.targetNodeName;
141     }
142 
143     @Override
144     public List<String> getTargetPrincipalIds() {
145         return this.targetPrincipalIds;
146     }
147 
148     @Override
149     public String getRoutingPrincipalId() {
150         return this.routingPrincipalId;
151     }
152 
153     @Override
154     public String getDocumentTypeName() {
155         return this.documentTypeName;
156     }
157 
158     @Override
159     public String getXmlContent() {
160         return this.xmlContent;
161     }
162 
163     @Override
164     public List<String> getRuleTemplateNames() {
165         return this.ruleTemplateNames;
166     }
167 
168     @Override
169     public List<String> getNodeNames() {
170         return this.nodeNames;
171     }
172 
173     @Override
174     public List<RoutingReportActionToTake> getActionsToTake() {
175         return this.actionsToTake;
176     }
177 
178     @Override
179     public boolean isActivateRequests() {
180         return this.activateRequests;
181     }
182 
183     @Override
184     public boolean isFlattenNodes() {
185         return this.flattenNodes;
186     }
187 
188     /**
189      * A builder which can be used to construct {@link RoutingReportCriteria} instances.  Enforces the constraints of
190      * the {@link RoutingReportCriteriaContract}.
191      */
192     public final static class Builder implements Serializable, ModelBuilder, RoutingReportCriteriaContract {
193 
194         private String documentId;
195         private String targetNodeName;
196         private List<String> targetPrincipalIds;
197         private String routingPrincipalId;
198         private String documentTypeName;
199         private String xmlContent;
200         private List<String> ruleTemplateNames;
201         private List<String> nodeNames;
202         private List<RoutingReportActionToTake.Builder> actionsToTake;
203         private boolean activateRequests;
204         private boolean flattenNodes;
205 
206         private Builder(String documentId, String targetNodeName) {
207             this.setDocumentId(documentId);
208             this.setTargetNodeName(targetNodeName);
209         }
210 
211         private Builder(String documentTypeName) {
212             this.setDocumentTypeName(documentTypeName);
213         }
214 
215         public static Builder createByDocumentTypeName(String documentTypeName) {
216             return new Builder(documentTypeName);
217         }
218 
219         public static Builder createByDocumentId(String documentId) {
220             return new Builder(documentId, null);
221         }
222 
223         public static Builder createByDocumentIdAndTargetNodeName(String documentId, String targetNodeName) {
224             return new Builder(documentId, targetNodeName);
225         }
226 
227         public static Builder create(RoutingReportCriteriaContract contract) {
228             if (contract == null) {
229                 throw new IllegalArgumentException("contract was null");
230             }
231             Builder builder =
232                     createByDocumentIdAndTargetNodeName(contract.getDocumentId(), contract.getTargetNodeName());
233             builder.setDocumentId(contract.getDocumentId());
234             builder.setTargetNodeName(contract.getTargetNodeName());
235             builder.setTargetPrincipalIds(contract.getTargetPrincipalIds());
236             builder.setRoutingPrincipalId(contract.getRoutingPrincipalId());
237             builder.setDocumentTypeName(contract.getDocumentTypeName());
238             builder.setXmlContent(contract.getXmlContent());
239             builder.setRuleTemplateNames(contract.getRuleTemplateNames());
240             builder.setNodeNames(contract.getNodeNames());
241             if (contract.getActionsToTake() != null) {
242                 List<RoutingReportActionToTake.Builder> actionsToTake = new ArrayList<RoutingReportActionToTake.Builder>();
243                 for (RoutingReportActionToTakeContract action : contract.getActionsToTake()) {
244                     actionsToTake.add(RoutingReportActionToTake.Builder.create(action));
245                 }
246                 builder.setActionsToTake(actionsToTake);
247             }
248             builder.setActivateRequests(contract.isActivateRequests());
249             builder.setFlattenNodes(contract.isFlattenNodes());
250 
251             return builder;
252         }
253 
254         public RoutingReportCriteria build() {
255             return new RoutingReportCriteria(this);
256         }
257 
258         @Override
259         public String getDocumentId() {
260             return this.documentId;
261         }
262 
263         @Override
264         public String getTargetNodeName() {
265             return this.targetNodeName;
266         }
267 
268         @Override
269         public List<String> getTargetPrincipalIds() {
270             return this.targetPrincipalIds;
271         }
272 
273         @Override
274         public String getRoutingPrincipalId() {
275             return this.routingPrincipalId;
276         }
277 
278         @Override
279         public String getDocumentTypeName() {
280             return this.documentTypeName;
281         }
282 
283         @Override
284         public String getXmlContent() {
285             return this.xmlContent;
286         }
287 
288         @Override
289         public List<String> getRuleTemplateNames() {
290             return this.ruleTemplateNames;
291         }
292 
293         @Override
294         public List<String> getNodeNames() {
295             return this.nodeNames;
296         }
297 
298         @Override
299         public List<RoutingReportActionToTake.Builder> getActionsToTake() {
300             return this.actionsToTake;
301         }
302 
303         @Override
304         public boolean isActivateRequests() {
305             return this.activateRequests;
306         }
307 
308         @Override
309         public boolean isFlattenNodes() {
310             return this.flattenNodes;
311         }
312 
313         public void setDocumentId(String documentId) {
314             // TODO add validation of input value if required and throw IllegalArgumentException if needed
315             this.documentId = documentId;
316         }
317 
318         public void setTargetNodeName(String targetNodeName) {
319             // TODO add validation of input value if required and throw IllegalArgumentException if needed
320             this.targetNodeName = targetNodeName;
321         }
322 
323         public void setTargetPrincipalIds(List<String> targetPrincipalIds) {
324             // TODO add validation of input value if required and throw IllegalArgumentException if needed
325             this.targetPrincipalIds = Collections.unmodifiableList(targetPrincipalIds);
326         }
327 
328         public void setRoutingPrincipalId(String routingPrincipalId) {
329             // TODO add validation of input value if required and throw IllegalArgumentException if needed
330             this.routingPrincipalId = routingPrincipalId;
331         }
332 
333         public void setDocumentTypeName(String documentTypeName) {
334             // TODO add validation of input value if required and throw IllegalArgumentException if needed
335             this.documentTypeName = documentTypeName;
336         }
337 
338         public void setXmlContent(String xmlContent) {
339             // TODO add validation of input value if required and throw IllegalArgumentException if needed
340             this.xmlContent = xmlContent;
341         }
342 
343         public void setRuleTemplateNames(List<String> ruleTemplateNames) {
344             // TODO add validation of input value if required and throw IllegalArgumentException if needed
345             this.ruleTemplateNames = Collections.unmodifiableList(ruleTemplateNames);
346         }
347 
348         public void setNodeNames(List<String> nodeNames) {
349             // TODO add validation of input value if required and throw IllegalArgumentException if needed
350             this.nodeNames = Collections.unmodifiableList(nodeNames);
351         }
352 
353         public void setActionsToTake(List<RoutingReportActionToTake.Builder> actionsToTake) {
354             // TODO add validation of input value if required and throw IllegalArgumentException if needed
355             this.actionsToTake = Collections.unmodifiableList(actionsToTake);
356         }
357 
358         public void setActivateRequests(boolean activateRequests) {
359             // TODO add validation of input value if required and throw IllegalArgumentException if needed
360             this.activateRequests = activateRequests;
361         }
362 
363         public void setFlattenNodes(boolean flattenNodes) {
364             // TODO add validation of input value if required and throw IllegalArgumentException if needed
365             this.flattenNodes = flattenNodes;
366         }
367     }
368 
369     /**
370      * Defines some internal constants used on this class.
371      */
372     static class Constants {
373 
374         final static String ROOT_ELEMENT_NAME = "routingReportCriteria";
375         final static String TYPE_NAME = "RoutingReportCriteriaType";
376     }
377 
378     /**
379      * A private class which exposes constants which define the XML element names to use when this object is marshalled
380      * to XML.
381      */
382     static class Elements {
383 
384         final static String DOCUMENT_ID = "documentId";
385         final static String TARGET_NODE_NAME = "targetNodeName";
386         final static String TARGET_PRINCIPAL_IDS = "targetPrincipalIds";
387         final static String TARGET_PRINCIPAL_ID = "targetPrincipalId";
388         final static String ROUTING_PRINCIPAL_ID = "routingPrincipalId";
389         final static String DOCUMENT_TYPE_NAME = "documentTypeName";
390         final static String XML_CONTENT = "xmlContent";
391         final static String RULE_TEMPLATE_NAMES = "ruleTemplateNames";
392         final static String RULE_TEMPLATE_NAME = "ruleTemplateName";
393         final static String NODE_NAMES = "nodeNames";
394         final static String NODE_NAME = "nodeName";
395         final static String ACTIONS_TO_TAKE = "actionsToTake";
396         final static String ACTION_TO_TAKE = "actionToTake";
397         final static String ACTIVATE_REQUESTS = "activateRequests";
398         final static String FLATTEN_NODES = "flattenNodes";
399     }
400 }