| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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.api.KewApiConstants; |
| 42 | |
import org.kuali.rice.kew.api.action.ActionRequestStatus; |
| 43 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 44 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
| 45 | |
import org.kuali.rice.kew.engine.ActivationContext; |
| 46 | |
import org.kuali.rice.kew.engine.RouteContext; |
| 47 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
| 48 | |
import org.kuali.rice.kew.engine.node.RouteNodeInstance; |
| 49 | |
import org.kuali.rice.kew.routeheader.AttributeDocumentContent; |
| 50 | |
import org.kuali.rice.kew.routeheader.DocumentContent; |
| 51 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 52 | |
import org.kuali.rice.kew.routelog.web.RouteLogAction; |
| 53 | |
import org.kuali.rice.kew.routelog.web.RouteLogForm; |
| 54 | |
import org.kuali.rice.kew.rule.FlexRM; |
| 55 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
| 56 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
| 57 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
| 58 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute; |
| 59 | |
import org.kuali.rice.kew.rule.service.RuleTemplateService; |
| 60 | |
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
| 61 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 62 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 63 | |
import org.kuali.rice.kew.web.KewKualiAction; |
| 64 | |
import org.kuali.rice.kns.web.ui.Field; |
| 65 | |
import org.kuali.rice.kns.web.ui.Row; |
| 66 | |
import org.kuali.rice.krad.UserSession; |
| 67 | |
import org.kuali.rice.krad.exception.ValidationException; |
| 68 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 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 (org.apache.commons.lang.StringUtils.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 (org.apache.commons.lang.StringUtils.isEmpty(routingForm.getDocumentTypeParam())) { |
| 98 | 0 | throw new RuntimeException("No document type was given"); |
| 99 | |
} |
| 100 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(routingForm.getInitiatorPrincipalId())) { |
| 101 | 0 | throw new RuntimeException("No initiator principal id was given"); |
| 102 | |
} |
| 103 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(routingForm.getDocumentContent())) { |
| 104 | 0 | throw new RuntimeException("No document content was given"); |
| 105 | |
} |
| 106 | 0 | } else if (!(TEMPLATE_REPORTING.equals(routingForm.getReportType()))) { |
| 107 | |
|
| 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 (!org.apache.commons.lang.StringUtils.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().hasNoErrors()) { |
| 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.setDocumentId(""); |
| 146 | 0 | routeHeader.setDocumentTypeId(docType.getDocumentTypeId()); |
| 147 | 0 | routeHeader.setDocRouteLevel(new Integer(0)); |
| 148 | 0 | routeHeader.setDocVersion(new Integer(KewApiConstants.DocumentContentVersions.CURRENT)); |
| 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 (Object element : ruleTemplateContainers) { |
| 180 | 0 | RouteReportRuleTemplateContainer ruleTemplateContainer = (RouteReportRuleTemplateContainer) element; |
| 181 | 0 | RuleTemplate ruleTemplate = ruleTemplateContainer.ruleTemplate; |
| 182 | 0 | for (Object element2 : ruleTemplate.getActiveRuleTemplateAttributes()) { |
| 183 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) element2; |
| 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().hasNoErrors()) { |
| 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 (Object element : ruleTemplateContainers) { |
| 222 | |
|
| 223 | 0 | RouteContext context = RouteContext.createNewRouteContext(); |
| 224 | 0 | context.setActivationContext(new ActivationContext(ActivationContext.CONTEXT_IS_SIMULATION)); |
| 225 | |
try { |
| 226 | 0 | RouteReportRuleTemplateContainer ruleTemplateContainer = (RouteReportRuleTemplateContainer) element; |
| 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 | |
|
| 239 | 0 | routeHeader.getSimulatedActionRequests().addAll(actionRequests); |
| 240 | |
} |
| 241 | |
} finally { |
| 242 | 0 | RouteContext.clearCurrentRouteContext(); |
| 243 | 0 | } |
| 244 | 0 | } |
| 245 | |
|
| 246 | 0 | if (numberOfActionRequests == 0) { |
| 247 | 0 | if (numberOfRules == 0) { |
| 248 | 0 | GlobalVariables.getMessageMap().putError("*", "routereport.noRules"); |
| 249 | |
} else { |
| 250 | 0 | GlobalVariables.getMessageMap().putError("*", "routereport.noMatchingRules"); |
| 251 | |
} |
| 252 | 0 | if (GlobalVariables.getMessageMap().hasErrors()) { |
| 253 | 0 | throw new ValidationException("errors in search criteria"); |
| 254 | |
} |
| 255 | |
} |
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | 0 | RouteLogForm routeLogForm = new RouteLogForm(); |
| 260 | 0 | routeLogForm.setShowFuture(true); |
| 261 | 0 | if (StringUtils.isNotBlank(routingForm.getBackUrl())) { |
| 262 | 0 | routeLogForm.setReturnUrlLocation(routingForm.getBackUrl()); |
| 263 | |
} |
| 264 | 0 | LOG.debug("Value of getDisplayCloseButton " + routingForm.getShowCloseButton()); |
| 265 | 0 | LOG.debug("Value of isDisplayCloseButton " + routingForm.isDisplayCloseButton()); |
| 266 | 0 | routeLogForm.setShowCloseButton(routingForm.isDisplayCloseButton()); |
| 267 | 0 | request.setAttribute("routeHeader", routeHeader); |
| 268 | 0 | new RouteLogAction().populateRouteLogFormActionRequests(routeLogForm, routeHeader); |
| 269 | 0 | request.setAttribute("KualiForm", routeLogForm); |
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | 0 | return mapping.findForward("routeLog"); |
| 274 | |
} |
| 275 | |
|
| 276 | 0 | private class RouteReportRuleTemplateContainer { |
| 277 | 0 | public RuleTemplate ruleTemplate = null; |
| 278 | 0 | public RouteNode routeNode = null; |
| 279 | 0 | public RouteReportRuleTemplateContainer(RuleTemplate template, RouteNode node) { |
| 280 | 0 | this.ruleTemplate = template; |
| 281 | 0 | this.routeNode = node; |
| 282 | 0 | } |
| 283 | |
} |
| 284 | |
|
| 285 | |
public long populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(RouteNode routeLevel, List actionRequests, long magicCounter) { |
| 286 | |
|
| 287 | 0 | for (Iterator iter = actionRequests.iterator(); iter.hasNext();) { |
| 288 | 0 | ActionRequestValue actionRequest = (ActionRequestValue) iter.next(); |
| 289 | 0 | populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(routeLevel, actionRequest.getChildrenRequests(), magicCounter); |
| 290 | 0 | actionRequest.setStatus(ActionRequestStatus.INITIALIZED.getCode()); |
| 291 | |
|
| 292 | 0 | RouteNodeInstance routeNode = new RouteNodeInstance(); |
| 293 | 0 | routeNode.setRouteNode(routeLevel); |
| 294 | 0 | actionRequest.setNodeInstance(routeNode); |
| 295 | 0 | actionRequest.setRouteLevel(new Integer(0)); |
| 296 | 0 | magicCounter++; |
| 297 | 0 | actionRequest.setActionRequestId(String.valueOf(magicCounter)); |
| 298 | 0 | } |
| 299 | 0 | return magicCounter; |
| 300 | |
} |
| 301 | |
|
| 302 | |
@Override |
| 303 | |
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 304 | 0 | return mapping.findForward("basic"); |
| 305 | |
} |
| 306 | |
|
| 307 | |
private ActionMessages initiateForm(HttpServletRequest request, ActionForm form) throws Exception { |
| 308 | 0 | RoutingReportForm routingReportForm = (RoutingReportForm) form; |
| 309 | 0 | if (routingReportForm.getReportType() == null) { |
| 310 | |
|
| 311 | 0 | if ( (!org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getDocumentTypeParam())) || |
| 312 | |
(!org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getInitiatorPrincipalId())) || |
| 313 | |
(!org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getDocumentContent())) ) { |
| 314 | |
|
| 315 | 0 | routingReportForm.setReportType(DOC_TYPE_REPORTING); |
| 316 | |
} else { |
| 317 | |
|
| 318 | 0 | routingReportForm.setReportType(TEMPLATE_REPORTING); |
| 319 | |
} |
| 320 | |
} |
| 321 | |
|
| 322 | 0 | if (routingReportForm.getReportType().equals(DOC_TYPE_REPORTING)) { |
| 323 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getDocumentTypeParam())) { |
| 324 | 0 | throw new RuntimeException("Document Type was not given"); |
| 325 | |
} else { |
| 326 | 0 | DocumentType docType = getDocumentTypeService().findByName(routingReportForm.getDocumentTypeParam()); |
| 327 | 0 | if (docType == null) { |
| 328 | 0 | throw new RuntimeException("Document Type is invalid"); |
| 329 | |
} |
| 330 | |
} |
| 331 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getInitiatorPrincipalId())) { |
| 332 | 0 | throw new RuntimeException("Initiator Principal ID was not given"); |
| 333 | |
} else { |
| 334 | 0 | KEWServiceLocator.getIdentityHelperService().getPrincipal(routingReportForm.getInitiatorPrincipalId()); |
| 335 | |
} |
| 336 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getDocumentContent())) { |
| 337 | 0 | throw new RuntimeException("Document Content was not given"); |
| 338 | |
} |
| 339 | |
|
| 340 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getDocumentType())) { |
| 341 | 0 | DocumentType docType = getDocumentTypeService().findByName(routingReportForm.getDocumentType()); |
| 342 | 0 | if (docType == null) { |
| 343 | 0 | throw new RuntimeException("Document Type is missing or invalid"); |
| 344 | |
} |
| 345 | 0 | routingReportForm.getRuleTemplateAttributes().clear(); |
| 346 | 0 | List routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(docType, true); |
| 347 | 0 | for (Iterator iter = routeNodes.iterator(); iter.hasNext();) { |
| 348 | 0 | RouteNode routeNode = (RouteNode) iter.next(); |
| 349 | 0 | if (routeNode.isFlexRM()) { |
| 350 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateName(routeNode.getRouteMethodName()); |
| 351 | 0 | if (ruleTemplate != null) { |
| 352 | 0 | loadRuleTemplateOnForm(ruleTemplate, routingReportForm, request, false); |
| 353 | 0 | if (ruleTemplate.getDelegationTemplate() != null) { |
| 354 | 0 | loadRuleTemplateOnForm(ruleTemplate.getDelegationTemplate(), routingReportForm, request, true); |
| 355 | |
} |
| 356 | |
} |
| 357 | |
} |
| 358 | 0 | } |
| 359 | 0 | } |
| 360 | |
|
| 361 | 0 | } else if (routingReportForm.getReportType().equals(TEMPLATE_REPORTING)) { |
| 362 | 0 | routingReportForm.setRuleTemplates(getRuleTemplateService().findAll()); |
| 363 | 0 | if (routingReportForm.getRuleTemplateId() != null) { |
| 364 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(routingReportForm.getRuleTemplateId()); |
| 365 | 0 | routingReportForm.getRuleTemplateAttributes().clear(); |
| 366 | 0 | loadRuleTemplateOnForm(ruleTemplate, routingReportForm, request, false); |
| 367 | 0 | if (ruleTemplate.getDelegationTemplate() != null) { |
| 368 | 0 | loadRuleTemplateOnForm(ruleTemplate.getDelegationTemplate(), routingReportForm, request, true); |
| 369 | |
} |
| 370 | |
} |
| 371 | |
} |
| 372 | 0 | return null; |
| 373 | |
} |
| 374 | |
|
| 375 | |
private void loadRuleTemplateOnForm(RuleTemplate ruleTemplate, RoutingReportForm routingReportForm, HttpServletRequest request, boolean isDelegate) { |
| 376 | |
|
| 377 | 0 | Map fieldValues = new HashMap(); |
| 378 | |
|
| 379 | 0 | List ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes(); |
| 380 | 0 | Collections.sort(ruleTemplateAttributes); |
| 381 | |
|
| 382 | 0 | List rows = new ArrayList(); |
| 383 | 0 | for (Iterator iter = ruleTemplateAttributes.iterator(); iter.hasNext();) { |
| 384 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next(); |
| 385 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
| 386 | 0 | continue; |
| 387 | |
} |
| 388 | 0 | WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
| 389 | |
|
| 390 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
| 391 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
| 392 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute); |
| 393 | |
} |
| 394 | 0 | for (Object element : workflowAttribute.getRoutingDataRows()) { |
| 395 | 0 | Row row = (Row) element; |
| 396 | |
|
| 397 | 0 | List fields = new ArrayList(); |
| 398 | 0 | for (Object element2 : row.getFields()) { |
| 399 | 0 | Field field = (Field) element2; |
| 400 | 0 | if (request.getParameter(field.getPropertyName()) != null) { |
| 401 | 0 | field.setPropertyValue(request.getParameter(field.getPropertyName())); |
| 402 | 0 | } else if (routingReportForm.getFields() != null && !routingReportForm.getFields().isEmpty()) { |
| 403 | 0 | field.setPropertyValue((String) routingReportForm.getFields().get(field.getPropertyName())); |
| 404 | |
} |
| 405 | 0 | fields.add(field); |
| 406 | 0 | fieldValues.put(field.getPropertyName(), field.getPropertyValue()); |
| 407 | 0 | } |
| 408 | 0 | } |
| 409 | |
|
| 410 | 0 | workflowAttribute.validateRuleData(fieldValues); |
| 411 | 0 | List<Row> rdRows = workflowAttribute.getRoutingDataRows(); |
| 412 | 0 | for (Row row : rdRows) |
| 413 | |
{ |
| 414 | 0 | List fields = new ArrayList(); |
| 415 | 0 | List<Field> rowFields = row.getFields(); |
| 416 | 0 | for (Field field : rowFields ) |
| 417 | |
{ |
| 418 | 0 | if (request.getParameter(field.getPropertyName()) != null) { |
| 419 | 0 | field.setPropertyValue(request.getParameter(field.getPropertyName())); |
| 420 | 0 | } else if (routingReportForm.getFields() != null && !routingReportForm.getFields().isEmpty()) { |
| 421 | 0 | field.setPropertyValue((String) routingReportForm.getFields().get(field.getPropertyName())); |
| 422 | |
} |
| 423 | 0 | fields.add(field); |
| 424 | 0 | fieldValues.put(field.getPropertyName(), field.getPropertyValue()); |
| 425 | |
} |
| 426 | 0 | row.setFields(fields); |
| 427 | 0 | rows.add(row); |
| 428 | |
|
| 429 | 0 | } |
| 430 | 0 | } |
| 431 | |
|
| 432 | 0 | routingReportForm.getFields().putAll(fieldValues); |
| 433 | 0 | routingReportForm.getRuleTemplateAttributes().addAll(rows); |
| 434 | 0 | routingReportForm.setShowFields(true); |
| 435 | 0 | routingReportForm.setShowViewResults(true); |
| 436 | 0 | } |
| 437 | |
|
| 438 | |
public ActionForward loadTemplate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 439 | 0 | RoutingReportForm routingReportForm = (RoutingReportForm) form; |
| 440 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(routingReportForm.getDateRef())) { |
| 441 | 0 | SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); |
| 442 | 0 | routingReportForm.setEffectiveHour("5"); |
| 443 | 0 | routingReportForm.setEffectiveMinute("0"); |
| 444 | 0 | routingReportForm.setAmPm("1"); |
| 445 | 0 | routingReportForm.setDateRef(sdf.format(new Date())); |
| 446 | |
} |
| 447 | 0 | return mapping.findForward("basic"); |
| 448 | |
} |
| 449 | |
|
| 450 | |
private RuleTemplateService getRuleTemplateService() { |
| 451 | 0 | return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE); |
| 452 | |
} |
| 453 | |
|
| 454 | |
private DocumentTypeService getDocumentTypeService() { |
| 455 | 0 | return (DocumentTypeService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE); |
| 456 | |
} |
| 457 | |
|
| 458 | |
private UserSession getUserSession(HttpServletRequest request) { |
| 459 | 0 | return GlobalVariables.getUserSession(); |
| 460 | |
} |
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
} |