Source Code Cross Referenced for MainPageAction.java in  » Portal » mypersonalizer » es » udc » mypersonalizer » portal » controller » actions » mainpage » 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 » Portal » mypersonalizer » es.udc.mypersonalizer.portal.controller.actions.mainpage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/controller/actions/mainpage/MainPageAction.java,v 1.1.1.1 2004/03/25 12:08:40 fbellas Exp $
003:         * $Revision: 1.1.1.1 $
004:         * $Date: 2004/03/25 12:08:40 $
005:         *
006:         * =============================================================================
007:         *
008:         * Copyright (c) 2003, The MyPersonalizer Development Group
009:         * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at 
010:         * University Of A Coruna
011:         * All rights reserved.
012:         *
013:         * Redistribution and use in source and binary forms, with or without
014:         * modification, are permitted provided that the following conditions are met:
015:         *
016:         *  - Redistributions of source code must retain the above copyright notice, 
017:         *    this list of conditions and the following disclaimer.
018:         *
019:         *  - Redistributions in binary form must reproduce the above copyright notice,
020:         *    this list of conditions and the following disclaimer in the documentation
021:         *    and/or other materials provided with the distribution.
022:         *
023:         *  - Neither the name of the University Of A Coruna nor the names of its 
024:         *    contributors may be used to endorse or promote products derived from 
025:         *    this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
028:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
036:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037:         * POSSIBILITY OF SUCH DAMAGE.
038:         *
039:         */
040:
041:        package es.udc.mypersonalizer.portal.controller.actions.mainpage;
042:
043:        import es.udc.mypersonalizer.portal.conventions.RequestParameterConventions;
044:        import es.udc.mypersonalizer.portal.conventions.ServiceConfigurationConventions;
045:        import es.udc.mypersonalizer.kernel.model.actions.ActionProcessorSingleton;
046:        import es.udc.mypersonalizer.kernel.model.editors.EditorFactory;
047:        import es.udc.mypersonalizer.kernel.model.editors.ServiceButtonsStateEditor;
048:        import es.udc.mypersonalizer.kernel.model.editors.ServiceKeys;
049:        import es.udc.mypersonalizer.kernel.model.editors.WorkspaceLayoutEditor;
050:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.CachedServiceReply;
051:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.CachedServiceReplyAccessor;
052:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.RepositoryAccessorFactory;
053:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceButtonPermission;
054:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceButtonsState;
055:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceConfiguration;
056:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceConfigurationRegistrySingleton;
057:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceProperty;
058:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServicePropertyKey;
059:        import es.udc.mypersonalizer.kernel.model.repository.interfaces.WorkspaceLayout;
060:        import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
061:        import es.udc.mypersonalizer.kernel.util.general.PersonalizationHelper;
062:        import es.udc.mypersonalizer.kernel.controller.actions.DefaultAction;
063:        import es.udc.mypersonalizer.portal.controller.session.SessionManager;
064:        import es.udc.mypersonalizer.portal.conventions.RequestAttributeNames;
065:        import es.udc.mypersonalizer.portal.model.permissions.PermissionCheckerSingleton;
066:        import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
067:        import es.udc.mypersonalizer.portal.model.types.mainpage.MainPageEvent;
068:        import es.udc.mypersonalizer.portal.model.types.mainpage.MainPageResult;
069:        import es.udc.mypersonalizer.portal.view.mainpage.ButtonView;
070:        import es.udc.mypersonalizer.portal.view.mainpage.DesktopLayoutView;
071:        import es.udc.mypersonalizer.portal.view.mainpage.ServiceView;
072:        import es.udc.mypersonalizer.portal.view.mainpage.UserView;
073:        import es.udc.mypersonalizer.portal.view.mainpage.WorkspaceLabelView;
074:        import es.udc.mypersonalizer.portal.view.mainpage.WorkspaceLayoutView;
075:        import java.util.*;
076:        import javax.servlet.http.HttpServletRequest;
077:        import javax.servlet.http.HttpServletResponse;
078:        import org.apache.struts.action.ActionForm;
079:        import org.apache.struts.action.ActionForward;
080:        import org.apache.struts.action.ActionMapping;
081:        import org.apache.struts.config.ForwardConfig;
082:
083:        /**
084:         * This action performs all the operations necessary to display the user's
085:         * main page. It acts the following way:
086:         * <ul>
087:         *  <li>Asks the cache for the responses of the services to be displayed
088:         *      in the current workspace.</il>
089:         *  <li>For the services which answer is not cached, asks the model for their
090:         *      ServiceProperty objects (containing their configuration) for this
091:         *      user through the model action called <tt>MainPageAction</tt> which
092:         *      must be registered in configuration.</il>
093:         *  <li>Builds the Desktop tree of objects (see {@link 
094:         *      es.udc.mypersonalizer.portal.view.mainpage.DesktopLayoutView}), 
095:         *      which contains all the data necessary for displaying the main page, 
096:         *      and puts it into the request.</il>
097:         *  <li>Builds an object with information about the user (see {@link 
098:         *      es.udc.mypersonalizer.portal.view.mainpage.UserView}),
099:         *      which is useful for the jsp page.</li>
100:         *  <li>Forwards to the jsp page which will display the contents.</li>
101:         * </ul>
102:         *
103:         * This action requires the following forwards to be declared for it:
104:         * <ul>
105:         *   <li><tt>Success</tt>: Which will point to the jsp that will display the 
106:         *       main page contents.</li>
107:         *   <li><tt>RemoveServiceFromWorspace</tt>: Which will point to the URL that 
108:         *       will allow the removal of a service from the main page (by clicking on
109:         *       the <tt>remove</tt> button).</li>
110:         *   <li><tt>ChangeServiceButtonState</tt>: Which will point to the URL that
111:         *       will allow to change a button's state.</li>
112:         * </ul>
113:         *
114:         * It populates the request (before performing any <i>forward</i> operations) 
115:         * with the following data:
116:         * <ul>
117:         *  <li><tt>desktopLayoutView</tt>: An object of class {@link 
118:         *      es.udc.mypersonalizer.portal.view.mainpage.DesktopLayoutView}
119:         *      that contains all the needed data for the user's desktop.</li>
120:         *  <li><tt>userView</tt>: An object of class {@link 
121:         *      es.udc.mypersonalizer.portal.view.mainpage.UserView} that contains
122:         *      the user's name (to greet him/her, f.i.), and a way to know whether
123:         *      he/she is authenticated or not. This way even the 
124:         *      <tt>anonymous</tt> user can authenticate to make arrangements on
125:         *      its desktop.</li>
126:         * </ul>
127:         *
128:         * 
129:         * @author Daniel Fernandez
130:         * @since 1.0
131:         */
132:        public class MainPageAction extends DefaultAction {
133:
134:            /**
135:             * Name of the model action for retrieving the data necessary to draw the
136:             * user's main page. This is "MainPageAction".
137:             */
138:            private static final String MAIN_PAGE_ACTION = "MainPageAction";
139:
140:            /**
141:             * The name of the forward for removing a service. It is set to
142:             * <tt>RemoveServiceFromWorkspace</tt>.
143:             */
144:            private static final String REMOVE_SERVICE_FROM_WORKSPACE_FORWARD_NAME = "RemoveServiceFromWorkspace";
145:
146:            /**
147:             * The name of the forward for changing the state of a button. It is
148:             * set to <tt>ChangeServiceButtonState</tt>.
149:             */
150:            private static final String CHANGE_SERVICE_BUTTON_STATE_FORWARD_NAME = "ChangeServiceButtonState";
151:
152:            protected ActionForward doExecute(ActionMapping mapping,
153:                    ActionForm form, HttpServletRequest request,
154:                    HttpServletResponse response) throws Exception {
155:
156:                /*
157:                 * Algorithm:
158:                 *     1. Get the currentWorkspaceLayout
159:                 *     2. Build the list of Services
160:                 *     4. Ask the cache for that services -> Map of replies
161:                 *     3. Ask the model for non-cached services -> ServiceProperties map
162:                 *     5. Iterate by Area to make map of ServiceViews
163:                 *     6. For each, build the ServiceView
164:                 *     7. Build the WoskspaceView
165:                 *     8. Get the workspaceTypes Map and build the WorkspaceLabel List
166:                 *     9. Build the desktopView -> request
167:                 */
168:
169:                ActionProcessorSingleton actionProcessorSingleton = ActionProcessorSingleton
170:                        .getInstance();
171:
172:                UserCredentials userCredentials = SessionManager
173:                        .getUserCredentials(request);
174:
175:                EditorFactory editorFactory = EditorFactory.getInstance();
176:
177:                PermissionCheckerSingleton permissionCheckerSingleton = PermissionCheckerSingleton
178:                        .getInstance();
179:
180:                /*
181:                 * The DesktopLayoutView that will be put into the request.
182:                 */
183:                DesktopLayoutView desktopLayoutView = null;
184:
185:                /*
186:                 * Check if we have active workspaces.
187:                 */
188:                if (SessionManager.getUserHasWorkspaces(request)) {
189:
190:                    /*
191:                     * We get the current WorkspaceLayout object
192:                     */
193:                    WorkspaceLayout currentWorkspaceLayout = SessionManager
194:                            .getCurrentWorkspaceLayout(request);
195:
196:                    WorkspaceLayoutEditor currentWorkspaceLayoutEditor = editorFactory
197:                            .createWorkspaceLayoutEditor(currentWorkspaceLayout
198:                                    .getProperty());
199:
200:                    /*
201:                     * We get the ServiceKeys for this workspace in a by-area Map
202:                     */
203:                    Map currentWorkspaceServiceKeys = currentWorkspaceLayoutEditor
204:                            .getServiceKeys();
205:
206:                    /* 
207:                     * We need to flatten the Map of ServiceKeys to make it more
208:                     * usable for our purposes
209:                     */
210:                    List servicePropertyKeysList = getServicePropertyKeysAsList(
211:                            currentWorkspaceServiceKeys, userCredentials,
212:                            currentWorkspaceLayoutEditor.getWorkspaceType());
213:
214:                    /*
215:                     * We try to get from the cache as many service replies as we can
216:                     * and mark the services which had no cached reply
217:                     */
218:                    List nonCachedServicePropertyKeysList = copyList(servicePropertyKeysList);
219:                    Map cachedRepliesByKey = askCacheForServices(
220:                            servicePropertyKeysList,
221:                            nonCachedServicePropertyKeysList);
222:
223:                    /*
224:                     * Now we ask the model for the ServiceProperties of the services
225:                     * which are not in the cache
226:                     */
227:                    MainPageEvent event = new MainPageEvent(userCredentials,
228:                            nonCachedServicePropertyKeysList);
229:                    MainPageResult mainPageResult = (MainPageResult) actionProcessorSingleton
230:                            .execute(MAIN_PAGE_ACTION, event);
231:                    Map nonCachedServicePropertiesByKey = mainPageResult
232:                            .getServicePropertiesByKey();
233:
234:                    /*
235:                     * Now, we'll build the view objects
236:                     */
237:                    Map serviceViewsByArea = new HashMap();
238:                    Iterator areasIter = currentWorkspaceServiceKeys.entrySet()
239:                            .iterator();
240:                    while (areasIter.hasNext()) {
241:
242:                        Map.Entry currentEntry = (Map.Entry) areasIter.next();
243:                        Integer area = (Integer) currentEntry.getKey();
244:                        List serviceKeysListForArea = (List) currentEntry
245:                                .getValue();
246:
247:                        List serviceViewsForArea = new ArrayList();
248:                        Iterator serviceKeysIter = serviceKeysListForArea
249:                                .iterator();
250:                        while (serviceKeysIter.hasNext()) {
251:
252:                            ServiceKeys serviceKeys = (ServiceKeys) serviceKeysIter
253:                                    .next();
254:                            ServicePropertyKey servicePropertyKey = serviceKeys
255:                                    .getServicePropertyKey();
256:
257:                            if (permissionCheckerSingleton
258:                                    .isAllowedToAddService(userCredentials,
259:                                            servicePropertyKey
260:                                                    .getServiceIdentifier(),
261:                                            currentWorkspaceLayoutEditor
262:                                                    .getWorkspaceType())) {
263:
264:                                /*
265:                                 * We prepare to build the ServiceView
266:                                 */
267:                                ServiceView serviceView = null;
268:                                String serviceIdentifier = servicePropertyKey
269:                                        .getServiceIdentifier();
270:                                String cachedReply = null;
271:                                CachedServiceReply cachedServiceReply = (CachedServiceReply) cachedRepliesByKey
272:                                        .get(servicePropertyKey);
273:                                if (cachedServiceReply != null) {
274:                                    cachedReply = cachedServiceReply
275:                                            .getServiceReply();
276:                                }
277:
278:                                ServiceButtonsState serviceButtonsState = null;
279:                                if (PersonalizationHelper.buttonsHaveState()) {
280:                                    serviceButtonsState = SessionManager
281:                                            .getServiceButtonsState(
282:                                                    request,
283:                                                    serviceKeys
284:                                                            .getServiceButtonsStateIdentifier());
285:                                }
286:
287:                                /* 
288:                                 * First, we need the allowed buttons 
289:                                 */
290:                                Map allowedButtons = getAllowedButtons(
291:                                        userCredentials, servicePropertyKey,
292:                                        serviceButtonsState, request, mapping);
293:
294:                                /* 
295:                                 * And now, the ServiceView can be built
296:                                 */
297:                                if (cachedReply == null) {
298:
299:                                    ServiceProperty serviceProperty = (ServiceProperty) nonCachedServicePropertiesByKey
300:                                            .get(servicePropertyKey);
301:
302:                                    serviceView = new ServiceView(
303:                                            serviceIdentifier, request,
304:                                            response, allowedButtons,
305:                                            servicePropertyKey,
306:                                            serviceProperty,
307:                                            serviceButtonsState);
308:
309:                                } else {
310:
311:                                    serviceView = new ServiceView(
312:                                            serviceIdentifier, request,
313:                                            response, allowedButtons,
314:                                            cachedReply);
315:
316:                                }
317:
318:                                serviceViewsForArea.add(serviceView);
319:
320:                            }
321:
322:                        }
323:
324:                        serviceViewsByArea.put(area.toString(),
325:                                serviceViewsForArea);
326:
327:                    }
328:
329:                    /*
330:                     * Now we'll build the WorkspaceLayoutView
331:                     */
332:                    long currentWorkspaceLayoutIdentifier = currentWorkspaceLayout
333:                            .getIdentifier().longValue();
334:                    String currentWorkspaceLayoutWorkspaceType = currentWorkspaceLayoutEditor
335:                            .getWorkspaceType();
336:                    String currentWorkspaceLayoutWorkspaceName = currentWorkspaceLayoutEditor
337:                            .getWorkspaceName();
338:                    String currentWorkspaceLayoutLayoutType = currentWorkspaceLayoutEditor
339:                            .getLayoutType();
340:
341:                    WorkspaceLayoutView currentWorkspaceLayoutView = new WorkspaceLayoutView(
342:                            currentWorkspaceLayoutIdentifier,
343:                            currentWorkspaceLayoutWorkspaceType,
344:                            currentWorkspaceLayoutWorkspaceName,
345:                            currentWorkspaceLayoutLayoutType,
346:                            serviceViewsByArea);
347:
348:                    /*
349:                     * We build the workspaceLabelView List now
350:                     */
351:                    List availableWorkspaces = SessionManager
352:                            .getAvailableWorkspaces(request);
353:                    List workspaceLabelViews = new ArrayList();
354:                    Iterator availableWorkspacesIter = availableWorkspaces
355:                            .iterator();
356:                    while (availableWorkspacesIter.hasNext()) {
357:                        Map workspaceData = (Map) availableWorkspacesIter
358:                                .next();
359:
360:                        String workspaceName = (String) workspaceData
361:                                .get("workspaceName");
362:                        Long workspaceLayoutIdentifier = (Long) workspaceData
363:                                .get("workspaceLayoutIdentifier");
364:
365:                        WorkspaceLabelView workspaceLabelView = new WorkspaceLabelView(
366:                                workspaceName, workspaceLayoutIdentifier
367:                                        .longValue());
368:                        workspaceLabelViews.add(workspaceLabelView);
369:
370:                    }
371:
372:                    /*
373:                     * And, finally, we can build a DesktopLayoutView with the
374:                     * workspace data we've gathered.
375:                     */
376:                    desktopLayoutView = new DesktopLayoutView(
377:                            workspaceLabelViews, currentWorkspaceLayoutView);
378:
379:                } else {
380:
381:                    /*
382:                     * We create a DesktopLayoutView without any information about
383:                     * workspaces, as we don't have them.
384:                     */
385:                    desktopLayoutView = new DesktopLayoutView();
386:
387:                }
388:
389:                /*
390:                 * ...and a UserView is built.
391:                 */
392:                UserView userView = new UserView(
393:                        userCredentials.getLoginName(), SessionManager
394:                                .isUserAuthenticated(request));
395:
396:                /*
397:                 * Let's put them into the request
398:                 */
399:                request
400:                        .setAttribute(
401:                                RequestAttributeNames.DESKTOP_LAYOUT_VIEW_ATTRIBUTE_NAME,
402:                                desktopLayoutView);
403:                request.setAttribute(
404:                        RequestAttributeNames.USER_VIEW_ATTRIBUTE_NAME,
405:                        userView);
406:
407:                return mapping
408:                        .findForward(DefaultAction.ACTION_SUCCESS_FORWARD);
409:
410:            }
411:
412:            private List copyList(List list) {
413:                List result = new ArrayList();
414:                Iterator listIter = list.iterator();
415:                while (listIter.hasNext()) {
416:                    result.add(listIter.next());
417:                }
418:                return result;
419:            }
420:
421:            private List getServicePropertyKeysAsList(Map serviceKeysAsMap,
422:                    UserCredentials userCredentials, String workspaceType) {
423:
424:                PermissionCheckerSingleton permissionCheckerSingleton = PermissionCheckerSingleton
425:                        .getInstance();
426:
427:                List servicePropertyKeysAsList = new ArrayList();
428:                Iterator entryIter = serviceKeysAsMap.entrySet().iterator();
429:                while (entryIter.hasNext()) {
430:                    Map.Entry entry = (Map.Entry) entryIter.next();
431:                    List currentServiceKeys = (List) entry.getValue();
432:                    Iterator serviceKeysIter = currentServiceKeys.iterator();
433:                    while (serviceKeysIter.hasNext()) {
434:                        ServiceKeys serviceKeys = (ServiceKeys) serviceKeysIter
435:                                .next();
436:
437:                        if (permissionCheckerSingleton.isAllowedToAddService(
438:                                userCredentials, serviceKeys
439:                                        .getServicePropertyKey()
440:                                        .getServiceIdentifier(), workspaceType)) {
441:
442:                            servicePropertyKeysAsList.add(serviceKeys
443:                                    .getServicePropertyKey());
444:
445:                        }
446:                    }
447:                }
448:                return servicePropertyKeysAsList;
449:
450:            }
451:
452:            private Map askCacheForServices(List servicePropertyKeys,
453:                    List nonCachedServicePropertyKeys)
454:                    throws InternalErrorException {
455:
456:                RepositoryAccessorFactory repositoryAccessorFactory = RepositoryAccessorFactory
457:                        .getInstance();
458:                CachedServiceReplyAccessor cachedServiceReplyAccessor = repositoryAccessorFactory
459:                        .createCachedServiceReplyAccessor();
460:                Map cachedReplies = cachedServiceReplyAccessor
461:                        .findCachedServiceReplies(servicePropertyKeys);
462:
463:                Iterator repliesIter = cachedReplies.keySet().iterator();
464:                while (repliesIter.hasNext()) {
465:                    ServicePropertyKey servicePropertyKey = (ServicePropertyKey) repliesIter
466:                            .next();
467:                    nonCachedServicePropertyKeys.remove(servicePropertyKey);
468:                }
469:                return cachedReplies;
470:            }
471:
472:            private Map getAllowedButtons(UserCredentials userCredentials,
473:                    ServicePropertyKey servicePropertyKey,
474:                    ServiceButtonsState serviceButtonsState,
475:                    HttpServletRequest request, ActionMapping mapping)
476:                    throws InternalErrorException {
477:
478:                Map allowedButtons = new HashMap();
479:
480:                PermissionCheckerSingleton permissionCheckerSingleton = PermissionCheckerSingleton
481:                        .getInstance();
482:
483:                String serviceIdentifier = servicePropertyKey
484:                        .getServiceIdentifier();
485:
486:                /*
487:                 * First, add the stateful (if any) buttons
488:                 */
489:                if (PersonalizationHelper.buttonsHaveState()) {
490:                    EditorFactory editorFactory = EditorFactory.getInstance();
491:                    ServiceButtonsStateEditor serviceButtonsStateEditor = editorFactory
492:                            .createServiceButtonsStateEditor(serviceButtonsState
493:                                    .getProperty());
494:                    Map buttonsStateByName = serviceButtonsStateEditor
495:                            .getButtonsState();
496:                    Iterator buttonsIter = buttonsStateByName.entrySet()
497:                            .iterator();
498:                    while (buttonsIter.hasNext()) {
499:                        Map.Entry entry = (Map.Entry) buttonsIter.next();
500:                        String buttonName = (String) entry.getKey();
501:                        Integer buttonState = (Integer) entry.getValue();
502:
503:                        if (permissionCheckerSingleton.isServiceButtonAllowed(
504:                                userCredentials, serviceIdentifier, buttonName)) {
505:
506:                            String changeButtonsStateURL = getChangeButtonsStateURL(
507:                                    serviceButtonsState, buttonName,
508:                                    serviceIdentifier, servicePropertyKey
509:                                            .getPropertyIdentifier(), request,
510:                                    mapping);
511:                            ButtonView buttonView = new ButtonView(buttonState
512:                                    .intValue(), changeButtonsStateURL);
513:
514:                            allowedButtons.put(buttonName, buttonView);
515:
516:                        }
517:                    }
518:                }
519:                /*
520:                 * Finally, add "personalize" and "remove" if allowed
521:                 */
522:                if (permissionCheckerSingleton.isServiceButtonAllowed(
523:                        userCredentials, serviceIdentifier,
524:                        ServiceButtonPermission.PERSONALIZE_BUTTON_NAME)) {
525:
526:                    String editURL = getEditURL(servicePropertyKey, request,
527:                            mapping);
528:                    ButtonView buttonView = new ButtonView(0, editURL);
529:
530:                    allowedButtons.put(
531:                            ServiceButtonPermission.PERSONALIZE_BUTTON_NAME,
532:                            buttonView);
533:
534:                }
535:                if (permissionCheckerSingleton.isServiceButtonAllowed(
536:                        userCredentials, serviceIdentifier,
537:                        ServiceButtonPermission.REMOVE_BUTTON_NAME)) {
538:
539:                    String removeURL = getRemoveURL(servicePropertyKey,
540:                            request, mapping);
541:                    ButtonView buttonView = new ButtonView(0, removeURL);
542:
543:                    allowedButtons.put(
544:                            ServiceButtonPermission.REMOVE_BUTTON_NAME,
545:                            buttonView);
546:                }
547:
548:                return allowedButtons;
549:
550:            }
551:
552:            private String getRemoveURL(ServicePropertyKey servicePropertyKey,
553:                    HttpServletRequest request, ActionMapping mapping) {
554:
555:                ForwardConfig forwardConfig = mapping
556:                        .findForwardConfig(REMOVE_SERVICE_FROM_WORKSPACE_FORWARD_NAME);
557:
558:                if (forwardConfig == null) {
559:                    return "";
560:                }
561:
562:                String path = forwardConfig.getPath();
563:
564:                String serviceIdentifier = servicePropertyKey
565:                        .getServiceIdentifier();
566:                Long propertyIdentifier = servicePropertyKey
567:                        .getPropertyIdentifier();
568:
569:                path += "?" + RequestParameterConventions.SERVICE_IDENTIFIER
570:                        + "=" + serviceIdentifier + "&"
571:                        + RequestParameterConventions.PROPERTY_IDENTIFIER + "="
572:                        + propertyIdentifier;
573:
574:                return path;
575:            }
576:
577:            private String getChangeButtonsStateURL(
578:                    ServiceButtonsState serviceButtonsState, String buttonName,
579:                    String serviceIdentifier, Long propertyIdentifier,
580:                    HttpServletRequest request, ActionMapping mapping) {
581:
582:                ForwardConfig forwardConfig = mapping
583:                        .findForwardConfig(CHANGE_SERVICE_BUTTON_STATE_FORWARD_NAME);
584:
585:                if (forwardConfig == null) {
586:                    return "";
587:                }
588:
589:                String path = forwardConfig.getPath();
590:
591:                Long serviceButtonsStateIdentifier = serviceButtonsState
592:                        .getPropertyIdentifier();
593:
594:                path += "?"
595:                        + RequestParameterConventions.SERVICE_IDENTIFIER
596:                        + "="
597:                        + serviceIdentifier
598:                        + "&"
599:                        + RequestParameterConventions.PROPERTY_IDENTIFIER
600:                        + "="
601:                        + propertyIdentifier
602:                        + "&"
603:                        + RequestParameterConventions.SERVICE_BUTTONS_STATE_IDENTIFIER
604:                        + "=" + serviceButtonsStateIdentifier + "&"
605:                        + RequestParameterConventions.BUTTON_NAME + "="
606:                        + buttonName;
607:
608:                return path;
609:            }
610:
611:            private String getEditURL(ServicePropertyKey servicePropertyKey,
612:                    HttpServletRequest request, ActionMapping mapping) {
613:
614:                String serviceIdentifier = servicePropertyKey
615:                        .getServiceIdentifier();
616:                Long propertyIdentifier = servicePropertyKey
617:                        .getPropertyIdentifier();
618:
619:                ServiceConfigurationRegistrySingleton serviceConfigurationRegistrySingleton = ServiceConfigurationRegistrySingleton
620:                        .getInstance();
621:                ServiceConfiguration serviceConfiguration = serviceConfigurationRegistrySingleton
622:                        .getServiceConfiguration(serviceIdentifier);
623:                String configurationEditURL = (String) serviceConfiguration
624:                        .getParameters().get(
625:                                ServiceConfigurationConventions.EDIT_URL);
626:
627:                if (configurationEditURL == null) {
628:                    return "";
629:                }
630:
631:                /* 
632:                 * This is a context-relative path. It will be allright when
633:                 * we use a struts tag to write it in the jsp file.
634:                 */
635:                String path = configurationEditURL;
636:
637:                path += "?" + RequestParameterConventions.SERVICE_IDENTIFIER
638:                        + "=" + serviceIdentifier + "&"
639:                        + RequestParameterConventions.PROPERTY_IDENTIFIER + "="
640:                        + propertyIdentifier;
641:
642:                return path;
643:            }
644:
645:        }
ww_w_.___j__a_va___2___s.__c___om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.