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.rule.web;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.apache.struts.action.ActionErrors;
020    import org.apache.struts.action.ActionMapping;
021    import org.apache.struts.action.ActionMessage;
022    import org.apache.struts.action.ActionMessages;
023    import org.kuali.rice.core.api.util.ConcreteKeyValue;
024    import org.kuali.rice.core.api.util.KeyValue;
025    import org.kuali.rice.kew.doctype.bo.DocumentType;
026    import org.kuali.rice.kew.doctype.service.DocumentTypeService;
027    import org.kuali.rice.kew.service.KEWServiceLocator;
028    import org.kuali.rice.kew.api.KewApiConstants;
029    import org.kuali.rice.kns.web.struts.form.KualiForm;
030    import org.kuali.rice.kns.web.ui.Row;
031    
032    import javax.servlet.http.HttpServletRequest;
033    import java.util.ArrayList;
034    import java.util.HashMap;
035    import java.util.List;
036    import java.util.Map;
037    
038    
039    /**
040     * Struts ActionForm for the {@link RoutingReportAction}.
041     *
042     * @author Kuali Rice Team (rice.collab@kuali.org)
043     */
044    public class RoutingReportForm extends KualiForm {
045    
046            private static final long serialVersionUID = 509542372934250061L;
047    
048        private String ruleTemplateId;
049        private String lookupableImplServiceName;
050        private String documentType;
051        private String reportType;
052    
053        // fields below used for document type report URL
054        private String documentTypeParam;
055        private String initiatorPrincipalId;
056        private String documentContent;
057        private String backUrl;
058        private String showCloseButton;
059    
060        private String dateRef;
061        private String effectiveHour;
062        private String effectiveMinute;
063        private String amPm;
064    
065        private List ruleTemplates;
066        private List actionRequests;
067        private Map fields;
068    
069        /*chb: 15Jan2009
070        ruleTemplateAttributes is set by RoutingReportAction.loadRuleTemplateOnForm(...)
071        */
072        private List<Row> ruleTemplateAttributes;
073        private List attributes;
074    
075        private boolean showFields;
076        private boolean showViewResults;
077    
078        public RoutingReportForm() {
079            attributes = new ArrayList();
080            ruleTemplates = new ArrayList();
081            actionRequests = new ArrayList();
082            fields = new HashMap();
083            ruleTemplateAttributes = new ArrayList();
084        }
085    
086        @Override
087            public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
088    
089            ActionErrors errors = new ActionErrors();
090            if (getReportType() != null && getReportType().equals(RoutingReportAction.DOC_TYPE_REPORTING)) {
091                if (!org.apache.commons.lang.StringUtils.isEmpty(getDocumentType())) {
092                    DocumentType docType = getDocumentTypeService().findByName(getDocumentType());
093                    if (docType == null) {
094                        ActionMessage error = new ActionMessage("routereport.documenttype.invalid");
095                        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
096                    }
097                }
098            }
099            return errors;
100        }
101    
102        public String getLookupableImplServiceName() {
103            return lookupableImplServiceName;
104        }
105    
106        public void setLookupableImplServiceName(String lookupableImplServiceName) {
107            this.lookupableImplServiceName = lookupableImplServiceName;
108        }
109    
110        public List<Row> getRuleTemplateAttributes() {
111            return ruleTemplateAttributes;
112        }
113    
114        //chb: 15Jan2009 set in RoutingReportAction.loadRuleTemplateOnForm(...)
115        public void setRuleTemplateAttributes(List<Row> ruleTemplateAttributes) {
116            this.ruleTemplateAttributes = ruleTemplateAttributes;
117        }
118    
119        public Map getFields() {
120            return fields;
121        }
122    
123        public void setFields(Map fields) {
124            this.fields = fields;
125        }
126    
127        public List getRuleTemplates() {
128            return ruleTemplates;
129        }
130    
131        public void setRuleTemplates(List ruleTemplates) {
132            this.ruleTemplates = ruleTemplates;
133        }
134    
135        public List<KeyValue> getHours() {
136            List<KeyValue> hours = new ArrayList<KeyValue>();
137            hours.add(new ConcreteKeyValue("0", "12"));
138            for (int i = 1; i < 12; i++) {
139                hours.add(new ConcreteKeyValue(i + "", i + ""));
140            }
141            return hours;
142        }
143        public List<KeyValue> getMinutes() {
144            List<KeyValue> mins = new ArrayList<KeyValue>();
145            for (int i = 0; i < 60; i++) {
146                mins.add(new ConcreteKeyValue(i + "", ":" + (i < 10 ? "0" : "") + i + ""));
147            }
148            return mins;
149        }
150    
151        public String getRuleTemplateId() {
152            return ruleTemplateId;
153        }
154    
155        public void setRuleTemplateId(String ruleTemplateId) {
156            this.ruleTemplateId = ruleTemplateId;
157        }
158    
159        public List getActionRequests() {
160            return actionRequests;
161        }
162    
163        public void setActionRequests(List actionRequests) {
164            this.actionRequests = actionRequests;
165        }
166    
167        public void setDocTypeFullName(String documentType) {
168            this.documentType = documentType;
169        }
170    
171        public void setDocTypeGroupName(String docTypeGroupName) {
172            this.documentType = docTypeGroupName;
173        }
174    
175        public String getDocumentType() {
176            return documentType;
177        }
178    
179        public void setDocumentType(String documentType) {
180            this.documentType = documentType;
181        }
182    
183        public List getAttributes() {
184            return attributes;
185        }
186    
187        public void setAttributes(List attributes) {
188            this.attributes = attributes;
189        }
190    
191        public String getReportType() {
192            return reportType;
193        }
194    
195        public void setReportType(String reportType) {
196            this.reportType = reportType;
197        }
198    
199        public boolean isShowFields() {
200            return showFields;
201        }
202    
203        public void setShowFields(boolean showFields) {
204            this.showFields = showFields;
205        }
206    
207        public boolean isShowViewResults() {
208            return showViewResults;
209        }
210    
211        public void setShowViewResults(boolean showViewResults) {
212            this.showViewResults = showViewResults;
213        }
214    
215        private DocumentTypeService getDocumentTypeService() {
216            return (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
217        }
218    
219        public String getDateRef() {
220            return dateRef;
221        }
222    
223        public void setDateRef(String dateRef) {
224            this.dateRef = dateRef;
225        }
226    
227        public String getEffectiveHour() {
228            return effectiveHour;
229        }
230    
231        public void setEffectiveHour(String effectiveHour) {
232            this.effectiveHour = effectiveHour;
233        }
234    
235        public String getEffectiveMinute() {
236            return effectiveMinute;
237        }
238    
239        public void setEffectiveMinute(String effectiveMinute) {
240            this.effectiveMinute = effectiveMinute;
241        }
242    
243        public String getAmPm() {
244            return amPm;
245        }
246    
247        public void setAmPm(String amPm) {
248            this.amPm = amPm;
249        }
250    
251        public String getDocumentContent() {
252            return documentContent;
253        }
254    
255        public void setDocumentContent(String documentContent) {
256            this.documentContent = documentContent;
257        }
258    
259        public String getInitiatorPrincipalId() {
260            return initiatorPrincipalId;
261        }
262    
263        public void setInitiatorPrincipalId(String initiatorNetworkId) {
264            this.initiatorPrincipalId = initiatorNetworkId;
265        }
266    
267        public String getBackUrl() {
268            if (StringUtils.isBlank(backUrl)) {
269                return null;
270            }
271            return backUrl;
272        }
273    
274        public void setBackUrl(String backUrl) {
275            this.backUrl = backUrl;
276        }
277    
278        public boolean isDisplayCloseButton() {
279            return (KewApiConstants.DISPLAY_CLOSE_BUTTON_TRUE_VALUE.equals(getShowCloseButton()));
280        }
281    
282        public String getShowCloseButton() {
283            return showCloseButton;
284        }
285    
286        public void setShowCloseButton(String showCloseButton) {
287            this.showCloseButton = showCloseButton;
288        }
289    
290        public String getDocumentTypeParam() {
291            return documentTypeParam;
292        }
293    
294        public void setDocumentTypeParam(String documentTypeParam) {
295            this.documentTypeParam = documentTypeParam;
296            this.documentType = documentTypeParam;
297        }
298    
299    }