Source Code Cross Referenced for UniversalUserRule.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » core » rules » 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 » org.kuali.core.rules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.core.rules;
017:
018:        import java.util.HashMap;
019:        import java.util.List;
020:        import java.util.Map;
021:
022:        import org.kuali.RiceConstants;
023:        import org.kuali.RiceKeyConstants;
024:        import org.kuali.core.KualiModule;
025:        import org.kuali.core.bo.user.UniversalUser;
026:        import org.kuali.core.document.MaintenanceDocument;
027:        import org.kuali.core.maintenance.rules.MaintenanceDocumentRule;
028:        import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
029:        import org.kuali.core.rule.event.ApproveDocumentEvent;
030:        import org.kuali.core.util.GlobalVariables;
031:        import org.kuali.core.web.format.PhoneNumberFormatter;
032:        import org.kuali.rice.KNSServiceLocator;
033:
034:        public class UniversalUserRule extends MaintenanceDocumentRuleBase {
035:
036:            private UniversalUser oldUser;
037:            private UniversalUser newUser;
038:
039:            private static final PhoneNumberFormatter phoneNumberFormatter = new PhoneNumberFormatter();
040:
041:            private static String userEditWorkgroupName;
042:            private static List<KualiModule> installedModules;
043:
044:            protected boolean processCustomRouteDocumentBusinessRules(
045:                    MaintenanceDocument document) {
046:                boolean success = true;
047:                setupConvenienceObjects(document);
048:                // get the group name that we need here
049:                // only check if the user can modify the universal user attributes
050:                if (GlobalVariables.getUserSession().getUniversalUser()
051:                        .isMember(userEditWorkgroupName)) {
052:                    success &= checkGeneralRules(document);
053:                }
054:                MaintenanceDocumentRule rule = null;
055:                for (KualiModule module : installedModules) {
056:                    rule = module.getModuleUserRule();
057:                    if (rule != null) {
058:                        success &= rule.processRouteDocument(document);
059:                    }
060:                }
061:                return success;
062:            }
063:
064:            protected boolean processCustomSaveDocumentBusinessRules(
065:                    MaintenanceDocument document) {
066:                boolean success = true;
067:                setupConvenienceObjects(document);
068:                // only check if the user can modify the universal user attributes
069:                if (GlobalVariables.getUserSession().getUniversalUser()
070:                        .isMember(userEditWorkgroupName)) {
071:                    success &= checkGeneralRules(document);
072:                }
073:                // save always succeeds even if there are rule violations
074:                MaintenanceDocumentRule rule = null;
075:                for (KualiModule module : installedModules) {
076:                    rule = module.getModuleUserRule();
077:                    if (rule != null) {
078:                        success &= rule.processSaveDocument(document);
079:                    }
080:                }
081:                return true;
082:            }
083:
084:            /**
085:             * 
086:             * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
087:             * old objects contained in the maintenance document.
088:             * 
089:             * It also calls the BusinessObjectBase.refresh(), which will attempt to load all sub-objects from the DB by their primary keys,
090:             * if available.
091:             * 
092:             * @param document - the maintenanceDocument being evaluated
093:             * 
094:             */
095:            private void setupConvenienceObjects(MaintenanceDocument document) {
096:
097:                // setup oldAccount convenience objects, make sure all possible sub-objects are populated
098:                oldUser = (UniversalUser) document.getOldMaintainableObject()
099:                        .getBusinessObject();
100:                oldUser.refresh();
101:
102:                // setup newAccount convenience objects, make sure all possible sub-objects are populated
103:                newUser = (UniversalUser) document.getNewMaintainableObject()
104:                        .getBusinessObject();
105:                newUser.refresh();
106:
107:                if (userEditWorkgroupName == null) {
108:                    userEditWorkgroupName = configService
109:                            .getParameterValue(
110:                                    RiceConstants.KNS_NAMESPACE,
111:                                    RiceConstants.DetailTypes.UNIVERSAL_USER_DETAIL_TYPE,
112:                                    RiceConstants.CoreApcParms.UNIVERSAL_USER_EDIT_WORKGROUP);
113:                    installedModules = KNSServiceLocator
114:                            .getKualiModuleService().getInstalledModules();
115:                }
116:            }
117:
118:            private boolean checkGeneralRules(MaintenanceDocument document) {
119:
120:                boolean success = true;
121:
122:                //KULCOA-1164: Validation phone number
123:
124:                String phoneNumber = newUser.getPersonLocalPhoneNumber();
125:                try {
126:                    newUser
127:                            .setPersonLocalPhoneNumber((String) phoneNumberFormatter
128:                                    .convertFromPresentationFormat(newUser
129:                                            .getPersonLocalPhoneNumber()));
130:                } catch (Exception e) {
131:                    putFieldError("personLocalPhoneNumber",
132:                            RiceKeyConstants.ERROR_INVALID_FORMAT,
133:                            new String[] { "Local Phone Number", phoneNumber });
134:                    success = false;
135:                }
136:
137:                if (oldUser == null) {
138:                    oldUser = new UniversalUser();
139:                }
140:
141:                // KULCOA-1164: Check whether User Id is unique or not
142:
143:                String userId = newUser.getPersonUserIdentifier();
144:                if (userId != null
145:                        && (!userId.equals(oldUser.getPersonUserIdentifier()) || "Copy"
146:                                .equals(document.getNewMaintainableObject()
147:                                        .getMaintenanceAction()))) {
148:                    if (userExists("personUserIdentifier", userId)) {
149:                        putFieldError(
150:                                "personUserIdentifier",
151:                                RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_KEYS_ALREADY_EXIST_ON_CREATE_NEW,
152:                                userId);
153:                        success = false;
154:                    }
155:                }
156:
157:                String emplId = newUser.getPersonPayrollIdentifier();
158:                // KULCOA-1164: Check whether Employee Id is unique or not
159:                if (emplId != null
160:                        && (!emplId
161:                                .equals(oldUser.getPersonPayrollIdentifier()) || "Copy"
162:                                .equals(document.getNewMaintainableObject()
163:                                        .getMaintenanceAction()))) {
164:                    if (userExists("personPayrollIdentifier", newUser
165:                            .getPersonPayrollIdentifier())) {
166:                        putFieldError(
167:                                "personPayrollIdentifier",
168:                                RiceKeyConstants.ERROR_DOCUMENT_KUALIUSERMAINT_UNIQUE_EMPLID);
169:                        success = false;
170:                    }
171:                }
172:
173:                return success;
174:            }
175:
176:            private boolean userExists(String field, String value) {
177:
178:                Map searchMap = new HashMap();
179:                searchMap.put(field, value);
180:
181:                return universalUserService.findUniversalUsers(searchMap)
182:                        .size() > 0;
183:
184:            }
185:
186:            @Override
187:            public boolean processApproveDocument(
188:                    ApproveDocumentEvent approveEvent) {
189:                boolean success = super .processApproveDocument(approveEvent);
190:
191:                // remove all items from the errorPath temporarily (because it may not
192:                // be what we expect, or what we need)
193:                clearErrorPath();
194:
195:                // loop over all installed modules and run their user rules
196:                MaintenanceDocumentRule rule = null;
197:                for (KualiModule module : installedModules) {
198:                    rule = module.getModuleUserRule();
199:                    if (rule != null) {
200:                        success &= rule.processApproveDocument(approveEvent);
201:                    }
202:                }
203:
204:                // return the original set of items to the errorPath, to ensure no impact
205:                // on other upstream or downstream items that rely on the errorPath
206:                resumeErrorPath();
207:
208:                return success;
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.