Source Code Cross Referenced for DelegateRule2Action.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » routetemplate » web » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.routetemplate.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.util.ArrayList;
020:        import java.util.Iterator;
021:        import java.util.List;
022:
023:        import javax.servlet.http.HttpServletRequest;
024:        import javax.servlet.http.HttpServletResponse;
025:
026:        import org.apache.struts.action.ActionErrors;
027:        import org.apache.struts.action.ActionForm;
028:        import org.apache.struts.action.ActionForward;
029:        import org.apache.struts.action.ActionMapping;
030:        import org.apache.struts.action.ActionMessage;
031:        import org.apache.struts.action.ActionMessages;
032:        import org.kuali.rice.resourceloader.GlobalResourceLoader;
033:
034:        import edu.iu.uis.eden.EdenConstants;
035:        import edu.iu.uis.eden.KEWServiceLocator;
036:        import edu.iu.uis.eden.WorkflowServiceErrorException;
037:        import edu.iu.uis.eden.WorkflowServiceErrorImpl;
038:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
039:        import edu.iu.uis.eden.clientapp.vo.WorkflowIdVO;
040:        import edu.iu.uis.eden.exception.WorkflowException;
041:        import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
042:        import edu.iu.uis.eden.routetemplate.MyRules2;
043:        import edu.iu.uis.eden.routetemplate.RuleBaseValues;
044:        import edu.iu.uis.eden.routetemplate.RuleDelegation;
045:        import edu.iu.uis.eden.routetemplate.RuleDelegationService;
046:        import edu.iu.uis.eden.routetemplate.RuleResponsibility;
047:        import edu.iu.uis.eden.routetemplate.RuleService;
048:        import edu.iu.uis.eden.routetemplate.RuleTemplate;
049:        import edu.iu.uis.eden.routetemplate.RuleTemplateService;
050:        import edu.iu.uis.eden.util.CodeTranslator;
051:        import edu.iu.uis.eden.util.Utilities;
052:        import edu.iu.uis.eden.web.ShowHideTree;
053:        import edu.iu.uis.eden.web.WorkflowAction;
054:
055:        /**
056:         * A Struts Action for creating a routing delegate rules.
057:         * 
058:         * @see RuleService
059:         * 
060:         * @author ewestfal
061:         */
062:        public class DelegateRule2Action extends WorkflowAction {
063:
064:            public ActionForward start(ActionMapping mapping, ActionForm form,
065:                    HttpServletRequest request, HttpServletResponse response)
066:                    throws Exception {
067:                Rule2Form rule2Form = (Rule2Form) form;
068:                rule2Form.getRuleCreationValues().setCreating(true);
069:                //createFlexDoc(request, rule2Form);
070:                return mapping.findForward("basic");
071:            }
072:
073:            public ActionForward performLookup(ActionMapping mapping,
074:                    ActionForm form, HttpServletRequest request,
075:                    HttpServletResponse response) throws Exception {
076:                Rule2Form ruleForm = (Rule2Form) form;
077:                String lookupType = ruleForm.getLookupType();
078:                ruleForm.setLookupType(null);
079:
080:                String delegateOnly = ruleForm.getDelegationSearchOnly();
081:                ruleForm.setDelegationSearchOnly(null);
082:
083:                String basePath = request.getScheme() + "://"
084:                        + request.getServerName() + ":"
085:                        + request.getServerPort() + request.getContextPath()
086:                        + mapping.getModuleConfig().getPrefix();
087:                ;
088:                StringBuffer lookupUrl = new StringBuffer(basePath);
089:                lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=")
090:                        .append(getUserSession(request).addObject(form))
091:                        .append("&lookupableImplServiceName=");
092:                lookupUrl.append(request
093:                        .getParameter("lookupableImplServiceName"));
094:                if (!Utilities.isEmpty(delegateOnly)) {
095:                    lookupUrl.append("&ruleDelegationOnly=true");
096:                }
097:                lookupUrl.append("&conversionFields=").append(
098:                        request.getParameter("conversionFields"));
099:
100:                if (lookupType != null && !lookupType.equals("")) {
101:                    WorkflowLookupable workflowLookupable = (WorkflowLookupable) GlobalResourceLoader
102:                            .getService(request
103:                                    .getParameter("lookupableImplServiceName"));//(WorkflowLookupable) SpringServiceLocator.getExtensionService().getLookupable(request.getParameter("lookupableImplServiceName"));
104:                    if (!Utilities.isEmpty(request
105:                            .getParameter("conversionFields"))) {
106:                        lookupUrl.append(",");
107:                    }
108:                    for (Iterator iterator = workflowLookupable
109:                            .getDefaultReturnType().iterator(); iterator
110:                            .hasNext();) {
111:                        String returnType = (String) iterator.next();
112:                        lookupUrl.append(returnType).append(":").append(
113:                                lookupType);
114:                    }
115:                }
116:
117:                lookupUrl.append("&returnLocation=").append(basePath).append(
118:                        mapping.getPath()).append(".do");
119:                return new ActionForward(lookupUrl.toString(), true);
120:            }
121:
122:            public ActionMessages establishRequiredState(
123:                    HttpServletRequest request, ActionForm form)
124:                    throws Exception {
125:                Rule2Form ruleForm = (Rule2Form) form;
126:                ruleForm.setActionRequestCodes(CodeTranslator.arLabels);
127:                ruleForm
128:                        .setApprovePolicyCodes(CodeTranslator.approvePolicyLabels);
129:
130:                //first time through edit I don't get called
131:                if (ruleForm.getRuleCreationValues().getRuleId() != null) {
132:                    RuleBaseValues parentRule = getRuleService()
133:                            .findRuleBaseValuesById(
134:                                    ruleForm.getRuleCreationValues()
135:                                            .getRuleId());
136:                    RuleResponsibility responsibility = null;
137:                    if (ruleForm.getRuleCreationValues()
138:                            .getRuleResponsibilityKey() != null) {
139:                        responsibility = parentRule.getResponsibility(ruleForm
140:                                .getRuleCreationValues()
141:                                .getRuleResponsibilityKey());
142:                    }
143:                    //this is so only the responsibility we're working on get's displayed
144:                    stripParentRule(parentRule, responsibility);
145:                    ruleForm.setParentRule(new WebRuleBaseValues(parentRule));
146:                    if (ruleForm.getParentShowHide().getChildren().isEmpty()) {
147:                        ShowHideTree parentRuleTree = ruleForm
148:                                .getParentShowHide().append();
149:                        parentRuleTree.setShow(Boolean.FALSE);
150:                        for (Iterator iterator = ruleForm.getParentRule()
151:                                .getResponsibilities().iterator(); iterator
152:                                .hasNext();) {
153:                            iterator.next();
154:                            parentRuleTree.append();
155:                        }
156:                    }
157:                }
158:                if (!ruleForm.getMyRules().getRules().isEmpty()) {
159:                    ruleForm.getRuleDelegation().setDelegationRuleBaseValues(
160:                            (RuleBaseValues) ruleForm.getMyRules().getRule(0));
161:                }
162:                MyRules2 myRules = ruleForm.getMyRules();
163:                for (Iterator ruleIt = myRules.getRules().iterator(); ruleIt
164:                        .hasNext();) {
165:                    WebRuleBaseValues rule = (WebRuleBaseValues) ruleIt.next();
166:                    rule.establishRequiredState();
167:                }
168:                if (ruleForm.getDocId() != null
169:                        && ruleForm.getFlexDoc() == null) {
170:                    ruleForm.setFlexDoc(new WorkflowDocument(new WorkflowIdVO(
171:                            getUserSession(request).getWorkflowUser()
172:                                    .getWorkflowId()), ruleForm.getDocId()));
173:                }
174:                ruleForm.establishVisibleActionRequestCds();
175:                return null;
176:            }
177:
178:            public ActionForward copy(ActionMapping mapping, ActionForm form,
179:                    HttpServletRequest request, HttpServletResponse response)
180:                    throws Exception {
181:                Rule2Form ruleForm = (Rule2Form) form;
182:                List errors = new ArrayList();
183:                WebRuleBaseValues webRule = null;
184:                if (ruleForm.getCurrentRuleId() != null) {
185:                    RuleBaseValues rule = getRuleService()
186:                            .findRuleBaseValuesById(ruleForm.getCurrentRuleId());
187:                    if (rule != null) {
188:                        if (!rule.getDelegateRule().booleanValue()) {
189:                            errors.add(new WorkflowServiceErrorImpl(
190:                                    "Rule with given id is not a delegate rule "
191:                                            + ruleForm.getCurrentRuleId(),
192:                                    "general.workflow.error",
193:                                    "Rule with given id is not a delegate rule "
194:                                            + ruleForm.getCurrentRuleId()));
195:                        } else {
196:                            List delegations = getRuleDelegationService()
197:                                    .findByDelegateRuleId(
198:                                            rule.getRuleBaseValuesId());
199:                            //hunt for the current parent rule of this delegation to determine what rule to check locking against
200:                            RuleDelegation ruleDelegation = null;
201:                            for (Iterator iter = delegations.iterator(); iter
202:                                    .hasNext();) {
203:                                RuleDelegation tmpRuleDelegation = (RuleDelegation) iter
204:                                        .next();
205:                                if (tmpRuleDelegation.getRuleResponsibility()
206:                                        .getRuleBaseValues().getCurrentInd()
207:                                        .booleanValue()) {
208:                                    ruleDelegation = tmpRuleDelegation;
209:                                    break;
210:                                }
211:                            }
212:                            if (ruleDelegation == null) {
213:                                errors
214:                                        .add(new WorkflowServiceErrorImpl(
215:                                                "This rule is not being delegated from a current rule, it cannot be copied.",
216:                                                "general.workflow.error",
217:                                                "This rule is not currently being delegated from a current rule, it cannot be copied."));
218:                            } else {
219:                                ruleForm.setRuleDelegation(ruleDelegation);
220:                                RuleBaseValues parentRule = ruleDelegation
221:                                        .getRuleResponsibility()
222:                                        .getRuleBaseValues();
223:                                ruleForm.getRuleCreationValues().setRuleId(
224:                                        parentRule.getRuleBaseValuesId());
225:                                webRule = WebRuleUtils
226:                                        .copyToNewRule(new WebRuleBaseValues(
227:                                                rule));
228:                                initializeShowHide(ruleForm.getShowHide(),
229:                                        webRule);
230:                            }
231:                        }
232:                    } else {
233:                        errors.add(new WorkflowServiceErrorImpl(
234:                                "Could not locate rule for given id "
235:                                        + ruleForm.getCurrentRuleId(),
236:                                "general.workflow.error",
237:                                "Could not locate rule for given id "
238:                                        + ruleForm.getCurrentRuleId()));
239:                    }
240:                } else {
241:                    errors.add(new WorkflowServiceErrorImpl(
242:                            "Error copying rule, no id specified.",
243:                            "general.workflow.error",
244:                            "Error copying rule, no id specified."));
245:                }
246:                if (!errors.isEmpty()) {
247:                    throw new WorkflowServiceErrorException(
248:                            "Errors copying rule.", errors);
249:                }
250:                ruleForm.getMyRules().addRule(webRule);
251:                ruleForm.getRuleCreationValues().setCreating(false);
252:                createFlexDoc(request, ruleForm, ruleForm.getMyRules()
253:                        .getRules());
254:
255:                ruleForm.getRuleCreationValues().setRuleResponsibilityKey(
256:                        ruleForm.getRuleDelegation().getRuleResponsibilityId());
257:
258:                ruleForm.getRuleDelegation().setDelegationRuleBaseValues(
259:                        webRule);
260:                ruleForm.setEditingDelegate(true);
261:                webRule.establishRequiredState();
262:                establishRequiredState(request, ruleForm);
263:                return mapping.findForward("basic");
264:            }
265:
266:            public ActionForward edit(ActionMapping mapping, ActionForm form,
267:                    HttpServletRequest request, HttpServletResponse response)
268:                    throws Exception {
269:                Rule2Form ruleForm = (Rule2Form) form;
270:                RuleBaseValues rule = getRuleService().findRuleBaseValuesById(
271:                        ruleForm.getCurrentRuleId());
272:                if (rule != null) {
273:                    ActionErrors errors = new ActionErrors();
274:                    if (!rule.getDelegateRule().booleanValue()) {
275:                        errors.add("hasErrors", new ActionMessage(
276:                                "routetemplate.select",
277:                                "valid delegation rule for editing.  The rule with id "
278:                                        + rule.getRuleBaseValuesId()
279:                                        + " is not a delegate rule"));
280:                        saveErrors(request, errors);
281:                        return mapping.findForward("basic");
282:                    }
283:
284:                    List delegations = getRuleDelegationService()
285:                            .findByDelegateRuleId(rule.getRuleBaseValuesId());
286:                    //hunt for the current parent rule of this delegation to determine what rule to check locking against
287:                    for (Iterator iter = delegations.iterator(); iter.hasNext();) {
288:                        RuleDelegation ruleDelegation = (RuleDelegation) iter
289:                                .next();
290:                        if (ruleDelegation.getRuleResponsibility()
291:                                .getRuleBaseValues().getCurrentInd()
292:                                .booleanValue()) {
293:                            ruleForm.setRuleDelegation(ruleDelegation);
294:                            break;
295:                        }
296:                    }
297:
298:                    RuleBaseValues oldParentRule = ruleForm.getRuleDelegation()
299:                            .getRuleResponsibility().getRuleBaseValues();
300:                    stripParentRule(oldParentRule, ruleForm.getRuleDelegation()
301:                            .getRuleResponsibility());
302:                    WebRuleBaseValues parentRule = new WebRuleBaseValues(
303:                            oldParentRule);
304:                    ruleForm.setParentRule(parentRule);
305:
306:                    if (checkLockedForRouting(errors, parentRule)) {
307:                        saveErrors(request, errors);
308:                        return mapping.findForward("basic");
309:                    }
310:
311:                    /*
312:                     * ShowHideTree ruleTree = ruleForm.getParentShowHide().append(); // be sure not to go down into the delegations for (Iterator iterator = parentRule.getResponsibilities().iterator(); iterator.hasNext();) { RuleResponsibility responsibility = (RuleResponsibility) iterator.next(); ruleTree.append(); } ruleTree.setShow(Boolean.FALSE);
313:                     */
314:                    WebRuleBaseValues webRule = new WebRuleBaseValues(rule);
315:                    webRule.setPreviousVersionId(rule.getRuleBaseValuesId());
316:                    ruleForm.getMyRules().addRule(webRule);
317:                    ruleForm.getRuleCreationValues().setCreating(false);
318:                    ruleForm.getRuleCreationValues().setRuleId(
319:                            parentRule.getRuleBaseValuesId());
320:                    ruleForm.getRuleCreationValues().setRuleResponsibilityKey(
321:                            ruleForm.getRuleDelegation()
322:                                    .getRuleResponsibilityId());
323:                    ruleForm.setEditingDelegate(true);
324:                    ruleForm.setShowHide(initializeShowHide(ruleForm
325:                            .getMyRules()));
326:                    String ruleDocTypeName = getRuleService()
327:                            .getRuleDocmentTypeName(
328:                                    ruleForm.getMyRules().getRules());
329:                    ruleForm.setFlexDoc(new WorkflowDocument(new WorkflowIdVO(
330:                            getUserSession(request).getWorkflowUser()
331:                                    .getWorkflowId()), ruleDocTypeName));
332:                    ruleForm.setDocId(ruleForm.getFlexDoc().getRouteHeaderId());
333:                    ruleForm.establishVisibleActionRequestCds();
334:                }
335:                //establishRequiredState(request, ruleForm);
336:                return mapping.findForward("basic");
337:            }
338:
339:            private ActionForward checkLocked(ActionMapping mapping,
340:                    Rule2Form ruleForm, HttpServletRequest request,
341:                    HttpServletResponse response) {
342:                if ("true".equalsIgnoreCase(Utilities
343:                        .getApplicationConstant(EdenConstants.RULE_LOCKING_ON))) {
344:                    Long routeHeaderId = getRuleService().isLockedForRouting(
345:                            ruleForm.getRuleCreationValues().getRuleId());
346:                    if (routeHeaderId != null) {
347:                        ActionErrors lockErrors = new ActionErrors();
348:                        lockErrors.add("hasErrors", new ActionMessage(
349:                                "routetemplate.RuleService.ruleInRoute", ""
350:                                        + routeHeaderId.longValue()));
351:                        saveErrors(request, lockErrors);
352:                        return mapping.findForward("basic");
353:                    }
354:                }
355:                return null;
356:            }
357:
358:            public ActionForward createDelegateRule(ActionMapping mapping,
359:                    ActionForm form, HttpServletRequest request,
360:                    HttpServletResponse response) throws Exception {
361:                Rule2Form ruleForm = (Rule2Form) form;
362:                ActionErrors errors = validateCreateDelegateRule(ruleForm);
363:
364:                if (!errors.isEmpty()) {
365:                    saveErrors(request, errors);
366:                    return mapping.findForward("basic");
367:                }
368:
369:                ActionForward checkLocked = checkLocked(mapping, ruleForm,
370:                        request, response);
371:                if (checkLocked != null) {
372:                    return checkLocked;
373:                }
374:
375:                ruleForm.getRuleCreationValues().setCreating(false);
376:                WebRuleBaseValues rule = new WebRuleBaseValues();
377:
378:                RuleBaseValues defaultRule = getRuleService()
379:                        .findDefaultRuleByRuleTemplateId(
380:                                ruleForm.getParentRule().getRuleTemplate()
381:                                        .getDelegationTemplateId());
382:                if (defaultRule != null) {
383:                    List ruleDelegations = getRuleDelegationService()
384:                            .findByDelegateRuleId(
385:                                    defaultRule.getRuleBaseValuesId());
386:                    defaultRule.setActivationDate(null);
387:                    defaultRule.setCurrentInd(null);
388:                    defaultRule.setDeactivationDate(null);
389:                    defaultRule.setDocTypeName(null);
390:                    defaultRule.setLockVerNbr(null);
391:                    defaultRule.setRuleBaseValuesId(null);
392:                    defaultRule.setTemplateRuleInd(Boolean.FALSE);
393:                    defaultRule.setVersionNbr(null);
394:                    rule.load(defaultRule);
395:
396:                    if (ruleDelegations != null && !ruleDelegations.isEmpty()) {
397:                        RuleDelegation defaultDelegation = (RuleDelegation) ruleDelegations
398:                                .get(0);
399:                        ruleForm.getRuleDelegation().setDelegationType(
400:                                defaultDelegation.getDelegationType());
401:                    }
402:                }
403:
404:                rule.setDocTypeName(ruleForm.getParentRule().getDocTypeName());
405:                rule.setRuleTemplateId(ruleForm.getParentRule()
406:                        .getRuleTemplate().getDelegationTemplateId());
407:                rule.setRuleTemplateName(ruleForm.getParentRule()
408:                        .getRuleTemplate().getDelegateTemplateName());
409:                rule.setDelegateRule(Boolean.TRUE);
410:                rule.loadFieldsWithDefaultValues();
411:                rule.createNewRuleResponsibility();
412:
413:                ruleForm.getRuleDelegation().setDelegationRuleBaseValues(rule);
414:                ruleForm.getMyRules().addRule(rule);
415:                createFlexDoc(request, ruleForm, ruleForm.getMyRules()
416:                        .getRules());
417:                ruleForm.getShowHide().append().append();
418:                ruleForm.setEditingDelegate(true);
419:                rule.establishRequiredState();
420:                return mapping.findForward("basic");
421:            }
422:
423:            public ActionForward removeRule(ActionMapping mapping,
424:                    ActionForm form, HttpServletRequest request,
425:                    HttpServletResponse response) throws Exception {
426:                Rule2Form ruleForm = (Rule2Form) form;
427:                /*
428:                 * if (ruleForm.getRuleCreationValues().getRuleId() != null) { RuleBaseValues rule = getRuleService().findRuleBaseValuesById(ruleForm.getRuleCreationValues().getRuleId()); initializeDelegationTemplate(ruleForm, rule); ruleForm.getMyRules().getRules().clear(); }
429:                 */
430:                ruleForm.getMyRules().getRules().clear();
431:                ruleForm.getShowHide().remove(0);
432:                ruleForm.getRuleCreationValues().setCreating(true);
433:                ruleForm.setEditingDelegate(false);
434:                return mapping.findForward("basic");
435:            }
436:
437:            public ActionErrors validateCreateDelegateRule(Rule2Form ruleForm) {
438:                ActionErrors errors = new ActionErrors();
439:                if (ruleForm.getRuleCreationValues().getRuleId() == null) {
440:                    errors.add("ruleCreationValues.ruleId", new ActionMessage(
441:                            "routetemplate.select", "Rule"));
442:                } else {
443:                    RuleBaseValues rule = getRuleService()
444:                            .findRuleBaseValuesById(
445:                                    ruleForm.getRuleCreationValues()
446:                                            .getRuleId());
447:                    if (rule.getDelegateRule().booleanValue()) {
448:                        errors
449:                                .add(
450:                                        "ruleCreationValues.ruleId",
451:                                        new ActionMessage(
452:                                                "routetemplate.select",
453:                                                "valid Delegating Rule.  The rule \""
454:                                                        + rule.getDescription()
455:                                                        + "\" is already a delegate rule"));
456:                    }
457:                    if (rule.getRuleTemplate().getDelegationTemplate() == null) {
458:                        errors
459:                                .add(
460:                                        "ruleCreationValues.ruleId",
461:                                        new ActionMessage(
462:                                                "routetemplate.select.ruletemplate.delegate.invalid"));
463:                    }
464:                }
465:                if (ruleForm.getRuleCreationValues().getRuleResponsibilityKey() == null) {
466:                    errors.add("ruleCreationValues.ruleResponsibilityKey",
467:                            new ActionMessage("routetemplate.select",
468:                                    "responsibility to delegate"));
469:                }
470:                return errors;
471:            }
472:
473:            public ActionForward addNewResponsibility(ActionMapping mapping,
474:                    ActionForm form, HttpServletRequest request,
475:                    HttpServletResponse response) throws Exception {
476:                Rule2Form ruleForm = (Rule2Form) form;
477:                int index = ruleForm.getRuleIndex().intValue();
478:                WebRuleBaseValues webRule = (WebRuleBaseValues) ruleForm
479:                        .getMyRules().getRule(index);
480:                WebRuleResponsibility responsibility = webRule
481:                        .createNewRuleResponsibility();
482:                ruleForm.getShowHide().getChild(index).append();
483:                responsibility.establishRequiredState();
484:                //        establishRequiredState(request, form);
485:                return mapping.findForward("basic");
486:            }
487:
488:            public ActionForward removeResponsibility(ActionMapping mapping,
489:                    ActionForm form, HttpServletRequest request,
490:                    HttpServletResponse response) throws Exception {
491:                Rule2Form ruleForm = (Rule2Form) form;
492:                int removeIndex = ruleForm.getResponsibilityIndex().intValue();
493:                RuleBaseValues rule = ruleForm.getMyRules().getRule(
494:                        ruleForm.getRuleIndex().intValue());
495:                rule.removeResponsibility(removeIndex);
496:                ruleForm.getShowHide().getChild(ruleForm.getRuleIndex())
497:                        .remove(removeIndex);
498:                return mapping.findForward("basic");
499:            }
500:
501:            public ActionForward showDelegations(ActionMapping mapping,
502:                    ActionForm form, HttpServletRequest request,
503:                    HttpServletResponse response) throws Exception {
504:                Rule2Form ruleForm = (Rule2Form) form;
505:                ruleForm.getRuleIndex().intValue();
506:                int respIndex = ruleForm.getResponsibilityIndex().intValue();
507:                // this should only happen for the parent rule
508:                WebRuleResponsibility responsibility = (WebRuleResponsibility) ruleForm
509:                        .getParentRule().getResponsibility(respIndex);
510:                responsibility.setShowDelegations(true);
511:                responsibility.loadDelegations();
512:                return mapping.findForward(ruleForm.getForward());
513:            }
514:
515:            public ActionForward blanketApprove(ActionMapping mapping,
516:                    ActionForm form, HttpServletRequest request,
517:                    HttpServletResponse response) throws Exception {
518:                Rule2Form ruleForm = (Rule2Form) form;
519:                ActionErrors errors = new ActionErrors();
520:                ActionForward forward = routeRule(errors, mapping, form,
521:                        request, response, true);
522:                if (!errors.isEmpty()) {
523:                    return forward;
524:                }
525:                ActionErrors messages = new ActionErrors();
526:                messages.add("hasErrors", new ActionMessage(
527:                        "general.routing.blanketApproved",
528:                        "Delegation Rule with document id = "
529:                                + ruleForm.getDocId()));
530:                saveErrors(request, messages);
531:                resetAfterRoute(ruleForm);
532:                return forward;
533:            }
534:
535:            public ActionForward route(ActionMapping mapping, ActionForm form,
536:                    HttpServletRequest request, HttpServletResponse response)
537:                    throws Exception {
538:                Rule2Form ruleForm = (Rule2Form) form;
539:                ActionErrors errors = new ActionErrors();
540:                ActionForward forward = routeRule(errors, mapping, form,
541:                        request, response, false);
542:                if (!errors.isEmpty()) {
543:                    return forward;
544:                }
545:                ActionErrors messages = new ActionErrors();
546:                messages.add("hasErrors", new ActionMessage(
547:                        "rule.route.confirmation", "" + ruleForm.getDocId()));
548:                saveErrors(request, messages);
549:                resetAfterRoute(ruleForm);
550:                return forward;
551:            }
552:
553:            public ActionForward save(ActionMapping mapping, ActionForm form,
554:                    HttpServletRequest request, HttpServletResponse response)
555:                    throws Exception {
556:                return route(mapping, form, request, response);
557:            }
558:
559:            public ActionForward routeRule(ActionErrors errors,
560:                    ActionMapping mapping, ActionForm form,
561:                    HttpServletRequest request, HttpServletResponse response,
562:                    boolean blanketApprove) throws Exception {
563:                Rule2Form ruleForm = (Rule2Form) form;
564:
565:                MyRules2 rules = ruleForm.getMyRules();
566:                if (rules.getRules().size() > 1) {
567:                    errors.add("hasErrors", new ActionMessage(
568:                            "rule.delegation.multipleRoute"));
569:                    saveErrors(request, errors);
570:                    return mapping.findForward("basic");
571:                }
572:                int ruleIndex = 0;
573:                for (Iterator iter = rules.getRules().iterator(); iter
574:                        .hasNext();) {
575:                    WebRuleBaseValues rule = (WebRuleBaseValues) iter.next();
576:                    rule.validateRule("myRules.rule[" + ruleIndex + "].",
577:                            errors);
578:                    ruleIndex++;
579:                }
580:                if (!errors.isEmpty()) {
581:                    errors.add("hasErrors", new ActionMessage(
582:                            "general.hasErrors"));
583:                    saveErrors(request, errors);
584:                    return mapping.findForward("basic");
585:                }
586:
587:                WebRuleBaseValues delegateRule = rules.getRule(0);
588:                delegateRule.setCurrentInd(Boolean.FALSE);
589:                boolean locked = false;
590:                if (delegateRule.getPreviousVersionId() != null) {
591:                    locked = checkLockedForRouting(errors, delegateRule);
592:                } else {
593:                    locked = checkLockedForRouting(errors, ruleForm
594:                            .getParentRule());
595:                }
596:                if (locked) {
597:                    saveErrors(request, errors);
598:                    return mapping.findForward("basic");
599:                }
600:
601:                // get the parent rule of the delegation-rule being submitted
602:                RuleBaseValues parentRule = getRuleService()
603:                        .findRuleBaseValuesById(
604:                                ruleForm.getParentRule().getRuleBaseValuesId());
605:                // new delegation rule
606:                //        if (delegateRule.getPreviousVersionId() == null) {
607:
608:                Long previousVersionId = parentRule.getRuleBaseValuesId();
609:
610:                RuleResponsibility delegateResponsibility = parentRule
611:                        .getResponsibility(ruleForm.getRuleCreationValues()
612:                                .getRuleResponsibilityKey());
613:
614:                RuleDelegation ruleDelegation = ruleForm.getRuleDelegation();
615:                ruleDelegation.setDelegationRuleBaseValues(delegateRule);
616:                ruleDelegation.setRuleResponsibility(delegateResponsibility);
617:
618:                if (delegateRule.getPreviousVersionId() != null) {
619:                    for (Iterator iter = delegateResponsibility
620:                            .getDelegationRules().iterator(); iter.hasNext();) {
621:                        RuleDelegation delegation = (RuleDelegation) iter
622:                                .next();
623:                        if (delegation.getDelegateRuleId().longValue() == delegateRule
624:                                .getPreviousVersionId().longValue()) {
625:                            iter.remove();
626:                            break;
627:                        }
628:                    }
629:                }
630:
631:                // add the new rule delegation to the responsibility
632:                delegateResponsibility.getDelegationRules().add(ruleDelegation);
633:
634:                // make a copy of the parent rule, which will be the new version
635:                // of the parent rule, that contains this new delegation
636:                parentRule = (RuleBaseValues) parentRule.copy(false);
637:                parentRule.setPreviousVersionId(previousVersionId);
638:                //        }
639:
640:                /*
641:                 * RuleBaseValues parentRule = getRuleService().findRuleBaseValuesById(ruleForm.getParentRule().getRuleBaseValuesId()); Long previousVersionId = parentRule.getRuleBaseValuesId(); RuleResponsibility delegateResponsibility = parentRule.getResponsibility(ruleForm.getRuleCreationValues().getRuleResponsibilityKey()); RuleDelegation ruleDelegation = ruleForm.getRuleDelegation(); ruleDelegation.setDelegationRuleBaseValues(delegateRule); ruleDelegation.setRuleResponsibility(delegateResponsibility); // replace the existing delegation in the parent rule boolean foundDelegation = false; int delIndex = 0; for (Iterator iterator = delegateResponsibility.getDelegationRules().iterator(); iterator.hasNext();) { RuleDelegation delegation = (RuleDelegation) iterator.next(); if (delegation.getDelegateRuleId().equals(delegateRule.getPreviousVersionId())) { iterator.remove(); foundDelegation = true; break; } delIndex++; } if (foundDelegation) {
642:                 * delegateResponsibility.getDelegationRules().add(delIndex, ruleDelegation); } else { delegateResponsibility.getDelegationRules().add(ruleDelegation); } parentRule = (RuleBaseValues) parentRule.copy(false); parentRule.setPreviousVersionId(previousVersionId);
643:                 */
644:
645:                // null out the responsibility keys for the delegate rule
646:                for (Iterator iterator = delegateRule.getResponsibilities()
647:                        .iterator(); iterator.hasNext();) {
648:                    RuleResponsibility responsibility = (RuleResponsibility) iterator
649:                            .next();
650:                    responsibility.setRuleResponsibilityKey(null);
651:                }
652:
653:                getRuleService().routeRuleWithDelegate(ruleForm.getDocId(),
654:                        parentRule, delegateRule,
655:                        getUserSession(request).getWorkflowUser(),
656:                        ruleForm.getAnnotation(), blanketApprove);
657:                ruleForm.setCurrentRuleId(delegateRule.getRuleBaseValuesId());
658:                return new Rule2Action().report(mapping, form, request,
659:                        response);
660:            }
661:
662:            private void resetAfterRoute(Rule2Form ruleForm) {
663:                ruleForm.getMyRules().getRules().clear();
664:                ruleForm.getRuleCreationValues().setCreating(true);
665:                ruleForm.setEditingDelegate(false);
666:                ruleForm.setDocId(null);
667:            }
668:
669:            public ActionForward refresh(ActionMapping mapping,
670:                    ActionForm form, HttpServletRequest request,
671:                    HttpServletResponse response) throws Exception {
672:                Rule2Form rule2Form = (Rule2Form) form;
673:                String ruleBaseValuesId = request
674:                        .getParameter("ruleBaseValuesId");
675:                if ("".equals(ruleBaseValuesId)) {
676:                    rule2Form.setParentRule(new WebRuleBaseValues());
677:                    rule2Form.getRuleCreationValues().setRuleId(null);
678:                } else if (ruleBaseValuesId != null) {
679:                    Long ruleId = new Long(ruleBaseValuesId);
680:                    RuleBaseValues rule = getRuleService()
681:                            .findRuleBaseValuesById(ruleId);
682:
683:                    if (rule.getDelegateRule().booleanValue()) {
684:                        ActionErrors errors = new ActionErrors();
685:                        errors
686:                                .add(
687:                                        "ruleCreationValues.ruleId",
688:                                        new ActionMessage(
689:                                                "routetemplate.select",
690:                                                "valid Delegating Rule.  The rule \""
691:                                                        + rule.getDescription()
692:                                                        + "\" is already a delegate rule"));
693:                        saveErrors(request, errors);
694:                        return mapping.findForward("basic");
695:                    }
696:                    //rule2Form.getParentRule().edit(rule);
697:                    rule2Form.getRuleCreationValues().setRuleId(ruleId);
698:                    rule2Form.setResponsibility(null);
699:                    initializeDelegationTemplate(rule2Form, rule);
700:                }
701:                String ruleTemplateIdValue = request
702:                        .getParameter("ruleTemplate.ruleTemplateId");
703:                if ("".equals(ruleTemplateIdValue)) {
704:                    rule2Form.getRuleCreationValues().setRuleTemplateId(null);
705:                    rule2Form.getRuleCreationValues().setRuleTemplateName("");
706:                    rule2Form.getRuleCreationValues()
707:                            .setManualDelegationTemplate(false);
708:                } else if (ruleTemplateIdValue != null) {
709:                    Long ruleTemplateId = new Long(ruleTemplateIdValue);
710:                    rule2Form.getRuleCreationValues().setRuleTemplateId(
711:                            ruleTemplateId);
712:                    RuleTemplate template = getRuleTemplateService()
713:                            .findByRuleTemplateId(
714:                                    rule2Form.getRuleCreationValues()
715:                                            .getRuleTemplateId());
716:                    rule2Form.getRuleCreationValues().setRuleTemplateName(
717:                            template.getName());
718:                    rule2Form.getRuleCreationValues()
719:                            .setManualDelegationTemplate(true);
720:                }
721:                establishRequiredState(request, form);
722:                return mapping.findForward("basic");
723:            }
724:
725:            private void createFlexDoc(HttpServletRequest request,
726:                    Rule2Form rule2Form, List rules) throws WorkflowException {
727:                if (rule2Form.getFlexDoc() == null) {
728:
729:                    //            rule2Form.setFlexDoc(new WorkflowDocument(EdenConstants.RULE_DOCUMENT_NAME, getUserSession(request).getWorkflowUser(), EdenConstants.EDEN_APP_CODE));
730:                    String ruleDocTypeName = getRuleService()
731:                            .getRuleDocmentTypeName(rules);
732:                    rule2Form.setFlexDoc(new WorkflowDocument(new WorkflowIdVO(
733:                            getUserSession(request).getWorkflowUser()
734:                                    .getWorkflowId()), ruleDocTypeName));
735:                    rule2Form.setDocId(rule2Form.getFlexDoc()
736:                            .getRouteHeaderId());
737:                    rule2Form.establishVisibleActionRequestCds();
738:                }
739:            }
740:
741:            private boolean checkLockedForRouting(ActionErrors errors,
742:                    RuleBaseValues rule) {
743:                if ("true".equalsIgnoreCase(Utilities
744:                        .getApplicationConstant(EdenConstants.RULE_LOCKING_ON))) {
745:                    Long id = rule.getRuleBaseValuesId();
746:                    if (id != null) {
747:                        Long routeHeaderId = getRuleService()
748:                                .isLockedForRouting(id);
749:                        if (routeHeaderId != null) {
750:                            errors.add("hasErrors", new ActionMessage(
751:                                    "routetemplate.RuleService.ruleInRoute", ""
752:                                            + routeHeaderId.longValue()));
753:                            return true;
754:                        }
755:                    }
756:                }
757:                return false;
758:            }
759:
760:            private void stripParentRule(RuleBaseValues parentRule,
761:                    RuleResponsibility ruleResponsibility) {
762:                for (Iterator iterator = parentRule.getResponsibilities()
763:                        .iterator(); iterator.hasNext();) {
764:                    RuleResponsibility responsibility = (RuleResponsibility) iterator
765:                            .next();
766:                    if (ruleResponsibility != null
767:                            && !responsibility
768:                                    .getRuleResponsibilityKey()
769:                                    .equals(
770:                                            ruleResponsibility
771:                                                    .getRuleResponsibilityKey())) {
772:                        iterator.remove();
773:                    } else {
774:                        responsibility.setDelegationRules(new ArrayList());
775:                    }
776:                }
777:            }
778:
779:            private void initializeDelegationTemplate(Rule2Form form,
780:                    RuleBaseValues rule) {
781:                RuleTemplate delegationTemplate = rule.getRuleTemplate()
782:                        .getDelegationTemplate();
783:                if (delegationTemplate != null
784:                        && !form.getRuleCreationValues()
785:                                .isManualDelegationTemplate()) {
786:                    form.getRuleCreationValues().setRuleTemplateId(
787:                            delegationTemplate.getRuleTemplateId());
788:                    form.getRuleCreationValues().setRuleTemplateName(
789:                            delegationTemplate.getName());
790:                }
791:            }
792:
793:            private ShowHideTree initializeShowHide(MyRules2 myRules) {
794:                ShowHideTree showHide = new ShowHideTree();
795:                for (Iterator ruleIt = myRules.getRules().iterator(); ruleIt
796:                        .hasNext();) {
797:                    RuleBaseValues rule = (RuleBaseValues) ruleIt.next();
798:                    initializeShowHide(showHide, rule);
799:                }
800:                return showHide;
801:            }
802:
803:            private ShowHideTree initializeShowHide(ShowHideTree showHide,
804:                    RuleBaseValues rule) {
805:                ShowHideTree ruleTree = showHide.append();
806:                for (Iterator respIt = rule.getResponsibilities().iterator(); respIt
807:                        .hasNext();) {
808:                    RuleResponsibility responsibility = (RuleResponsibility) respIt
809:                            .next();
810:                    ShowHideTree respTree = ruleTree.append();
811:                    for (Iterator delIt = responsibility.getDelegationRules()
812:                            .iterator(); delIt.hasNext();) {
813:                        RuleDelegation delegation = (RuleDelegation) delIt
814:                                .next();
815:                        ShowHideTree delTree = respTree.append();
816:                        for (Iterator delRespIt = delegation
817:                                .getDelegationRuleBaseValues()
818:                                .getResponsibilities().iterator(); delRespIt
819:                                .hasNext();) {
820:                            delRespIt.next();
821:                            delTree.append();
822:                        }
823:                    }
824:                }
825:                return ruleTree;
826:            }
827:
828:            private RuleService getRuleService() {
829:                return (RuleService) KEWServiceLocator
830:                        .getService(KEWServiceLocator.RULE_SERVICE);
831:            }
832:
833:            private RuleTemplateService getRuleTemplateService() {
834:                return (RuleTemplateService) KEWServiceLocator
835:                        .getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
836:            }
837:
838:            private RuleDelegationService getRuleDelegationService() {
839:                return (RuleDelegationService) KEWServiceLocator
840:                        .getService(KEWServiceLocator.RULE_DELEGATION_SERVICE);
841:            }
842:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.