Source Code Cross Referenced for WebRuleBaseValues.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.sql.Timestamp;
020:        import java.text.ParseException;
021:        import java.text.SimpleDateFormat;
022:        import java.util.ArrayList;
023:        import java.util.Calendar;
024:        import java.util.Collection;
025:        import java.util.Collections;
026:        import java.util.Date;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Map;
031:
032:        import org.apache.commons.beanutils.PropertyUtils;
033:        import org.apache.struts.action.ActionErrors;
034:        import org.apache.struts.action.ActionMessage;
035:
036:        import edu.iu.uis.eden.EdenConstants;
037:        import edu.iu.uis.eden.KEWServiceLocator;
038:        import edu.iu.uis.eden.WorkflowServiceError;
039:        import edu.iu.uis.eden.lookupable.Field;
040:        import edu.iu.uis.eden.lookupable.Row;
041:        import edu.iu.uis.eden.plugin.attributes.RoleAttribute;
042:        import edu.iu.uis.eden.plugin.attributes.WorkflowAttribute;
043:        import edu.iu.uis.eden.routetemplate.KeyValueId;
044:        import edu.iu.uis.eden.routetemplate.RuleAttribute;
045:        import edu.iu.uis.eden.routetemplate.RuleBaseValues;
046:        import edu.iu.uis.eden.routetemplate.RuleDelegation;
047:        import edu.iu.uis.eden.routetemplate.RuleDelegationService;
048:        import edu.iu.uis.eden.routetemplate.RuleExtension;
049:        import edu.iu.uis.eden.routetemplate.RuleExtensionValue;
050:        import edu.iu.uis.eden.routetemplate.RuleResponsibility;
051:        import edu.iu.uis.eden.routetemplate.RuleTemplate;
052:        import edu.iu.uis.eden.routetemplate.RuleTemplateAttribute;
053:        import edu.iu.uis.eden.routetemplate.RuleTemplateService;
054:        import edu.iu.uis.eden.routetemplate.xmlrouting.GenericXMLRuleAttribute;
055:        import edu.iu.uis.eden.util.CodeTranslator;
056:        import edu.iu.uis.eden.util.Utilities;
057:
058:        /**
059:         * A decorator around a {@link RuleBaseValues} object which provides some
060:         * convienance functions for interacting with the bean from the web-tier.
061:         * This helps to alleviate some of the weaknesses of JSTL.
062:         * 
063:         * @author ewestfal
064:         * @author jhopf
065:         */
066:        public class WebRuleBaseValues extends RuleBaseValues {
067:
068:            private static final long serialVersionUID = 5938997470219200474L;
069:            private static final int TO_DATE_UPPER_LIMIT = 2100;
070:            private List rows = new ArrayList();
071:            private List fields = new ArrayList();
072:            private List roles = new ArrayList();
073:            private String fromDateValue;
074:            private String toDateValue;
075:            private String ruleTemplateName;
076:            private boolean hasExtensionValueErrors = false;
077:
078:            public WebRuleBaseValues() {
079:            }
080:
081:            public WebRuleBaseValues(RuleBaseValues rule) throws Exception {
082:                edit(rule);
083:            }
084:
085:            private void loadFields() {
086:                fields.clear();
087:                if (getRuleTemplateId() != null) {
088:                    RuleTemplate ruleTemplate = getRuleTemplateService()
089:                            .findByRuleTemplateId(getRuleTemplateId());
090:                    if (ruleTemplate != null) {
091:                        List ruleTemplateAttributes = ruleTemplate
092:                                .getRuleTemplateAttributes();
093:                        Collections.sort(ruleTemplateAttributes);
094:                        for (Iterator iter = ruleTemplateAttributes.iterator(); iter
095:                                .hasNext();) {
096:                            RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
097:                                    .next();
098:                            if (!ruleTemplateAttribute.isWorkflowAttribute()) {
099:                                continue;
100:                            }
101:                            WorkflowAttribute workflowAttribute = ruleTemplateAttribute
102:                                    .getWorkflowAttribute();
103:                            RuleAttribute ruleAttribute = ruleTemplateAttribute
104:                                    .getRuleAttribute();
105:                            if (ruleAttribute.getType().equals(
106:                                    EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
107:                                ((GenericXMLRuleAttribute) workflowAttribute)
108:                                        .setRuleAttribute(ruleAttribute);
109:                            }
110:                            for (Iterator iterator = workflowAttribute
111:                                    .getRuleRows().iterator(); iterator
112:                                    .hasNext();) {
113:                                Row row = (Row) iterator.next();
114:                                for (Iterator rowIter = row.getFields()
115:                                        .iterator(); rowIter.hasNext();) {
116:                                    Field field = (Field) rowIter.next();
117:                                    if (ruleAttribute
118:                                            .getType()
119:                                            .equals(
120:                                                    EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
121:                                        String fieldValue = "";
122:                                        RuleExtensionValue extensionValue = getRuleExtensionValue(
123:                                                ruleTemplateAttribute
124:                                                        .getRuleTemplateAttributeId(),
125:                                                (String) field
126:                                                        .getPropertyName());
127:                                        if (extensionValue != null) {
128:                                            fieldValue = extensionValue
129:                                                    .getValue();
130:                                        } else {
131:                                            fieldValue = field
132:                                                    .getPropertyValue();
133:                                        }
134:                                        fields
135:                                                .add(new KeyValueId(
136:                                                        field.getPropertyName(),
137:                                                        fieldValue,
138:                                                        ruleTemplateAttribute
139:                                                                .getRuleTemplateAttributeId()
140:                                                                + ""));
141:                                    } else if (!Utilities.isEmpty(field
142:                                            .getDefaultLookupableName())) {
143:                                        String fieldValue = "";
144:                                        RuleExtensionValue extensionValue = getRuleExtensionValue(
145:                                                ruleTemplateAttribute
146:                                                        .getRuleTemplateAttributeId(),
147:                                                (String) field
148:                                                        .getDefaultLookupableName());
149:                                        if (extensionValue != null) {
150:                                            fieldValue = extensionValue
151:                                                    .getValue();
152:                                        } else {
153:                                            fieldValue = field
154:                                                    .getPropertyValue();
155:                                        }
156:                                        fields
157:                                                .add(new KeyValueId(
158:                                                        field
159:                                                                .getDefaultLookupableName(),
160:                                                        fieldValue,
161:                                                        ruleTemplateAttribute
162:                                                                .getRuleTemplateAttributeId()
163:                                                                + ""));
164:                                    } else {
165:                                        String fieldValue = "";
166:                                        RuleExtensionValue extensionValue = getRuleExtensionValue(
167:                                                ruleTemplateAttribute
168:                                                        .getRuleTemplateAttributeId(),
169:                                                (String) field
170:                                                        .getPropertyName());
171:                                        if (extensionValue != null) {
172:                                            fieldValue = extensionValue
173:                                                    .getValue();
174:                                        } else {
175:                                            fieldValue = field
176:                                                    .getPropertyValue();
177:                                        }
178:                                        fields
179:                                                .add(new KeyValueId(
180:                                                        field.getPropertyName(),
181:                                                        fieldValue,
182:                                                        ruleTemplateAttribute
183:                                                                .getRuleTemplateAttributeId()
184:                                                                + ""));
185:                                    }
186:
187:                                    // if (workflowAttribute.getFieldConversions() !=
188:                                    // null &&
189:                                    // !workflowAttribute.getFieldConversions().isEmpty())
190:                                    // {
191:                                    // boolean found = false;
192:                                    // for (Iterator iterator4 =
193:                                    // workflowAttribute.getFieldConversions().iterator();
194:                                    // iterator4.hasNext();) {
195:                                    // KeyLabelPair pair = (KeyLabelPair)
196:                                    // iterator4.next();
197:                                    // if
198:                                    // (pair.getLabel().equals(field.getPropertyName()))
199:                                    // {
200:                                    // String fieldValue = "";
201:                                    // RuleExtensionValue extensionValue =
202:                                    // getRuleExtensionValue((String) pair.getKey());
203:                                    // if (extensionValue != null) {
204:                                    // fieldValue = extensionValue.getValue();
205:                                    // }
206:                                    // fields.add(new KeyLabelPair(pair.getKey(),
207:                                    // fieldValue));
208:                                    // found = true;
209:                                    // break;
210:                                    // }
211:                                    // }
212:                                    // if (!found) {
213:                                    // String fieldValue = "";
214:                                    // RuleExtensionValue extensionValue =
215:                                    // getRuleExtensionValue((String)
216:                                    // field.getPropertyName());
217:                                    // if (extensionValue != null) {
218:                                    // fieldValue = extensionValue.getValue();
219:                                    // }
220:                                    // fields.add(new
221:                                    // KeyLabelPair(field.getPropertyName(),
222:                                    // fieldValue));
223:                                    // }
224:                                    // } else {
225:                                    // String fieldValue = "";
226:                                    // RuleExtensionValue extensionValue =
227:                                    // getRuleExtensionValue((String)
228:                                    // field.getPropertyName());
229:                                    // if (extensionValue != null) {
230:                                    // fieldValue = extensionValue.getValue();
231:                                    // }
232:                                    // fields.add(new
233:                                    // KeyLabelPair(field.getPropertyName(),
234:                                    // fieldValue));
235:                                    // }
236:                                }
237:                            }
238:                        }
239:                    }
240:                }
241:            }
242:
243:            public void loadFieldsWithDefaultValues() {
244:                fields.clear();
245:                if (getRuleTemplateId() != null) {
246:                    RuleTemplate ruleTemplate = getRuleTemplateService()
247:                            .findByRuleTemplateId(getRuleTemplateId());
248:                    if (ruleTemplate != null) {
249:                        List ruleTemplateAttributes = ruleTemplate
250:                                .getRuleTemplateAttributes();
251:                        Collections.sort(ruleTemplateAttributes);
252:                        for (Iterator iter = ruleTemplateAttributes.iterator(); iter
253:                                .hasNext();) {
254:                            RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
255:                                    .next();
256:                            if (!ruleTemplateAttribute.isWorkflowAttribute()) {
257:                                continue;
258:                            }
259:                            WorkflowAttribute workflowAttribute = ruleTemplateAttribute
260:                                    .getWorkflowAttribute();
261:                            RuleAttribute ruleAttribute = ruleTemplateAttribute
262:                                    .getRuleAttribute();
263:                            if (ruleAttribute.getType().equals(
264:                                    EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
265:                                ((GenericXMLRuleAttribute) workflowAttribute)
266:                                        .setRuleAttribute(ruleAttribute);
267:                            }
268:                            for (Iterator iterator = workflowAttribute
269:                                    .getRuleRows().iterator(); iterator
270:                                    .hasNext();) {
271:                                Row row = (Row) iterator.next();
272:                                for (Iterator rowIter = row.getFields()
273:                                        .iterator(); rowIter.hasNext();) {
274:                                    Field field = (Field) rowIter.next();
275:                                    if (ruleAttribute
276:                                            .getType()
277:                                            .equals(
278:                                                    EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
279:                                        fields
280:                                                .add(new KeyValueId(
281:                                                        field.getPropertyName(),
282:                                                        field
283:                                                                .getPropertyValue(),
284:                                                        ruleTemplateAttribute
285:                                                                .getRuleTemplateAttributeId()
286:                                                                + ""));
287:                                    } else if (!Utilities.isEmpty(field
288:                                            .getDefaultLookupableName())) {
289:                                        fields
290:                                                .add(new KeyValueId(
291:                                                        field
292:                                                                .getDefaultLookupableName(),
293:                                                        field
294:                                                                .getPropertyValue(),
295:                                                        ruleTemplateAttribute
296:                                                                .getRuleTemplateAttributeId()
297:                                                                + ""));
298:                                    } else {
299:                                        fields
300:                                                .add(new KeyValueId(
301:                                                        field.getPropertyName(),
302:                                                        field
303:                                                                .getPropertyValue(),
304:                                                        ruleTemplateAttribute
305:                                                                .getRuleTemplateAttributeId()
306:                                                                + ""));
307:                                    }
308:                                }
309:                            }
310:                        }
311:                    }
312:                }
313:            }
314:
315:            private void loadWebValues() {
316:                loadRows();
317:                loadDates();
318:                loadRuleTemplateName();
319:            }
320:
321:            private void loadRows() {
322:                getRoles().clear();
323:                if (getRuleTemplateId() != null) {
324:                    RuleTemplate ruleTemplate = getRuleTemplateService()
325:                            .findByRuleTemplateId(getRuleTemplateId());
326:                    if (ruleTemplate != null) {
327:                        setRuleTemplateName(ruleTemplate.getName());
328:                        List ruleTemplateAttributes = ruleTemplate
329:                                .getRuleTemplateAttributes();
330:                        Collections.sort(ruleTemplateAttributes);
331:                        List rows = new ArrayList();
332:                        for (Iterator iter = ruleTemplateAttributes.iterator(); iter
333:                                .hasNext();) {
334:                            RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter
335:                                    .next();
336:                            if (!ruleTemplateAttribute.isWorkflowAttribute()) {
337:                                continue;
338:                            }
339:                            WorkflowAttribute workflowAttribute = ruleTemplateAttribute
340:                                    .getWorkflowAttribute();
341:
342:                            RuleAttribute ruleAttribute = ruleTemplateAttribute
343:                                    .getRuleAttribute();
344:                            if (ruleAttribute.getType().equals(
345:                                    EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
346:                                ((GenericXMLRuleAttribute) workflowAttribute)
347:                                        .setRuleAttribute(ruleAttribute);
348:                            }
349:                            workflowAttribute
350:                                    .validateRuleData(getFieldMap(ruleTemplateAttribute
351:                                            .getRuleTemplateAttributeId()
352:                                            + ""));
353:                            rows.addAll(workflowAttribute.getRuleRows());
354:                            if (workflowAttribute instanceof  RoleAttribute) {
355:                                RoleAttribute roleAttribute = (RoleAttribute) workflowAttribute;
356:                                getRoles().addAll(roleAttribute.getRoleNames());
357:                            }
358:                        }
359:                        setRows(rows);
360:                    }
361:                }
362:            }
363:
364:            private void loadDates() {
365:                if (getFromDate() != null) {
366:                    setFromDateValue(EdenConstants.getDefaultDateFormat()
367:                            .format(getFromDate()));
368:                }
369:                if (getToDate() != null) {
370:                    setToDateValue(EdenConstants.getDefaultDateFormat().format(
371:                            getToDate()));
372:                }
373:            }
374:
375:            private void loadRuleTemplateName() {
376:                if (Utilities.isEmpty(getRuleTemplateName())
377:                        && getRuleTemplateId() != null) {
378:                    RuleTemplate ruleTemplate = getRuleTemplateService()
379:                            .findByRuleTemplateId(getRuleTemplateId());
380:                    if (ruleTemplate != null) {
381:                        setRuleTemplateName(ruleTemplate.getName());
382:                    }
383:                }
384:            }
385:
386:            public List getFields() {
387:                return fields;
388:            }
389:
390:            public void setFields(List fields) {
391:                this .fields = fields;
392:            }
393:
394:            public KeyValueId getField(int index) {
395:                while (getFields().size() <= index) {
396:                    KeyValueId field = new KeyValueId();
397:                    getFields().add(field);
398:                }
399:                return (KeyValueId) getFields().get(index);
400:            }
401:
402:            public String getFromDateValue() {
403:                return fromDateValue;
404:            }
405:
406:            public void setFromDateValue(String fromDateValue) {
407:                this .fromDateValue = fromDateValue;
408:            }
409:
410:            public List getRoles() {
411:                return roles;
412:            }
413:
414:            public void setRoles(List roles) {
415:                this .roles = roles;
416:            }
417:
418:            public List getRows() {
419:                return rows;
420:            }
421:
422:            public void setRows(List ruleTemplateAttributes) {
423:                this .rows = ruleTemplateAttributes;
424:            }
425:
426:            public String getToDateValue() {
427:                return toDateValue;
428:            }
429:
430:            public void setToDateValue(String toDateValue) {
431:                this .toDateValue = toDateValue;
432:            }
433:
434:            public String getRuleTemplateName() {
435:                return ruleTemplateName;
436:            }
437:
438:            public void setRuleTemplateName(String ruleTemplateName) {
439:                this .ruleTemplateName = ruleTemplateName;
440:            }
441:
442:            public boolean isHasExtensionValueErrors() {
443:                return hasExtensionValueErrors;
444:            }
445:
446:            public void setHasExtensionValueErrors(
447:                    boolean hasRuleExtensionValueErrors) {
448:                this .hasExtensionValueErrors = hasRuleExtensionValueErrors;
449:            }
450:
451:            /** Web Logic * */
452:
453:            /**
454:             * Populates this WebRuleBaseValues object for editing the given rule.
455:             */
456:            public void edit(RuleBaseValues rule) throws Exception {
457:                load(rule);
458:                initialize();
459:            }
460:
461:            /**
462:             * Loads the given rule into this WebRuleBaseValues.
463:             */
464:            public void load(RuleBaseValues rule) throws Exception {
465:                PropertyUtils.copyProperties(this , rule);
466:                injectWebMembers();
467:            }
468:
469:            public void initialize() throws Exception {
470:                loadFields();
471:                // setPreviousVersionId(getRuleBaseValuesId());
472:                for (Iterator iterator = getResponsibilities().iterator(); iterator
473:                        .hasNext();) {
474:                    WebRuleResponsibility responsibility = (WebRuleResponsibility) iterator
475:                            .next();
476:                    responsibility.initialize();
477:                }
478:                establishRequiredState();
479:            }
480:
481:            private void injectWebMembers() throws Exception {
482:                List currentResponsibilities = getResponsibilities();
483:                setResponsibilities(new ArrayList());
484:                for (Iterator iterator = currentResponsibilities.iterator(); iterator
485:                        .hasNext();) {
486:                    RuleResponsibility responsibility = (RuleResponsibility) iterator
487:                            .next();
488:                    WebRuleResponsibility webResponsibility = createNewRuleResponsibility();
489:                    webResponsibility.load(responsibility);
490:                }
491:            }
492:
493:            /**
494:             * Establishes any missing and required state in the WebRuleBaseValues.
495:             */
496:            public void establishRequiredState() throws Exception {
497:                if (getActiveInd() == null) {
498:                    setActiveInd(Boolean.TRUE);
499:                }
500:                if (getIgnorePrevious() == null) {
501:                    setIgnorePrevious(Boolean.FALSE);
502:                }
503:                loadWebValues();
504:                if (getResponsibilities().isEmpty()) {
505:                    createNewRuleResponsibility();
506:                }
507:                for (Iterator iterator = getResponsibilities().iterator(); iterator
508:                        .hasNext();) {
509:                    WebRuleResponsibility responsibility = (WebRuleResponsibility) iterator
510:                            .next();
511:                    responsibility.establishRequiredState();
512:                }
513:            }
514:
515:            public RuleResponsibility getResponsibility(int index) {
516:                while (getResponsibilities().size() <= index) {
517:                    createNewRuleResponsibility();
518:                }
519:                return (RuleResponsibility) getResponsibilities().get(index);
520:            }
521:
522:            public int getResponsibilitiesSize() {
523:                return getResponsibilities().size();
524:            }
525:
526:            public WebRuleResponsibility createNewRuleResponsibility() {
527:                WebRuleResponsibility responsibility = new WebRuleResponsibility();
528:                responsibility.setRuleBaseValues(this );
529:                addRuleResponsibility(responsibility);
530:                return responsibility;
531:            }
532:
533:            public Map getFieldMap(String ruleTemplateAttributeId) {
534:                Map fieldMap = new HashMap();
535:                for (Iterator iterator = getFields().iterator(); iterator
536:                        .hasNext();) {
537:                    KeyValueId field = (KeyValueId) iterator.next();
538:                    if (ruleTemplateAttributeId.equals(field.getId())) {
539:                        fieldMap.put(field.getKey(), field.getValue());
540:                    }
541:                }
542:                return fieldMap;
543:            }
544:
545:            public void populatePreviousVersionIds() {
546:                if (getPreviousVersionId() == null) {
547:                    setPreviousVersionId(getRuleBaseValuesId());
548:                }
549:                for (Iterator respIt = getResponsibilities().iterator(); respIt
550:                        .hasNext();) {
551:                    WebRuleResponsibility responsibility = (WebRuleResponsibility) respIt
552:                            .next();
553:                    responsibility.populatePreviousVersionIds();
554:                }
555:            }
556:
557:            /**
558:             * This method is used to "materialize" the web rule before it gets saved, if we don't do this then certain fields will be saved as NULL. For example, ruleTemplate.
559:             */
560:            public void materialize() {
561:                if (getRuleTemplate() == null && getRuleTemplateId() != null) {
562:                    setRuleTemplate(getRuleTemplateService()
563:                            .findByRuleTemplateId(getRuleTemplateId()));
564:                }
565:            }
566:
567:            public void validateRule(String keyPrefix, ActionErrors errors) {
568:                /** Validate Template * */
569:                if (getRuleTemplateId() == null) {
570:                    errors.add(keyPrefix + "ruleTemplateId", new ActionMessage(
571:                            "routetemplate.required.html", "rule template"));
572:                } else {
573:                    List errorList = new ArrayList();
574:                    populateRuleExtensionValues(errorList);
575:                    saveServiceErrors(keyPrefix + "ruleExtensionValues",
576:                            errorList, errors);
577:                    if (!errorList.isEmpty()) {
578:                        setHasExtensionValueErrors(true);
579:                    }
580:                }
581:
582:                /** Validate dates * */
583:
584:                boolean dateParseProblem = false;
585:                try {
586:                    setToDate(decodeTimestamp(getToDateValue()));
587:                } catch (ParseException e) {
588:                    errors.add(keyPrefix + "toDateValue", new ActionMessage(
589:                            "routetemplate.required.html",
590:                            "to date (MM/DD/YYYY)"));
591:                    dateParseProblem = true;
592:                }
593:                try {
594:                    setFromDate(decodeTimestamp(getFromDateValue()));
595:                } catch (ParseException e) {
596:                    errors.add(keyPrefix + "fromDateValue", new ActionMessage(
597:                            "routetemplate.required.html",
598:                            "from date (MM/DD/YYYY)"));
599:                    dateParseProblem = true;
600:                }
601:                throttleDates();
602:                if (getFromDate() == null) {
603:                    setFromDate(new Timestamp(new Date().getTime()));
604:                }
605:                if (getToDate() == null) {
606:                    try {
607:                        setToDate(new Timestamp(new SimpleDateFormat(
608:                                "MM/dd/yyyy").parse("01/01/2100").getTime()));
609:                    } catch (ParseException e) {
610:                        errors.add(keyPrefix + "toDateValue",
611:                                new ActionMessage(
612:                                        "routetemplate.required.html",
613:                                        "to date"));
614:                        dateParseProblem = true;
615:                    }
616:                }
617:                if (!dateParseProblem && getToDate().before(getFromDate())) {
618:                    errors.add(keyPrefix + "toDateValue", new ActionMessage(
619:                            "routetemplate.ruleservice.daterange.fromafterto"));
620:                }
621:
622:                if (getActiveInd() == null) {
623:                    errors.add(keyPrefix + "activeInd", new ActionMessage(
624:                            "routetemplate.ruleservice.activeind.required"));
625:                }
626:
627:                if (Utilities.isEmpty(getDescription())) {
628:                    errors.add(keyPrefix + "description", new ActionMessage(
629:                            "routetemplate.ruleservice.description.required"));
630:                }
631:
632:                if (getIgnorePrevious() == null) {
633:                    errors
634:                            .add(
635:                                    keyPrefix + "ignorePrevious",
636:                                    new ActionMessage(
637:                                            "routetemplate.ruleservice.ignoreprevious.required"));
638:                }
639:
640:                if (getResponsibilities().isEmpty()) {
641:                    errors
642:                            .add(
643:                                    keyPrefix + "responsibilities",
644:                                    new ActionMessage(
645:                                            "routetemplate.ruleservice.responsibility.required"));
646:                }
647:
648:                int respIndex = 0;
649:                for (Iterator iterator = getResponsibilities().iterator(); iterator
650:                        .hasNext();) {
651:                    WebRuleResponsibility responsibility = (WebRuleResponsibility) iterator
652:                            .next();
653:                    String respPrefix = keyPrefix + "responsibility["
654:                            + respIndex + "].";
655:                    responsibility.validateResponsibility(respPrefix, errors);
656:                    respIndex++;
657:                }
658:            }
659:
660:            /**
661:             * This will ensure that the toDate is never larger than 2100, currently
662:             * doesn't do any throttling on the from date
663:             */
664:            private void throttleDates() {
665:                if (getToDate() != null) {
666:                    Calendar calendar = Calendar.getInstance();
667:                    calendar.setTime(getToDate());
668:                    if (calendar.get(Calendar.YEAR) > TO_DATE_UPPER_LIMIT) {
669:                        calendar.set(Calendar.YEAR, TO_DATE_UPPER_LIMIT);
670:                        setToDate(new Timestamp(calendar.getTimeInMillis()));
671:                        setToDateValue(new SimpleDateFormat("MM/dd/yyyy")
672:                                .format(getToDate()));
673:                    }
674:                }
675:            }
676:
677:            private void saveServiceErrors(String errorKey,
678:                    Collection srvErrors, ActionErrors errors) {
679:                for (Iterator iterator = srvErrors.iterator(); iterator
680:                        .hasNext();) {
681:                    WorkflowServiceError error = (WorkflowServiceError) iterator
682:                            .next();
683:                    if (error.getArg1() == null && error.getArg2() == null) {
684:                        errors.add(errorKey, new ActionMessage(error.getKey()));
685:                    } else if (error.getArg1() != null
686:                            && error.getArg2() == null) {
687:                        errors.add(errorKey, new ActionMessage(error.getKey(),
688:                                error.getArg1()));
689:                    } else {
690:                        errors.add(errorKey, new ActionMessage(error.getKey(),
691:                                error.getArg1(), error.getArg2()));
692:                    }
693:                }
694:            }
695:
696:            private Timestamp decodeTimestamp(String dateValue)
697:                    throws ParseException {
698:                if (Utilities.isEmpty(dateValue)) {
699:                    return null;
700:                }
701:                Date date = EdenConstants.getDefaultDateFormat().parse(
702:                        dateValue);
703:                return new Timestamp(date.getTime());
704:            }
705:
706:            private void populateRuleExtensionValues(List errorList) {
707:                RuleTemplate ruleTemplate = getRuleTemplateService()
708:                        .findByRuleTemplateId(getRuleTemplateId());
709:                setRuleTemplate(ruleTemplate);
710:
711:                /** Populate rule extension values * */
712:                List extensions = new ArrayList();
713:                for (Iterator iterator = ruleTemplate
714:                        .getRuleTemplateAttributes().iterator(); iterator
715:                        .hasNext();) {
716:                    RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iterator
717:                            .next();
718:                    if (!ruleTemplateAttribute.isWorkflowAttribute()) {
719:                        continue;
720:                    }
721:                    WorkflowAttribute workflowAttribute = ruleTemplateAttribute
722:                            .getWorkflowAttribute();
723:
724:                    RuleAttribute ruleAttribute = ruleTemplateAttribute
725:                            .getRuleAttribute();
726:                    if (ruleAttribute.getType().equals(
727:                            EdenConstants.RULE_XML_ATTRIBUTE_TYPE)) {
728:                        ((GenericXMLRuleAttribute) workflowAttribute)
729:                                .setRuleAttribute(ruleAttribute);
730:                    }
731:
732:                    List attValidationErrors = workflowAttribute
733:                            .validateRuleData(getFieldMap(ruleTemplateAttribute
734:                                    .getRuleTemplateAttributeId()
735:                                    + ""));
736:                    if (attValidationErrors != null
737:                            && !attValidationErrors.isEmpty()) {
738:                        errorList.addAll(attValidationErrors);
739:                    } else {
740:                        List ruleExtensionValues = workflowAttribute
741:                                .getRuleExtensionValues();
742:                        if (ruleExtensionValues != null
743:                                && !ruleExtensionValues.isEmpty()) {
744:                            RuleExtension ruleExtension = new RuleExtension();
745:                            ruleExtension
746:                                    .setRuleTemplateAttributeId(ruleTemplateAttribute
747:                                            .getRuleTemplateAttributeId());
748:
749:                            ruleExtension
750:                                    .setExtensionValues(ruleExtensionValues);
751:                            extensions.add(ruleExtension);
752:                        }
753:                    }
754:                }
755:                setRuleExtensions(extensions);
756:                setRuleTemplate(ruleTemplate);
757:
758:                for (Iterator iterator = getRuleExtensions().iterator(); iterator
759:                        .hasNext();) {
760:                    RuleExtension ruleExtension = (RuleExtension) iterator
761:                            .next();
762:                    ruleExtension.setRuleBaseValues(this );
763:
764:                    for (Iterator iterator2 = ruleTemplate
765:                            .getRuleTemplateAttributes().iterator(); iterator2
766:                            .hasNext();) {
767:                        RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iterator2
768:                                .next();
769:                        if (ruleTemplateAttribute.getRuleTemplateAttributeId()
770:                                .longValue() == ruleExtension
771:                                .getRuleTemplateAttributeId().longValue()) {
772:                            ruleExtension
773:                                    .setRuleTemplateAttribute(ruleTemplateAttribute);
774:                            break;
775:                        }
776:                    }
777:
778:                    for (Iterator iterator2 = ruleExtension
779:                            .getExtensionValues().iterator(); iterator2
780:                            .hasNext();) {
781:                        RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) iterator2
782:                                .next();
783:                        ruleExtensionValue.setExtension(ruleExtension);
784:                    }
785:                }
786:
787:            }
788:
789:            private RuleTemplateService getRuleTemplateService() {
790:                return (RuleTemplateService) KEWServiceLocator
791:                        .getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
792:            }
793:
794:            /**
795:             * @return Returns the actionRequestCodes.
796:             */
797:            public Map getActionRequestCodes() {
798:                Map actionRequestCodes = new HashMap();
799:                actionRequestCodes.putAll(CodeTranslator.arLabels);
800:                if (getRuleTemplateId() != null) {
801:                    RuleTemplate ruleTemplate = getRuleTemplateService()
802:                            .findByRuleTemplateId(getRuleTemplateId());
803:                    if (ruleTemplate != null) {
804:                        if (ruleTemplate.getAcknowledge() != null
805:                                && "false".equals(ruleTemplate.getAcknowledge()
806:                                        .getValue())) {
807:                            actionRequestCodes
808:                                    .remove(EdenConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ);
809:                        }
810:                        if (ruleTemplate.getComplete() != null
811:                                && "false".equals(ruleTemplate.getComplete()
812:                                        .getValue())) {
813:                            actionRequestCodes
814:                                    .remove(EdenConstants.ACTION_REQUEST_COMPLETE_REQ);
815:                        }
816:                        if (ruleTemplate.getApprove() != null
817:                                && "false".equals(ruleTemplate.getApprove()
818:                                        .getValue())) {
819:                            actionRequestCodes
820:                                    .remove(EdenConstants.ACTION_REQUEST_APPROVE_REQ);
821:                        }
822:                        if (ruleTemplate.getFyi() != null
823:                                && "false".equals(ruleTemplate.getFyi()
824:                                        .getValue())) {
825:                            actionRequestCodes
826:                                    .remove(EdenConstants.ACTION_REQUEST_FYI_REQ);
827:                        }
828:                    }
829:                }
830:                return actionRequestCodes;
831:            }
832:
833:            public String getRuleInstructions() {
834:                String instructions = null;
835:                if (getRuleTemplateId() != null) {
836:                    RuleTemplate ruleTemplate = getRuleTemplateService()
837:                            .findByRuleTemplateId(getRuleTemplateId());
838:                    if (ruleTemplate != null) {
839:                        if (ruleTemplate.getInstructions() != null
840:                                && ruleTemplate.getInstructions().getValue() != null) {
841:                            instructions = ruleTemplate.getInstructions()
842:                                    .getValue();
843:                        }
844:                    }
845:                }
846:                return instructions;
847:            }
848:
849:            public RuleDelegation getRuleDelegation() {
850:                if (getDelegateRule().booleanValue()) {
851:                    List ruleDelegations = getRuleDelegationService()
852:                            .findByDelegateRuleId(getRuleBaseValuesId());
853:                    RuleDelegation currentRuleDelegation = (RuleDelegation) ruleDelegations
854:                            .get(0);
855:                    RuleBaseValues mostRecentRule = currentRuleDelegation
856:                            .getRuleResponsibility().getRuleBaseValues();
857:
858:                    for (Iterator iter = ruleDelegations.iterator(); iter
859:                            .hasNext();) {
860:                        RuleDelegation ruleDelegation = (RuleDelegation) iter
861:                                .next();
862:                        RuleBaseValues parentRule = ruleDelegation
863:                                .getRuleResponsibility().getRuleBaseValues();
864:
865:                        if (parentRule.getActivationDate().after(
866:                                mostRecentRule.getActivationDate())) {
867:                            mostRecentRule = ruleDelegation
868:                                    .getRuleResponsibility()
869:                                    .getRuleBaseValues();
870:                            currentRuleDelegation = ruleDelegation;
871:                        }
872:                    }
873:                    return currentRuleDelegation;
874:                }
875:                return null;
876:            }
877:
878:            public Long getParentRuleId() {
879:                if (getDelegateRule().booleanValue()) {
880:                    List ruleDelegations = getRuleDelegationService()
881:                            .findByDelegateRuleId(getRuleBaseValuesId());
882:                    RuleDelegation currentRuleDelegation = (RuleDelegation) ruleDelegations
883:                            .get(0);
884:                    RuleBaseValues mostRecentRule = currentRuleDelegation
885:                            .getRuleResponsibility().getRuleBaseValues();
886:
887:                    for (Iterator iter = ruleDelegations.iterator(); iter
888:                            .hasNext();) {
889:                        RuleDelegation ruleDelegation = (RuleDelegation) iter
890:                                .next();
891:                        RuleBaseValues parentRule = ruleDelegation
892:                                .getRuleResponsibility().getRuleBaseValues();
893:
894:                        if (parentRule.getActivationDate().after(
895:                                mostRecentRule.getActivationDate())) {
896:                            mostRecentRule = ruleDelegation
897:                                    .getRuleResponsibility()
898:                                    .getRuleBaseValues();
899:                        }
900:                    }
901:                    return mostRecentRule.getRuleBaseValuesId();
902:                }
903:                return null;
904:            }
905:
906:            private RuleDelegationService getRuleDelegationService() {
907:                return (RuleDelegationService) KEWServiceLocator
908:                        .getService(KEWServiceLocator.RULE_DELEGATION_SERVICE);
909:            }
910:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.