001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routetemplate.web;
018:
019: import java.sql.Timestamp;
020: import java.text.SimpleDateFormat;
021: import java.util.ArrayList;
022: import java.util.Calendar;
023: import java.util.Collections;
024: import java.util.Date;
025: import java.util.HashMap;
026: import java.util.HashSet;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.Map;
030: import java.util.Set;
031:
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.commons.lang.StringUtils;
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.apache.struts.action.ActionMessages;
040:
041: import edu.iu.uis.eden.EdenConstants;
042: import edu.iu.uis.eden.KEWServiceLocator;
043: import edu.iu.uis.eden.WorkflowServiceErrorException;
044: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
045: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
046: import edu.iu.uis.eden.doctype.DocumentType;
047: import edu.iu.uis.eden.doctype.DocumentTypeService;
048: import edu.iu.uis.eden.engine.ActivationContext;
049: import edu.iu.uis.eden.engine.RouteContext;
050: import edu.iu.uis.eden.engine.node.RouteNode;
051: import edu.iu.uis.eden.engine.node.RouteNodeInstance;
052: import edu.iu.uis.eden.lookupable.Field;
053: import edu.iu.uis.eden.lookupable.Row;
054: import edu.iu.uis.eden.plugin.attributes.WorkflowAttribute;
055: import edu.iu.uis.eden.routeheader.AttributeDocumentContent;
056: import edu.iu.uis.eden.routeheader.DocumentContent;
057: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
058: import edu.iu.uis.eden.routelog.web.RouteLogAction;
059: import edu.iu.uis.eden.routelog.web.RouteLogForm;
060: import edu.iu.uis.eden.routetemplate.FlexRM;
061: import edu.iu.uis.eden.routetemplate.RuleAttribute;
062: import edu.iu.uis.eden.routetemplate.RuleTemplate;
063: import edu.iu.uis.eden.routetemplate.RuleTemplateAttribute;
064: import edu.iu.uis.eden.routetemplate.RuleTemplateService;
065: import edu.iu.uis.eden.routetemplate.xmlrouting.GenericXMLRuleAttribute;
066: import edu.iu.uis.eden.user.AuthenticationUserId;
067: import edu.iu.uis.eden.user.UserService;
068: import edu.iu.uis.eden.user.WorkflowUser;
069: import edu.iu.uis.eden.util.Utilities;
070: import edu.iu.uis.eden.web.WorkflowAction;
071:
072: /**
073: * A Struts Action for executing routing reports and retrieving the results.
074: *
075: * @author rkirkend
076: * @author jhopf
077: * @author ewestfal
078: * @author delyea
079: */
080: public class RoutingReportAction extends WorkflowAction {
081: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
082: .getLogger(RoutingReportAction.class);
083:
084: public static final String DOC_TYPE_REPORTING = "documentType";
085: public static final String TEMPLATE_REPORTING = "template";
086:
087: public ActionForward start(ActionMapping mapping, ActionForm form,
088: HttpServletRequest request, HttpServletResponse response)
089: throws Exception {
090: RoutingReportForm routingForm = (RoutingReportForm) form;
091: if (Utilities.isEmpty(routingForm.getDateRef())) {
092: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
093: routingForm.setEffectiveHour("5");
094: routingForm.setEffectiveMinute("0");
095: routingForm.setAmPm("1");
096: routingForm.setDateRef(sdf.format(new Date()));
097: }
098: if (DOC_TYPE_REPORTING.equals(routingForm.getReportType())) {
099: if (Utilities.isEmpty(routingForm.getDocumentTypeParam())) {
100: throw new RuntimeException("No document type was given");
101: }
102: if (Utilities.isEmpty(routingForm.getInitiatorNetworkId())) {
103: throw new RuntimeException(
104: "No initiator network id was given");
105: }
106: if (Utilities.isEmpty(routingForm.getDocumentContent())) {
107: throw new RuntimeException(
108: "No document content was given");
109: }
110: return calculateRoute(mapping, form, request, response);
111: } else if (!(TEMPLATE_REPORTING.equals(routingForm
112: .getReportType()))) {
113: // report type is not Document Type or Template Type... error out
114: throw new RuntimeException(
115: "The Routing Report type is not set");
116: }
117: return mapping.findForward("basic");
118: }
119:
120: public ActionForward calculateRoute(ActionMapping mapping,
121: ActionForm form, HttpServletRequest request,
122: HttpServletResponse response) throws Exception {
123: RoutingReportForm routingForm = (RoutingReportForm) form;
124:
125: List errors = new ArrayList();
126:
127: if (getDocumentTypeService().findByName(
128: routingForm.getDocumentType()) == null) {
129: errors
130: .add(new WorkflowServiceErrorImpl(
131: "Document type is required.",
132: "doctype.documenttypeservice.doctypename.required"));
133: }
134: Timestamp date = null;
135: if (!Utilities.isEmpty(routingForm.getDateRef())) {
136: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
137: try {
138: Calendar calendar = Calendar.getInstance();
139: calendar.setTime(sdf.parse(routingForm.getDateRef()));
140: calendar.set(Calendar.HOUR, Integer
141: .parseInt(routingForm.getEffectiveHour()));
142: calendar.set(Calendar.MINUTE, Integer
143: .parseInt(routingForm.getEffectiveMinute()));
144: calendar.set(Calendar.AM_PM, Integer
145: .parseInt(routingForm.getAmPm()));
146: date = new Timestamp(calendar.getTimeInMillis());
147: } catch (Exception e) {
148: LOG.error("error parsing date", e);
149: errors.add(new WorkflowServiceErrorImpl(
150: "Invalid date.",
151: "routereport.effectiveDate.invalid"));
152: }
153: }
154:
155: if (!errors.isEmpty()) {
156: throw new WorkflowServiceErrorException(
157: "Errors populating rule attributes.", errors);
158: }
159:
160: DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator
161: .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
162: DocumentType docType = documentTypeService
163: .findByName(routingForm.getDocumentType());
164:
165: DocumentRouteHeaderValue routeHeader = new DocumentRouteHeaderValue();
166: routeHeader.setRouteHeaderId(new Long(0));
167: routeHeader.setDocumentTypeId(docType.getDocumentTypeId());
168: routeHeader.setDocRouteLevel(new Integer(0));
169: routeHeader.setDocVersion(new Integer(
170: EdenConstants.CURRENT_DOCUMENT_VERSION));
171:
172: List<RouteReportRuleTemplateContainer> ruleTemplateContainers = new ArrayList<RouteReportRuleTemplateContainer>();
173: if (routingForm.getReportType().equals(DOC_TYPE_REPORTING)) {
174: List routeNodes = KEWServiceLocator.getRouteNodeService()
175: .getFlattenedNodes(docType, true);
176: for (Iterator iter = routeNodes.iterator(); iter.hasNext();) {
177: RouteNode routeNode = (RouteNode) iter.next();
178: if (routeNode.isFlexRM()) {
179: RuleTemplate ruleTemplate = getRuleTemplateService()
180: .findByRuleTemplateName(
181: routeNode.getRouteMethodName());
182: if (ruleTemplate != null) {
183: ruleTemplateContainers
184: .add(new RouteReportRuleTemplateContainer(
185: ruleTemplate, routeNode));
186: if (ruleTemplate.getDelegationTemplate() != null) {
187: ruleTemplateContainers
188: .add(new RouteReportRuleTemplateContainer(
189: ruleTemplate
190: .getDelegationTemplate(),
191: routeNode));
192: }
193: }
194: }
195: }
196:
197: } else {
198: RuleTemplate ruleTemplate = getRuleTemplateService()
199: .findByRuleTemplateId(
200: routingForm.getRuleTemplateId());
201: RouteNode routeNode = new RouteNode();
202: routeNode.setRouteNodeName(ruleTemplate.getName());
203: ruleTemplateContainers
204: .add(new RouteReportRuleTemplateContainer(
205: ruleTemplate, routeNode));
206: if (ruleTemplate.getDelegationTemplate() != null) {
207: ruleTemplateContainers
208: .add(new RouteReportRuleTemplateContainer(
209: ruleTemplate.getDelegationTemplate(),
210: routeNode));
211: }
212: }
213:
214: String xmlDocumentContent = routingForm.getDocumentContent();
215: if (routingForm.getReportType().equals(TEMPLATE_REPORTING)) {
216: List attributes = new ArrayList();
217: for (Iterator iterator = ruleTemplateContainers.iterator(); iterator
218: .hasNext();) {
219: RouteReportRuleTemplateContainer ruleTemplateContainer = (RouteReportRuleTemplateContainer) iterator
220: .next();
221: RuleTemplate ruleTemplate = ruleTemplateContainer.ruleTemplate;
222: for (Iterator iter = ruleTemplate
223: .getRuleTemplateAttributes().iterator(); iter
224: .hasNext();) {
225: RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
226: .next();
227: if (!ruleTemplateAttribute.isWorkflowAttribute()) {
228: continue;
229: }
230: WorkflowAttribute workflowAttribute = ruleTemplateAttribute
231: .getWorkflowAttribute();
232:
233: RuleAttribute ruleAttribute = ruleTemplateAttribute
234: .getRuleAttribute();
235: if (ruleAttribute.getType().equals(
236: EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
237: ((GenericXMLRuleAttribute) workflowAttribute)
238: .setRuleAttribute(ruleAttribute);
239: }
240: List attValidationErrors = workflowAttribute
241: .validateRoutingData(routingForm
242: .getFields());
243: if (attValidationErrors != null
244: && !attValidationErrors.isEmpty()) {
245: errors.addAll(attValidationErrors);
246: }
247: attributes.add(workflowAttribute);
248: }
249: }
250:
251: if (!errors.isEmpty()) {
252: throw new WorkflowServiceErrorException(
253: "Errors populating rule attributes.", errors);
254: }
255:
256: DocumentContent docContent = new AttributeDocumentContent(
257: attributes);
258: xmlDocumentContent = docContent.getDocContent();
259: }
260:
261: routeHeader.setDocContent(xmlDocumentContent);
262: routeHeader.setInitiatorWorkflowId(getUserSession(request)
263: .getWorkflowUser().getWorkflowUserId().getWorkflowId());
264: routeHeader
265: .setDocRouteStatus(EdenConstants.ROUTE_HEADER_INITIATED_CD);
266: routeHeader.setDocTitle("Routing Report");
267: routeHeader.setRoutingReport(true);
268: long magicCounter = 0;
269:
270: FlexRM flexRM = new FlexRM(date);
271:
272: int numberOfRules = 0;
273: int numberOfActionRequests = 0;
274: Set<String> alreadyProcessedRuleTemplateNames = new HashSet<String>();
275: for (Iterator iterator = ruleTemplateContainers.iterator(); iterator
276: .hasNext();) {
277: // initialize the RouteContext
278: // RouteContext context = RouteContext.getCurrentRouteContext();
279: RouteContext context = RouteContext.createNewRouteContext();
280: context.setActivationContext(new ActivationContext(
281: ActivationContext.CONTEXT_IS_SIMULATION));
282: context.setDocument(routeHeader);
283: try {
284: RouteReportRuleTemplateContainer ruleTemplateContainer = (RouteReportRuleTemplateContainer) iterator
285: .next();
286: RuleTemplate ruleTemplate = ruleTemplateContainer.ruleTemplate;
287: RouteNode routeLevel = ruleTemplateContainer.routeNode;
288:
289: if (!alreadyProcessedRuleTemplateNames
290: .contains(ruleTemplate.getName())) {
291: alreadyProcessedRuleTemplateNames.add(ruleTemplate
292: .getName());
293: List actionRequests = flexRM.getActionRequests(
294: routeHeader, ruleTemplate.getName());
295:
296: numberOfActionRequests += actionRequests.size();
297: numberOfRules += flexRM.getNumberOfMatchingRules();
298:
299: magicCounter = populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(
300: routeLevel, actionRequests, magicCounter);
301: routeHeader.getActionRequests().addAll(
302: actionRequests);
303: }
304: } finally {
305: RouteContext.clearCurrentRouteContext();
306: }
307: }
308:
309: if (numberOfActionRequests == 0) {
310: if (numberOfRules == 0) {
311: errors.add(new WorkflowServiceErrorImpl(
312: "There are no rules.", "routereport.noRules"));
313: } else {
314: errors.add(new WorkflowServiceErrorImpl(
315: "There are rules, but no matches.",
316: "routereport.noMatchingRules"));
317: }
318: if (!errors.isEmpty()) {
319: throw new WorkflowServiceErrorException(
320: "Errors populating rule attributes.", errors);
321: }
322: }
323:
324: RouteLogForm routeLogForm = new RouteLogForm();
325: routeLogForm.setShowFuture(true);
326: if (StringUtils.isNotBlank(routingForm.getBackUrl())) {
327: routeLogForm.setReturnUrlLocation(routingForm.getBackUrl());
328: }
329: LOG.debug("Value of getDisplayCloseButton "
330: + routingForm.getShowCloseButton());
331: LOG.debug("Value of isDisplayCloseButton "
332: + routingForm.isDisplayCloseButton());
333: routeLogForm.setShowCloseButton(routingForm
334: .isDisplayCloseButton());
335: request.setAttribute("routeHeader", routeHeader);
336: new RouteLogAction().populateRouteLogFormActionRequests(
337: routeLogForm, routeHeader);
338: request.setAttribute("RouteLogForm", routeLogForm);
339:
340: return mapping.findForward("routeLog");
341: }
342:
343: private class RouteReportRuleTemplateContainer {
344: public RuleTemplate ruleTemplate = null;
345: public RouteNode routeNode = null;
346:
347: public RouteReportRuleTemplateContainer(RuleTemplate template,
348: RouteNode node) {
349: this .ruleTemplate = template;
350: this .routeNode = node;
351: }
352: }
353:
354: public long populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(
355: RouteNode routeLevel, List actionRequests, long magicCounter) {
356:
357: for (Iterator iter = actionRequests.iterator(); iter.hasNext();) {
358: ActionRequestValue actionRequest = (ActionRequestValue) iter
359: .next();
360: populateActionRequestsWithRouteLevelInformationAndIterateMagicCounter(
361: routeLevel, actionRequest.getChildrenRequests(),
362: magicCounter);
363: actionRequest
364: .setStatus(EdenConstants.ACTION_REQUEST_INITIALIZED);
365: // actionRequest.setRouteMethodName(routeLevel.getRouteMethodName());
366: RouteNodeInstance routeNode = new RouteNodeInstance();
367: routeNode.setRouteNode(routeLevel);
368: actionRequest.setNodeInstance(routeNode);
369: actionRequest.setRouteLevel(new Integer(0));
370: magicCounter++;
371: actionRequest.setActionRequestId(new Long(magicCounter));
372: }
373: return magicCounter;
374: }
375:
376: public ActionForward refresh(ActionMapping mapping,
377: ActionForm form, HttpServletRequest request,
378: HttpServletResponse response) throws Exception {
379: return mapping.findForward("basic");
380: }
381:
382: public ActionMessages establishRequiredState(
383: HttpServletRequest request, ActionForm form)
384: throws Exception {
385: RoutingReportForm routingReportForm = (RoutingReportForm) form;
386: if (routingReportForm.getReportType() == null) {
387: // no report type means we must check for potential setup
388: if ((!Utilities.isEmpty(routingReportForm
389: .getDocumentTypeParam()))
390: || (!Utilities.isEmpty(routingReportForm
391: .getInitiatorNetworkId()))
392: || (!Utilities.isEmpty(routingReportForm
393: .getDocumentContent()))) {
394: // at least one parameter was passed... attempt to use Doc Type Report
395: routingReportForm.setReportType(DOC_TYPE_REPORTING);
396: } else {
397: // no parameters passed... default to Template Type Rreport
398: routingReportForm.setReportType(TEMPLATE_REPORTING);
399: }
400: }
401:
402: if (routingReportForm.getReportType()
403: .equals(DOC_TYPE_REPORTING)) {
404: if (Utilities.isEmpty(routingReportForm
405: .getDocumentTypeParam())) {
406: throw new RuntimeException(
407: "Document Type was not given");
408: } else {
409: DocumentType docType = getDocumentTypeService()
410: .findByName(
411: routingReportForm
412: .getDocumentTypeParam());
413: if (docType == null) {
414: throw new RuntimeException(
415: "Document Type is invalid");
416: }
417: }
418: if (Utilities.isEmpty(routingReportForm
419: .getInitiatorNetworkId())) {
420: throw new RuntimeException(
421: "Initiator Network ID was not given");
422: } else {
423: WorkflowUser initiatorUser = getUserService()
424: .getWorkflowUser(
425: new AuthenticationUserId(
426: routingReportForm
427: .getInitiatorNetworkId()));
428: if (initiatorUser == null) {
429: throw new RuntimeException(
430: "Initiator Network ID is invalid");
431: }
432: }
433: if (Utilities.isEmpty(routingReportForm
434: .getDocumentContent())) {
435: throw new RuntimeException(
436: "Document Content was not given");
437: }
438:
439: if (!Utilities.isEmpty(routingReportForm.getDocumentType())) {
440: DocumentType docType = getDocumentTypeService()
441: .findByName(routingReportForm.getDocumentType());
442: if (docType == null) {
443: throw new RuntimeException(
444: "Document Type is missing or invalid");
445: }
446: routingReportForm.getRuleTemplateAttributes().clear();
447: List routeNodes = KEWServiceLocator
448: .getRouteNodeService().getFlattenedNodes(
449: docType, true);
450: for (Iterator iter = routeNodes.iterator(); iter
451: .hasNext();) {
452: RouteNode routeNode = (RouteNode) iter.next();
453: if (routeNode.isFlexRM()) {
454: RuleTemplate ruleTemplate = getRuleTemplateService()
455: .findByRuleTemplateName(
456: routeNode.getRouteMethodName());
457: if (ruleTemplate != null) {
458: loadRuleTemplateOnForm(ruleTemplate,
459: routingReportForm, request, false);
460: if (ruleTemplate.getDelegationTemplate() != null) {
461: loadRuleTemplateOnForm(ruleTemplate
462: .getDelegationTemplate(),
463: routingReportForm, request,
464: true);
465: }
466: }
467: }
468: }
469: }
470: // routingReportForm.setShowFields(true);
471: } else if (routingReportForm.getReportType().equals(
472: TEMPLATE_REPORTING)) {
473: routingReportForm.setRuleTemplates(getRuleTemplateService()
474: .findAll());
475: if (routingReportForm.getRuleTemplateId() != null) {
476: RuleTemplate ruleTemplate = getRuleTemplateService()
477: .findByRuleTemplateId(
478: routingReportForm.getRuleTemplateId());
479: routingReportForm.getRuleTemplateAttributes().clear();
480: loadRuleTemplateOnForm(ruleTemplate, routingReportForm,
481: request, false);
482: if (ruleTemplate.getDelegationTemplate() != null) {
483: loadRuleTemplateOnForm(ruleTemplate
484: .getDelegationTemplate(),
485: routingReportForm, request, true);
486: }
487: }
488: }
489: return null;
490: }
491:
492: private void loadRuleTemplateOnForm(RuleTemplate ruleTemplate,
493: RoutingReportForm routingReportForm,
494: HttpServletRequest request, boolean isDelegate) {
495:
496: Map fieldValues = new HashMap();
497:
498: List ruleTemplateAttributes = ruleTemplate
499: .getRuleTemplateAttributes();
500: Collections.sort(ruleTemplateAttributes);
501:
502: List rows = new ArrayList();
503: for (Iterator iter = ruleTemplateAttributes.iterator(); iter
504: .hasNext();) {
505: RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
506: .next();
507: if (!ruleTemplateAttribute.isWorkflowAttribute()) {
508: continue;
509: }
510: WorkflowAttribute workflowAttribute = ruleTemplateAttribute
511: .getWorkflowAttribute();
512:
513: RuleAttribute ruleAttribute = ruleTemplateAttribute
514: .getRuleAttribute();
515: if (ruleAttribute.getType().equals(
516: EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
517: ((GenericXMLRuleAttribute) workflowAttribute)
518: .setRuleAttribute(ruleAttribute);
519: }
520: for (Iterator iterator = workflowAttribute
521: .getRoutingDataRows().iterator(); iterator
522: .hasNext();) {
523: Row row = (Row) iterator.next();
524:
525: List fields = new ArrayList();
526: for (Iterator iterator2 = row.getFields().iterator(); iterator2
527: .hasNext();) {
528: Field field = (Field) iterator2.next();
529: if (request.getParameter(field.getPropertyName()) != null) {
530: field.setPropertyValue(request
531: .getParameter(field.getPropertyName()));
532: } else if (routingReportForm.getFields() != null
533: && !routingReportForm.getFields().isEmpty()) {
534: field
535: .setPropertyValue((String) routingReportForm
536: .getFields()
537: .get(field.getPropertyName()));
538: }
539: fields.add(field);
540: fieldValues.put(field.getPropertyName(), field
541: .getPropertyValue());
542: }
543: // row.setFields(fields);
544: // rows.add(row);
545: }
546:
547: workflowAttribute.validateRuleData(fieldValues);// populate attribute
548: for (Iterator iterator = workflowAttribute
549: .getRoutingDataRows().iterator(); iterator
550: .hasNext();) {
551: Row row = (Row) iterator.next();
552: List fields = new ArrayList();
553: for (Iterator iterator2 = row.getFields().iterator(); iterator2
554: .hasNext();) {
555: Field field = (Field) iterator2.next();
556: if (request.getParameter(field.getPropertyName()) != null) {
557: field.setPropertyValue(request
558: .getParameter(field.getPropertyName()));
559: } else if (routingReportForm.getFields() != null
560: && !routingReportForm.getFields().isEmpty()) {
561: field
562: .setPropertyValue((String) routingReportForm
563: .getFields()
564: .get(field.getPropertyName()));
565: }
566: fields.add(field);
567: fieldValues.put(field.getPropertyName(), field
568: .getPropertyValue());
569: }
570: row.setFields(fields);
571: if (isDelegate) {
572: row.setRowsGroupLabel("Delegate "
573: + row.getRowsGroupLabel());
574: }
575: rows.add(row);
576:
577: }
578: }
579:
580: routingReportForm.getFields().putAll(fieldValues);
581: // routingReportForm.setFields(fieldValues);
582: routingReportForm.getRuleTemplateAttributes().addAll(rows);
583: // routingReportForm.setRuleTemplateAttributes(rows);
584: routingReportForm.setShowFields(true);
585: routingReportForm.setShowViewResults(true);
586: }
587:
588: public ActionForward performLookup(ActionMapping mapping,
589: ActionForm form, HttpServletRequest request,
590: HttpServletResponse response) throws Exception {
591:
592: RoutingReportForm routingReportForm = (RoutingReportForm) form;
593:
594: String basePath = request.getScheme() + "://"
595: + request.getServerName() + ":"
596: + request.getServerPort() + request.getContextPath()
597: + mapping.getModuleConfig().getPrefix();
598: StringBuffer lookupUrl = new StringBuffer(basePath);
599: lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=")
600: .append(getUserSession(request).addObject(form))
601: .append("&lookupableImplServiceName=");
602: lookupUrl.append(request
603: .getParameter("lookupableImplServiceName"));
604:
605: lookupUrl.append("&conversionFields=");
606:
607: List ruleTemplateAttributes = null;
608:
609: if (routingReportForm.getReportType()
610: .equals(DOC_TYPE_REPORTING)) {
611: if (!Utilities.isEmpty(routingReportForm.getDocumentType())) {
612: DocumentType docType = getDocumentTypeService()
613: .findByName(routingReportForm.getDocumentType());
614: if (docType == null) {
615: throw new RuntimeException("Document Type is null");
616: }
617: ruleTemplateAttributes = new ArrayList();
618: }
619: } else if (routingReportForm.getRuleTemplateId() != null) {
620: RuleTemplate ruleTemplate = getRuleTemplateService()
621: .findByRuleTemplateId(
622: routingReportForm.getRuleTemplateId());
623: ruleTemplateAttributes = ruleTemplate
624: .getRuleTemplateAttributes();
625: }
626: if (ruleTemplateAttributes != null) {
627: Collections.sort(ruleTemplateAttributes);
628: for (Iterator iter = ruleTemplateAttributes.iterator(); iter
629: .hasNext();) {
630: RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
631: .next();
632: if (!ruleTemplateAttribute.isWorkflowAttribute()) {
633: continue;
634: }
635: WorkflowAttribute workflowAttribute = ruleTemplateAttribute
636: .getWorkflowAttribute();
637:
638: RuleAttribute ruleAttribute = ruleTemplateAttribute
639: .getRuleAttribute();
640: if (ruleAttribute.getType().equals(
641: EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
642: ((GenericXMLRuleAttribute) workflowAttribute)
643: .setRuleAttribute(ruleAttribute);
644: }
645: boolean foundQuickFinder = false;
646: for (Iterator iterator = workflowAttribute
647: .getRoutingDataRows().iterator(); iterator
648: .hasNext();) {
649: Row row = (Row) iterator.next();
650: for (Iterator iterator2 = row.getFields()
651: .iterator(); iterator2.hasNext();) {
652: Field field = (Field) iterator2.next();
653: if (field.getFieldType().equals(
654: Field.QUICKFINDER)
655: && field
656: .getQuickFinderClassNameImpl()
657: .equals(
658: request
659: .getParameter("lookupableImplServiceName"))) {
660: foundQuickFinder = true;
661: }
662: }
663: }
664:
665: if (foundQuickFinder) {
666: StringBuffer conversionFields = new StringBuffer();
667: for (Iterator iterator = workflowAttribute
668: .getRoutingDataRows().iterator(); iterator
669: .hasNext();) {
670: Row row = (Row) iterator.next();
671: for (Iterator iterator2 = row.getFields()
672: .iterator(); iterator2.hasNext();) {
673: Field field = (Field) iterator2.next();
674: if (!Utilities.isEmpty(field
675: .getDefaultLookupableName())) {
676: conversionFields
677: .append(
678: field
679: .getDefaultLookupableName())
680: .append(":")
681: .append(field.getPropertyName())
682: .append(",");
683: }
684: }
685: }
686: if (!Utilities.isEmpty(conversionFields.toString())) {
687: lookupUrl.append(conversionFields.substring(0,
688: conversionFields.lastIndexOf(",")));
689: }
690: }
691: }
692: }
693:
694: lookupUrl.append("&returnLocation=").append(basePath).append(
695: mapping.getPath()).append(".do");
696: return new ActionForward(lookupUrl.toString(), true);
697:
698: }
699:
700: public ActionForward loadTemplate(ActionMapping mapping,
701: ActionForm form, HttpServletRequest request,
702: HttpServletResponse response) throws Exception {
703: RoutingReportForm routingReportForm = (RoutingReportForm) form;
704: if (Utilities.isEmpty(routingReportForm.getDateRef())) {
705: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
706: routingReportForm.setEffectiveHour("5");
707: routingReportForm.setEffectiveMinute("0");
708: routingReportForm.setAmPm("1");
709: routingReportForm.setDateRef(sdf.format(new Date()));
710: }
711: return mapping.findForward("basic");
712: }
713:
714: private UserService getUserService() {
715: return (UserService) KEWServiceLocator
716: .getService(KEWServiceLocator.USER_SERVICE);
717: }
718:
719: private RuleTemplateService getRuleTemplateService() {
720: return (RuleTemplateService) KEWServiceLocator
721: .getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
722: }
723:
724: private DocumentTypeService getDocumentTypeService() {
725: return (DocumentTypeService) KEWServiceLocator
726: .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
727: }
728: }
|