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


001:        /*
002:         * Copyright 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.lookup;
017:
018:        import java.sql.Timestamp;
019:        import java.util.ArrayList;
020:        import java.util.Collection;
021:        import java.util.HashMap;
022:        import java.util.List;
023:        import java.util.Map;
024:        import java.util.Set;
025:
026:        import org.apache.commons.codec.binary.Base64;
027:        import org.kuali.RiceConstants;
028:        import org.kuali.RicePropertyConstants;
029:        import org.kuali.core.bo.LookupResults;
030:        import org.kuali.core.bo.MultipleValueLookupMetadata;
031:        import org.kuali.core.bo.PersistableBusinessObject;
032:        import org.kuali.core.bo.SelectedObjectIds;
033:        import org.kuali.core.dao.PersistedLookupMetadataDao;
034:        import org.kuali.core.exceptions.AuthorizationException;
035:        import org.kuali.core.service.BusinessObjectService;
036:        import org.kuali.core.util.ObjectUtils;
037:        import org.kuali.core.web.ui.ResultRow;
038:        import org.kuali.rice.KNSServiceLocator;
039:        import org.springframework.transaction.annotation.Transactional;
040:
041:        @Transactional
042:        public class LookupResultsServiceImpl implements  LookupResultsService {
043:            private BusinessObjectService businessObjectService;
044:            private PersistedLookupMetadataDao persistedLookupMetadataDao;
045:
046:            /**
047:             * @see org.kuali.core.lookup.LookupResultsService#persistResultsTable(java.lang.String, java.util.List, java.lang.String)
048:             */
049:            public void persistResultsTable(String lookupResultsSequenceNumber,
050:                    List<ResultRow> resultTable, String universalUserId)
051:                    throws Exception {
052:                String resultTableString = new String(Base64
053:                        .encodeBase64(ObjectUtils.toByteArray(resultTable)));
054:
055:                Timestamp now = KNSServiceLocator.getDateTimeService()
056:                        .getCurrentTimestamp();
057:
058:                LookupResults lookupResults = retrieveLookupResults(lookupResultsSequenceNumber);
059:                if (lookupResults == null) {
060:                    lookupResults = new LookupResults();
061:                    lookupResults
062:                            .setLookupResultsSequenceNumber(lookupResultsSequenceNumber);
063:                }
064:                lookupResults
065:                        .setLookupResultsSequenceNumber(lookupResultsSequenceNumber);
066:                lookupResults.setLookupUniversalUserId(universalUserId);
067:                lookupResults.setSerializedLookupResults(resultTableString);
068:                lookupResults.setLookupDate(now);
069:                businessObjectService.save(lookupResults);
070:            }
071:
072:            /**
073:             * @see org.kuali.core.lookup.LookupResultsService#persistSelectedObjectIds(java.lang.String, java.util.Set, java.lang.String)
074:             */
075:            public void persistSelectedObjectIds(
076:                    String lookupResultsSequenceNumber,
077:                    Set<String> selectedObjectIds, String universalUserId)
078:                    throws Exception {
079:                SelectedObjectIds selectedObjectIdsBO = retrieveSelectedObjectIds(lookupResultsSequenceNumber);
080:                if (selectedObjectIdsBO == null) {
081:                    selectedObjectIdsBO = new SelectedObjectIds();
082:                    selectedObjectIdsBO
083:                            .setLookupResultsSequenceNumber(lookupResultsSequenceNumber);
084:                }
085:                selectedObjectIdsBO
086:                        .setLookupResultsSequenceNumber(lookupResultsSequenceNumber);
087:                selectedObjectIdsBO.setLookupUniversalUserId(universalUserId);
088:                selectedObjectIdsBO.setSelectedObjectIds(LookupUtils
089:                        .convertSetOfObjectIdsToString(selectedObjectIds));
090:                selectedObjectIdsBO.setLookupDate(KNSServiceLocator
091:                        .getDateTimeService().getCurrentTimestamp());
092:                businessObjectService.save(selectedObjectIdsBO);
093:            }
094:
095:            /**
096:             * Retrieves the LookupResults BO with the given sequence number.  Does not check authentication.
097:             * @param lookupResultsSequenceNumber
098:             * @return
099:             * @throws Exception
100:             */
101:            protected LookupResults retrieveLookupResults(
102:                    String lookupResultsSequenceNumber) throws Exception {
103:                Map<String, String> queryCriteria = new HashMap<String, String>();
104:                queryCriteria.put(RiceConstants.LOOKUP_RESULTS_SEQUENCE_NUMBER,
105:                        lookupResultsSequenceNumber);
106:                LookupResults lookupResults = (LookupResults) businessObjectService
107:                        .findByPrimaryKey(LookupResults.class, queryCriteria);
108:
109:                return lookupResults;
110:            }
111:
112:            /**
113:             * Retrieves the SelectedObjectIds BO with the given sequence number.  Does not check authentication.
114:             * @param lookupResultsSequenceNumber
115:             * @return
116:             * @throws Exception
117:             */
118:            protected SelectedObjectIds retrieveSelectedObjectIds(
119:                    String lookupResultsSequenceNumber) throws Exception {
120:                Map<String, String> queryCriteria = new HashMap<String, String>();
121:                queryCriteria.put(RiceConstants.LOOKUP_RESULTS_SEQUENCE_NUMBER,
122:                        lookupResultsSequenceNumber);
123:                SelectedObjectIds selectedObjectIds = (SelectedObjectIds) businessObjectService
124:                        .findByPrimaryKey(SelectedObjectIds.class,
125:                                queryCriteria);
126:
127:                return selectedObjectIds;
128:            }
129:
130:            /**
131:             * @see org.kuali.core.lookup.LookupResultsService#isAuthorizedToAccessLookupResults(java.lang.String, java.lang.String)
132:             */
133:            public boolean isAuthorizedToAccessLookupResults(
134:                    String lookupResultsSequenceNumber, String universalUserId) {
135:                try {
136:                    LookupResults lookupResults = retrieveLookupResults(lookupResultsSequenceNumber);
137:                    return isAuthorizedToAccessLookupResults(lookupResults,
138:                            universalUserId);
139:                } catch (Exception e) {
140:                    return false;
141:                }
142:            }
143:
144:            /**
145:             * Returns whether the user ID parameter is allowed to view the results.
146:             * 
147:             * @param lookupResults
148:             * @param universalUserId
149:             * @return
150:             */
151:            protected boolean isAuthorizedToAccessLookupResults(
152:                    LookupResults lookupResults, String universalUserId) {
153:                return isAuthorizedToAccessMultipleValueLookupMetadata(
154:                        lookupResults, universalUserId);
155:            }
156:
157:            /**
158:             * @see org.kuali.core.lookup.LookupResultsService#isAuthorizedToAccessSelectedObjectIds(java.lang.String, java.lang.String)
159:             */
160:            public boolean isAuthorizedToAccessSelectedObjectIds(
161:                    String lookupResultsSequenceNumber, String universalUserId) {
162:                try {
163:                    SelectedObjectIds selectedObjectIds = retrieveSelectedObjectIds(lookupResultsSequenceNumber);
164:                    return isAuthorizedToAccessSelectedObjectIds(
165:                            selectedObjectIds, universalUserId);
166:                } catch (Exception e) {
167:                    return false;
168:                }
169:            }
170:
171:            /**
172:             * Returns whether the user ID parameter is allowed to view the selected object IDs
173:             * 
174:             * @param selectedObjectIds
175:             * @param universalUserId
176:             * @return
177:             */
178:            protected boolean isAuthorizedToAccessSelectedObjectIds(
179:                    SelectedObjectIds selectedObjectIds, String universalUserId) {
180:                return isAuthorizedToAccessMultipleValueLookupMetadata(
181:                        selectedObjectIds, universalUserId);
182:            }
183:
184:            /**
185:             * @see org.kuali.core.lookup.LookupResultsService#retrieveResultsTable(java.lang.String, java.lang.String)
186:             */
187:            public List<ResultRow> retrieveResultsTable(
188:                    String lookupResultsSequenceNumber, String universalUserId)
189:                    throws Exception {
190:                LookupResults lookupResults = retrieveLookupResults(lookupResultsSequenceNumber);
191:                if (!isAuthorizedToAccessLookupResults(lookupResults,
192:                        universalUserId)) {
193:                    // TODO: use the other identifier
194:                    throw new AuthorizationException(universalUserId,
195:                            "retrieve lookup results",
196:                            "lookup sequence number "
197:                                    + lookupResultsSequenceNumber);
198:                }
199:                List<ResultRow> resultTable = (List<ResultRow>) ObjectUtils
200:                        .fromByteArray(Base64.decodeBase64(lookupResults
201:                                .getSerializedLookupResults().getBytes()));
202:                return resultTable;
203:            }
204:
205:            /**
206:             * Returns a list of BOs that were selected.
207:             * 
208:             * This implementation makes an attempt to retrieve all BOs with the given object IDs, unless they have been deleted or the object ID changed.
209:             * Since data may have changed since the search, the returned BOs may not match the criteria used to search.
210:             * 
211:             * @see org.kuali.core.lookup.LookupResultsService#retrieveSelectedResultBOs(java.lang.String, java.lang.Class, java.lang.String)
212:             */
213:            public Collection<PersistableBusinessObject> retrieveSelectedResultBOs(
214:                    String lookupResultsSequenceNumber, Class boClass,
215:                    String universalUserId) throws Exception {
216:                SelectedObjectIds selectedObjectIds = retrieveSelectedObjectIds(lookupResultsSequenceNumber);
217:
218:                if (!isAuthorizedToAccessSelectedObjectIds(selectedObjectIds,
219:                        universalUserId)) {
220:                    // TODO: use the other identifier
221:                    throw new AuthorizationException(universalUserId,
222:                            "retrieve lookup results",
223:                            "lookup sequence number "
224:                                    + lookupResultsSequenceNumber);
225:                }
226:
227:                Set<String> setOfSelectedObjIds = LookupUtils
228:                        .convertStringOfObjectIdsToSet(selectedObjectIds
229:                                .getSelectedObjectIds());
230:
231:                if (setOfSelectedObjIds.isEmpty()) {
232:                    // OJB throws exception if querying on empty set
233:                    return new ArrayList<PersistableBusinessObject>();
234:                }
235:                Map<String, Collection<String>> queryCriteria = new HashMap<String, Collection<String>>();
236:                queryCriteria.put(RicePropertyConstants.OBJECT_ID,
237:                        setOfSelectedObjIds);
238:                return businessObjectService.findMatching(boClass,
239:                        queryCriteria);
240:            }
241:
242:            /**
243:             * @see org.kuali.core.lookup.LookupResultsService#clearPersistedLookupResults(java.lang.String)
244:             */
245:            public void clearPersistedLookupResults(
246:                    String lookupResultsSequenceNumber) throws Exception {
247:                LookupResults lookupResults = retrieveLookupResults(lookupResultsSequenceNumber);
248:                if (lookupResults != null) {
249:                    businessObjectService.delete(lookupResults);
250:                }
251:            }
252:
253:            /**
254:             * @see org.kuali.core.lookup.LookupResultsService#clearPersistedSelectedObjectIds(java.lang.String)
255:             */
256:            public void clearPersistedSelectedObjectIds(
257:                    String lookupResultsSequenceNumber) throws Exception {
258:                SelectedObjectIds selectedObjectIds = retrieveSelectedObjectIds(lookupResultsSequenceNumber);
259:                if (selectedObjectIds != null) {
260:                    businessObjectService.delete(selectedObjectIds);
261:                }
262:            }
263:
264:            public BusinessObjectService getBusinessObjectService() {
265:                return businessObjectService;
266:            }
267:
268:            public void setBusinessObjectService(
269:                    BusinessObjectService businessObjectService) {
270:                this .businessObjectService = businessObjectService;
271:            }
272:
273:            /**
274:             * Determines whether the passed in user ID is allowed to view the lookup metadata (object IDs or results table)
275:             * @param mvlm
276:             * @param universalUserId
277:             * @return
278:             */
279:            protected boolean isAuthorizedToAccessMultipleValueLookupMetadata(
280:                    MultipleValueLookupMetadata mvlm, String universalUserId) {
281:                return universalUserId.equals(mvlm.getLookupUniversalUserId());
282:            }
283:
284:            public void deleteOldLookupResults(Timestamp expirationDate) {
285:                persistedLookupMetadataDao
286:                        .deleteOldLookupResults(expirationDate);
287:
288:            }
289:
290:            public void deleteOldSelectedObjectIds(Timestamp expirationDate) {
291:                persistedLookupMetadataDao
292:                        .deleteOldSelectedObjectIds(expirationDate);
293:            }
294:
295:            public PersistedLookupMetadataDao getPersistedLookupMetadataDao() {
296:                return persistedLookupMetadataDao;
297:            }
298:
299:            public void setPersistedLookupMetadataDao(
300:                    PersistedLookupMetadataDao persistedLookupMetadataDao) {
301:                this.persistedLookupMetadataDao = persistedLookupMetadataDao;
302:            }
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.