Source Code Cross Referenced for LibresourceSurveyServiceBean.java in  » Groupware » LibreSource » org » libresource » survey » ejb » 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 » Groupware » LibreSource » org.libresource.survey.ejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * LibreSource
003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
004:         * http://www.libresource.org - contact@artenum.com
005:         *
006:         * This file is part of the LibreSource software, 
007:         * which can be used and distributed under license conditions.
008:         * The license conditions are provided in the LICENSE.TXT file 
009:         * at the root path of the packaging that enclose this file. 
010:         * More information can be found at 
011:         * - http://dev.libresource.org/home/license
012:         *
013:         * Initial authors :
014:         *
015:         * Guillaume Bort / INRIA
016:         * Francois Charoy / Universite Nancy 2
017:         * Julien Forest / Artenum
018:         * Claude Godart / Universite Henry Poincare
019:         * Florent Jouille / INRIA
020:         * Sebastien Jourdain / INRIA / Artenum
021:         * Yves Lerumeur / Artenum
022:         * Pascal Molli / Universite Henry Poincare
023:         * Gerald Oster / INRIA
024:         * Mariarosa Penzi / Artenum
025:         * Gerard Sookahet / Artenum
026:         * Raphael Tani / INRIA
027:         *
028:         * Contributors :
029:         *
030:         * Stephane Bagnier / Artenum
031:         * Amadou Dia / Artenum-IUP Blois
032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033:         */package org.libresource.survey.ejb;
034:
035:        import org.libresource.Libresource;
036:        import org.libresource.LibresourceEvent;
037:        import org.libresource.LibresourceException;
038:        import org.libresource.LibresourceResourceIdentifier;
039:        import org.libresource.LibresourceResourceValue;
040:        import org.libresource.LibresourceServiceBase;
041:
042:        import org.libresource.kernel.KernelConstants;
043:        import org.libresource.kernel.LibresourceSecurityException;
044:        import org.libresource.kernel.URINotExistException;
045:        import org.libresource.kernel.interfaces.KernelService;
046:
047:        import org.libresource.search.LibresourceIndexableContent;
048:
049:        import org.libresource.survey.LibresourceSurveyException;
050:        import org.libresource.survey.Option;
051:        import org.libresource.survey.SurveyConstants;
052:        import org.libresource.survey.SurveyExportHandler;
053:        import org.libresource.survey.SurveyImportHandler;
054:        import org.libresource.survey.ejb.model.SurveyResourceValue;
055:        import org.libresource.survey.interfaces.SurveyResourceLocal;
056:        import org.libresource.survey.util.SurveyResourceUtil;
057:
058:        import org.libresource.xml.LibresourceExportHandler;
059:        import org.libresource.xml.LibresourceImportHandler;
060:
061:        import java.net.URI;
062:
063:        import java.util.Date;
064:        import java.util.Iterator;
065:        import java.util.Vector;
066:
067:        /**
068:         * The Libresource Survey service
069:         *
070:         * @libresource.service name="LibresourceSurvey" depends="Kernel,Membership"
071:         */
072:        public abstract class LibresourceSurveyServiceBean extends
073:                LibresourceServiceBase {
074:            /**
075:             * @ejb.interface-method
076:             * @ejb.transaction type="Supports"
077:             */
078:            public LibresourceSurveyServiceBean() {
079:            }
080:
081:            /**
082:             * @ejb.interface-method
083:             * @ejb.transaction type="Required"
084:             */
085:            public void createSurvey(URI uri, String question,
086:                    String votersList, String state, String displayMode,
087:                    Date creationDate, Date lastVoteDate)
088:                    throws LibresourceSurveyException,
089:                    LibresourceSecurityException {
090:                try {
091:                    KernelService kernelService = (KernelService) Libresource
092:                            .getService(KernelConstants.SERVICE);
093:
094:                    if (!kernelService.checkSecurity(uri,
095:                            KernelConstants.SECURITY_CREATE)) {
096:                        throw new LibresourceSecurityException(uri,
097:                                KernelConstants.SECURITY_CREATE);
098:                    }
099:
100:                    if ((displayMode == null)
101:                            || (displayMode.trim().length() == 0)) {
102:                        displayMode = "HTML";
103:                    }
104:
105:                    SurveyResourceLocal surveyResourceLocal = SurveyResourceUtil
106:                            .getLocalHome().create(question, votersList, state,
107:                                    displayMode, creationDate, lastVoteDate);
108:                    kernelService.bind(surveyResourceLocal
109:                            .getLibresourceResourceIdentifier(), uri, question);
110:
111:                    // event
112:                    LibresourceEvent event = new LibresourceEvent(uri,
113:                            surveyResourceLocal
114:                                    .getLibresourceResourceIdentifier(),
115:                            kernelService.getConnectedResource(),
116:                            SurveyConstants.EVENT_SURVEY_CREATE);
117:                    Libresource.throwEvent(event);
118:                } catch (LibresourceSecurityException se) {
119:                    ctx.setRollbackOnly();
120:                    throw se;
121:                } catch (Exception e) {
122:                    ctx.setRollbackOnly();
123:                    throw new LibresourceSurveyException(
124:                            "Error in createSurvey : " + e.getMessage(), e);
125:                }
126:            }
127:
128:            /**
129:             * @ejb.interface-method
130:             * @ejb.transaction type="Required"
131:             */
132:            public void editSurvey(URI uri, String question, String displayMode)
133:                    throws LibresourceSurveyException,
134:                    LibresourceSecurityException, URINotExistException {
135:                try {
136:                    KernelService kernelService = (KernelService) Libresource
137:                            .getService(KernelConstants.SERVICE);
138:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
139:                            .lookup(uri);
140:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
141:                            .findResource(resourceIdentifier,
142:                                    SurveyResourceLocal.class);
143:
144:                    if (!kernelService.checkSecurity(uri,
145:                            KernelConstants.SECURITY_UPDATE)) {
146:                        throw new LibresourceSecurityException(uri,
147:                                KernelConstants.SECURITY_UPDATE);
148:                    }
149:
150:                    if (question.trim().length() == 0) {
151:                        throw new LibresourceSurveyException(
152:                                "The question is required");
153:                    }
154:
155:                    surveyResourceLocal.setQuestion(question);
156:                    surveyResourceLocal.setDisplayMode(displayMode);
157:
158:                    // update node
159:                    kernelService.setShortName(uri, question);
160:                    kernelService.setUpdateDate(uri, new Date());
161:
162:                    // event
163:                    LibresourceEvent event = new LibresourceEvent(uri,
164:                            resourceIdentifier, kernelService
165:                                    .getConnectedResource(),
166:                            SurveyConstants.EVENT_SURVEY_EDIT);
167:                    Libresource.throwEvent(event);
168:
169:                    // indexation
170:                    Libresource.index(uri);
171:                } catch (LibresourceSecurityException se) {
172:                    ctx.setRollbackOnly();
173:                    throw se;
174:                } catch (URINotExistException se) {
175:                    ctx.setRollbackOnly();
176:                    throw se;
177:                } catch (Exception e) {
178:                    ctx.setRollbackOnly();
179:                    throw new LibresourceSurveyException(
180:                            "Error in editSurvey : " + e.getMessage(), e);
181:                }
182:            }
183:
184:            /**
185:             * @ejb.interface-method
186:             * @ejb.transaction type="Required"
187:             */
188:            public void deleteSurvey(URI uri)
189:                    throws LibresourceSurveyException,
190:                    LibresourceSecurityException, URINotExistException {
191:                try {
192:                    KernelService kernelService = (KernelService) Libresource
193:                            .getService(KernelConstants.SERVICE);
194:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
195:                            .lookup(uri);
196:
197:                    // event
198:                    LibresourceEvent event = new LibresourceEvent(uri,
199:                            resourceIdentifier, kernelService
200:                                    .getConnectedResource(),
201:                            SurveyConstants.EVENT_SURVEY_DELETE);
202:                    Libresource.throwEvent(event);
203:
204:                    Libresource.checkType(resourceIdentifier,
205:                            SurveyResourceLocal.class);
206:                    kernelService.deleteURI(uri);
207:                } catch (LibresourceSecurityException se) {
208:                    ctx.setRollbackOnly();
209:                    throw se;
210:                } catch (URINotExistException se) {
211:                    ctx.setRollbackOnly();
212:                    throw se;
213:                } catch (Exception e) {
214:                    ctx.setRollbackOnly();
215:                    throw new LibresourceSurveyException(
216:                            "Error in deleteSurvey : " + e.getMessage(), e);
217:                }
218:            }
219:
220:            /**
221:             * @ejb.interface-method
222:             * @ejb.transaction type="Supports"
223:             */
224:            public SurveyResourceValue getSurvey(URI uri)
225:                    throws LibresourceSurveyException,
226:                    LibresourceSecurityException, URINotExistException {
227:                try {
228:                    KernelService kernelService = (KernelService) Libresource
229:                            .getService(KernelConstants.SERVICE);
230:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
231:                            .lookup(uri);
232:                    SurveyResourceLocal SurveyResourceLocal = (SurveyResourceLocal) Libresource
233:                            .findResource(resourceIdentifier,
234:                                    SurveyResourceLocal.class);
235:                    SurveyResourceValue surveyValue = SurveyResourceLocal
236:                            .getSurveyResourceValue();
237:                    surveyValue.setUri(kernelService.normalizeURI(uri));
238:
239:                    return surveyValue;
240:                } catch (LibresourceSecurityException se) {
241:                    throw se;
242:                } catch (URINotExistException se) {
243:                    throw se;
244:                } catch (Exception e) {
245:                    throw new LibresourceSurveyException(
246:                            "Error in getSurvey : " + e.getMessage(), e);
247:                }
248:            }
249:
250:            /**
251:             * @ejb.interface-method
252:             * @ejb.transaction type="Supports"
253:             */
254:            public SurveyResourceValue[] listSurveysAt(URI uri)
255:                    throws LibresourceSurveyException,
256:                    LibresourceSecurityException, URINotExistException {
257:                try {
258:                    KernelService kernelService = (KernelService) Libresource
259:                            .getService(KernelConstants.SERVICE);
260:                    LibresourceResourceValue[] pages = kernelService
261:                            .listResourcesAt(
262:                                    uri,
263:                                    SurveyResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
264:                                    SurveyResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
265:                    SurveyResourceValue[] surveyResourceValues = new SurveyResourceValue[pages.length];
266:
267:                    for (int i = 0; i < surveyResourceValues.length; i++) {
268:                        LibresourceResourceIdentifier resourceIdentifier = pages[i]
269:                                .getLibresourceResourceIdentifier();
270:                        surveyResourceValues[i] = ((SurveyResourceLocal) Libresource
271:                                .findResource(resourceIdentifier))
272:                                .getSurveyResourceValue();
273:                        surveyResourceValues[i].setUri(kernelService
274:                                .normalizeURI(pages[i].getUri()));
275:                    }
276:
277:                    return surveyResourceValues;
278:                } catch (LibresourceSecurityException se) {
279:                    throw se;
280:                } catch (URINotExistException se) {
281:                    throw se;
282:                } catch (Exception e) {
283:                    throw new LibresourceSurveyException(
284:                            "Error in listSurveysAt : " + e.getMessage(), e);
285:                }
286:            }
287:
288:            /**
289:             * @ejb.interface-method
290:             * @ejb.transaction type="Supports"
291:             */
292:            public Vector getOptionsInSurvey(URI surveyUri)
293:                    throws LibresourceSurveyException,
294:                    LibresourceSecurityException, URINotExistException {
295:                try {
296:                    KernelService kernelService = (KernelService) Libresource
297:                            .getService(KernelConstants.SERVICE);
298:                    SurveyResourceLocal surveyResourceLocal;
299:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
300:                            .lookup(surveyUri);
301:                    surveyResourceLocal = (SurveyResourceLocal) Libresource
302:                            .findResource(resourceIdentifier,
303:                                    SurveyResourceLocal.class);
304:
305:                    return surveyResourceLocal.getOptionsList();
306:                } catch (LibresourceSecurityException se) {
307:                    throw se;
308:                } catch (URINotExistException se) {
309:                    throw se;
310:                } catch (Exception e) {
311:                    throw new LibresourceSurveyException(
312:                            "Error in getOptionsInSurvey : " + e.getMessage(),
313:                            e);
314:                }
315:            }
316:
317:            /**
318:             * @ejb.interface-method
319:             * @ejb.transaction type="Supports"
320:             */
321:            public Option getOptionInSurvey(URI surveyUri, String optionId)
322:                    throws LibresourceSurveyException,
323:                    LibresourceSecurityException, URINotExistException {
324:                try {
325:                    KernelService kernelService = (KernelService) Libresource
326:                            .getService(KernelConstants.SERVICE);
327:                    SurveyResourceLocal surveyResourceLocal;
328:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
329:                            .lookup(surveyUri);
330:                    surveyResourceLocal = (SurveyResourceLocal) Libresource
331:                            .findResource(resourceIdentifier,
332:                                    SurveyResourceLocal.class);
333:
334:                    return surveyResourceLocal.getOption(optionId);
335:                } catch (LibresourceSecurityException se) {
336:                    throw se;
337:                } catch (URINotExistException se) {
338:                    throw se;
339:                } catch (Exception e) {
340:                    throw new LibresourceSurveyException(
341:                            "Error in getOptionsInSurvey : " + e.getMessage(),
342:                            e);
343:                }
344:            }
345:
346:            /**
347:             * @ejb.interface-method
348:             * @ejb.transaction type="Required"
349:             */
350:            public void addOptionInSurvey(URI surveyUri, String choice,
351:                    int nbVotes) throws LibresourceSurveyException,
352:                    LibresourceSecurityException, URINotExistException {
353:                try {
354:                    KernelService kernelService = (KernelService) Libresource
355:                            .getService(KernelConstants.SERVICE);
356:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
357:                            .lookup(surveyUri);
358:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
359:                            .findResource(resourceIdentifier,
360:                                    SurveyResourceLocal.class);
361:
362:                    if (!kernelService.checkSecurity(surveyUri,
363:                            KernelConstants.SECURITY_UPDATE)) {
364:                        throw new LibresourceSecurityException(surveyUri,
365:                                KernelConstants.SECURITY_UPDATE);
366:                    }
367:
368:                    if (choice.trim().length() == 0) {
369:                        throw new LibresourceSurveyException(
370:                                "An new option could not be blank");
371:                    }
372:
373:                    surveyResourceLocal.addOption(choice, nbVotes);
374:
375:                    // update node
376:                    kernelService.setUpdateDate(surveyUri, new Date());
377:
378:                    // event
379:                    Libresource.throwEvent(new LibresourceEvent(surveyUri,
380:                            resourceIdentifier, kernelService
381:                                    .getConnectedResource(),
382:                            SurveyConstants.EVENT_SURVEY_ADD_OPTION, choice));
383:                } catch (LibresourceSecurityException se) {
384:                    ctx.setRollbackOnly();
385:                    throw se;
386:                } catch (URINotExistException se) {
387:                    ctx.setRollbackOnly();
388:                    throw se;
389:                } catch (Exception e) {
390:                    ctx.setRollbackOnly();
391:                    throw new LibresourceSurveyException(
392:                            "Error in addOptionInSurvey : " + e.getMessage(), e);
393:                }
394:            }
395:
396:            /**
397:             * @ejb.interface-method
398:             * @ejb.transaction type="Required"
399:             */
400:            public void editOptionInSurvey(URI surveyUri, String optionId,
401:                    String choice) throws LibresourceSurveyException,
402:                    LibresourceSecurityException, URINotExistException {
403:                try {
404:                    KernelService kernelService = (KernelService) Libresource
405:                            .getService(KernelConstants.SERVICE);
406:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
407:                            .lookup(surveyUri);
408:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
409:                            .findResource(resourceIdentifier,
410:                                    SurveyResourceLocal.class);
411:
412:                    if (!kernelService.checkSecurity(surveyUri,
413:                            KernelConstants.SECURITY_UPDATE)) {
414:                        throw new LibresourceSecurityException(surveyUri,
415:                                KernelConstants.SECURITY_UPDATE);
416:                    }
417:
418:                    if (choice.trim().length() == 0) {
419:                        throw new LibresourceSurveyException(
420:                                "An option could not be blank");
421:                    }
422:
423:                    surveyResourceLocal.editOption(optionId, choice);
424:
425:                    // update node
426:                    kernelService.setUpdateDate(surveyUri, new Date());
427:
428:                    // event
429:                    Libresource.throwEvent(new LibresourceEvent(surveyUri,
430:                            resourceIdentifier, kernelService
431:                                    .getConnectedResource(),
432:                            SurveyConstants.EVENT_SURVEY_ADD_OPTION, choice));
433:                } catch (LibresourceSecurityException se) {
434:                    ctx.setRollbackOnly();
435:                    throw se;
436:                } catch (URINotExistException se) {
437:                    ctx.setRollbackOnly();
438:                    throw se;
439:                } catch (Exception e) {
440:                    ctx.setRollbackOnly();
441:                    throw new LibresourceSurveyException(
442:                            "Error in editOptionInSurvey : " + e.getMessage(),
443:                            e);
444:                }
445:            }
446:
447:            /**
448:             * @ejb.interface-method
449:             * @ejb.transaction type="Required"
450:             */
451:            public void deleteOptionInSurvey(URI surveyUri, String optionId)
452:                    throws LibresourceSurveyException,
453:                    LibresourceSecurityException, URINotExistException {
454:                try {
455:                    KernelService kernelService = (KernelService) Libresource
456:                            .getService(KernelConstants.SERVICE);
457:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
458:                            .lookup(surveyUri);
459:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
460:                            .findResource(resourceIdentifier,
461:                                    SurveyResourceLocal.class);
462:
463:                    if (!kernelService.checkSecurity(surveyUri,
464:                            KernelConstants.SECURITY_UPDATE)) {
465:                        throw new LibresourceSecurityException(surveyUri,
466:                                KernelConstants.SECURITY_UPDATE);
467:                    }
468:
469:                    String choice = ((Option) surveyResourceLocal
470:                            .getOption(optionId)).getChoice();
471:                    surveyResourceLocal.deleteOption(optionId);
472:
473:                    if (choice != null) {
474:                        // event
475:                        Libresource.throwEvent(new LibresourceEvent(surveyUri,
476:                                resourceIdentifier, kernelService
477:                                        .getConnectedResource(),
478:                                SurveyConstants.EVENT_SURVEY_DELETE_OPTION,
479:                                choice));
480:                    }
481:
482:                    // update node
483:                    kernelService.setUpdateDate(surveyUri, new Date());
484:                } catch (LibresourceSecurityException se) {
485:                    ctx.setRollbackOnly();
486:                    throw se;
487:                } catch (URINotExistException se) {
488:                    ctx.setRollbackOnly();
489:                    throw se;
490:                } catch (Exception e) {
491:                    ctx.setRollbackOnly();
492:                    throw new LibresourceSurveyException(
493:                            "Error in deleteOptionInSurvey : " + e.getMessage(),
494:                            e);
495:                }
496:            }
497:
498:            /**
499:             * @ejb.interface-method
500:             * @ejb.transaction type="Required"
501:             */
502:            public void voteInSurvey(URI surveyUri, String optionId)
503:                    throws LibresourceSurveyException,
504:                    LibresourceSecurityException, URINotExistException {
505:                try {
506:                    KernelService kernelService = (KernelService) Libresource
507:                            .getService(KernelConstants.SERVICE);
508:
509:                    if (!kernelService.checkSecurity(surveyUri,
510:                            SurveyConstants.SECURITY_VOTE)) {
511:                        throw new LibresourceSecurityException(surveyUri,
512:                                SurveyConstants.SECURITY_VOTE);
513:                    }
514:
515:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
516:                            .lookup(surveyUri);
517:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
518:                            .findResource(resourceIdentifier,
519:                                    SurveyResourceLocal.class);
520:
521:                    if (surveyResourceLocal.getState().compareTo("OPEN") != 0) {
522:                        throw new LibresourceSurveyException(
523:                                "You can't vote in this closed survey...");
524:                    }
525:
526:                    Option option = surveyResourceLocal.getOption(optionId);
527:
528:                    if (option == null) {
529:                        throw new LibresourceSurveyException(
530:                                "Invalid option ID for this survey...");
531:                    }
532:
533:                    if (!surveyResourceLocal.isVoter(kernelService
534:                            .getConnectedResource().getPath())) {
535:                        surveyResourceLocal.addVoter(kernelService
536:                                .getConnectedResource().getPath());
537:                        surveyResourceLocal.setLastVoteDate(new Date());
538:                        surveyResourceLocal.incNbVote(option.getId());
539:
540:                        // update node
541:                        kernelService.setUpdateDate(surveyUri, new Date());
542:
543:                        // event
544:                        Libresource.throwEvent(new LibresourceEvent(surveyUri,
545:                                resourceIdentifier, kernelService
546:                                        .getConnectedResource(),
547:                                SurveyConstants.EVENT_SURVEY_VOTE));
548:                    }
549:                } catch (LibresourceSecurityException se) {
550:                    ctx.setRollbackOnly();
551:                    throw se;
552:                } catch (URINotExistException se) {
553:                    ctx.setRollbackOnly();
554:                    throw se;
555:                } catch (Exception e) {
556:                    ctx.setRollbackOnly();
557:                    throw new LibresourceSurveyException(
558:                            "Error in voteInSurvey : " + e.getMessage(), e);
559:                }
560:            }
561:
562:            /**
563:             * @ejb.interface-method
564:             * @ejb.transaction type="Supports"
565:             */
566:            public boolean isVoterInSurvey(URI surveyUri)
567:                    throws LibresourceSurveyException,
568:                    LibresourceSecurityException, URINotExistException {
569:                try {
570:                    KernelService kernelService = (KernelService) Libresource
571:                            .getService(KernelConstants.SERVICE);
572:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
573:                            .lookup(surveyUri);
574:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
575:                            .findResource(resourceIdentifier,
576:                                    SurveyResourceLocal.class);
577:
578:                    return surveyResourceLocal.isVoter(kernelService
579:                            .getConnectedResource().getPath());
580:                } catch (LibresourceSecurityException se) {
581:                    ctx.setRollbackOnly();
582:                    throw se;
583:                } catch (URINotExistException se) {
584:                    ctx.setRollbackOnly();
585:                    throw se;
586:                } catch (Exception e) {
587:                    ctx.setRollbackOnly();
588:                    throw new LibresourceSurveyException(
589:                            "Error in isVoterInSurvey : " + e.getMessage(), e);
590:                }
591:            }
592:
593:            /**
594:             * @ejb.interface-method
595:             * @ejb.transaction type="Supports"
596:             */
597:            public Vector getResults(URI surveyUri, int nbVoters)
598:                    throws LibresourceSurveyException,
599:                    LibresourceSecurityException, URINotExistException {
600:                try {
601:                    Vector options = getOptionsInSurvey(surveyUri);
602:                    Vector results = new Vector();
603:
604:                    for (Iterator i = options.iterator(); i.hasNext();) {
605:                        Option option = (Option) i.next();
606:                        Object[] tab = new Object[4];
607:                        tab[0] = option.getId();
608:                        tab[1] = option.getChoice();
609:                        tab[2] = new Integer(option.getNbVote());
610:
611:                        if (nbVoters == 0) {
612:                            tab[3] = new Integer(0);
613:                        } else {
614:                            //double nb = (double) option.getNbVote() / nbVoters;
615:                            //tab[3] = new Double( Math.floor(nb * 100));
616:                            tab[3] = new Integer(option.getNbVote());
617:                        }
618:
619:                        results.add(tab);
620:                    }
621:
622:                    return results;
623:                } catch (LibresourceSecurityException se) {
624:                    throw se;
625:                } catch (URINotExistException se) {
626:                    throw se;
627:                } catch (Exception e) {
628:                    throw new LibresourceSurveyException(
629:                            "Error in getResults : " + e.getMessage(), e);
630:                }
631:            }
632:
633:            /**
634:             * @ejb.interface-method
635:             * @ejb.transaction type="Required"
636:             */
637:            public void closeSurvey(URI surveyUri)
638:                    throws LibresourceSurveyException,
639:                    LibresourceSecurityException, URINotExistException {
640:                try {
641:                    KernelService kernelService = (KernelService) Libresource
642:                            .getService(KernelConstants.SERVICE);
643:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
644:                            .lookup(surveyUri);
645:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
646:                            .findResource(resourceIdentifier,
647:                                    SurveyResourceLocal.class);
648:
649:                    if (!kernelService.checkSecurity(surveyUri,
650:                            KernelConstants.SECURITY_UPDATE)) {
651:                        throw new LibresourceSecurityException(surveyUri,
652:                                KernelConstants.SECURITY_UPDATE);
653:                    }
654:
655:                    surveyResourceLocal.setState("CLOSED");
656:
657:                    // update node
658:                    kernelService.setUpdateDate(surveyUri, new Date());
659:
660:                    // event
661:                    Libresource.throwEvent(new LibresourceEvent(surveyUri,
662:                            resourceIdentifier, kernelService
663:                                    .getConnectedResource(),
664:                            SurveyConstants.EVENT_SURVEY_CLOSE));
665:                } catch (LibresourceSecurityException se) {
666:                    throw se;
667:                } catch (URINotExistException se) {
668:                    throw se;
669:                } catch (Exception e) {
670:                    throw new LibresourceSurveyException(
671:                            "Error in getResults : " + e.getMessage(), e);
672:                }
673:            }
674:
675:            /**
676:             * @ejb.interface-method
677:             * @ejb.transaction type="Required"
678:             */
679:            public void openSurvey(URI surveyUri)
680:                    throws LibresourceSurveyException,
681:                    LibresourceSecurityException, URINotExistException {
682:                try {
683:                    KernelService kernelService = (KernelService) Libresource
684:                            .getService(KernelConstants.SERVICE);
685:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
686:                            .lookup(surveyUri);
687:                    SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
688:                            .findResource(resourceIdentifier,
689:                                    SurveyResourceLocal.class);
690:
691:                    if (!kernelService.checkSecurity(surveyUri,
692:                            KernelConstants.SECURITY_UPDATE)) {
693:                        throw new LibresourceSecurityException(surveyUri,
694:                                KernelConstants.SECURITY_UPDATE);
695:                    }
696:
697:                    surveyResourceLocal.setState("OPEN");
698:
699:                    // update node
700:                    kernelService.setUpdateDate(surveyUri, new Date());
701:
702:                    // event
703:                    Libresource.throwEvent(new LibresourceEvent(surveyUri,
704:                            resourceIdentifier, kernelService
705:                                    .getConnectedResource(),
706:                            SurveyConstants.EVENT_SURVEY_OPEN));
707:                } catch (LibresourceSecurityException se) {
708:                    throw se;
709:                } catch (URINotExistException se) {
710:                    throw se;
711:                } catch (Exception e) {
712:                    throw new LibresourceSurveyException(
713:                            "Error in getResults : " + e.getMessage(), e);
714:                }
715:            }
716:
717:            // libresource service
718:
719:            /**
720:             * @ejb.interface-method
721:             * @ejb.transaction type="Supports"
722:             */
723:            public LibresourceIndexableContent getIndexableContent(
724:                    LibresourceResourceIdentifier resourceIdentifier)
725:                    throws LibresourceException {
726:                try {
727:                    try {
728:                        Libresource.checkType(resourceIdentifier,
729:                                SurveyResourceLocal.class);
730:
731:                        LibresourceIndexableContent content = new LibresourceIndexableContent();
732:                        SurveyResourceLocal surveyResourceLocal = (SurveyResourceLocal) Libresource
733:                                .findResource(resourceIdentifier);
734:                        content.addContentPart(surveyResourceLocal
735:                                .getQuestion());
736:
737:                        return content;
738:                    } catch (LibresourceException e) {
739:                        //
740:                    }
741:
742:                    return null;
743:                } catch (Exception e) {
744:                    throw new LibresourceException(
745:                            "error in LibresourceSurvey.getIndexableContent("
746:                                    + resourceIdentifier + ")", e);
747:                }
748:            }
749:
750:            /**
751:             * @ejb.interface-method
752:             * @ejb.transaction type="Supports"
753:             */
754:            public String[] listAvailablesPermissions(
755:                    LibresourceResourceIdentifier resourceIdentifier)
756:                    throws LibresourceException {
757:                if (resourceIdentifier.getService().equals(
758:                        SurveyConstants.SERVICE)) {
759:                    if (resourceIdentifier.getResourceType().equals(
760:                            SurveyConstants.RESOURCE)) {
761:                        return new String[] { SurveyConstants.SECURITY_VOTE };
762:                    }
763:                }
764:
765:                return super .listAvailablesPermissions(resourceIdentifier);
766:            }
767:
768:            /**
769:             * @ejb.interface-method
770:             * @ejb.transaction type="Supports"
771:             */
772:            public String[] listAvailablesEvents(
773:                    LibresourceResourceIdentifier resourceIdentifier)
774:                    throws LibresourceException {
775:                if (resourceIdentifier.getService().equals(
776:                        SurveyConstants.SERVICE)) {
777:                    if (resourceIdentifier.getResourceType().equals(
778:                            SurveyConstants.RESOURCE)) {
779:                        return new String[] {
780:                                SurveyConstants.EVENT_SURVEY_CREATE,
781:                                SurveyConstants.EVENT_SURVEY_EDIT,
782:                                SurveyConstants.EVENT_SURVEY_ADD_OPTION,
783:                                SurveyConstants.EVENT_SURVEY_DELETE_OPTION,
784:                                SurveyConstants.EVENT_SURVEY_VOTE,
785:                                SurveyConstants.EVENT_SURVEY_CLOSE,
786:                                SurveyConstants.EVENT_SURVEY_OPEN };
787:                    }
788:                }
789:
790:                return super .listAvailablesPermissions(resourceIdentifier);
791:            }
792:
793:            /**
794:             * @ejb.interface-method
795:             * @ejb.transaction type="Supports"
796:             */
797:            public LibresourceExportHandler getXmlExportHandlerForResource(
798:                    URI uri) throws LibresourceException {
799:                try {
800:                    KernelService kernelService = (KernelService) Libresource
801:                            .getService(KernelConstants.SERVICE);
802:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
803:                            .lookup(uri);
804:
805:                    try {
806:                        Libresource.checkType(resourceIdentifier,
807:                                SurveyResourceLocal.class);
808:
809:                        return new SurveyExportHandler(uri);
810:                    } catch (Exception e) {
811:                        //
812:                    }
813:
814:                    return super .getXmlExportHandlerForResource(uri);
815:                } catch (Exception e) {
816:                    throw new LibresourceException(
817:                            "Can't obtain exportHandler for uri " + uri, e);
818:                }
819:            }
820:
821:            /**
822:             * @ejb.interface-method
823:             * @ejb.transaction type="Supports"
824:             */
825:            public LibresourceImportHandler getXmlImportHandler(String type)
826:                    throws LibresourceException {
827:                if (type.equals(SurveyConstants.RESOURCE)) {
828:                    return new SurveyImportHandler();
829:                }
830:
831:                return super.getXmlImportHandler(type);
832:            }
833:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.