Source Code Cross Referenced for ReportsTool.java in  » ERP-CRM-Financial » sakai » org » theospi » portfolio » reports » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.theospi.portfolio.reports.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL:https://source.sakaiproject.org/svn/osp/trunk/reports/tool/src/java/org/theospi/portfolio/reports/tool/ReportsTool.java $
0003:         * $Id:ReportsTool.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2005, 2006 The Sakai Foundation.
0007:         *
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0009:         * you may not use this file except in compliance with the License.
0010:         * You may obtain a copy of the License at
0011:         *
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         *
0014:         * Unless required by applicable law or agreed to in writing, software
0015:         * distributed under the License is distributed on an "AS IS" BASIS,
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017:         * See the License for the specific language governing permissions and
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.theospi.portfolio.reports.tool;
0021:
0022:        import org.apache.commons.logging.Log;
0023:        import org.apache.commons.logging.LogFactory;
0024:        import org.quartz.*;
0025:        import org.sakaiproject.api.app.scheduler.JobDetailWrapper;
0026:        import org.sakaiproject.api.app.scheduler.SchedulerManager;
0027:        import org.sakaiproject.api.app.scheduler.TriggerWrapper;
0028:        import org.sakaiproject.authz.api.PermissionsHelper;
0029:        import org.sakaiproject.component.api.ServerConfigurationService;
0030:        import org.sakaiproject.component.app.scheduler.JobDetailWrapperImpl;
0031:        import org.sakaiproject.component.app.scheduler.TriggerWrapperImpl;
0032:        import org.sakaiproject.component.cover.ComponentManager;
0033:        import org.sakaiproject.content.api.ContentHostingService;
0034:        import org.sakaiproject.content.api.ContentResource;
0035:        import org.sakaiproject.content.api.FilePickerHelper;
0036:        import org.sakaiproject.entity.api.Reference;
0037:        import org.sakaiproject.exception.*;
0038:        import org.sakaiproject.metaobj.shared.mgt.IdManager;
0039:        import org.sakaiproject.metaobj.shared.model.OspException;
0040:        import org.sakaiproject.site.api.Site;
0041:        import org.sakaiproject.site.cover.SiteService;
0042:        import org.sakaiproject.tool.api.Tool;
0043:        import org.sakaiproject.tool.api.ToolSession;
0044:        import org.sakaiproject.tool.cover.SessionManager;
0045:        import org.sakaiproject.tool.cover.ToolManager;
0046:        import org.theospi.portfolio.reports.model.*;
0047:        import org.theospi.portfolio.security.AudienceSelectionHelper;
0048:        import org.theospi.portfolio.shared.tool.ToolBase;
0049:
0050:        import javax.faces.application.FacesMessage;
0051:        import javax.faces.component.UIComponent;
0052:        import javax.faces.context.ExternalContext;
0053:        import javax.faces.context.FacesContext;
0054:        import javax.faces.validator.ValidatorException;
0055:        import java.io.IOException;
0056:        import java.text.ParseException;
0057:        import java.util.*;
0058:
0059:        /**
0060:         * This class is the controller and model to the jsp view.<BR>
0061:         * <p/>
0062:         * There is an inner class for allowing the report data classes to
0063:         * interact with the jsp.<BR>
0064:         * <p/>
0065:         * Each session gets its own ReportsTool.<BR><BR>
0066:         * <p/>
0067:         * &nbsp; &nbsp; Testing procedures:<BR>
0068:         * <p/>
0069:         * Test the different parameter types
0070:         * Make sure the sql param is pulling data
0071:         * Test a live and a non-live report
0072:         * Save the results
0073:         * Re-run a live report, save results
0074:         * External dependencies:
0075:         * worksite, users, tool,
0076:         *
0077:         * @author andersjb
0078:         */
0079:
0080:        public class ReportsTool extends ToolBase {
0081:
0082:            private String jobName;
0083:            private String triggerName;
0084:            private String triggerExpression;
0085:            private JobDetail jobDetail = null;
0086:            private JobDetailWrapper jobDetailWrapper = new JobDetailWrapperImpl();
0087:            private boolean isSelectAllTriggersSelected = false;
0088:            private List filteredTriggersWrapperList;
0089:            /**
0090:             * A singlton manager for reports
0091:             */
0092:            private ReportsManager reportsManager = null;
0093:            private SchedulerManager schedulerManager;
0094:            /**
0095:             * The reports to which the user has access
0096:             */
0097:            private List decoratedReportDefinition = null;
0098:
0099:            /**
0100:             * The reportDefinition from which the tool is working with
0101:             */
0102:            private DecoratedReportDefinition workingReportDefinition = null;
0103:
0104:            /**
0105:             * The report from which the tool is working with
0106:             */
0107:            private DecoratedReport workingReport = null;
0108:
0109:            /**
0110:             * The reportresult from which the tool is working with
0111:             */
0112:            private DecoratedReportResult workingResult = null;
0113:
0114:            private Site worksite = null;
0115:
0116:            private Tool tool = null;
0117:            private Map userCan = null;
0118:
0119:            protected static final String mainPage = "main";
0120:            protected static final String createReportPage = "processCreateReport";
0121:            protected static final String createReportParamsPage = "processCreateReportParams";
0122:            protected static final String reportResultsPage = "showReportResults";
0123:            protected static final String saveResultsPage = "saveReportResults";
0124:            protected static final String importReportDef = "importReportDef";
0125:            protected static final String shareReportResult = "shareReportResult";
0126:            protected static final String scheduleReport = "scheduleReport";
0127:            protected static final String createTrigger = "createTrigger";
0128:            protected static final String deleteTriggers = "deleteTriggers";
0129:
0130:            private static final String CRON_CHECK_ASTERISK = "**";
0131:            private static final String CRON_CHECK_QUESTION_MARK = "??";
0132:            //	import variables
0133:            private String importFilesString = "";
0134:            private List importFiles = new ArrayList();
0135:
0136:            private ContentHostingService contentHosting;
0137:
0138:            protected final Log logger = LogFactory.getLog(getClass());
0139:            private IdManager idManager;
0140:
0141:            private boolean invalidImport = false;
0142:            private boolean invalidXslFile = false;
0143:            private String invalidImportMessage = "Invalid Report Definition XML File";
0144:
0145:            public SchedulerManager getSchedulerManager() {
0146:                return schedulerManager;
0147:            }
0148:
0149:            public void setSchedulerManager(SchedulerManager schedulerManager) {
0150:                this .schedulerManager = schedulerManager;
0151:            }
0152:
0153:            public String getInvalidImportMessage() {
0154:                return invalidImportMessage;
0155:            }
0156:
0157:            public void setInvalidImportMessage(String invalidImportMessage) {
0158:                this .invalidImportMessage = invalidImportMessage;
0159:            }
0160:
0161:            public boolean isInvalidImport() {
0162:                return invalidImport;
0163:            }
0164:
0165:            public void setInvalidImport(boolean invalidImport) {
0166:                this .invalidImport = invalidImport;
0167:            }
0168:
0169:            public boolean isInvalidXslFile() {
0170:                return invalidXslFile;
0171:            }
0172:
0173:            public void setInvalidXslFile(boolean invalidXslFile) {
0174:                this .invalidXslFile = invalidXslFile;
0175:            }
0176:
0177:            public IdManager getIdManager() {
0178:                return idManager;
0179:            }
0180:
0181:            public void setIdManager(IdManager idManager) {
0182:                this .idManager = idManager;
0183:            }
0184:
0185:            /**
0186:             * when a live report is saved, tell the user
0187:             */
0188:            private boolean savedLiveReport = false;
0189:
0190:            /**
0191:             * getter for the ReportsManager property
0192:             *
0193:             * @return ReportsManager
0194:             */
0195:            public ReportsManager getReportsManager() {
0196:                return reportsManager;
0197:            }
0198:
0199:            /**
0200:             * setter for the ReportsManager property
0201:             *
0202:             * @param reportsManager
0203:             */
0204:            public void setReportsManager(ReportsManager reportsManager) {
0205:                this .reportsManager = reportsManager;
0206:            }
0207:
0208:            public Tool getTool() {
0209:                if (tool == null) {
0210:                    tool = ToolManager.getCurrentTool();
0211:                }
0212:                return tool;
0213:            }
0214:
0215:            public void setTool(Tool tool) {
0216:                this .tool = tool;
0217:            }
0218:
0219:            public Site getWorksite() {
0220:                if (worksite == null) {
0221:                    try {
0222:                        worksite = SiteService.getSite(ToolManager
0223:                                .getCurrentPlacement().getContext());
0224:                    } catch (IdUnusedException e) {
0225:                        throw new RuntimeException(e);
0226:                    }
0227:                }
0228:                return worksite;
0229:            }
0230:
0231:            public String getReportFunctionPrefix() {
0232:                return ReportFunctions.REPORT_FUNCTION_PREFIX;
0233:            }
0234:
0235:            public String getPermissionsMessage() {
0236:                return getMessageFromBundle("perm_description", new Object[] {
0237:                        getTool().getTitle(), getWorksite().getTitle() });
0238:            }
0239:
0240:            public void setWorkingReportDefinition(
0241:                    DecoratedReportDefinition workingReportDefinition) {
0242:                this .workingReportDefinition = workingReportDefinition;
0243:            }
0244:
0245:            /**
0246:             * getter for the WorkingReportDefinition property
0247:             *
0248:             * @return DecoratedReportDefinition
0249:             */
0250:            public DecoratedReportDefinition getWorkingReportDefinition() {
0251:                return workingReportDefinition;
0252:            }
0253:
0254:            /**
0255:             * setter for the Working Report
0256:             *
0257:             * @param workingReport DecoratedReport
0258:             */
0259:            public void setWorkingReport(DecoratedReport workingReport) {
0260:                this .workingReport = workingReport;
0261:            }
0262:
0263:            /**
0264:             * getter for the WorkingReport property
0265:             *
0266:             * @return DecoratedReport
0267:             */
0268:            public DecoratedReport getWorkingReport() {
0269:                return workingReport;
0270:            }
0271:
0272:            public void setWorkingResult(DecoratedReportResult workingResult) {
0273:                this .workingResult = workingResult;
0274:                getReportsManager().setCurrentResult(
0275:                        workingResult.getReportResult());
0276:            }
0277:
0278:            /**
0279:             * getter for the WorkingReport property
0280:             *
0281:             * @return DecoratedReport
0282:             */
0283:            public DecoratedReportResult getWorkingResult() {
0284:                return workingResult;
0285:            }
0286:
0287:            /**
0288:             * This method gets the list of reports encapsulated by
0289:             * DecoratedReportDefinition.
0290:             *
0291:             * @return List of DecoratedReportDefinition
0292:             */
0293:            public List getReports() {
0294:                List reportDefinitions = reportsManager.getReportDefinitions();
0295:                decoratedReportDefinition = new ArrayList();
0296:
0297:                Iterator iter = reportDefinitions.iterator();
0298:                while (iter.hasNext()) {
0299:                    ReportDefinition reportDef = (ReportDefinition) iter.next();
0300:                    decoratedReportDefinition
0301:                            .add(new DecoratedReportDefinition(reportDef, this ));
0302:                }
0303:                return decoratedReportDefinition;
0304:            }
0305:
0306:            public List getResults() {
0307:                List decoratedResults = new ArrayList();
0308:
0309:                List results = reportsManager.getCurrentUserResults();
0310:
0311:                List tempResults = reportsManager.getReportsByViewer();
0312:
0313:                Iterator iter = results.iterator();
0314:                while (iter.hasNext()) {
0315:                    Object rr = iter.next();
0316:
0317:                    if (rr instanceof  ReportResult)
0318:                        decoratedResults.add(new DecoratedReportResult(
0319:                                (ReportResult) rr, this ));
0320:                    else if (rr instanceof  Report)
0321:                        decoratedResults.add(new DecoratedReport((Report) rr,
0322:                                this ));
0323:                }
0324:
0325:                for (Iterator i = tempResults.iterator(); i.hasNext();) {
0326:                    decoratedResults.add(new DecoratedReportResult(
0327:                            (ReportResult) i.next(), this ));
0328:
0329:                }
0330:                return decoratedResults;
0331:            }
0332:
0333:            /**
0334:             * Tells the interface if the live report was saved.  it goes to false
0335:             * after the message is complete.
0336:             */
0337:            public boolean getSavedLiveReport() {
0338:                boolean saved = savedLiveReport;
0339:                return saved;
0340:            }
0341:
0342:            //***********************************************************
0343:            //***********************************************************
0344:            //	Actions for the JSP
0345:
0346:            /**
0347:             * An action called from the JSP through the JSF framework.
0348:             * This is called when the user wants to move to the next screen
0349:             *
0350:             * @return String the next page
0351:             */
0352:            public String processReportBaseProperties() {
0353:                String nextPage = ReportsTool.createReportParamsPage;
0354:
0355:                //	ensure that there is a title for the report
0356:                if (getWorkingReport().testInvalidateTitle())
0357:                    nextPage = "";
0358:
0359:                if (getWorkingReport().getReportParams().size() > 0) {
0360:                    return nextPage;
0361:                } else {
0362:                    return processEditParamsContinue();
0363:                }
0364:
0365:            }
0366:
0367:            /**
0368:             * An action called from the JSP through the JSF framework.
0369:             * Called when the user wants to stop creating a new report
0370:             *
0371:             * @return String the next page
0372:             */
0373:            public String processCancelReport() {
0374:                savedLiveReport = false;
0375:
0376:                //	remove the working report
0377:                setWorkingReport(null);
0378:
0379:                return ReportsTool.mainPage;
0380:            }
0381:
0382:            public String processCancelExport() {
0383:                savedLiveReport = false;
0384:                return ReportsTool.reportResultsPage;
0385:            }
0386:
0387:            /**
0388:             * This goes from entering the parameter values to the results page
0389:             *
0390:             * @return Next page
0391:             */
0392:            public String processEditParamsContinue() {
0393:                //check that the parameters are all good
0394:                if (!getWorkingReport().getParamsAreValid()) {
0395:
0396:                    String msg = "";
0397:                    for (Iterator iter = getWorkingReport().getReportParams()
0398:                            .iterator(); iter.hasNext();) {
0399:                        DecoratedReportParam drp = (DecoratedReportParam) iter
0400:                                .next();
0401:
0402:                        if (!drp.getIsValid()) {
0403:                            if (msg.length() != 0)
0404:                                msg += "<BR />";
0405:                            msg += getMessageFromBundle("badParam_start");
0406:                            msg += drp.getReportDefinitionParam().getTitle();
0407:                            msg += getMessageFromBundle("badParam_mid");
0408:                            if (drp.getIsString())
0409:                                msg += getMessageFromBundle("badParam_string_reason");
0410:                            if (drp.getIsInteger())
0411:                                msg += getMessageFromBundle("badParam_int_reason");
0412:                            if (drp.getIsFloat())
0413:                                msg += getMessageFromBundle("badParam_float_reason");
0414:                            if (drp.getIsDate())
0415:                                msg += getMessageFromBundle("badParam_date_reason");
0416:                            msg += getMessageFromBundle("badParam_end");
0417:                        }
0418:                    }
0419:                    getWorkingReport().setParamErrorMessages(msg);
0420:                    return "";
0421:                }
0422:
0423:                try {
0424:                    //	get the results
0425:                    ReportResult result = reportsManager
0426:                            .generateResults(getWorkingReport().getReport());
0427:
0428:                    //	make it the working result
0429:                    setWorkingResult(new DecoratedReportResult(result, this ));
0430:
0431:                    //	go to the results page
0432:                    return reportResultsPage;
0433:                } catch (ReportExecutionException ree) {
0434:                    getWorkingReport().setParamErrorMessages(
0435:                            getMessageFromBundle("run_report_problem"));
0436:                    return "";
0437:                }
0438:            }
0439:
0440:            public String processEditParamsBack() {
0441:                return createReportPage;
0442:            }
0443:
0444:            public String processChangeViewXsl() {
0445:                savedLiveReport = false;
0446:                return reportResultsPage;
0447:            }
0448:
0449:            /**
0450:             * We want to use an action to forward to the helper.  We don't want
0451:             * to forward to the permission helper in the jsp beause we need to
0452:             * clear out the cached permissions
0453:             *
0454:             * @return String unused
0455:             */
0456:            public String processPermissions() {
0457:                ExternalContext context = FacesContext.getCurrentInstance()
0458:                        .getExternalContext();
0459:
0460:                userCan = null;
0461:
0462:                try {
0463:                    String url = "sakai.permissions.helper.helper/tool?"
0464:                            + "session." + PermissionsHelper.DESCRIPTION + "="
0465:                            + getPermissionsMessage() + "&session."
0466:                            + PermissionsHelper.TARGET_REF + "="
0467:                            + getWorksite().getReference() + "&session."
0468:                            + PermissionsHelper.PREFIX + "="
0469:                            + getReportFunctionPrefix();
0470:
0471:                    context.redirect(url);
0472:                } catch (IOException e) {
0473:                    throw new RuntimeException("Failed to redirect to helper",
0474:                            e);
0475:                }
0476:                return null;
0477:            }
0478:
0479:            /**
0480:             * An action called from the JSP through the JSF framework.
0481:             *
0482:             * @return String the next page
0483:             */
0484:            public String gotoOptions() {
0485:                return mainPage;
0486:            }
0487:
0488:            public String processSaveResults() {
0489:                savedLiveReport = false;
0490:                return saveResultsPage;
0491:            }
0492:
0493:            public String processCancelSave() {
0494:                savedLiveReport = false;
0495:                return reportResultsPage;
0496:            }
0497:
0498:            public String processSaveResultsToDB() {
0499:                savedLiveReport = false;
0500:                reportsManager.saveReportResult(getWorkingResult()
0501:                        .getReportResult());
0502:
0503:                return reportResultsPage;
0504:            }
0505:
0506:            public String processSaveResultsToResources(
0507:                    DecoratedReportResult reportResult) throws IOException {
0508:                ReportResult result = reportsManager.loadResult(reportResult
0509:                        .getReportResult());
0510:                String fileName = reportsManager
0511:                        .processSaveResultsToResources(result);
0512:                if (fileName.length() > 0) {
0513:                    FacesContext.getCurrentInstance().addMessage(
0514:                            null,
0515:                            getFacesMessageFromBundle("resource_saved",
0516:                                    new Object[] { fileName }));
0517:                }
0518:                return ReportsTool.mainPage;
0519:            }
0520:
0521:            public String processSaveReport() {
0522:                reportsManager.saveReport(getWorkingResult().getReportResult()
0523:                        .getReport());
0524:                savedLiveReport = true;
0525:                return reportResultsPage;
0526:            }
0527:
0528:            /**
0529:             * this function loads the full report result and the report
0530:             * sets these in the tool
0531:             *
0532:             * @return String which page to go to next
0533:             */
0534:            public String processSelectReportResult(
0535:                    DecoratedReportResult reportResult) {
0536:                ReportResult result = reportsManager.loadResult(reportResult
0537:                        .getReportResult());
0538:                Report report = result.getReport();
0539:
0540:                setWorkingReport(new DecoratedReport(report, this ));
0541:                setWorkingResult(new DecoratedReportResult(result, this ));
0542:
0543:                return ReportsTool.reportResultsPage;
0544:            }
0545:
0546:            /**
0547:             * this function loads a live report.  It generates a new result,
0548:             * sets the report as having been saved (aka, it was loaded from the db)
0549:             *
0550:             * @param report DecoratedReport
0551:             * @return String the next page
0552:             */
0553:            public String processSelectLiveReport(DecoratedReport report) {
0554:                ReportResult result = reportsManager.generateResults(report
0555:                        .getReport());
0556:
0557:                result.getReport().setIsSaved(true);
0558:
0559:                //	make it the working result
0560:                setWorkingReport(new DecoratedReport(result.getReport(), this ));
0561:                setWorkingResult(new DecoratedReportResult(result, this ));
0562:
0563:                return ReportsTool.reportResultsPage;
0564:            }
0565:
0566:            /**
0567:             * When deleting a report result, delete the report result...
0568:             * then if the report is not live, then delete the report as well
0569:             *
0570:             * @param reportResult
0571:             * @return String the next page
0572:             */
0573:            public String processDeleteReportResult(
0574:                    DecoratedReportResult reportResult) {
0575:                reportsManager.deleteReportResult(reportResult
0576:                        .getReportResult());
0577:
0578:                return "";
0579:            }
0580:
0581:            /**
0582:             * @param report
0583:             * @return String the next page
0584:             */
0585:            public String processDeleteLiveReport(DecoratedReport report) {
0586:                reportsManager.deleteReport(report.getReport(), true);
0587:                return "";
0588:            }
0589:
0590:            public String processDeleteReportDef(ReportDefinition reportDef) {
0591:                reportsManager.deleteReportDefXmlFile(reportDef);
0592:                return ReportsTool.mainPage;
0593:            }
0594:
0595:            public String processActionCancel() {
0596:                setImportFilesString(null);
0597:                return ReportsTool.mainPage;
0598:            }
0599:
0600:            /**
0601:             * @param report
0602:             * @return String the next page
0603:             */
0604:            public String processEditLiveReport(DecoratedReport report) {
0605:                getReportsManager().checkEditAccess();
0606:                setWorkingReport(report);
0607:                if (report.getReportParams().size() > 0) {
0608:                    return createReportParamsPage;
0609:                } else {
0610:                    return reportResultsPage;
0611:                }
0612:            }
0613:
0614:            public Map getUserCan() {
0615:                if (userCan == null) {
0616:                    userCan = getReportsManager().getAuthorizationsMap();
0617:                }
0618:                return userCan;
0619:            }
0620:
0621:            public void setUserCan(Map userCan) {
0622:                this .userCan = userCan;
0623:            }
0624:
0625:            public boolean isMaintainer() {
0626:                return getReportsManager().isMaintaner();
0627:            }
0628:
0629:            public void processActionAudienceHelper(
0630:                    DecoratedReportResult reportResult) {
0631:                ExternalContext context = FacesContext.getCurrentInstance()
0632:                        .getExternalContext();
0633:                //Tool tool = ToolManager.getCurrentTool();
0634:                ToolSession session = SessionManager.getCurrentToolSession();
0635:                ServerConfigurationService configService = org.sakaiproject.component.cover.ServerConfigurationService
0636:                        .getInstance();
0637:                String baseUrl = configService.getServerUrl();
0638:                String url = baseUrl
0639:                        + "/osp-reports-tool/viewReportResults.osp?id="
0640:                        + reportResult.getReportResult().getResultId();
0641:                url += "&"
0642:                        + Tool.PLACEMENT_ID
0643:                        + "="
0644:                        + SessionManager.getCurrentToolSession()
0645:                                .getPlacementId();
0646:
0647:                ResourceBundle myResources = ResourceBundle
0648:                        .getBundle(ReportsManager.REPORTS_MESSAGE_BUNDLE);
0649:                session.setAttribute(AudienceSelectionHelper.AUDIENCE_FUNCTION,
0650:                        "osp.reports.view");
0651:
0652:                session.setAttribute(
0653:                        AudienceSelectionHelper.AUDIENCE_PORTFOLIO_WIZARD,
0654:                        "false");
0655:                session
0656:                        .setAttribute(
0657:                                AudienceSelectionHelper.AUDIENCE_QUALIFIER,
0658:                                reportResult.getReportResult().getResultId()
0659:                                        .getValue());
0660:                session.setAttribute(
0661:                        AudienceSelectionHelper.AUDIENCE_GLOBAL_TITLE,
0662:                        myResources.getString("title_share_report"));
0663:                session
0664:                        .setAttribute(
0665:                                AudienceSelectionHelper.AUDIENCE_INSTRUCTIONS,
0666:                                myResources
0667:                                        .getString("instructions_addViewersToPresentation"));
0668:                session.setAttribute(
0669:                        AudienceSelectionHelper.AUDIENCE_GROUP_TITLE,
0670:                        myResources.getString("instructions_publishToGroup"));
0671:
0672:                session.setAttribute(
0673:                        AudienceSelectionHelper.AUDIENCE_INDIVIDUAL_TITLE,
0674:                        myResources
0675:                                .getString("instructions_publishToIndividual"));
0676:
0677:                session.setAttribute(
0678:                        AudienceSelectionHelper.AUDIENCE_PUBLIC_FLAG, "false");
0679:                // session.setAttribute(AudienceSelectionHelper.AUDIENCE_PUBLIC_TITLE, myResources.getString("instructions_publishToInternet"));
0680:                session.setAttribute(
0681:                        AudienceSelectionHelper.AUDIENCE_SELECTED_TITLE,
0682:                        myResources.getString("instructions_selectedAudience"));
0683:                session
0684:                        .setAttribute(
0685:                                AudienceSelectionHelper.AUDIENCE_FILTER_INSTRUCTIONS,
0686:                                myResources
0687:                                        .getString("instructions_selectFilterUserList"));
0688:                session.setAttribute(
0689:                        AudienceSelectionHelper.AUDIENCE_GUEST_EMAIL, "true");
0690:                session.setAttribute(
0691:                        AudienceSelectionHelper.AUDIENCE_WORKSITE_LIMITED,
0692:                        "false");
0693:                session.setAttribute(
0694:                        AudienceSelectionHelper.AUDIENCE_PUBLIC_INSTRUCTIONS,
0695:                        myResources.getString("publish_message"));
0696:                session.setAttribute(
0697:                        AudienceSelectionHelper.AUDIENCE_PUBLIC_URL, url);
0698:
0699:                session.setAttribute(
0700:                        AudienceSelectionHelper.AUDIENCE_BROWSE_INDIVIDUAL,
0701:                        myResources.getString("audience_browse_individual"));
0702:                try {
0703:                    context.redirect("osp.audience.helper/tool.jsf?panel=Main");
0704:                } catch (IOException e) {
0705:                    throw new RuntimeException("Failed to redirect to helper",
0706:                            e);
0707:                }
0708:            }
0709:
0710:            public String processImportDefinition() {
0711:                return ReportsTool.importReportDef;
0712:            }
0713:
0714:            public String processPickImportFiles() {
0715:                ExternalContext context = FacesContext.getCurrentInstance()
0716:                        .getExternalContext();
0717:                ToolSession session = SessionManager.getCurrentToolSession();
0718:                session.setAttribute(FilePickerHelper.FILE_PICKER_ATTACH_LINKS,
0719:                        new Boolean(true).toString());
0720:                /*
0721:                List wsItemRefs = EntityManager.newReferenceList();
0722:
0723:                for (Iterator i=importFiles.iterator();i.hasNext();) {
0724:                   WizardStyleItem wsItem = (WizardStyleItem)i.next();
0725:                   wsItemRefs.add(wsItem.getBaseReference().getBase());
0726:                }*/
0727:
0728:                session.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS,
0729:                        importFiles);
0730:                session
0731:                        .setAttribute(
0732:                                FilePickerHelper.FILE_PICKER_RESOURCE_FILTER,
0733:                                ComponentManager
0734:                                        .get("org.sakaiproject.content.api.ContentResourceFilter.reportImportFile"));
0735:
0736:                try {
0737:                    context.redirect("sakai.filepicker.helper/tool");
0738:                } catch (IOException e) {
0739:                    throw new RuntimeException("Failed to redirect to helper",
0740:                            e);
0741:                }
0742:                return null;
0743:            }
0744:
0745:            /**
0746:             * This is called to put the file names into the text box.
0747:             * It updates the list of files if the user is returning from the file picker
0748:             *
0749:             * @return String the names of the files being imported
0750:             */
0751:            public String getImportFilesString() {
0752:                ToolSession session = SessionManager.getCurrentToolSession();
0753:                if (session.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
0754:                        && session
0755:                                .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) {
0756:
0757:                    List refs = (List) session
0758:                            .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
0759:                    //importFiles.clear();
0760:                    importFilesString = "";
0761:                    for (int i = 0; i < refs.size(); i++) {
0762:                        Reference ref = (Reference) refs.get(i);
0763:                        String nodeId = getContentHosting()
0764:                                .getUuid(ref.getId());
0765:                        String id = getContentHosting().resolveUuid(nodeId);
0766:
0767:                        ContentResource resource = null;
0768:                        try {
0769:                            resource = getContentHosting().getResource(id);
0770:                        } catch (PermissionException pe) {
0771:                            logger
0772:                                    .warn(
0773:                                            "Failed loading content: no permission to view file",
0774:                                            pe);
0775:                        } catch (TypeException pe) {
0776:                            logger.warn("Wrong type", pe);
0777:                        } catch (IdUnusedException pe) {
0778:                            logger.warn("UnusedId: ", pe);
0779:                        }
0780:
0781:                        importFilesString += resource.getProperties()
0782:                                .getProperty(
0783:                                        resource.getProperties()
0784:                                                .getNamePropDisplayName())
0785:                                + " ";
0786:                    }
0787:                    importFiles = refs;
0788:                    session
0789:                            .removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
0790:                } else if (session
0791:                        .getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
0792:                        && session
0793:                                .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) == null) {
0794:                    importFiles.clear();
0795:                    importFilesString = "";
0796:                }
0797:
0798:                return importFilesString;
0799:            }
0800:
0801:            public void setImportFilesString(String importFilesString) {
0802:                this .importFilesString = importFilesString;
0803:            }
0804:
0805:            /**
0806:             * Called when the user clicks the Import Button
0807:             *
0808:             * @return String next view
0809:             */
0810:            public String processImportReports() {
0811:
0812:                if (importFiles.size() == 0) {
0813:                    return ReportsTool.importReportDef;
0814:                }
0815:
0816:                for (Iterator i = importFiles.iterator(); i.hasNext();) {
0817:                    Reference ref = (Reference) i.next();
0818:
0819:                    try {
0820:                        reportsManager.importResource(getIdManager().getId(
0821:                                getWorksite().getId()), getContentHosting()
0822:                                .getUuid(ref.getId()));
0823:                    } catch (OspException ie) {
0824:                        this .setInvalidImport(true);
0825:                        this .setInvalidImportMessage(invalidImportMessage + " "
0826:                                + ie.getMessage());
0827:
0828:                    } catch (ImportException ie) {
0829:                        this .setInvalidImport(true);
0830:                    } catch (UnsupportedFileTypeException ufte) {
0831:                        this .setInvalidImport(true);
0832:                    } catch (Exception ie) {
0833:                        if (ie
0834:                                .getCause()
0835:                                .toString()
0836:                                .equals(
0837:                                        "org.sakaiproject.metaobj.shared.model.OspException"))
0838:                            ;
0839:                        this .setInvalidImportMessage(invalidImportMessage + " "
0840:                                + ie.getMessage());
0841:                        this .setInvalidImport(true);
0842:                    }
0843:
0844:                }
0845:
0846:                return ReportsTool.mainPage;
0847:            }
0848:
0849:            public ContentHostingService getContentHosting() {
0850:                return contentHosting;
0851:            }
0852:
0853:            public void setContentHosting(ContentHostingService contentHosting) {
0854:                this .contentHosting = contentHosting;
0855:            }
0856:
0857:            public String processScheduleReport(DecoratedReport report) {
0858:                setJobDetail(reportsManager
0859:                        .processCreateJob(report.getReport()));
0860:                jobDetailWrapper.setJobDetail(getJobDetail());
0861:                jobDetailWrapper
0862:                        .setTriggerWrapperList(getJobTriggerList(getJobDetail()));
0863:                return ReportsTool.scheduleReport;
0864:            }
0865:
0866:            public String getTriggerExpression() {
0867:                return triggerExpression;
0868:            }
0869:
0870:            public void setTriggerExpression(String triggerExpression) {
0871:                this .triggerExpression = triggerExpression;
0872:            }
0873:
0874:            public void validateTriggerExpression(FacesContext context,
0875:                    UIComponent component, Object value) {
0876:                if (value != null) {
0877:                    try {
0878:                        String expression = (String) value;
0879:                        CronTrigger trigger = new CronTrigger();
0880:                        trigger.setCronExpression(expression);
0881:
0882:                        // additional checks
0883:                        // quartz does not check for more than 7 tokens in expression
0884:                        String[] arr = expression.split("\\s");
0885:                        if (arr.length > 7) {
0886:                            throw new ParseException(
0887:                                    "Expression has more than 7 tokens", 7);
0888:                        }
0889:
0890:                        //(check that last 2 entries are not both * or ?
0891:                        String trimmed_expression = expression.replaceAll(
0892:                                "\\s", ""); // remove whitespace
0893:                        if (trimmed_expression.endsWith(CRON_CHECK_ASTERISK)
0894:                                || trimmed_expression
0895:                                        .endsWith(CRON_CHECK_QUESTION_MARK)) {
0896:                            throw new ParseException(
0897:                                    "Cannot End in * * or ? ?", 1);
0898:                        }
0899:                    } catch (ParseException e) {
0900:                        // not giving a detailed message to prevent line wraps
0901:                        FacesMessage message = new FacesMessage(
0902:                                "Parse Exception");
0903:                        message.setSeverity(FacesMessage.SEVERITY_WARN);
0904:                        throw new ValidatorException(message);
0905:                    }
0906:                }
0907:
0908:            }
0909:
0910:            public void validateTriggerName(FacesContext context,
0911:                    UIComponent component, Object value) {
0912:                if (value != null) {
0913:                    try {
0914:                        Trigger trigger = schedulerManager.getScheduler()
0915:                                .getTrigger((String) value,
0916:                                        Scheduler.DEFAULT_GROUP);
0917:                        if (trigger != null) {
0918:                            FacesMessage message = new FacesMessage(
0919:                                    "Existing Trigger Name");
0920:                            message.setSeverity(FacesMessage.SEVERITY_WARN);
0921:                            throw new ValidatorException(message);
0922:                        }
0923:                    } catch (SchedulerException e) {
0924:                        logger.error("Scheduler down!");
0925:                    }
0926:                }
0927:            }
0928:
0929:            public JobDetail getJobDetail() {
0930:                return jobDetail;
0931:            }
0932:
0933:            public void setJobDetail(JobDetail jobDetail) {
0934:                this .jobDetail = jobDetail;
0935:            }
0936:
0937:            public List setJobTriggers(JobDetail jobDetail) {
0938:                return getJobTriggerList(jobDetail);
0939:            }
0940:
0941:            public List getJobTriggerList(JobDetail jobDetail) {
0942:                List triggerWrapperList = new ArrayList();
0943:                try {
0944:
0945:                    jobDetailWrapper.setJobDetail(jobDetail);
0946:                    Trigger[] triggerArr = getSchedulerManager().getScheduler()
0947:                            .getTriggersOfJob(jobDetail.getName(),
0948:                                    ReportsManager.reportGroup);
0949:
0950:                    TriggerWrapper tw;
0951:                    for (int j = 0; j < triggerArr.length; j++) {
0952:                        tw = new TriggerWrapperImpl();
0953:                        tw.setTrigger(triggerArr[j]);
0954:                        triggerWrapperList.add(tw);
0955:                    }
0956:                    jobDetailWrapper.setTriggerWrapperList(triggerWrapperList);
0957:
0958:                } catch (SchedulerException e) {
0959:                    logger.error("scheduler error while getting job detail");
0960:                }
0961:                return triggerWrapperList;
0962:            }
0963:
0964:            public String getJobName() {
0965:                return jobName;
0966:            }
0967:
0968:            public void setJobName(String jobName) {
0969:                this .jobName = jobName;
0970:            }
0971:
0972:            public String getTriggerName() {
0973:                return triggerName;
0974:            }
0975:
0976:            public void setTriggerName(String triggerName) {
0977:                this .triggerName = triggerName;
0978:            }
0979:
0980:            public JobDetailWrapper getJobDetailWrapper() {
0981:                return jobDetailWrapper;
0982:            }
0983:
0984:            public void setJobDetailWrapper(JobDetailWrapper jobDetailWrapper) {
0985:                this .jobDetailWrapper = jobDetailWrapper;
0986:            }
0987:
0988:            public String processCreateTrigger() {
0989:                Scheduler scheduler = schedulerManager.getScheduler();
0990:                if (scheduler == null) {
0991:                    logger.error("Scheduler is down!");
0992:                    return "error";
0993:                }
0994:                try {
0995:                    Trigger trigger = new CronTrigger(triggerName,
0996:                            ReportsManager.reportGroup, getJobDetail()
0997:                                    .getName(), ReportsManager.reportGroup,
0998:                            triggerExpression);
0999:                    scheduler.scheduleJob(trigger);
1000:                    TriggerWrapper tempTriggerWrapper = new TriggerWrapperImpl();
1001:                    tempTriggerWrapper.setTrigger(trigger);
1002:                    getJobDetailWrapper().getTriggerWrapperList().add(
1003:                            tempTriggerWrapper);
1004:
1005:                    triggerName = null;
1006:                    triggerExpression = null;
1007:                    return scheduleReport;
1008:                } catch (Exception e) {
1009:                    triggerName = null;
1010:                    triggerExpression = null;
1011:                    logger.error("Failed to create trigger");
1012:                    return "error";
1013:                }
1014:            }
1015:
1016:            public String processSelectAllTriggers() {
1017:
1018:                isSelectAllTriggersSelected = !isSelectAllTriggersSelected;
1019:                for (Iterator i = getJobDetailWrapper().getTriggerWrapperList()
1020:                        .iterator(); i.hasNext();) {
1021:                    if (isSelectAllTriggersSelected) {
1022:                        ((TriggerWrapper) i.next()).setIsSelected(true);
1023:                    } else {
1024:                        ((TriggerWrapper) i.next()).setIsSelected(false);
1025:                    }
1026:                }
1027:                return scheduleReport;
1028:            }
1029:
1030:            public List getFilteredTriggersWrapperList() {
1031:                return filteredTriggersWrapperList;
1032:            }
1033:
1034:            public void setFilteredTriggersWrapperList(
1035:                    List filteredTriggersWrapperList) {
1036:                this .filteredTriggersWrapperList = filteredTriggersWrapperList;
1037:            }
1038:
1039:            public String processRefreshFilteredTriggers() {
1040:                filteredTriggersWrapperList = new ArrayList();
1041:                for (Iterator i = getJobDetailWrapper().getTriggerWrapperList()
1042:                        .iterator(); i.hasNext();) {
1043:                    TriggerWrapper triggerWrapper = (TriggerWrapper) i.next();
1044:                    if (triggerWrapper.getIsSelected()) {
1045:                        filteredTriggersWrapperList.add(triggerWrapper);
1046:                    }
1047:                }
1048:                return deleteTriggers;
1049:            }
1050:
1051:            public String processDeleteTriggers() {
1052:                try {
1053:                    TriggerWrapper triggerWrapper;
1054:                    for (Iterator i = filteredTriggersWrapperList.iterator(); i
1055:                            .hasNext();) {
1056:                        triggerWrapper = (TriggerWrapper) i.next();
1057:                        schedulerManager.getScheduler().unscheduleJob(
1058:                                triggerWrapper.getTrigger().getName(),
1059:                                ReportsManager.reportGroup);
1060:                        getJobDetailWrapper().getTriggerWrapperList().remove(
1061:                                triggerWrapper);
1062:                    }
1063:                } catch (SchedulerException e) {
1064:                    logger.error("Scheduler Down");
1065:                }
1066:                return scheduleReport;
1067:            }
1068:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.