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


0001:        /**
0002:         * LibreSource
0003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
0004:         * http://www.libresource.org - contact@artenum.com
0005:         *
0006:         * This file is part of the LibreSource software, 
0007:         * which can be used and distributed under license conditions.
0008:         * The license conditions are provided in the LICENSE.TXT file 
0009:         * at the root path of the packaging that enclose this file. 
0010:         * More information can be found at 
0011:         * - http://dev.libresource.org/home/license
0012:         *
0013:         * Initial authors :
0014:         *
0015:         * Guillaume Bort / INRIA
0016:         * Francois Charoy / Universite Nancy 2
0017:         * Julien Forest / Artenum
0018:         * Claude Godart / Universite Henry Poincare
0019:         * Florent Jouille / INRIA
0020:         * Sebastien Jourdain / INRIA / Artenum
0021:         * Yves Lerumeur / Artenum
0022:         * Pascal Molli / Universite Henry Poincare
0023:         * Gerald Oster / INRIA
0024:         * Mariarosa Penzi / Artenum
0025:         * Gerard Sookahet / Artenum
0026:         * Raphael Tani / INRIA
0027:         *
0028:         * Contributors :
0029:         *
0030:         * Stephane Bagnier / Artenum
0031:         * Amadou Dia / Artenum-IUP Blois
0032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0033:         */package org.libresource.core.ejb;
0034:
0035:        import org.libresource.Libresource;
0036:        import org.libresource.LibresourceEvent;
0037:        import org.libresource.LibresourceException;
0038:        import org.libresource.LibresourceResourceIdentifier;
0039:        import org.libresource.LibresourceResourceValue;
0040:        import org.libresource.LibresourceServiceBase;
0041:
0042:        import org.libresource.core.CoreConstants;
0043:        import org.libresource.core.FileData;
0044:        import org.libresource.core.FileDataImpl;
0045:        import org.libresource.core.LibresourceCoreServiceException;
0046:        import org.libresource.core.ProjectExportHandler;
0047:        import org.libresource.core.ProjectImportHandler;
0048:        import org.libresource.core.TemplateExportHandler;
0049:        import org.libresource.core.TemplateImportExportLogger;
0050:        import org.libresource.core.TemplateImportHandler;
0051:        import org.libresource.core.TimelineDateItem;
0052:        import org.libresource.core.TimelineExportHandler;
0053:        import org.libresource.core.TimelineImportHandler;
0054:        import org.libresource.core.TimelineItem;
0055:        import org.libresource.core.URIResolver;
0056:        import org.libresource.core.ejb.model.EventFilterValue;
0057:        import org.libresource.core.ejb.model.ProjectResourceValue;
0058:        import org.libresource.core.ejb.model.TemplateResourceValue;
0059:        import org.libresource.core.ejb.model.TimelineResourceValue;
0060:        import org.libresource.core.interfaces.ProjectResourceLocal;
0061:        import org.libresource.core.interfaces.TemplateResourceLocal;
0062:        import org.libresource.core.interfaces.TimelineResourceLocal;
0063:        import org.libresource.core.util.ProjectResourceUtil;
0064:        import org.libresource.core.util.TemplateResourceUtil;
0065:        import org.libresource.core.util.TimelineResourceUtil;
0066:
0067:        import org.libresource.kernel.KernelConstants;
0068:        import org.libresource.kernel.LibresourceSecurityException;
0069:        import org.libresource.kernel.URINotExistException;
0070:        import org.libresource.kernel.interfaces.KernelService;
0071:
0072:        import org.libresource.membership.MembershipConstants;
0073:        import org.libresource.membership.interfaces.MembershipService;
0074:
0075:        import org.libresource.scheduler.LibresourceJob;
0076:
0077:        import org.libresource.search.LibresourceIndexableContent;
0078:
0079:        import org.libresource.xml.LibresourceExportHandler;
0080:        import org.libresource.xml.LibresourceImportExport;
0081:        import org.libresource.xml.LibresourceImportHandler;
0082:
0083:        import java.io.BufferedInputStream;
0084:        import java.io.BufferedOutputStream;
0085:        import java.io.File;
0086:        import java.io.FileOutputStream;
0087:        import java.io.InputStream;
0088:        import java.io.OutputStream;
0089:
0090:        import java.net.URI;
0091:
0092:        import java.sql.Connection;
0093:        import java.sql.PreparedStatement;
0094:        import java.sql.ResultSet;
0095:        import java.sql.Statement;
0096:
0097:        import java.util.ArrayList;
0098:        import java.util.Collection;
0099:        import java.util.Date;
0100:        import java.util.HashSet;
0101:        import java.util.Hashtable;
0102:        import java.util.Iterator;
0103:        import java.util.Vector;
0104:
0105:        import javax.naming.InitialContext;
0106:
0107:        /**
0108:         * The main Libresource service
0109:         *
0110:         * @libresource.service name="LibresourceCore" depends="Kernel,Membership"
0111:         *
0112:         * @ejb.env-entry name="uri-resolver-class"
0113:         *                value="org.libresource.core.BasicURIResolver"
0114:         */
0115:        public abstract class LibresourceCoreServiceBean extends
0116:                LibresourceServiceBase {
0117:            static {
0118:                try {
0119:                    KernelService kernelService = (KernelService) Libresource
0120:                            .getService(KernelConstants.SERVICE);
0121:                    LibresourceJob libresourceJob = new LibresourceJob(
0122:                            "project.stats.compute", new Hashtable());
0123:                    kernelService.scheduleJob(libresourceJob,
0124:                            "Compute Projects Statistics", "0 30 0 * * ?");
0125:                } catch (Exception e) {
0126:                }
0127:            }
0128:
0129:            private transient HashSet loggedEventsTypes;
0130:            private transient String distributedFilesystem;
0131:            private transient URIResolver uriResolver;
0132:            private transient File fileSystemBase;
0133:
0134:            // miscelleanous
0135:
0136:            /**
0137:             * @ejb.interface-method
0138:             * @ejb.transaction type="Supports"
0139:             */
0140:            public URIResolver getUriResolver()
0141:                    throws LibresourceCoreServiceException {
0142:                try {
0143:                    if (uriResolver == null) {
0144:                        uriResolver = (URIResolver) Class.forName(
0145:                                new InitialContext().lookup(
0146:                                        "java:comp/env/uri-resolver-class")
0147:                                        .toString()).newInstance();
0148:                    }
0149:
0150:                    return uriResolver;
0151:                } catch (Exception e) {
0152:                    throw new LibresourceCoreServiceException(
0153:                            "Error in getUriResolver " + e.getMessage(), e);
0154:                }
0155:            }
0156:
0157:            /**
0158:             * @ejb.interface-method
0159:             * @ejb.transaction type="Supports"
0160:             */
0161:            public String getDistributedFileSystem()
0162:                    throws LibresourceCoreServiceException,
0163:                    LibresourceSecurityException {
0164:                try {
0165:                    if (distributedFilesystem == null) {
0166:                        //distributedFilesystem = (String) new InitialContext().lookup("java:comp/env/distributed-filesystem");
0167:                        distributedFilesystem = org.libresource.Libresource
0168:                                .getLibresourceConfiguration("libresource.distributedFilesystem");
0169:
0170:                        if ((distributedFilesystem == null)
0171:                                || distributedFilesystem.trim().equals("")) {
0172:                            distributedFilesystem = System
0173:                                    .getProperty("java.io.tmpdir")
0174:                                    + File.separator + "libresource-tmp";
0175:                        }
0176:                    }
0177:
0178:                    // exists ?
0179:                    File tempDirectory = new File(distributedFilesystem);
0180:
0181:                    if (!tempDirectory.exists()) {
0182:                        tempDirectory.mkdirs();
0183:                    }
0184:
0185:                    return tempDirectory.getAbsolutePath();
0186:
0187:                    //return distributedFilesystem;
0188:                } catch (Exception e) {
0189:                    throw new LibresourceCoreServiceException(e);
0190:                }
0191:            }
0192:
0193:            /**
0194:             * @ejb.interface-method
0195:             * @ejb.transaction type="Supports"
0196:             */
0197:            public HashSet getDefaultLoggedEvents() {
0198:                if (loggedEventsTypes == null) {
0199:                    loggedEventsTypes = new HashSet();
0200:                    loggedEventsTypes.add("libresourceCore.project.create");
0201:                    loggedEventsTypes
0202:                            .add("libresourceCore.project.editSummary");
0203:                    loggedEventsTypes.add("libresourceWiki.page.create");
0204:                    loggedEventsTypes.add("libresourceWiki.page.editContent");
0205:                    loggedEventsTypes
0206:                            .add("libresourceBugTracker.bugTracker.create");
0207:                    loggedEventsTypes.add("libresourceBugTracker.issue.create");
0208:                    loggedEventsTypes
0209:                            .add("libresourceBugTracker.issue.resolve");
0210:                    loggedEventsTypes.add("libresourceForum.forum.create");
0211:                    loggedEventsTypes.add("libresourceForum.forum.post");
0212:                    loggedEventsTypes.add("libresourceForum.thread.reply");
0213:                    loggedEventsTypes.add("libresourceFiles.repository.create");
0214:                    loggedEventsTypes.add("libresourceFiles.file.create");
0215:                    loggedEventsTypes.add("libresourceFiles.file.edit");
0216:                    loggedEventsTypes
0217:                            .add("libresourceSynchronizer.synchronizer.create");
0218:                    loggedEventsTypes
0219:                            .add("libresourceSynchronizer.synchronizer.addPatch");
0220:                }
0221:
0222:                return (HashSet) loggedEventsTypes.clone();
0223:            }
0224:
0225:            // template management
0226:
0227:            /**
0228:             * @ejb.interface-method
0229:             * @ejb.transaction type="Required"
0230:             */
0231:            public void createTemplate(URI uri, String name, String description)
0232:                    throws LibresourceCoreServiceException,
0233:                    LibresourceSecurityException {
0234:                try {
0235:                    KernelService kernelService = (KernelService) Libresource
0236:                            .getService(KernelConstants.SERVICE);
0237:
0238:                    if (!kernelService.checkSecurity(uri,
0239:                            KernelConstants.SECURITY_CREATE)) {
0240:                        throw new LibresourceSecurityException(uri,
0241:                                KernelConstants.SECURITY_CREATE);
0242:                    }
0243:
0244:                    TemplateResourceLocal templateResourceLocal = TemplateResourceUtil
0245:                            .getLocalHome().create(name, description);
0246:                    kernelService.bind(templateResourceLocal
0247:                            .getLibresourceResourceIdentifier(), uri, name);
0248:
0249:                    // event
0250:                    LibresourceEvent event = new LibresourceEvent(uri,
0251:                            templateResourceLocal
0252:                                    .getLibresourceResourceIdentifier(),
0253:                            kernelService.getConnectedResource(),
0254:                            CoreConstants.EVENT_TEMPLATE_CREATE);
0255:                    Libresource.throwEvent(event);
0256:                } catch (LibresourceSecurityException se) {
0257:                    ctx.setRollbackOnly();
0258:                    throw se;
0259:                } catch (Exception e) {
0260:                    ctx.setRollbackOnly();
0261:                    throw new LibresourceCoreServiceException(
0262:                            "Error in createTemplate : " + e.getMessage(), e);
0263:                }
0264:            }
0265:
0266:            /**
0267:             * @ejb.interface-method
0268:             * @ejb.transaction type="Required"
0269:             */
0270:            public void editTemplate(URI uri, String name, String description)
0271:                    throws LibresourceCoreServiceException,
0272:                    LibresourceSecurityException, URINotExistException {
0273:                try {
0274:                    KernelService kernelService = (KernelService) Libresource
0275:                            .getService(KernelConstants.SERVICE);
0276:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0277:                            .lookup(uri);
0278:
0279:                    if (!kernelService.checkSecurity(uri,
0280:                            KernelConstants.SECURITY_UPDATE)) {
0281:                        throw new LibresourceSecurityException(uri,
0282:                                KernelConstants.SECURITY_UPDATE);
0283:                    }
0284:
0285:                    TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) Libresource
0286:                            .findResource(resourceIdentifier,
0287:                                    TemplateResourceLocal.class);
0288:                    templateResourceLocal.setName(name);
0289:                    templateResourceLocal.setDescription(description);
0290:
0291:                    // update node
0292:                    kernelService.setShortName(uri, name);
0293:                    kernelService.setUpdateDate(uri, new Date());
0294:
0295:                    // event
0296:                    LibresourceEvent event = new LibresourceEvent(uri,
0297:                            resourceIdentifier, kernelService
0298:                                    .getConnectedResource(),
0299:                            CoreConstants.EVENT_TEMPLATE_EDIT);
0300:                    Libresource.throwEvent(event);
0301:
0302:                    // indexation
0303:                    Libresource.index(uri);
0304:                } catch (LibresourceSecurityException se) {
0305:                    ctx.setRollbackOnly();
0306:                    throw se;
0307:                } catch (URINotExistException se) {
0308:                    ctx.setRollbackOnly();
0309:                    throw se;
0310:                } catch (Exception e) {
0311:                    ctx.setRollbackOnly();
0312:                    throw new LibresourceCoreServiceException(
0313:                            "Error in editTemplate : " + e.getMessage(), e);
0314:                }
0315:            }
0316:
0317:            /**
0318:             * @ejb.interface-method
0319:             * @ejb.transaction type="Supports"
0320:             */
0321:            public TemplateResourceValue getTemplate(URI uri)
0322:                    throws LibresourceCoreServiceException,
0323:                    LibresourceSecurityException, URINotExistException {
0324:                try {
0325:                    KernelService kernelService = (KernelService) Libresource
0326:                            .getService(KernelConstants.SERVICE);
0327:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0328:                            .lookup(uri);
0329:                    TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) Libresource
0330:                            .findResource(resourceIdentifier,
0331:                                    TemplateResourceLocal.class);
0332:
0333:                    return templateResourceLocal.getTemplateResourceValue();
0334:                } catch (LibresourceSecurityException se) {
0335:                    throw se;
0336:                } catch (URINotExistException se) {
0337:                    throw se;
0338:                } catch (Exception e) {
0339:                    throw new LibresourceCoreServiceException(
0340:                            "Error in getTemplate : " + e.getMessage(), e);
0341:                }
0342:            }
0343:
0344:            // timeline management
0345:
0346:            /**
0347:             * @ejb.interface-method
0348:             * @ejb.transaction type="Required"
0349:             */
0350:            public void createTimeline(URI uri, String name, String uriPattern)
0351:                    throws LibresourceCoreServiceException,
0352:                    LibresourceSecurityException {
0353:                try {
0354:                    if (uriPattern.indexOf("%") != -1) {
0355:                        throw new Exception(
0356:                                "% is not a valid symbol in this expression");
0357:                    }
0358:
0359:                    KernelService kernelService = (KernelService) Libresource
0360:                            .getService(KernelConstants.SERVICE);
0361:
0362:                    if (!kernelService.checkSecurity(uri,
0363:                            KernelConstants.SECURITY_CREATE)) {
0364:                        throw new LibresourceSecurityException(uri,
0365:                                KernelConstants.SECURITY_CREATE);
0366:                    }
0367:
0368:                    TimelineResourceLocal timelineResourceLocal = TimelineResourceUtil
0369:                            .getLocalHome().create(name,
0370:                                    resolveTimelineUriPattern(uri, uriPattern));
0371:                    kernelService.bind(timelineResourceLocal
0372:                            .getLibresourceResourceIdentifier(), uri, name);
0373:
0374:                    // event
0375:                    LibresourceEvent event = new LibresourceEvent(uri,
0376:                            timelineResourceLocal
0377:                                    .getLibresourceResourceIdentifier(),
0378:                            kernelService.getConnectedResource(),
0379:                            CoreConstants.EVENT_TIMELINE_CREATE);
0380:                    Libresource.throwEvent(event);
0381:                } catch (LibresourceSecurityException se) {
0382:                    ctx.setRollbackOnly();
0383:                    throw se;
0384:                } catch (Exception e) {
0385:                    ctx.setRollbackOnly();
0386:                    throw new LibresourceCoreServiceException(
0387:                            "Error in createTimeline : " + e.getMessage(), e);
0388:                }
0389:            }
0390:
0391:            /**
0392:             * @ejb.interface-method
0393:             * @ejb.transaction type="Required"
0394:             */
0395:            public void editTimeline(URI uri, String name, String uriPattern,
0396:                    boolean publicEvents)
0397:                    throws LibresourceCoreServiceException,
0398:                    LibresourceSecurityException, URINotExistException {
0399:                try {
0400:                    KernelService kernelService = (KernelService) Libresource
0401:                            .getService(KernelConstants.SERVICE);
0402:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0403:                            .lookup(uri);
0404:
0405:                    if (!kernelService.checkSecurity(uri,
0406:                            KernelConstants.SECURITY_UPDATE)) {
0407:                        throw new LibresourceSecurityException(uri,
0408:                                KernelConstants.SECURITY_UPDATE);
0409:                    }
0410:
0411:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0412:                            .findResource(resourceIdentifier,
0413:                                    TimelineResourceLocal.class);
0414:                    timelineResourceLocal.setName(name);
0415:                    timelineResourceLocal.setRootURI(resolveTimelineUriPattern(
0416:                            uri, uriPattern));
0417:                    timelineResourceLocal.setPublicEvents(publicEvents);
0418:
0419:                    // update node
0420:                    kernelService.setShortName(uri, name);
0421:                    kernelService.setUpdateDate(uri, new Date());
0422:
0423:                    // event
0424:                    LibresourceEvent event = new LibresourceEvent(uri,
0425:                            resourceIdentifier, kernelService
0426:                                    .getConnectedResource(),
0427:                            CoreConstants.EVENT_TIMELINE_EDIT);
0428:                    Libresource.throwEvent(event);
0429:
0430:                    // indexation
0431:                    Libresource.index(uri);
0432:                } catch (LibresourceSecurityException se) {
0433:                    ctx.setRollbackOnly();
0434:                    throw se;
0435:                } catch (URINotExistException se) {
0436:                    ctx.setRollbackOnly();
0437:                    throw se;
0438:                } catch (Exception e) {
0439:                    ctx.setRollbackOnly();
0440:                    throw new LibresourceCoreServiceException(
0441:                            "Error in editTimeline : " + e.getMessage(), e);
0442:                }
0443:            }
0444:
0445:            /**
0446:             * @ejb.interface-method
0447:             * @ejb.transaction type="Required"
0448:             */
0449:            public void cleanTimeline(URI uri)
0450:                    throws LibresourceCoreServiceException,
0451:                    LibresourceSecurityException, URINotExistException {
0452:                try {
0453:                    KernelService kernelService = (KernelService) Libresource
0454:                            .getService(KernelConstants.SERVICE);
0455:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0456:                            .lookup(uri);
0457:
0458:                    if (!kernelService.checkSecurity(uri,
0459:                            KernelConstants.SECURITY_UPDATE)) {
0460:                        throw new LibresourceSecurityException(uri,
0461:                                KernelConstants.SECURITY_UPDATE);
0462:                    }
0463:
0464:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0465:                            .findResource(resourceIdentifier,
0466:                                    TimelineResourceLocal.class);
0467:                    timelineResourceLocal.clean();
0468:
0469:                    // update node
0470:                    kernelService.setUpdateDate(uri, new Date());
0471:
0472:                    // indexation
0473:                    Libresource.index(uri);
0474:                } catch (LibresourceSecurityException se) {
0475:                    ctx.setRollbackOnly();
0476:                    throw se;
0477:                } catch (URINotExistException se) {
0478:                    ctx.setRollbackOnly();
0479:                    throw se;
0480:                } catch (Exception e) {
0481:                    ctx.setRollbackOnly();
0482:                    throw new LibresourceCoreServiceException(
0483:                            "Error in editTimeline : " + e.getMessage(), e);
0484:                }
0485:            }
0486:
0487:            /**
0488:             * @ejb.interface-method
0489:             * @ejb.transaction type="Required"
0490:             */
0491:            public void addLoggedEventInTimeline(URI timelineUri, String event)
0492:                    throws LibresourceCoreServiceException,
0493:                    LibresourceSecurityException, URINotExistException {
0494:                try {
0495:                    KernelService kernelService = (KernelService) Libresource
0496:                            .getService(KernelConstants.SERVICE);
0497:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0498:                            .lookup(timelineUri);
0499:
0500:                    if (!kernelService.checkSecurity(timelineUri,
0501:                            KernelConstants.SECURITY_UPDATE)) {
0502:                        throw new LibresourceSecurityException(timelineUri,
0503:                                KernelConstants.SECURITY_UPDATE);
0504:                    }
0505:
0506:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0507:                            .findResource(resourceIdentifier,
0508:                                    TimelineResourceLocal.class);
0509:
0510:                    if (getDefaultLoggedEvents().contains(event)) {
0511:                        timelineResourceLocal.addLoggedEvents(event);
0512:                    }
0513:
0514:                    // update node
0515:                    kernelService.setUpdateDate(timelineUri, new Date());
0516:                } catch (LibresourceSecurityException se) {
0517:                    ctx.setRollbackOnly();
0518:                    throw se;
0519:                } catch (URINotExistException se) {
0520:                    ctx.setRollbackOnly();
0521:                    throw se;
0522:                } catch (Exception e) {
0523:                    ctx.setRollbackOnly();
0524:                    throw new LibresourceCoreServiceException(
0525:                            "Error in addLoggedEventInTimeline : "
0526:                                    + e.getMessage(), e);
0527:                }
0528:            }
0529:
0530:            /**
0531:             * @ejb.interface-method
0532:             * @ejb.transaction type="Required"
0533:             */
0534:            public void removeLoggedEventInTimeline(URI timelineUri,
0535:                    String event) throws LibresourceCoreServiceException,
0536:                    LibresourceSecurityException, URINotExistException {
0537:                try {
0538:                    KernelService kernelService = (KernelService) Libresource
0539:                            .getService(KernelConstants.SERVICE);
0540:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0541:                            .lookup(timelineUri);
0542:
0543:                    if (!kernelService.checkSecurity(timelineUri,
0544:                            KernelConstants.SECURITY_UPDATE)) {
0545:                        throw new LibresourceSecurityException(timelineUri,
0546:                                KernelConstants.SECURITY_UPDATE);
0547:                    }
0548:
0549:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0550:                            .findResource(resourceIdentifier,
0551:                                    TimelineResourceLocal.class);
0552:                    timelineResourceLocal.removeLoggedEvents(event);
0553:
0554:                    // update node
0555:                    kernelService.setUpdateDate(timelineUri, new Date());
0556:                } catch (LibresourceSecurityException se) {
0557:                    ctx.setRollbackOnly();
0558:                    throw se;
0559:                } catch (URINotExistException se) {
0560:                    ctx.setRollbackOnly();
0561:                    throw se;
0562:                } catch (Exception e) {
0563:                    ctx.setRollbackOnly();
0564:                    throw new LibresourceCoreServiceException(
0565:                            "Error in removeLoggedEventInTimeline : "
0566:                                    + e.getMessage(), e);
0567:                }
0568:            }
0569:
0570:            /**
0571:             * @ejb.interface-method
0572:             * @ejb.transaction type="Required"
0573:             */
0574:            public void resetLoggedEventsInTimeline(URI timelineUri)
0575:                    throws LibresourceCoreServiceException,
0576:                    LibresourceSecurityException, URINotExistException {
0577:                try {
0578:                    KernelService kernelService = (KernelService) Libresource
0579:                            .getService(KernelConstants.SERVICE);
0580:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0581:                            .lookup(timelineUri);
0582:
0583:                    if (!kernelService.checkSecurity(timelineUri,
0584:                            KernelConstants.SECURITY_UPDATE)) {
0585:                        throw new LibresourceSecurityException(timelineUri,
0586:                                KernelConstants.SECURITY_UPDATE);
0587:                    }
0588:
0589:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0590:                            .findResource(resourceIdentifier,
0591:                                    TimelineResourceLocal.class);
0592:                    timelineResourceLocal
0593:                            .setLoggedEvents((HashSet) getDefaultLoggedEvents()
0594:                                    .clone());
0595:
0596:                    // update node
0597:                    kernelService.setUpdateDate(timelineUri, new Date());
0598:                } catch (LibresourceSecurityException se) {
0599:                    ctx.setRollbackOnly();
0600:                    throw se;
0601:                } catch (URINotExistException se) {
0602:                    ctx.setRollbackOnly();
0603:                    throw se;
0604:                } catch (Exception e) {
0605:                    ctx.setRollbackOnly();
0606:                    throw new LibresourceCoreServiceException(
0607:                            "Error in removeLoggedEventInTimeline : "
0608:                                    + e.getMessage(), e);
0609:                }
0610:            }
0611:
0612:            private String resolveTimelineUriPattern(URI uri, String pattern)
0613:                    throws Exception {
0614:                if (pattern.indexOf("%") != -1) {
0615:                    throw new Exception(
0616:                            "% is not a valid symbol in this expression");
0617:                }
0618:
0619:                if (pattern.startsWith("/")) {
0620:                    return pattern.replaceAll("\\*", "%");
0621:                }
0622:
0623:                String path = uri.getPath();
0624:
0625:                if (!path.endsWith("/")) {
0626:                    path = path + "/";
0627:                }
0628:
0629:                return new URI(path).resolve(pattern).getPath().replaceAll(
0630:                        "\\*", "%");
0631:            }
0632:
0633:            /**
0634:             * @ejb.interface-method
0635:             * @ejb.transaction type="Supports"
0636:             */
0637:            public TimelineResourceValue getTimeline(URI uri)
0638:                    throws LibresourceCoreServiceException,
0639:                    LibresourceSecurityException, URINotExistException {
0640:                try {
0641:                    KernelService kernelService = (KernelService) Libresource
0642:                            .getService(KernelConstants.SERVICE);
0643:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0644:                            .lookup(uri);
0645:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0646:                            .findResource(resourceIdentifier,
0647:                                    TimelineResourceLocal.class);
0648:
0649:                    return timelineResourceLocal.getTimelineResourceValue();
0650:                } catch (LibresourceSecurityException se) {
0651:                    throw se;
0652:                } catch (URINotExistException se) {
0653:                    throw se;
0654:                } catch (Exception e) {
0655:                    throw new LibresourceCoreServiceException(
0656:                            "Error in getTimeline : " + e.getMessage(), e);
0657:                }
0658:            }
0659:
0660:            /**
0661:             * @ejb.interface-method
0662:             * @ejb.transaction type="Supports"
0663:             */
0664:            public Date[] getTimelineDates(URI uri)
0665:                    throws LibresourceCoreServiceException,
0666:                    LibresourceSecurityException, URINotExistException {
0667:                try {
0668:                    KernelService kernelService = (KernelService) Libresource
0669:                            .getService(KernelConstants.SERVICE);
0670:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0671:                            .lookup(uri);
0672:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0673:                            .findResource(resourceIdentifier,
0674:                                    TimelineResourceLocal.class);
0675:                    Vector dates = timelineResourceLocal.getDates();
0676:                    Date[] result = new Date[dates.size()];
0677:
0678:                    for (int i = 0; i < result.length; i++) {
0679:                        result[i] = (Date) dates.get(i);
0680:                    }
0681:
0682:                    return result;
0683:                } catch (LibresourceSecurityException se) {
0684:                    throw se;
0685:                } catch (URINotExistException se) {
0686:                    throw se;
0687:                } catch (Exception e) {
0688:                    throw new LibresourceCoreServiceException(
0689:                            "Error in getTimelineDates : " + e.getMessage(), e);
0690:                }
0691:            }
0692:
0693:            /**
0694:             * @ejb.interface-method
0695:             * @ejb.transaction type="Supports"
0696:             */
0697:            public TimelineItem[] getTimelineItems(URI uri, Date date)
0698:                    throws LibresourceCoreServiceException,
0699:                    LibresourceSecurityException, URINotExistException {
0700:                try {
0701:                    KernelService kernelService = (KernelService) Libresource
0702:                            .getService(KernelConstants.SERVICE);
0703:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0704:                            .lookup(uri);
0705:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0706:                            .findResource(resourceIdentifier,
0707:                                    TimelineResourceLocal.class);
0708:                    Vector items = timelineResourceLocal.getItems(date);
0709:                    TimelineItem[] result = new TimelineItem[items.size()];
0710:
0711:                    for (int i = 0; i < result.length; i++) {
0712:                        result[i] = (TimelineItem) items.get(i);
0713:                    }
0714:
0715:                    return result;
0716:                } catch (LibresourceSecurityException se) {
0717:                    throw se;
0718:                } catch (URINotExistException se) {
0719:                    throw se;
0720:                } catch (Exception e) {
0721:                    throw new LibresourceCoreServiceException(
0722:                            "Error in getTimelineItems : " + e.getMessage(), e);
0723:                }
0724:            }
0725:
0726:            /**
0727:             * @ejb.interface-method
0728:             * @ejb.transaction type="Supports"
0729:             */
0730:            public TimelineDateItem[] getTimelineDateItems(URI uri, int maxDays)
0731:                    throws LibresourceCoreServiceException,
0732:                    LibresourceSecurityException, URINotExistException {
0733:                try {
0734:                    KernelService kernelService = (KernelService) Libresource
0735:                            .getService(KernelConstants.SERVICE);
0736:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0737:                            .lookup(uri);
0738:                    TimelineResourceLocal timelineResourceLocal = (TimelineResourceLocal) Libresource
0739:                            .findResource(resourceIdentifier,
0740:                                    TimelineResourceLocal.class);
0741:                    Vector dates = timelineResourceLocal.getDates();
0742:                    TimelineDateItem[] result = new TimelineDateItem[((maxDays == -1) || (dates
0743:                            .size() < maxDays)) ? dates.size() : maxDays];
0744:
0745:                    for (int i = 0; i < result.length; i++) {
0746:                        if ((i < maxDays) || (maxDays == -1)) {
0747:                            Vector items = timelineResourceLocal
0748:                                    .getItems((Date) dates.get(i));
0749:                            result[i] = new TimelineDateItem((Date) dates
0750:                                    .get(i), items);
0751:                        }
0752:                    }
0753:
0754:                    return result;
0755:                } catch (LibresourceSecurityException se) {
0756:                    throw se;
0757:                } catch (URINotExistException se) {
0758:                    throw se;
0759:                } catch (Exception e) {
0760:                    throw new LibresourceCoreServiceException(
0761:                            "Error in getTimelineDateItems : " + e.getMessage(),
0762:                            e);
0763:                }
0764:            }
0765:
0766:            // templates management
0767:
0768:            /**
0769:             * @ejb.interface-method
0770:             * @ejb.transaction type="Required"
0771:             */
0772:            public void importInTemplate(URI uri, URI importFrom)
0773:                    throws LibresourceCoreServiceException,
0774:                    LibresourceSecurityException, URINotExistException {
0775:                try {
0776:                    KernelService kernelService = (KernelService) Libresource
0777:                            .getService(KernelConstants.SERVICE);
0778:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0779:                            .lookup(uri);
0780:
0781:                    if (!kernelService.checkSecurity(uri,
0782:                            KernelConstants.SECURITY_UPDATE)) {
0783:                        throw new LibresourceSecurityException(uri,
0784:                                KernelConstants.SECURITY_UPDATE);
0785:                    }
0786:
0787:                    TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) Libresource
0788:                            .findResource(resourceIdentifier,
0789:                                    TemplateResourceLocal.class);
0790:                    File temp = createTempFile(templateResourceLocal.getId()
0791:                            + "_temp");
0792:                    OutputStream os = new FileOutputStream(temp);
0793:                    LibresourceImportExport importExport = new LibresourceImportExport(
0794:                            true);
0795:                    importExport.exportXML(importFrom, os,
0796:                            new TemplateImportExportLogger());
0797:                    os.close();
0798:                    putFileData("templates_content_", templateResourceLocal
0799:                            .getId(), new FileDataImpl(temp));
0800:
0801:                    // update node
0802:                    kernelService.setUpdateDate(uri, new Date());
0803:                } catch (LibresourceSecurityException se) {
0804:                    ctx.setRollbackOnly();
0805:                    throw se;
0806:                } catch (URINotExistException se) {
0807:                    ctx.setRollbackOnly();
0808:                    throw se;
0809:                } catch (Exception e) {
0810:                    ctx.setRollbackOnly();
0811:                    throw new LibresourceCoreServiceException(
0812:                            "Error in importInTemplate : " + e.getMessage(), e);
0813:                }
0814:            }
0815:
0816:            /**
0817:             * @ejb.interface-method
0818:             * @ejb.transaction type="Required"
0819:             */
0820:            public void setTemplateContent(URI uri, FileData content)
0821:                    throws LibresourceCoreServiceException,
0822:                    LibresourceSecurityException, URINotExistException {
0823:                try {
0824:                    KernelService kernelService = (KernelService) Libresource
0825:                            .getService(KernelConstants.SERVICE);
0826:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0827:                            .lookup(uri);
0828:
0829:                    if (!kernelService.checkSecurity(uri,
0830:                            KernelConstants.SECURITY_UPDATE)) {
0831:                        throw new LibresourceSecurityException(uri,
0832:                                KernelConstants.SECURITY_UPDATE);
0833:                    }
0834:
0835:                    TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) Libresource
0836:                            .findResource(resourceIdentifier,
0837:                                    TemplateResourceLocal.class);
0838:                    putFileData("templates_content_", templateResourceLocal
0839:                            .getId(), content);
0840:
0841:                    // update node
0842:                    kernelService.setUpdateDate(uri, new Date());
0843:                } catch (LibresourceSecurityException se) {
0844:                    ctx.setRollbackOnly();
0845:                    throw se;
0846:                } catch (URINotExistException se) {
0847:                    ctx.setRollbackOnly();
0848:                    throw se;
0849:                } catch (Exception e) {
0850:                    ctx.setRollbackOnly();
0851:                    throw new LibresourceCoreServiceException(
0852:                            "Error in setTemplateContent : " + e.getMessage(),
0853:                            e);
0854:                }
0855:            }
0856:
0857:            /**
0858:             * @ejb.interface-method
0859:             * @ejb.transaction type="Supports"
0860:             */
0861:            public void newInstanceTemplate(URI uri, URI instanceUri)
0862:                    throws LibresourceCoreServiceException,
0863:                    LibresourceSecurityException, URINotExistException {
0864:                try {
0865:                    KernelService kernelService = (KernelService) Libresource
0866:                            .getService(KernelConstants.SERVICE);
0867:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0868:                            .lookup(uri);
0869:                    TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) Libresource
0870:                            .findResource(resourceIdentifier,
0871:                                    TemplateResourceLocal.class);
0872:                    FileData fileData = getFileData("templates_content_",
0873:                            templateResourceLocal.getId());
0874:                    LibresourceImportExport importExport = new LibresourceImportExport(
0875:                            true);
0876:                    importExport
0877:                            .importXML(instanceUri, fileData.getInputStream(),
0878:                                    new TemplateImportExportLogger());
0879:                } catch (LibresourceSecurityException se) {
0880:                    throw se;
0881:                } catch (URINotExistException se) {
0882:                    throw se;
0883:                } catch (Exception e) {
0884:                    throw new LibresourceCoreServiceException(
0885:                            "Error in newInstanceTemplate : " + e.getMessage(),
0886:                            e);
0887:                }
0888:            }
0889:
0890:            /**
0891:             * @ejb.interface-method
0892:             * @ejb.transaction type="Supports"
0893:             */
0894:            public FileData getTemplateContent(URI uri)
0895:                    throws LibresourceCoreServiceException,
0896:                    LibresourceSecurityException, URINotExistException {
0897:                try {
0898:                    KernelService kernelService = (KernelService) Libresource
0899:                            .getService(KernelConstants.SERVICE);
0900:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0901:                            .lookup(uri);
0902:                    TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) Libresource
0903:                            .findResource(resourceIdentifier,
0904:                                    TemplateResourceLocal.class);
0905:
0906:                    return getFileData("templates_content_",
0907:                            templateResourceLocal.getId());
0908:                } catch (LibresourceSecurityException se) {
0909:                    throw se;
0910:                } catch (URINotExistException se) {
0911:                    throw se;
0912:                } catch (Exception e) {
0913:                    throw new LibresourceCoreServiceException(
0914:                            "Error in newInstanceTemplate : " + e.getMessage(),
0915:                            e);
0916:                }
0917:            }
0918:
0919:            // project management
0920:
0921:            /**
0922:             * @ejb.interface-method
0923:             * @ejb.transaction type="Required"
0924:             */
0925:            public void createProject(URI uri, String name, String description)
0926:                    throws LibresourceCoreServiceException,
0927:                    LibresourceSecurityException {
0928:                try {
0929:                    KernelService kernelService = (KernelService) Libresource
0930:                            .getService(KernelConstants.SERVICE);
0931:                    MembershipService membershipService = (MembershipService) Libresource
0932:                            .getService(MembershipConstants.SERVICE);
0933:
0934:                    if (!kernelService.checkSecurity(uri,
0935:                            KernelConstants.SECURITY_CREATE)) {
0936:                        throw new LibresourceSecurityException(uri,
0937:                                KernelConstants.SECURITY_CREATE);
0938:                    }
0939:
0940:                    ProjectResourceLocal projectResourceLocal = ProjectResourceUtil
0941:                            .getLocalHome().create(
0942:                                    name,
0943:                                    description,
0944:                                    membershipService.getProfile(
0945:                                            kernelService
0946:                                                    .getConnectedResource())
0947:                                            .getFullName());
0948:                    kernelService.bind(projectResourceLocal
0949:                            .getLibresourceResourceIdentifier(), uri, name);
0950:
0951:                    // event
0952:                    LibresourceEvent event = new LibresourceEvent(uri,
0953:                            projectResourceLocal
0954:                                    .getLibresourceResourceIdentifier(),
0955:                            kernelService.getConnectedResource(),
0956:                            CoreConstants.EVENT_PROJECT_CREATE);
0957:                    Libresource.throwEvent(event);
0958:                } catch (LibresourceSecurityException se) {
0959:                    ctx.setRollbackOnly();
0960:                    throw se;
0961:                } catch (Exception e) {
0962:                    ctx.setRollbackOnly();
0963:                    throw new LibresourceCoreServiceException(
0964:                            "Error in createProject : " + e.getMessage(), e);
0965:                }
0966:            }
0967:
0968:            /**
0969:             * @ejb.interface-method
0970:             * @ejb.transaction type="Required"
0971:             */
0972:            public void editProject(URI uri, String name, String description)
0973:                    throws LibresourceCoreServiceException,
0974:                    LibresourceSecurityException, URINotExistException {
0975:                try {
0976:                    KernelService kernelService = (KernelService) Libresource
0977:                            .getService(KernelConstants.SERVICE);
0978:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
0979:                            .lookup(uri);
0980:
0981:                    if (!kernelService.checkSecurity(uri,
0982:                            KernelConstants.SECURITY_UPDATE)) {
0983:                        throw new LibresourceSecurityException(uri,
0984:                                KernelConstants.SECURITY_UPDATE);
0985:                    }
0986:
0987:                    ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) Libresource
0988:                            .findResource(resourceIdentifier,
0989:                                    ProjectResourceLocal.class);
0990:                    projectResourceLocal.setName(name);
0991:                    projectResourceLocal.setDescription(description);
0992:
0993:                    // update node
0994:                    kernelService.setShortName(uri, name);
0995:                    kernelService.setUpdateDate(uri, new Date());
0996:
0997:                    // event
0998:                    LibresourceEvent event = new LibresourceEvent(uri,
0999:                            resourceIdentifier, kernelService
1000:                                    .getConnectedResource(),
1001:                            CoreConstants.EVENT_PROJECT_EDIT);
1002:                    Libresource.throwEvent(event);
1003:
1004:                    // indexation
1005:                    Libresource.index(uri);
1006:                } catch (LibresourceSecurityException se) {
1007:                    ctx.setRollbackOnly();
1008:                    throw se;
1009:                } catch (URINotExistException se) {
1010:                    ctx.setRollbackOnly();
1011:                    throw se;
1012:                } catch (Exception e) {
1013:                    ctx.setRollbackOnly();
1014:                    throw new LibresourceCoreServiceException(
1015:                            "Error in editProject : " + e.getMessage(), e);
1016:                }
1017:            }
1018:
1019:            /**
1020:             * @ejb.interface-method
1021:             * @ejb.transaction type="Required"
1022:             */
1023:            public void editProjectSummary(URI uri, String summary)
1024:                    throws LibresourceCoreServiceException,
1025:                    LibresourceSecurityException, URINotExistException {
1026:                try {
1027:                    KernelService kernelService = (KernelService) Libresource
1028:                            .getService(KernelConstants.SERVICE);
1029:                    MembershipService membershipService = (MembershipService) Libresource
1030:                            .getService(MembershipConstants.SERVICE);
1031:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
1032:                            .lookup(uri);
1033:
1034:                    if (!kernelService.checkSecurity(uri,
1035:                            KernelConstants.SECURITY_UPDATE)) {
1036:                        throw new LibresourceSecurityException(uri,
1037:                                KernelConstants.SECURITY_UPDATE);
1038:                    }
1039:
1040:                    ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) Libresource
1041:                            .findResource(resourceIdentifier,
1042:                                    ProjectResourceLocal.class);
1043:                    projectResourceLocal.setSummary(summary);
1044:                    projectResourceLocal.setLastEditedSummary(new Date());
1045:                    projectResourceLocal.setLastEditor(membershipService
1046:                            .getProfile(kernelService.getConnectedResource())
1047:                            .getFullName());
1048:
1049:                    // update node
1050:                    kernelService.setUpdateDate(uri, new Date());
1051:
1052:                    // event
1053:                    LibresourceEvent event = new LibresourceEvent(uri,
1054:                            resourceIdentifier, kernelService
1055:                                    .getConnectedResource(),
1056:                            CoreConstants.EVENT_PROJECT_EDIT_SUMMARY);
1057:                    Libresource.throwEvent(event);
1058:
1059:                    // indexation
1060:                    Libresource.index(uri);
1061:                } catch (LibresourceSecurityException se) {
1062:                    ctx.setRollbackOnly();
1063:                    throw se;
1064:                } catch (URINotExistException se) {
1065:                    ctx.setRollbackOnly();
1066:                    throw se;
1067:                } catch (Exception e) {
1068:                    ctx.setRollbackOnly();
1069:                    throw new LibresourceCoreServiceException(
1070:                            "Error in editProjectSummary : " + e.getMessage(),
1071:                            e);
1072:                }
1073:            }
1074:
1075:            /**
1076:             * @ejb.interface-method
1077:             * @ejb.transaction type="Required"
1078:             */
1079:            public void editProjectSummary(URI uri, String summary,
1080:                    String editor, Date editionDate)
1081:                    throws LibresourceCoreServiceException,
1082:                    LibresourceSecurityException, URINotExistException {
1083:                try {
1084:                    KernelService kernelService = (KernelService) Libresource
1085:                            .getService(KernelConstants.SERVICE);
1086:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
1087:                            .lookup(uri);
1088:
1089:                    if (!kernelService.checkSecurity(uri,
1090:                            KernelConstants.SECURITY_UPDATE)) {
1091:                        throw new LibresourceSecurityException(uri,
1092:                                KernelConstants.SECURITY_UPDATE);
1093:                    }
1094:
1095:                    ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) Libresource
1096:                            .findResource(resourceIdentifier,
1097:                                    ProjectResourceLocal.class);
1098:                    projectResourceLocal.setSummary(summary);
1099:                    projectResourceLocal.setLastEditedSummary(editionDate);
1100:                    projectResourceLocal.setLastEditor(editor);
1101:
1102:                    // update node
1103:                    kernelService.setUpdateDate(uri, new Date());
1104:
1105:                    // event
1106:                    LibresourceEvent event = new LibresourceEvent(uri,
1107:                            resourceIdentifier, kernelService
1108:                                    .getConnectedResource(),
1109:                            CoreConstants.EVENT_PROJECT_EDIT_SUMMARY);
1110:                    Libresource.throwEvent(event);
1111:
1112:                    // indexation
1113:                    Libresource.index(uri);
1114:                } catch (LibresourceSecurityException se) {
1115:                    ctx.setRollbackOnly();
1116:                    throw se;
1117:                } catch (URINotExistException se) {
1118:                    ctx.setRollbackOnly();
1119:                    throw se;
1120:                } catch (Exception e) {
1121:                    ctx.setRollbackOnly();
1122:                    throw new LibresourceCoreServiceException(
1123:                            "Error in editProjectSummary : " + e.getMessage(),
1124:                            e);
1125:                }
1126:            }
1127:
1128:            /**
1129:             * @ejb.interface-method
1130:             * @ejb.transaction type="Supports"
1131:             */
1132:            public ProjectResourceValue getProject(URI uri)
1133:                    throws LibresourceCoreServiceException,
1134:                    LibresourceSecurityException, URINotExistException {
1135:                try {
1136:                    KernelService kernelService = (KernelService) Libresource
1137:                            .getService(KernelConstants.SERVICE);
1138:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
1139:                            .lookup(uri);
1140:                    ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) Libresource
1141:                            .findResource(resourceIdentifier,
1142:                                    ProjectResourceLocal.class);
1143:                    ProjectResourceValue resourceValue = projectResourceLocal
1144:                            .getProjectResourceValue();
1145:                    resourceValue.setUri(kernelService.normalizeURI(uri));
1146:
1147:                    return resourceValue;
1148:                } catch (LibresourceSecurityException se) {
1149:                    throw se;
1150:                } catch (URINotExistException se) {
1151:                    throw se;
1152:                } catch (Exception e) {
1153:                    throw new LibresourceCoreServiceException(
1154:                            "Error in getProject : " + e.getMessage(), e);
1155:                }
1156:            }
1157:
1158:            /**
1159:             * @ejb.interface-method
1160:             * @ejb.transaction type="Supports"
1161:             */
1162:            public ProjectResourceValue[] listProjectAt(URI uri)
1163:                    throws LibresourceCoreServiceException,
1164:                    LibresourceSecurityException, URINotExistException {
1165:                try {
1166:                    KernelService kernelService = (KernelService) Libresource
1167:                            .getService(KernelConstants.SERVICE);
1168:                    LibresourceResourceValue[] projects = kernelService
1169:                            .listResourcesAt(
1170:                                    uri,
1171:                                    ProjectResourceLocal.LIBRESOURCE_RESOURCE_SERVICE,
1172:                                    ProjectResourceLocal.LIBRESOURCE_RESOURCE_TYPE);
1173:
1174:                    // Filter
1175:                    ArrayList result = new ArrayList();
1176:                    ProjectResourceValue projectResource = null;
1177:
1178:                    for (int i = 0; i < projects.length; i++) {
1179:                        if (kernelService.checkSecurity(projects[i].getUri(),
1180:                                KernelConstants.SECURITY_READ)) {
1181:                            LibresourceResourceIdentifier resourceIdentifier = projects[i]
1182:                                    .getLibresourceResourceIdentifier();
1183:                            projectResource = ((ProjectResourceLocal) Libresource
1184:                                    .findResource(resourceIdentifier))
1185:                                    .getProjectResourceValue();
1186:                            projectResource.setUri(kernelService
1187:                                    .normalizeURI(projects[i].getUri()));
1188:                            result.add(projectResource);
1189:                        }
1190:                    }
1191:
1192:                    // Convert
1193:                    ProjectResourceValue[] projectResourceValues = new ProjectResourceValue[result
1194:                            .size()];
1195:
1196:                    for (int i = 0; i < projectResourceValues.length; i++) {
1197:                        projectResourceValues[i] = (ProjectResourceValue) result
1198:                                .get(i);
1199:                    }
1200:
1201:                    return projectResourceValues;
1202:                } catch (LibresourceSecurityException se) {
1203:                    throw se;
1204:                } catch (URINotExistException se) {
1205:                    throw se;
1206:                } catch (Exception e) {
1207:                    throw new LibresourceCoreServiceException(
1208:                            "Error in listProjectAt : " + e.getMessage(), e);
1209:                }
1210:            }
1211:
1212:            // events filters management
1213:
1214:            /**
1215:             * @ejb.interface-method
1216:             * @ejb.transaction type="Required"
1217:             */
1218:            public void addEventFilter(String name, URI user, String uriFilter,
1219:                    String eventTypeFilter, String argsFilter,
1220:                    String sendingType) throws Exception {
1221:                Connection connection = null;
1222:                PreparedStatement st = null;
1223:
1224:                KernelService kernelService = (KernelService) Libresource
1225:                        .getService(KernelConstants.SERVICE);
1226:
1227:                if (!kernelService.checkSecurity(user,
1228:                        KernelConstants.SECURITY_UPDATE)) {
1229:                    throw new LibresourceSecurityException(user,
1230:                            KernelConstants.SECURITY_UPDATE);
1231:                }
1232:
1233:                // update node
1234:                kernelService.setUpdateDate(user, new Date());
1235:
1236:                try {
1237:                    if ((uriFilter.indexOf("%") != -1)
1238:                            || (eventTypeFilter.indexOf("%") != -1)
1239:                            || (argsFilter.indexOf("%") != -1)) {
1240:                        throw new Exception(
1241:                                "% is not a valid symbol in this expression");
1242:                    }
1243:
1244:                    connection = getConnectionForEvents(true);
1245:
1246:                    String userUriPath = kernelService.normalizeURI(user)
1247:                            .getPath();
1248:                    st = connection
1249:                            .prepareStatement("DELETE FROM events_filter_ WHERE user_uri_=? AND uri_filter_=? AND type_filter_=? AND args_filter_=?");
1250:                    st.setString(1, userUriPath);
1251:                    st.setString(2, uriFilter.replaceAll("\\*", "%"));
1252:                    st.setString(3, eventTypeFilter.replaceAll("\\*", "%"));
1253:                    st.setString(4, argsFilter.replaceAll("\\*", "%"));
1254:                    st.executeUpdate();
1255:                    st = connection
1256:                            .prepareStatement("INSERT INTO events_filter_ (name_, user_uri_, uri_filter_, type_filter_, args_filter_, sending_type_) VALUES (?,?,?,?,?,?);");
1257:                    st.setString(1, name);
1258:                    st.setString(2, userUriPath);
1259:                    st.setString(3, uriFilter.replaceAll("\\*", "%"));
1260:                    st.setString(4, eventTypeFilter.replaceAll("\\*", "%"));
1261:                    st.setString(5, argsFilter.replaceAll("\\*", "%"));
1262:                    st.setString(6, sendingType);
1263:                    st.execute();
1264:                    st.close();
1265:                    connection.close();
1266:                } catch (Exception e) {
1267:                    ctx.setRollbackOnly();
1268:                    throw e;
1269:                } finally {
1270:                    try {
1271:                        if (st != null) {
1272:                            st.close();
1273:                        }
1274:
1275:                        if (connection != null) {
1276:                            connection.close();
1277:                        }
1278:                    } catch (Exception e) {
1279:                    }
1280:                }
1281:            }
1282:
1283:            /**
1284:             * @ejb.interface-method
1285:             * @ejb.transaction type="Required"
1286:             */
1287:            public void editEventFilter(int id, URI user, String name,
1288:                    String uriFilter, String eventTypeFilter,
1289:                    String argsFilter, String sendingType) throws Exception {
1290:                Connection connection = null;
1291:                PreparedStatement st = null;
1292:
1293:                KernelService kernelService = (KernelService) Libresource
1294:                        .getService(KernelConstants.SERVICE);
1295:
1296:                if (!kernelService.checkSecurity(user,
1297:                        KernelConstants.SECURITY_UPDATE)) {
1298:                    throw new LibresourceSecurityException(user,
1299:                            KernelConstants.SECURITY_UPDATE);
1300:                }
1301:
1302:                // update node
1303:                kernelService.setUpdateDate(user, new Date());
1304:
1305:                try {
1306:                    if ((uriFilter.indexOf("%") != -1)
1307:                            || (eventTypeFilter.indexOf("%") != -1)
1308:                            || (argsFilter.indexOf("%") != -1)) {
1309:                        throw new Exception(
1310:                                "% is not a valid symbol in this expression");
1311:                    }
1312:
1313:                    connection = getConnectionForEvents(true);
1314:
1315:                    String userUriPath = kernelService.normalizeURI(user)
1316:                            .getPath();
1317:                    st = connection
1318:                            .prepareStatement("UPDATE events_filter_ SET name_=?, uri_filter_=?, type_filter_=?, args_filter_=?, sending_type_=? WHERE id_ = ?;");
1319:                    st.setString(1, name);
1320:                    st.setString(2, uriFilter.replaceAll("\\*", "%"));
1321:                    st.setString(3, eventTypeFilter.replaceAll("\\*", "%"));
1322:                    st.setString(4, argsFilter.replaceAll("\\*", "%"));
1323:                    st.setString(5, sendingType);
1324:                    st.setInt(6, id);
1325:                    st.executeUpdate();
1326:                } catch (Exception e) {
1327:                    ctx.setRollbackOnly();
1328:                    throw e;
1329:                } finally {
1330:                    try {
1331:                        if (st != null) {
1332:                            st.close();
1333:                        }
1334:
1335:                        if (connection != null) {
1336:                            connection.close();
1337:                        }
1338:                    } catch (Exception e) {
1339:                    }
1340:                }
1341:            }
1342:
1343:            /**
1344:             * @ejb.interface-method
1345:             * @ejb.transaction type="Required"
1346:             */
1347:            public void removeEventFilter(int id) throws Exception {
1348:                Connection connection = null;
1349:                PreparedStatement st = null;
1350:
1351:                try {
1352:                    connection = getConnectionForEvents(true);
1353:                    st = connection
1354:                            .prepareStatement("DELETE FROM events_filter_ WHERE id_ = ?;");
1355:                    st.setInt(1, id);
1356:                    st.execute();
1357:                } catch (Exception e) {
1358:                    ctx.setRollbackOnly();
1359:                    throw e;
1360:                } finally {
1361:                    try {
1362:                        if (st != null) {
1363:                            st.close();
1364:                        }
1365:
1366:                        if (connection != null) {
1367:                            connection.close();
1368:                        }
1369:                    } catch (Exception e) {
1370:                    }
1371:                }
1372:            }
1373:
1374:            /**
1375:             * @ejb.interface-method
1376:             * @ejb.transaction type="Supports"
1377:             */
1378:            public EventFilterValue[] listEventFilter(URI user)
1379:                    throws Exception {
1380:                Connection connection = null;
1381:                PreparedStatement st = null;
1382:                ResultSet rs = null;
1383:
1384:                try {
1385:                    KernelService kernelService = (KernelService) Libresource
1386:                            .getService(KernelConstants.SERVICE);
1387:                    connection = getConnectionForEvents(true);
1388:
1389:                    String userUriPath = kernelService.normalizeURI(user)
1390:                            .getPath();
1391:                    st = connection
1392:                            .prepareStatement("SELECT * FROM events_filter_ WHERE user_uri_ = ? ORDER BY id_ DESC;");
1393:                    st.setString(1, userUriPath);
1394:
1395:                    rs = st.executeQuery();
1396:
1397:                    Vector result = new Vector();
1398:
1399:                    while (rs.next()) {
1400:                        EventFilterValue eventFilterValue = new EventFilterValue(
1401:                                rs.getInt("id_"), kernelService
1402:                                        .normalizeURI(new URI(rs
1403:                                                .getString("user_uri_"))), rs
1404:                                        .getString("name_"), rs.getString(
1405:                                        "type_filter_").replaceAll("%", "*"),
1406:                                rs.getString("uri_filter_")
1407:                                        .replaceAll("%", "*"), rs.getString(
1408:                                        "args_filter_").replaceAll("%", "*"),
1409:                                rs.getString("sending_type_"));
1410:                        result.add(eventFilterValue);
1411:                    }
1412:
1413:                    EventFilterValue[] array = new EventFilterValue[result
1414:                            .size()];
1415:
1416:                    for (int i = 0; i < array.length; i++) {
1417:                        array[i] = (EventFilterValue) result.get(i);
1418:                    }
1419:
1420:                    return array;
1421:                } catch (Exception e) {
1422:                    throw e;
1423:                } finally {
1424:                    try {
1425:                        if (rs != null) {
1426:                            rs.close();
1427:                        }
1428:
1429:                        if (st != null) {
1430:                            st.close();
1431:                        }
1432:
1433:                        if (connection != null) {
1434:                            connection.close();
1435:                        }
1436:                    } catch (Exception e) {
1437:                    }
1438:                }
1439:            }
1440:
1441:            /**
1442:             * @ejb.interface-method
1443:             * @ejb.transaction type="Supports"
1444:             */
1445:            public EventFilterValue[] getInterestedEventFilters(
1446:                    String eventType, URI fromUri, String args)
1447:                    throws Exception {
1448:                Connection connection = null;
1449:                PreparedStatement st = null;
1450:                ResultSet rs = null;
1451:
1452:                try {
1453:                    KernelService kernelService = (KernelService) Libresource
1454:                            .getService(KernelConstants.SERVICE);
1455:                    connection = getConnectionForEvents(true);
1456:
1457:                    String uriPath = kernelService.normalizeURI(fromUri)
1458:                            .getPath();
1459:                    st = connection
1460:                            .prepareStatement("SELECT * FROM events_filter_ WHERE ? LIKE type_filter_ AND ? LIKE uri_filter_ AND ? LIKE args_filter_ ;");
1461:                    st.setString(1, eventType);
1462:                    st.setString(2, uriPath);
1463:                    st.setString(3, args);
1464:
1465:                    rs = st.executeQuery();
1466:
1467:                    Vector result = new Vector();
1468:
1469:                    while (rs.next()) {
1470:                        EventFilterValue eventFilterValue = new EventFilterValue(
1471:                                rs.getInt("id_"), kernelService
1472:                                        .normalizeURI(new URI(rs
1473:                                                .getString("user_uri_"))), rs
1474:                                        .getString("name_"), rs.getString(
1475:                                        "type_filter_").replaceAll("%", "*"),
1476:                                rs.getString("uri_filter_")
1477:                                        .replaceAll("%", "*"), rs.getString(
1478:                                        "args_filter_").replaceAll("%", "*"),
1479:                                rs.getString("sending_type_"));
1480:                        result.add(eventFilterValue);
1481:                    }
1482:
1483:                    EventFilterValue[] array = new EventFilterValue[result
1484:                            .size()];
1485:
1486:                    for (int i = 0; i < array.length; i++) {
1487:                        array[i] = (EventFilterValue) result.get(i);
1488:                    }
1489:
1490:                    return array;
1491:                } catch (Exception e) {
1492:                    throw e;
1493:                } finally {
1494:                    try {
1495:                        if (rs != null) {
1496:                            rs.close();
1497:                        }
1498:
1499:                        if (st != null) {
1500:                            st.close();
1501:                        }
1502:
1503:                        if (connection != null) {
1504:                            connection.close();
1505:                        }
1506:                    } catch (Exception e) {
1507:                    }
1508:                }
1509:            }
1510:
1511:            /**
1512:             * @ejb.interface-method
1513:             * @ejb.transaction type="Supports"
1514:             */
1515:            public EventFilterValue getEventFilter(int id) throws Exception {
1516:                Connection connection = null;
1517:                PreparedStatement st = null;
1518:                ResultSet rs = null;
1519:
1520:                try {
1521:                    KernelService kernelService = (KernelService) Libresource
1522:                            .getService(KernelConstants.SERVICE);
1523:                    connection = getConnectionForEvents(true);
1524:                    st = connection
1525:                            .prepareStatement("SELECT * FROM events_filter_ WHERE id_ = ?;");
1526:                    st.setInt(1, id);
1527:
1528:                    rs = st.executeQuery();
1529:
1530:                    EventFilterValue result = null;
1531:
1532:                    if (rs.next()) {
1533:                        result = new EventFilterValue(rs.getInt("id_"),
1534:                                kernelService.normalizeURI(new URI(rs
1535:                                        .getString("user_uri_"))), rs
1536:                                        .getString("name_"), rs.getString(
1537:                                        "type_filter_").replaceAll("%", "*"),
1538:                                rs.getString("uri_filter_")
1539:                                        .replaceAll("%", "*"), rs.getString(
1540:                                        "args_filter_").replaceAll("%", "*"),
1541:                                rs.getString("sending_type_"));
1542:                    }
1543:
1544:                    return result;
1545:                } catch (Exception e) {
1546:                    throw e;
1547:                } finally {
1548:                    try {
1549:                        if (rs != null) {
1550:                            rs.close();
1551:                        }
1552:
1553:                        if (st != null) {
1554:                            st.close();
1555:                        }
1556:
1557:                        if (connection != null) {
1558:                            connection.close();
1559:                        }
1560:                    } catch (Exception e) {
1561:                    }
1562:                }
1563:            }
1564:
1565:            // platform informations
1566:
1567:            /**
1568:             * @ejb.interface-method
1569:             * @ejb.transaction type="Supports"
1570:             */
1571:            public ProjectResourceValue[] listPublicProjects()
1572:                    throws LibresourceCoreServiceException {
1573:                try {
1574:                    Collection projects = ProjectResourceUtil.getLocalHome()
1575:                            .findAll();
1576:                    Vector publicProjects = new Vector();
1577:                    KernelService kernelService = (KernelService) Libresource
1578:                            .getService(KernelConstants.SERVICE);
1579:
1580:                    for (Iterator i = projects.iterator(); i.hasNext();) {
1581:                        ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) i
1582:                                .next();
1583:                        LibresourceResourceIdentifier identifier = projectResourceLocal
1584:                                .getLibresourceResourceIdentifier();
1585:
1586:                        try {
1587:                            URI projectURI = kernelService.getMyURI(identifier);
1588:
1589:                            MembershipService membershipService = (MembershipService) Libresource
1590:                                    .getService(MembershipConstants.SERVICE);
1591:
1592:                            if (kernelService
1593:                                    .checkSecurity(
1594:                                            new URI(
1595:                                                    membershipService
1596:                                                            .getUsersRootURI()
1597:                                                            + "/"
1598:                                                            + membershipService
1599:                                                                    .getUnauthentifiedUserId()),
1600:                                            projectURI,
1601:                                            KernelConstants.SECURITY_READ)) {
1602:                                ProjectResourceValue resourceValue = projectResourceLocal
1603:                                        .getProjectResourceValue();
1604:                                resourceValue.setUri(projectURI);
1605:                                publicProjects.add(resourceValue);
1606:                            }
1607:                        } catch (Exception e) {
1608:                            // lazy
1609:                        }
1610:                    }
1611:
1612:                    ProjectResourceValue[] result = new ProjectResourceValue[publicProjects
1613:                            .size()];
1614:
1615:                    for (int i = 0; i < result.length; i++) {
1616:                        result[i] = (ProjectResourceValue) publicProjects
1617:                                .get(i);
1618:                    }
1619:
1620:                    return result;
1621:                } catch (Exception e) {
1622:                    throw new LibresourceCoreServiceException(
1623:                            "Can't list public projects", e);
1624:                }
1625:            }
1626:
1627:            /**
1628:             * @ejb.interface-method
1629:             * @ejb.transaction type="Supports"
1630:             */
1631:            public TemplateResourceValue[] listPublicTemplates()
1632:                    throws LibresourceCoreServiceException {
1633:                try {
1634:                    Collection templates = TemplateResourceUtil.getLocalHome()
1635:                            .findAll();
1636:                    Vector publicTemplates = new Vector();
1637:                    KernelService kernelService = (KernelService) Libresource
1638:                            .getService(KernelConstants.SERVICE);
1639:
1640:                    for (Iterator i = templates.iterator(); i.hasNext();) {
1641:                        TemplateResourceLocal templateResourceLocal = (TemplateResourceLocal) i
1642:                                .next();
1643:                        LibresourceResourceIdentifier identifier = templateResourceLocal
1644:                                .getLibresourceResourceIdentifier();
1645:
1646:                        try {
1647:                            URI projectURI = kernelService.getMyURI(identifier);
1648:
1649:                            MembershipService membershipService = (MembershipService) Libresource
1650:                                    .getService(MembershipConstants.SERVICE);
1651:
1652:                            if (kernelService
1653:                                    .checkSecurity(
1654:                                            new URI(
1655:                                                    membershipService
1656:                                                            .getUsersRootURI()
1657:                                                            + "/"
1658:                                                            + membershipService
1659:                                                                    .getUnauthentifiedUserId()),
1660:                                            projectURI,
1661:                                            KernelConstants.SECURITY_READ)) {
1662:                                TemplateResourceValue resourceValue = templateResourceLocal
1663:                                        .getTemplateResourceValue();
1664:                                resourceValue.setUri(projectURI);
1665:                                publicTemplates.add(resourceValue);
1666:                            }
1667:                        } catch (Exception e) {
1668:                            // lazy
1669:                        }
1670:                    }
1671:
1672:                    TemplateResourceValue[] result = new TemplateResourceValue[publicTemplates
1673:                            .size()];
1674:
1675:                    for (int i = 0; i < result.length; i++) {
1676:                        result[i] = (TemplateResourceValue) publicTemplates
1677:                                .get(i);
1678:                    }
1679:
1680:                    return result;
1681:                } catch (Exception e) {
1682:                    throw new LibresourceCoreServiceException(
1683:                            "Can't list public templates", e);
1684:                }
1685:            }
1686:
1687:            /**
1688:             * @ejb.interface-method
1689:             * @ejb.transaction type="Supports"
1690:             */
1691:            public ProjectResourceValue[] listAllProjects()
1692:                    throws LibresourceCoreServiceException {
1693:                try {
1694:                    KernelService kernelService = (KernelService) Libresource
1695:                            .getService(KernelConstants.SERVICE);
1696:                    Collection projects = ProjectResourceUtil.getLocalHome()
1697:                            .findAll();
1698:                    Vector allProjects = new Vector();
1699:
1700:                    for (Iterator i = projects.iterator(); i.hasNext();) {
1701:                        ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) i
1702:                                .next();
1703:                        LibresourceResourceIdentifier identifier = projectResourceLocal
1704:                                .getLibresourceResourceIdentifier();
1705:
1706:                        try {
1707:                            URI projectURI = kernelService.getMyURI(identifier);
1708:
1709:                            if (kernelService.checkSecurity(projectURI,
1710:                                    KernelConstants.SECURITY_READ)) {
1711:                                ProjectResourceValue resourceValue = projectResourceLocal
1712:                                        .getProjectResourceValue();
1713:                                resourceValue.setUri(projectURI);
1714:                                allProjects.add(resourceValue);
1715:                            }
1716:                        } catch (Exception e) {
1717:                            // lazy
1718:                        }
1719:                    }
1720:
1721:                    ProjectResourceValue[] result = new ProjectResourceValue[allProjects
1722:                            .size()];
1723:
1724:                    for (int i = 0; i < result.length; i++) {
1725:                        result[i] = (ProjectResourceValue) allProjects.get(i);
1726:                    }
1727:
1728:                    return result;
1729:                } catch (Exception e) {
1730:                    throw new LibresourceCoreServiceException(
1731:                            "Can't list all projects", e);
1732:                }
1733:            }
1734:
1735:            // libresource service
1736:
1737:            /**
1738:             * @ejb.interface-method
1739:             * @ejb.transaction type="Supports"
1740:             */
1741:            public LibresourceIndexableContent getIndexableContent(
1742:                    LibresourceResourceIdentifier resourceIdentifier)
1743:                    throws LibresourceException {
1744:                try {
1745:                    try {
1746:                        Libresource.checkType(resourceIdentifier,
1747:                                ProjectResourceLocal.class);
1748:                    } catch (LibresourceException e) {
1749:                        return null;
1750:                    }
1751:
1752:                    LibresourceIndexableContent content = new LibresourceIndexableContent();
1753:                    ProjectResourceLocal projectResourceLocal = (ProjectResourceLocal) Libresource
1754:                            .findResource(resourceIdentifier);
1755:                    content.addContentPart(projectResourceLocal.getName());
1756:                    content.addContentPart(projectResourceLocal
1757:                            .getDescription());
1758:
1759:                    if (projectResourceLocal.getSummary() != null) {
1760:                        content.addContentPart(projectResourceLocal
1761:                                .getSummary().replaceAll("\\{.*\\}", ""));
1762:                    }
1763:
1764:                    return content;
1765:                } catch (Exception e) {
1766:                    throw new LibresourceException(
1767:                            "error in LibresourceCore.getIndexableContent("
1768:                                    + resourceIdentifier + ")", e);
1769:                }
1770:            }
1771:
1772:            /**
1773:             * @ejb.interface-method
1774:             * @ejb.transaction type="Supports"
1775:             */
1776:            public LibresourceExportHandler getXmlExportHandlerForResource(
1777:                    URI uri) throws LibresourceException {
1778:                try {
1779:                    KernelService kernelService = (KernelService) Libresource
1780:                            .getService(KernelConstants.SERVICE);
1781:                    LibresourceResourceIdentifier resourceIdentifier = kernelService
1782:                            .lookup(uri);
1783:
1784:                    try {
1785:                        Libresource.checkType(resourceIdentifier,
1786:                                ProjectResourceLocal.class);
1787:
1788:                        ProjectExportHandler exportHandler = new ProjectExportHandler(
1789:                                uri);
1790:
1791:                        return exportHandler;
1792:                    } catch (Exception e) {
1793:                        //
1794:                    }
1795:
1796:                    try {
1797:                        Libresource.checkType(resourceIdentifier,
1798:                                TemplateResourceLocal.class);
1799:
1800:                        TemplateExportHandler exportHandler = new TemplateExportHandler(
1801:                                uri);
1802:
1803:                        return exportHandler;
1804:                    } catch (Exception e) {
1805:                        //
1806:                    }
1807:
1808:                    try {
1809:                        Libresource.checkType(resourceIdentifier,
1810:                                TimelineResourceLocal.class);
1811:
1812:                        TimelineExportHandler exportHandler = new TimelineExportHandler(
1813:                                uri);
1814:
1815:                        return exportHandler;
1816:                    } catch (Exception e) {
1817:                        //
1818:                    }
1819:
1820:                    return super .getXmlExportHandlerForResource(uri);
1821:                } catch (Exception e) {
1822:                    throw new LibresourceException(
1823:                            "Can't obtain exportHandler for uri " + uri, e);
1824:                }
1825:            }
1826:
1827:            /**
1828:             * @ejb.interface-method
1829:             * @ejb.transaction type="Supports"
1830:             */
1831:            public LibresourceImportHandler getXmlImportHandler(String type)
1832:                    throws LibresourceException {
1833:                if (type.equals("Project")) {
1834:                    return new ProjectImportHandler();
1835:                }
1836:
1837:                if (type.equals("Template")) {
1838:                    return new TemplateImportHandler();
1839:                }
1840:
1841:                if (type.equals("Timeline")) {
1842:                    return new TimelineImportHandler();
1843:                }
1844:
1845:                return super .getXmlImportHandler(type);
1846:            }
1847:
1848:            /**
1849:             * @ejb.interface-method
1850:             * @ejb.transaction type="Supports"
1851:             */
1852:            public String[] listAvailablesEvents(
1853:                    LibresourceResourceIdentifier resourceIdentifier)
1854:                    throws LibresourceException {
1855:                if (resourceIdentifier.getService().equals("LibresourceCore")) {
1856:                    if (resourceIdentifier.getResourceType().equals("Project")) {
1857:                        return new String[] { "libresourceCore.project.create",
1858:                                "libresourceCore.project.edit",
1859:                                CoreConstants.EVENT_PROJECT_EDIT_SUMMARY };
1860:                    }
1861:
1862:                    if (resourceIdentifier.getResourceType().equals("Timeline")) {
1863:                        return new String[] {
1864:                                CoreConstants.EVENT_TIMELINE_CREATE,
1865:                                CoreConstants.EVENT_TIMELINE_EDIT };
1866:                    }
1867:
1868:                    if (resourceIdentifier.getResourceType().equals("Template")) {
1869:                        return new String[] {
1870:                                CoreConstants.EVENT_TEMPLATE_CREATE,
1871:                                CoreConstants.EVENT_TEMPLATE_EDIT };
1872:                    }
1873:                }
1874:
1875:                return super .listAvailablesPermissions(resourceIdentifier);
1876:            }
1877:
1878:            // file database repository access
1879:
1880:            /**
1881:             * @ejb.interface-method
1882:             * @ejb.transaction type="Required"
1883:             */
1884:            public void putFileData(String tableName, String fileId,
1885:                    FileData fileData) throws Exception {
1886:                Connection con = getConnectionForOID(tableName, true);
1887:
1888:                //templates_content_
1889:                //files_content_
1890:                try {
1891:                    File temp = createTempFile(fileId, fileData);
1892:                    PreparedStatement deleteOld = con
1893:                            .prepareStatement("DELETE FROM " + tableName
1894:                                    + " WHERE id=?");
1895:                    deleteOld.setString(1, fileId);
1896:                    deleteOld.execute();
1897:                    deleteOld.close();
1898:
1899:                    PreparedStatement putFile = con
1900:                            .prepareStatement("INSERT INTO " + tableName
1901:                                    + " (id) VALUES (?)");
1902:                    putFile.setString(1, fileId);
1903:                    putFile.execute();
1904:                    putFile.close();
1905:                    putFile = con.prepareStatement("UPDATE " + tableName
1906:                            + " SET content=lo_import(?) WHERE id=?");
1907:                    putFile.setString(1, temp.getAbsolutePath());
1908:                    putFile.setString(2, fileId);
1909:                    putFile.execute();
1910:                    putFile.close();
1911:                } catch (Exception e) {
1912:                    throw e;
1913:                } finally {
1914:                    // Close connection anyway
1915:                    con.close();
1916:
1917:                    // Delete it when it saved in database
1918:                    try {
1919:                        fileData.delete();
1920:                    } catch (RuntimeException e) {
1921:                    }
1922:                }
1923:            }
1924:
1925:            /**
1926:             * @ejb.interface-method
1927:             * @ejb.transaction type="Required"
1928:             */
1929:            public FileData getFileData(String tableName, String fileId)
1930:                    throws Exception {
1931:                // Use the filesystem as a cache to prevent database extraction at each time
1932:                File temp = getTempFile(fileId);
1933:
1934:                if (temp.exists()) {
1935:                    return new FileDataImpl(temp);
1936:                }
1937:
1938:                Connection con = getConnectionForOID(tableName, false);
1939:
1940:                try {
1941:                    temp = createTempFile(fileId);
1942:
1943:                    PreparedStatement exportFile = con
1944:                            .prepareStatement("SELECT lo_export(content,?) FROM "
1945:                                    + tableName + " WHERE id=?");
1946:                    exportFile.setString(1, temp.getAbsolutePath());
1947:
1948:                    //String path = System.getProperty("java.io.tmpdir") + File.separator + fileId;
1949:                    //exportFile.setString(1, path);
1950:                    exportFile.setString(2, fileId);
1951:                    exportFile.execute();
1952:                    exportFile.close();
1953:
1954:                    //FileData fileData = new FileDataImpl(new File(path));
1955:                    FileData fileData = new FileDataImpl(temp);
1956:
1957:                    return fileData;
1958:                } catch (Exception e) {
1959:                    throw e;
1960:                } finally {
1961:                    try {
1962:                        con.close();
1963:                    } catch (Exception e) {
1964:                    }
1965:                }
1966:            }
1967:
1968:            /**
1969:             * @ejb.interface-method
1970:             * @ejb.transaction type="Required"
1971:             */
1972:            public void deleteFileData(String tableName, String fileId)
1973:                    throws Exception {
1974:                Connection con = getConnectionForOID(tableName, false);
1975:
1976:                try {
1977:                    PreparedStatement deletesFile = con
1978:                            .prepareStatement("DELETE FROM " + tableName
1979:                                    + " WHERE id=?");
1980:                    deletesFile.setString(1, fileId);
1981:                    deletesFile.execute();
1982:                    deletesFile.close();
1983:                } catch (Exception e) {
1984:                    throw e;
1985:                } finally {
1986:                    try {
1987:                        con.close();
1988:                    } catch (Exception e) {
1989:                    }
1990:                }
1991:            }
1992:
1993:            /**
1994:             * @ejb.interface-method
1995:             * @ejb.transaction type="Required"
1996:             */
1997:            public String getTempFilePath(String tableName, String fileId)
1998:                    throws Exception {
1999:                Connection con = getConnectionForOID(tableName, false);
2000:
2001:                try {
2002:                    File temp = createTempFile(fileId);
2003:                    PreparedStatement exportFile = con
2004:                            .prepareStatement("select lo_export(content,?) from "
2005:                                    + tableName + " where id=?");
2006:                    exportFile.setString(1, temp.getAbsolutePath());
2007:
2008:                    //String path = System.getProperty("java.io.tmpdir") + File.separator + fileId;
2009:                    //exportFile.setString(1, path);
2010:                    exportFile.setString(2, fileId);
2011:                    exportFile.execute();
2012:                    exportFile.close();
2013:
2014:                    return temp.getAbsolutePath();
2015:                } catch (Exception e) {
2016:                    throw e;
2017:                } finally {
2018:                    try {
2019:                        con.close();
2020:                    } catch (Exception e) {
2021:                    }
2022:                }
2023:            }
2024:
2025:            /**
2026:             * @ejb.interface-method
2027:             * @ejb.transaction type="Supports"
2028:             */
2029:            public File createTempFile(String fileId, FileData fileData)
2030:                    throws Exception {
2031:                File tempFile = createTempFile(fileId);
2032:                BufferedOutputStream fos = new BufferedOutputStream(
2033:                        new FileOutputStream(tempFile));
2034:                BufferedInputStream is = new BufferedInputStream(fileData
2035:                        .getInputStream());
2036:                int readCount = -1;
2037:                byte[] buffer = new byte[1024 * 1024 * 2];
2038:
2039:                while ((readCount = is.read(buffer)) > 0) {
2040:                    fos.write(buffer, 0, readCount);
2041:                }
2042:
2043:                fos.close();
2044:
2045:                return tempFile;
2046:            }
2047:
2048:            /**
2049:             * @ejb.interface-method
2050:             * @ejb.transaction type="Supports"
2051:             */
2052:            public File createTempFile(String fileId) throws Exception {
2053:                File result = getTempFile(fileId);
2054:
2055:                if (result.exists()) {
2056:                    result.delete();
2057:                }
2058:
2059:                return result;
2060:            }
2061:
2062:            /**
2063:             * @ejb.interface-method
2064:             * @ejb.transaction type="Supports"
2065:             */
2066:            public File getTempFile(String fileId) throws Exception {
2067:                if (fileSystemBase == null) {
2068:                    fileSystemBase = new File(getDistributedFileSystem());
2069:                }
2070:
2071:                return new File(fileSystemBase, fileId);
2072:            }
2073:
2074:            // datasource
2075:            protected static Connection getConnectionForOID(String tableName,
2076:                    boolean createTable) throws Exception {
2077:                Connection con = Libresource.getDatasource().getConnection();
2078:
2079:                if (createTable) {
2080:                    Statement st = con.createStatement();
2081:                    ResultSet rs = st
2082:                            .executeQuery("SELECT tablename FROM pg_tables WHERE tablename='"
2083:                                    + tableName + "';");
2084:
2085:                    if (!rs.next()) {
2086:                        Statement st2 = con.createStatement();
2087:                        st2.executeUpdate("CREATE TABLE " + tableName
2088:                                + " (id VARCHAR, content OID);");
2089:                        st2.close();
2090:                    }
2091:
2092:                    rs.close();
2093:                    st.close();
2094:                }
2095:
2096:                return con;
2097:            }
2098:
2099:            protected static Connection getConnectionForEvents(
2100:                    boolean createTable) throws Exception {
2101:                Connection con = Libresource.getDatasource().getConnection();
2102:
2103:                if (createTable) {
2104:                    Statement st = con.createStatement();
2105:                    ResultSet rs = st
2106:                            .executeQuery("SELECT tablename FROM pg_tables WHERE tablename='events_filter_';");
2107:
2108:                    if (!rs.next()) {
2109:                        Statement st2 = con.createStatement();
2110:                        st2
2111:                                .executeUpdate("CREATE TABLE events_filter_ (id_ SERIAL PRIMARY KEY, name_ VARCHAR, user_uri_ VARCHAR, type_filter_ VARCHAR, uri_filter_ VARCHAR, args_filter_ VARCHAR, sending_type_ VARCHAR);");
2112:                        st2.close();
2113:                    }
2114:
2115:                    rs.close();
2116:                    st.close();
2117:                }
2118:
2119:                return con;
2120:            }
2121:
2122:            protected static Connection getConnectionForProjectStats(
2123:                    boolean createTable) throws Exception {
2124:                Connection con = Libresource.getDatasource().getConnection();
2125:
2126:                if (createTable) {
2127:                    Statement st = con.createStatement();
2128:                    ResultSet rs = con.getMetaData().getTables(null, null,
2129:                            "projects_stats_", null);
2130:
2131:                    if (!rs.next()) {
2132:                        Statement st2 = con.createStatement();
2133:                        st2
2134:                                .executeUpdate("CREATE TABLE projects_stats_ (project_id_ VARCHAR, week_ INTEGER, activity_ FLOAT4, popularity_ FLOAT4, reads_ INTEGER, writes_ INTEGER);");
2135:                        st2
2136:                                .executeUpdate("CREATE TABLE projects_mostactive_users_ (project_id_ VARCHAR, week_ INTEGER, user_ VARCHAR, activity_ FLOAT4);");
2137:                        st2
2138:                                .executeUpdate("CREATE TABLE projects_mostactive_resources_ (project_id_ VARCHAR, week_ INTEGER, resource_ VARCHAR, activity_ FLOAT4);");
2139:                        st2
2140:                                .executeUpdate("CREATE TABLE projects_prefered_resources_ (project_id_ VARCHAR, week_ INTEGER, resource_ VARCHAR, popularity_ FLOAT4);");
2141:                        st2.close();
2142:                    }
2143:
2144:                    rs.close();
2145:                    st.close();
2146:                }
2147:
2148:                return con;
2149:            }
2150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.