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