001    /**
002     * Copyright 2005-2013 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.rule;
017    
018    import org.kuali.rice.core.api.CoreConstants;
019    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
020    import org.kuali.rice.core.api.mo.ModelBuilder;
021    import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
022    import org.w3c.dom.Element;
023    
024    import javax.xml.bind.annotation.XmlAccessType;
025    import javax.xml.bind.annotation.XmlAccessorType;
026    import javax.xml.bind.annotation.XmlAnyElement;
027    import javax.xml.bind.annotation.XmlElement;
028    import javax.xml.bind.annotation.XmlElementWrapper;
029    import javax.xml.bind.annotation.XmlRootElement;
030    import javax.xml.bind.annotation.XmlType;
031    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
032    import java.io.Serializable;
033    import java.util.Collection;
034    import java.util.Collections;
035    import java.util.List;
036    import java.util.Map;
037    
038    @XmlRootElement(name = RuleReportCriteria.Constants.ROOT_ELEMENT_NAME)
039    @XmlAccessorType(XmlAccessType.NONE)
040    @XmlType(name = RuleReportCriteria.Constants.TYPE_NAME, propOrder = {
041        RuleReportCriteria.Elements.RULE_DESCRIPTION,
042        RuleReportCriteria.Elements.DOCUMENT_TYPE_NAME,
043        RuleReportCriteria.Elements.RULE_TEMPLATE_NAME,
044        RuleReportCriteria.Elements.ACTION_REQUEST_CODES,
045        RuleReportCriteria.Elements.RESPONSIBLE_PRINCIPAL_ID,
046        RuleReportCriteria.Elements.RESPONSIBLE_GROUP_ID,
047        RuleReportCriteria.Elements.RESPONSIBLE_ROLE_NAME,
048        RuleReportCriteria.Elements.RULE_EXTENSIONS,
049        RuleReportCriteria.Elements.ACTIVE,
050        RuleReportCriteria.Elements.CONSIDER_GROUP_MEMBERSHIP,
051        RuleReportCriteria.Elements.INCLUDE_DELEGATIONS,
052        CoreConstants.CommonElements.FUTURE_ELEMENTS
053    })
054    public final class RuleReportCriteria
055        extends AbstractDataTransferObject
056        implements RuleReportCriteriaContract
057    {
058    
059        @XmlElement(name = Elements.RULE_DESCRIPTION, required = false)
060        private final String ruleDescription;
061    
062        @XmlElement(name = Elements.DOCUMENT_TYPE_NAME, required = false)
063        private final String documentTypeName;
064    
065        @XmlElement(name = Elements.RULE_TEMPLATE_NAME, required = false)
066        private final String ruleTemplateName;
067    
068        @XmlElementWrapper(name = Elements.ACTION_REQUEST_CODES, required = false)
069        @XmlElement(name = Elements.ACTION_REQUEST_CODE, required = false)
070        private final List<String> actionRequestCodes;
071    
072        @XmlElement(name = Elements.RESPONSIBLE_PRINCIPAL_ID, required = false)
073        private final String responsiblePrincipalId;
074    
075        @XmlElement(name = Elements.RESPONSIBLE_GROUP_ID, required = false)
076        private final String responsibleGroupId;
077    
078        @XmlElement(name = Elements.RESPONSIBLE_ROLE_NAME, required = false)
079        private final String responsibleRoleName;
080    
081        @XmlElement(name = Elements.RULE_EXTENSIONS, required = false)
082        @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
083        private final Map<String, String> ruleExtensions;
084    
085        @XmlElement(name = Elements.ACTIVE, required = false)
086        private final boolean active;
087    
088        @XmlElement(name = Elements.CONSIDER_GROUP_MEMBERSHIP, required = false)
089        private final boolean considerGroupMembership;
090    
091        @XmlElement(name = Elements.INCLUDE_DELEGATIONS, required = false)
092        private final boolean includeDelegations;
093    
094        @SuppressWarnings("unused")
095        @XmlAnyElement
096        private final Collection<Element> _futureElements = null;
097    
098        /**
099         * Private constructor used only by JAXB.
100         *
101         */
102        private RuleReportCriteria() {
103            this.ruleDescription = null;
104            this.documentTypeName = null;
105            this.ruleTemplateName = null;
106            this.actionRequestCodes = null;
107            this.responsiblePrincipalId = null;
108            this.responsibleGroupId = null;
109            this.responsibleRoleName = null;
110            this.ruleExtensions = null;
111            this.active = false;
112            this.considerGroupMembership = false;
113            this.includeDelegations = false;
114        }
115    
116        private RuleReportCriteria(Builder builder) {
117            this.ruleDescription = builder.getRuleDescription();
118            this.documentTypeName = builder.getDocumentTypeName();
119            this.ruleTemplateName = builder.getRuleTemplateName();
120            this.actionRequestCodes = builder.getActionRequestCodes();
121            this.responsiblePrincipalId = builder.getResponsiblePrincipalId();
122            this.responsibleGroupId = builder.getResponsibleGroupId();
123            this.responsibleRoleName = builder.getResponsibleRoleName();
124            this.ruleExtensions = builder.getRuleExtensions();
125            this.active = builder.isActive();
126            this.considerGroupMembership = builder.isConsiderGroupMembership();
127            this.includeDelegations = builder.isIncludeDelegations();
128        }
129    
130        @Override
131        public String getRuleDescription() {
132            return this.ruleDescription;
133        }
134    
135        @Override
136        public String getDocumentTypeName() {
137            return this.documentTypeName;
138        }
139    
140        @Override
141        public String getRuleTemplateName() {
142            return this.ruleTemplateName;
143        }
144    
145        @Override
146        public List<String> getActionRequestCodes() {
147            return this.actionRequestCodes;
148        }
149    
150        @Override
151        public String getResponsiblePrincipalId() {
152            return this.responsiblePrincipalId;
153        }
154    
155        @Override
156        public String getResponsibleGroupId() {
157            return this.responsibleGroupId;
158        }
159    
160        @Override
161        public String getResponsibleRoleName() {
162            return this.responsibleRoleName;
163        }
164    
165        @Override
166        public Map<String, String> getRuleExtensions() {
167            return this.ruleExtensions;
168        }
169    
170        @Override
171        public boolean isActive() {
172            return this.active;
173        }
174    
175        @Override
176        public boolean isConsiderGroupMembership() {
177            return this.considerGroupMembership;
178        }
179    
180        @Override
181        public boolean isIncludeDelegations() {
182            return this.includeDelegations;
183        }
184    
185    
186        /**
187         * A builder which can be used to construct {@link RuleReportCriteria} instances.  Enforces the constraints of the {@link RuleReportCriteriaContract}.
188         *
189         */
190        public final static class Builder
191            implements Serializable, ModelBuilder, RuleReportCriteriaContract
192        {
193    
194            private String ruleDescription;
195            private String documentTypeName;
196            private String ruleTemplateName;
197            private List<String> actionRequestCodes;
198            private String responsiblePrincipalId;
199            private String responsibleGroupId;
200            private String responsibleRoleName;
201            private Map<String, String> ruleExtensions;
202            private boolean active;
203            private boolean considerGroupMembership;
204            private boolean includeDelegations;
205    
206            private Builder() {
207                setActive(true);
208                setConsiderGroupMembership(true);
209            }
210    
211            public static Builder create() {
212                return new Builder();
213            }
214    
215            public static Builder create(RuleReportCriteriaContract contract) {
216                if (contract == null) {
217                    throw new IllegalArgumentException("contract was null");
218                }
219                Builder builder = create();
220                builder.setRuleDescription(contract.getRuleDescription());
221                builder.setDocumentTypeName(contract.getDocumentTypeName());
222                builder.setRuleTemplateName(contract.getRuleTemplateName());
223                builder.setActionRequestCodes(contract.getActionRequestCodes());
224                builder.setResponsiblePrincipalId(contract.getResponsiblePrincipalId());
225                builder.setResponsibleGroupId(contract.getResponsibleGroupId());
226                builder.setResponsibleRoleName(contract.getResponsibleRoleName());
227                builder.setRuleExtensions(contract.getRuleExtensions());
228                builder.setActive(contract.isActive());
229                builder.setConsiderGroupMembership(contract.isConsiderGroupMembership());
230                builder.setIncludeDelegations(contract.isIncludeDelegations());
231                return builder;
232            }
233    
234            public RuleReportCriteria build() {
235                return new RuleReportCriteria(this);
236            }
237    
238            @Override
239            public String getRuleDescription() {
240                return this.ruleDescription;
241            }
242    
243            @Override
244            public String getDocumentTypeName() {
245                return this.documentTypeName;
246            }
247    
248            @Override
249            public String getRuleTemplateName() {
250                return this.ruleTemplateName;
251            }
252    
253            @Override
254            public List<String> getActionRequestCodes() {
255                return this.actionRequestCodes;
256            }
257    
258            @Override
259            public String getResponsiblePrincipalId() {
260                return this.responsiblePrincipalId;
261            }
262    
263            @Override
264            public String getResponsibleGroupId() {
265                return this.responsibleGroupId;
266            }
267    
268            @Override
269            public String getResponsibleRoleName() {
270                return this.responsibleRoleName;
271            }
272    
273            @Override
274            public Map<String, String> getRuleExtensions() {
275                return this.ruleExtensions;
276            }
277    
278            @Override
279            public boolean isActive() {
280                return this.active;
281            }
282    
283            @Override
284            public boolean isConsiderGroupMembership() {
285                return this.considerGroupMembership;
286            }
287    
288            @Override
289            public boolean isIncludeDelegations() {
290                return this.includeDelegations;
291            }
292    
293            public void setRuleDescription(String ruleDescription) {
294    
295                this.ruleDescription = ruleDescription;
296            }
297    
298            public void setDocumentTypeName(String documentTypeName) {
299    
300                this.documentTypeName = documentTypeName;
301            }
302    
303            public void setRuleTemplateName(String ruleTemplateName) {
304    
305                this.ruleTemplateName = ruleTemplateName;
306            }
307    
308            public void setActionRequestCodes(List<String> actionRequestCodes) {
309    
310                this.actionRequestCodes = actionRequestCodes;
311            }
312    
313            public void setResponsiblePrincipalId(String responsiblePrincipalId) {
314    
315                this.responsiblePrincipalId = responsiblePrincipalId;
316            }
317    
318            public void setResponsibleGroupId(String responsibleGroupId) {
319    
320                this.responsibleGroupId = responsibleGroupId;
321            }
322    
323            public void setResponsibleRoleName(String responsibleRoleName) {
324    
325                this.responsibleRoleName = responsibleRoleName;
326            }
327    
328            public void setRuleExtensions(Map<String, String> ruleExtensions) {
329    
330                this.ruleExtensions = Collections.unmodifiableMap(ruleExtensions);
331            }
332    
333            public void setActive(boolean active) {
334    
335                this.active = active;
336            }
337    
338            public void setConsiderGroupMembership(boolean considerGroupMembership) {
339    
340                this.considerGroupMembership = considerGroupMembership;
341            }
342    
343            public void setIncludeDelegations(boolean includeDelegations) {
344    
345                this.includeDelegations = includeDelegations;
346            }
347    
348        }
349    
350    
351        /**
352         * Defines some internal constants used on this class.
353         *
354         */
355        static class Constants {
356    
357            final static String ROOT_ELEMENT_NAME = "ruleReportCriteria";
358            final static String TYPE_NAME = "RuleReportCriteriaType";
359    
360        }
361    
362    
363        /**
364         * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
365         *
366         */
367        static class Elements {
368    
369            final static String RULE_DESCRIPTION = "ruleDescription";
370            final static String DOCUMENT_TYPE_NAME = "documentTypeName";
371            final static String RULE_TEMPLATE_NAME = "ruleTemplateName";
372            final static String ACTION_REQUEST_CODES = "actionRequestCodes";
373            final static String ACTION_REQUEST_CODE = "actionRequestCode";
374            final static String RESPONSIBLE_PRINCIPAL_ID = "responsiblePrincipalId";
375            final static String RESPONSIBLE_GROUP_ID = "responsibleGroupId";
376            final static String RESPONSIBLE_ROLE_NAME = "responsibleRoleName";
377            final static String RULE_EXTENSIONS = "ruleExtensions";
378            final static String ACTIVE = "active";
379            final static String CONSIDER_GROUP_MEMBERSHIP = "considerGroupMembership";
380            final static String INCLUDE_DELEGATIONS = "includeDelegations";
381    
382        }
383    
384    }