Coverage Report - org.kuali.rice.kew.rule.web.RoutingReportAction
 
Classes in this File Line Coverage Branch Coverage Complexity
RoutingReportAction
0%
0/249
0%
0/124
7.25
RoutingReportAction$RouteReportRuleTemplateContainer
0%
0/6
N/A
7.25
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.rule.web;
 18  
 
 19  
 import java.sql.Timestamp;
 20  
 import java.text.SimpleDateFormat;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Calendar;
 23  
 import java.util.Collections;
 24  
 import java.util.Date;
 25  
 import java.util.HashMap;
 26  
 import java.util.HashSet;
 27  
 import java.util.Iterator;
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 import java.util.Set;
 31  
 
 32  
 import javax.servlet.http.HttpServletRequest;
 33  
 import javax.servlet.http.HttpServletResponse;
 34  
 
 35  
 import org.apache.commons.lang.StringUtils;
 36  
 import org.apache.struts.action.ActionForm;
 37  
 import org.apache.struts.action.ActionForward;
 38  
 import org.apache.struts.action.ActionMapping;
 39  
 import org.apache.struts.action.ActionMessages;
 40  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 41  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 42  
 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
 43  
 import org.kuali.rice.kew.engine.ActivationContext;
 44  
 import org.kuali.rice.kew.engine.RouteContext;
 45  
 import org.kuali.rice.kew.engine.node.RouteNode;
 46  
 import org.kuali.rice.kew.engine.node.RouteNodeInstance;
 47  
 import org.kuali.rice.kew.routeheader.AttributeDocumentContent;
 48  
 import org.kuali.rice.kew.routeheader.DocumentContent;
 49  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 50  
 import org.kuali.rice.kew.routelog.web.RouteLogAction;
 51  
 import org.kuali.rice.kew.routelog.web.RouteLogForm;
 52  
 import org.kuali.rice.kew.rule.FlexRM;
 53  
 import org.kuali.rice.kew.rule.WorkflowAttribute;
 54  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 55  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 56  
 import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute;
 57  
 import org.kuali.rice.kew.rule.service.RuleTemplateService;
 58  
 import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute;
 59  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 60  
 import org.kuali.rice.kew.util.KEWConstants;
 61  
 import org.kuali.rice.kew.util.Utilities;
 62  
 import org.kuali.rice.kew.web.KewKualiAction;
 63  
 import org.kuali.rice.kew.web.session.UserSession;
 64  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 65  
 import org.kuali.rice.kns.exception.ValidationException;
 66  
 import org.kuali.rice.kns.util.GlobalVariables;
 67  
 import org.kuali.rice.kns.web.ui.Field;
 68  
 import org.kuali.rice.kns.web.ui.Row;
 69  
 
 70  
 
 71  
 /**
 72  
  * A Struts Action for executing routing reports and retrieving the results.
 73  
  *
 74  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 75  
  */
 76  0
 public class RoutingReportAction extends KewKualiAction {
 77  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RoutingReportAction.class);
 78  
 
 79  
         public static final String DOC_TYPE_REPORTING = "documentType";
 80  
         public static final String TEMPLATE_REPORTING = "template";
 81  
 
 82  
     @Override
 83  
     public ActionForward execute(ActionMapping mapping, ActionForm form,
 84  
             HttpServletRequest request, HttpServletResponse response)
 85  
             throws Exception {
 86  0
         this.initiateForm(request, form);
 87  0
         RoutingReportForm routingForm = (RoutingReportForm)form;
 88  0
         if (Utilities.isEmpty(routingForm.getDateRef())) {
 89  0
             SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
 90  0
             routingForm.setEffectiveHour("5");
 91  0
             routingForm.setEffectiveMinute("0");
 92  0
             routingForm.setAmPm("1");
 93  0
             routingForm.setDateRef(sdf.format(new Date()));
 94  0
             routingForm.setReportType(TEMPLATE_REPORTING);
 95  
         }
 96  0
         if (DOC_TYPE_REPORTING.equals(routingForm.getReportType())) {
 97  0
             if (Utilities.isEmpty(routingForm.getDocumentTypeParam())) {
 98  0
                 throw new RuntimeException("No document type was given");
 99  
             }
 100  0
             if (Utilities.isEmpty(routingForm.getInitiatorPrincipalId())) {
 101  0
                 throw new RuntimeException("No initiator principal id was given");
 102  
             }
 103  0
             if (Utilities.isEmpty(routingForm.getDocumentContent())) {
 104  0
                 throw new RuntimeException("No document content was given");
 105  
             }
 106  0
         } else if (!(TEMPLATE_REPORTING.equals(routingForm.getReportType()))) {
 107  
             // report type is not Document Type or Template Type... error out
 108  0
             throw new RuntimeException("The Routing Report type is not set");
 109  
         }
 110  0
         return super.execute(mapping, form, request, response);
 111  
     }
 112  
 
 113  
         public ActionForward calculateRoute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 114  0
                 RoutingReportForm routingForm = (RoutingReportForm) form;
 115  
 
 116  0
                 List errors = new ArrayList();
 117  
 
 118  0
                 if (getDocumentTypeService().findByName(routingForm.getDocumentType()) == null) {
 119  0
                     GlobalVariables.getMessageMap().putError("Document type is required.", "doctype.documenttypeservice.doctypename.required");
 120  
                 }
 121  0
                 Timestamp date = null;
 122  0
                 if (!Utilities.isEmpty(routingForm.getDateRef())) {
 123  0
                         SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
 124  
                         try {
 125  0
                                 Calendar calendar = Calendar.getInstance();
 126  0
                                 calendar.setTime(sdf.parse(routingForm.getDateRef()));
 127  0
                                 calendar.set(Calendar.HOUR, Integer.parseInt(routingForm.getEffectiveHour()));
 128  0
                                 calendar.set(Calendar.MINUTE, Integer.parseInt(routingForm.getEffectiveMinute()));
 129  0
                                 calendar.set(Calendar.AM_PM, Integer.parseInt(routingForm.getAmPm()));
 130  0
                                 date = new Timestamp(calendar.getTimeInMillis());
 131  0
                         } catch (Exception e) {
 132  0
                                 LOG.error("error parsing date", e);
 133  0
                                 GlobalVariables.getMessageMap().putError("Invalid date.", "routereport.effectiveDate.invalid");
 134  0
                         }
 135  
                 }
 136  
 
 137  0
                 if (!GlobalVariables.getMessageMap().isEmpty()) {
 138  0
             throw new ValidationException("Errors populating rule attributes.");
 139  
         }
 140  
 
 141  0
                 DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
 142  0
                 DocumentType docType = documentTypeService.findByName(routingForm.getDocumentType());
 143  
 
 144  0
                 DocumentRouteHeaderValue routeHeader = new DocumentRouteHeaderValue();
 145  0
                 routeHeader.setRouteHeaderId(new Long(0));
 146  0
                 routeHeader.setDocumentTypeId(docType.getDocumentTypeId());
 147  0
                 routeHeader.setDocRouteLevel(new Integer(0));
 148  0
         routeHeader.setDocVersion(new Integer(KEWConstants.CURRENT_DOCUMENT_VERSION));
 149  
 
 150  0
         List<RouteReportRuleTemplateContainer> ruleTemplateContainers = new ArrayList<RouteReportRuleTemplateContainer>();
 151  0
                 if (routingForm.getReportType().equals(DOC_TYPE_REPORTING)) {
 152  
 
 153  0
           List routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(docType, true);
 154  0
                         for (Iterator iter = routeNodes.iterator(); iter.hasNext();) {
 155  0
                 RouteNode routeNode = (RouteNode) iter.next();
 156  0
                                 if (routeNode.isFlexRM()) {
 157  0
                                         RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateName(routeNode.getRouteMethodName());
 158  0
                                         if (ruleTemplate != null) {
 159  0
                                             ruleTemplateContainers.add(new RouteReportRuleTemplateContainer(ruleTemplate, routeNode));
 160  0
                                                 if (ruleTemplate.getDelegationTemplate() != null) {
 161  0
                                                     ruleTemplateContainers.add(new RouteReportRuleTemplateContainer(ruleTemplate.getDelegationTemplate(), routeNode));
 162  
                                                 }
 163  
                                         }
 164  
                                 }
 165  0
                         }
 166  0
                 } else {
 167  0
                         RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(routingForm.getRuleTemplateId());
 168  0
                         RouteNode routeNode = new RouteNode();
 169  0
                         routeNode.setRouteNodeName(ruleTemplate.getName());
 170  0
                         ruleTemplateContainers.add(new RouteReportRuleTemplateContainer(ruleTemplate, routeNode));
 171  0
                         if (ruleTemplate.getDelegationTemplate() != null) {
 172  0
                             ruleTemplateContainers.add(new RouteReportRuleTemplateContainer(ruleTemplate.getDelegationTemplate(), routeNode));
 173  
                         }
 174  
                 }
 175  
 
 176  0
         String xmlDocumentContent = routingForm.getDocumentContent();
 177  0
         if (routingForm.getReportType().equals(TEMPLATE_REPORTING)) {
 178  0
             List attributes = new ArrayList();
 179  0
             for (Iterator iterator = ruleTemplateContainers.iterator(); iterator.hasNext();) {
 180  0
                 RouteReportRuleTemplateContainer ruleTemplateContainer = (RouteReportRuleTemplateContainer) iterator.next();
 181  0
                 RuleTemplate ruleTemplate = ruleTemplateContainer.ruleTemplate;
 182  0
                 for (Iterator iter = ruleTemplate.getActiveRuleTemplateAttributes().iterator(); iter.hasNext();) {
 183  0
                     RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next();
 184  0
                     if (!ruleTemplateAttribute.isWorkflowAttribute()) {
 185  0
                         continue;
 186  
                     }
 187  0
                     WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute();
 188  
 
 189  0
                     RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
 190  0
                     if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 191  0
                         ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute);
 192  
                     }
 193  0
                     List attValidationErrors = workflowAttribute.validateRoutingData(routingForm.getFields());
 194  0
                     if (attValidationErrors != null && !attValidationErrors.isEmpty()) {
 195  0
                         errors.addAll(attValidationErrors);
 196  
                     }
 197  0
                     attributes.add(workflowAttribute);
 198  0
                 }
 199  0
             }
 200  
 
 201  0
             if (!GlobalVariables.getMessageMap().isEmpty()) {
 202  0
                 throw new ValidationException("errors in search criteria");
 203  
             }
 204  
 
 205  0
             DocumentContent docContent = new AttributeDocumentContent(attributes);
 206  0
             xmlDocumentContent = docContent.getDocContent();
 207  
         }
 208  
 
 209  0
                 routeHeader.setDocContent(xmlDocumentContent);
 210  0
                 routeHeader.setInitiatorWorkflowId(getUserSession(request).getPrincipalId());
 211  0
                 routeHeader.setDocRouteStatus(KEWConstants.ROUTE_HEADER_INITIATED_CD);
 212  0
                 routeHeader.setDocTitle("Routing Report");
 213  0
                 routeHeader.setRoutingReport(true);
 214  0
                 long magicCounter = 0;
 215  
 
 216  0
                 FlexRM flexRM = new FlexRM(date);
 217  
 
 218  0
                 int numberOfRules = 0;
 219  0
                 int numberOfActionRequests = 0;
 220  0
                 Set<String> alreadyProcessedRuleTemplateNames = new HashSet<String>();
 221  0
                 for (Iterator iterator = ruleTemplateContainers.iterator(); iterator.hasNext();) {
 222  
                         // initialize the RouteContext
 223  0
                     RouteContext context = RouteContext.createNewRouteContext();
 224  0
                 context.setActivationContext(new ActivationContext(ActivationContext.CONTEXT_IS_SIMULATION));
 225  
                         try {
 226  0
                             RouteReportRuleTemplateContainer ruleTemplateContainer = (RouteReportRuleTemplateContainer) iterator.next();
 227  0
                                 RuleTemplate ruleTemplate = ruleTemplateContainer.ruleTemplate;
 228  0
                                 RouteNode routeLevel = ruleTemplateContainer.routeNode;
 229  
 
 230  0
                                 if (!alreadyProcessedRuleTemplateNames.contains(ruleTemplate.getName())) {
 231  0
                                     alreadyProcessedRuleTemplateNames.add(ruleTemplate.getName());
 232  0
                                     List actionRequests = flexRM.getActionRequests(routeHeader, routeLevel, null, ruleTemplate.getName());
 233  
 
 234  0
                                     numberOfActionRequests += actionRequests.size();
 235  0
                                     numberOfRules += flexRM.getNumberOfMatchingRules();
 236  
 
 237  0
                                     magicCounter = populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(routeLevel, actionRequests, magicCounter);
 238  0
                                     routeHeader.getActionRequests().addAll(actionRequests);
 239  
                                 }
 240  0
                         } finally {
 241  0
                                 RouteContext.clearCurrentRouteContext();
 242  0
                         }
 243  0
                 }
 244  
 
 245  0
                 if (numberOfActionRequests == 0) {
 246  0
                         if (numberOfRules == 0) {
 247  0
                             GlobalVariables.getMessageMap().putError("*", "routereport.noRules");
 248  
                         } else {
 249  0
                             GlobalVariables.getMessageMap().putError("*", "routereport.noMatchingRules");
 250  
                         }
 251  0
                         if (GlobalVariables.getMessageMap().hasErrors()) {
 252  0
                     throw new ValidationException("errors in search criteria");
 253  
                 }
 254  
                 }
 255  
 
 256  
 
 257  
                 // PROBLEM HERE!!!!
 258  0
                 RouteLogForm routeLogForm = new RouteLogForm();
 259  0
                 routeLogForm.setShowFuture(true);
 260  0
         if (StringUtils.isNotBlank(routingForm.getBackUrl())) {
 261  0
             routeLogForm.setReturnUrlLocation(routingForm.getBackUrl());
 262  
         }
 263  0
         LOG.debug("Value of getDisplayCloseButton " + routingForm.getShowCloseButton());
 264  0
         LOG.debug("Value of isDisplayCloseButton " + routingForm.isDisplayCloseButton());
 265  0
         routeLogForm.setShowCloseButton(routingForm.isDisplayCloseButton());
 266  0
                 request.setAttribute("routeHeader", routeHeader);
 267  0
                 new RouteLogAction().populateRouteLogFormActionRequests(routeLogForm, routeHeader);
 268  0
                 request.setAttribute("KualiForm", routeLogForm);
 269  
                 //END PROBLEM AREA
 270  
 
 271  
                 //return mapping.findForward("basic");
 272  0
                 return mapping.findForward("routeLog");
 273  
         }
 274  
 
 275  0
         private class RouteReportRuleTemplateContainer {
 276  0
             public RuleTemplate ruleTemplate = null;
 277  0
             public RouteNode routeNode = null;
 278  0
             public RouteReportRuleTemplateContainer(RuleTemplate template, RouteNode node) {
 279  0
                 this.ruleTemplate = template;
 280  0
                 this.routeNode = node;
 281  0
             }
 282  
         }
 283  
 
 284  
         public long populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(RouteNode routeLevel, List actionRequests, long magicCounter) {
 285  
 
 286  0
                 for (Iterator iter = actionRequests.iterator(); iter.hasNext();) {
 287  0
                         ActionRequestValue actionRequest = (ActionRequestValue) iter.next();
 288  0
                         populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(routeLevel, actionRequest.getChildrenRequests(), magicCounter);
 289  0
                         actionRequest.setStatus(KEWConstants.ACTION_REQUEST_INITIALIZED);
 290  
 //                        actionRequest.setRouteMethodName(routeLevel.getRouteMethodName());
 291  0
                         RouteNodeInstance routeNode = new RouteNodeInstance();
 292  0
                         routeNode.setRouteNode(routeLevel);
 293  0
                         actionRequest.setNodeInstance(routeNode);
 294  0
                         actionRequest.setRouteLevel(new Integer(0));
 295  0
                         magicCounter++;
 296  0
                         actionRequest.setActionRequestId(new Long(magicCounter));
 297  0
                 }
 298  0
                 return magicCounter;
 299  
         }
 300  
 
 301  
         public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 302  0
             return mapping.findForward("basic");
 303  
         }
 304  
 
 305  
         private ActionMessages initiateForm(HttpServletRequest request, ActionForm form) throws Exception {
 306  0
         RoutingReportForm routingReportForm = (RoutingReportForm) form;
 307  0
         if (routingReportForm.getReportType() == null) {
 308  
             // no report type means we must check for potential setup
 309  0
             if ( (!Utilities.isEmpty(routingReportForm.getDocumentTypeParam())) ||
 310  
                  (!Utilities.isEmpty(routingReportForm.getInitiatorPrincipalId())) ||
 311  
                  (!Utilities.isEmpty(routingReportForm.getDocumentContent())) ) {
 312  
                 // at least one parameter was passed... attempt to use Doc Type Report
 313  0
                 routingReportForm.setReportType(DOC_TYPE_REPORTING);
 314  
             } else {
 315  
                 // no parameters passed... default to Template Type Rreport
 316  0
                 routingReportForm.setReportType(TEMPLATE_REPORTING);
 317  
             }
 318  
         }
 319  
 
 320  0
         if (routingReportForm.getReportType().equals(DOC_TYPE_REPORTING)) {
 321  0
             if (Utilities.isEmpty(routingReportForm.getDocumentTypeParam())) {
 322  0
                 throw new RuntimeException("Document Type was not given");
 323  
             } else {
 324  0
                 DocumentType docType = getDocumentTypeService().findByName(routingReportForm.getDocumentTypeParam());
 325  0
                 if (docType == null) {
 326  0
                     throw new RuntimeException("Document Type is invalid");
 327  
                 }
 328  
             }
 329  0
             if (Utilities.isEmpty(routingReportForm.getInitiatorPrincipalId())) {
 330  0
                 throw new RuntimeException("Initiator Principal ID was not given");
 331  
             } else {
 332  0
                 KimPrincipal initiatorPrincipal = KEWServiceLocator.getIdentityHelperService().getPrincipal(routingReportForm.getInitiatorPrincipalId());
 333  
             }
 334  0
             if (Utilities.isEmpty(routingReportForm.getDocumentContent())) {
 335  0
                 throw new RuntimeException("Document Content was not given");
 336  
             }
 337  
 
 338  0
             if (!Utilities.isEmpty(routingReportForm.getDocumentType())) {
 339  0
                 DocumentType docType = getDocumentTypeService().findByName(routingReportForm.getDocumentType());
 340  0
                 if (docType == null) {
 341  0
                     throw new RuntimeException("Document Type is missing or invalid");
 342  
                 }
 343  0
                 routingReportForm.getRuleTemplateAttributes().clear();
 344  0
                 List routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(docType, true);
 345  0
                 for (Iterator iter = routeNodes.iterator(); iter.hasNext();) {
 346  0
                     RouteNode routeNode = (RouteNode) iter.next();
 347  0
                     if (routeNode.isFlexRM()) {
 348  0
                         RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateName(routeNode.getRouteMethodName());
 349  0
                         if (ruleTemplate != null) {
 350  0
                             loadRuleTemplateOnForm(ruleTemplate, routingReportForm, request, false);
 351  0
                             if (ruleTemplate.getDelegationTemplate() != null) {
 352  0
                                 loadRuleTemplateOnForm(ruleTemplate.getDelegationTemplate(), routingReportForm, request, true);
 353  
                             }
 354  
                         }
 355  
                     }
 356  0
                 }
 357  0
             }
 358  
 //          routingReportForm.setShowFields(true);
 359  0
         } else if (routingReportForm.getReportType().equals(TEMPLATE_REPORTING)) {
 360  0
             routingReportForm.setRuleTemplates(getRuleTemplateService().findAll());
 361  0
             if (routingReportForm.getRuleTemplateId() != null) {
 362  0
                 RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(routingReportForm.getRuleTemplateId());
 363  0
                 routingReportForm.getRuleTemplateAttributes().clear();
 364  0
                 loadRuleTemplateOnForm(ruleTemplate, routingReportForm, request, false);
 365  0
                 if (ruleTemplate.getDelegationTemplate() != null) {
 366  0
                     loadRuleTemplateOnForm(ruleTemplate.getDelegationTemplate(), routingReportForm, request, true);
 367  
                 }
 368  
             }
 369  
         }
 370  0
         return null;
 371  
         }
 372  
 
 373  
         private void loadRuleTemplateOnForm(RuleTemplate ruleTemplate, RoutingReportForm routingReportForm, HttpServletRequest request, boolean isDelegate) {
 374  
 
 375  0
                 Map fieldValues = new HashMap();
 376  
 
 377  0
                 List ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes();
 378  0
                 Collections.sort(ruleTemplateAttributes);
 379  
 
 380  0
                 List rows = new ArrayList();
 381  0
                 for (Iterator iter = ruleTemplateAttributes.iterator(); iter.hasNext();) {
 382  0
                         RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next();
 383  0
                         if (!ruleTemplateAttribute.isWorkflowAttribute()) {
 384  0
                                 continue;
 385  
                         }
 386  0
                         WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute();
 387  
 
 388  0
                         RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute();
 389  0
                         if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) {
 390  0
                                 ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute);
 391  
                         }
 392  0
                         for (Iterator iterator = workflowAttribute.getRoutingDataRows().iterator(); iterator.hasNext();) {
 393  0
                                 Row row = (Row) iterator.next();
 394  
 
 395  0
                                 List fields = new ArrayList();
 396  0
                                 for (Iterator iterator2 = row.getFields().iterator(); iterator2.hasNext();) {
 397  0
                                         Field field = (Field) iterator2.next();
 398  0
                                         if (request.getParameter(field.getPropertyName()) != null) {
 399  0
                                                 field.setPropertyValue(request.getParameter(field.getPropertyName()));
 400  0
                                         } else if (routingReportForm.getFields() != null && !routingReportForm.getFields().isEmpty()) {
 401  0
                                                 field.setPropertyValue((String) routingReportForm.getFields().get(field.getPropertyName()));
 402  
                                         }
 403  0
                                         fields.add(field);
 404  0
                                         fieldValues.put(field.getPropertyName(), field.getPropertyValue());
 405  0
                                 }
 406  0
                         }
 407  
 
 408  0
                         workflowAttribute.validateRuleData(fieldValues);// populate attribute
 409  0
                         List<Row> rdRows = workflowAttribute.getRoutingDataRows();
 410  0
                         for (Row row : rdRows)
 411  
                         {
 412  0
                                 List fields = new ArrayList();
 413  0
                                 List<Field> rowFields = row.getFields();
 414  0
                                 for (Field field : rowFields )
 415  
                                 {
 416  0
                                         if (request.getParameter(field.getPropertyName()) != null) {
 417  0
                                                 field.setPropertyValue(request.getParameter(field.getPropertyName()));
 418  0
                                         } else if (routingReportForm.getFields() != null && !routingReportForm.getFields().isEmpty()) {
 419  0
                                                 field.setPropertyValue((String) routingReportForm.getFields().get(field.getPropertyName()));
 420  
                                         }
 421  0
                                         fields.add(field);
 422  0
                                         fieldValues.put(field.getPropertyName(), field.getPropertyValue());
 423  
                                 }
 424  0
                                 row.setFields(fields);
 425  0
                                 rows.add(row);
 426  
 
 427  0
                         }
 428  0
                 }
 429  
 
 430  0
                 routingReportForm.getFields().putAll(fieldValues);
 431  0
                 routingReportForm.getRuleTemplateAttributes().addAll(rows);
 432  0
                 routingReportForm.setShowFields(true);
 433  0
                 routingReportForm.setShowViewResults(true);
 434  0
         }
 435  
 
 436  
         public ActionForward loadTemplate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 437  0
                 RoutingReportForm routingReportForm = (RoutingReportForm) form;
 438  0
                 if (Utilities.isEmpty(routingReportForm.getDateRef())) {
 439  0
                         SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
 440  0
                         routingReportForm.setEffectiveHour("5");
 441  0
                         routingReportForm.setEffectiveMinute("0");
 442  0
                         routingReportForm.setAmPm("1");
 443  0
                         routingReportForm.setDateRef(sdf.format(new Date()));
 444  
                 }
 445  0
                 return mapping.findForward("basic");
 446  
         }
 447  
 
 448  
         private void makeLookupPathParam(ActionMapping mapping, HttpServletRequest request) {
 449  0
         String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix();
 450  0
         request.setAttribute("basePath", basePath);
 451  0
     }
 452  
 
 453  
         private RuleTemplateService getRuleTemplateService() {
 454  0
                 return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
 455  
         }
 456  
 
 457  
         private DocumentTypeService getDocumentTypeService() {
 458  0
                 return (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
 459  
         }
 460  
 
 461  
         private UserSession getUserSession(HttpServletRequest request) {
 462  0
             return UserSession.getAuthenticatedUser();
 463  
         }
 464  
 
 465  
 
 466  
 
 467  
 
 468  
 }