Source Code Cross Referenced for SubscriptionHelper.java in  » Report » pentaho-report » org » pentaho » core » subscribe » 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 » Report » pentaho report » org.pentaho.core.subscribe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Oct 15, 2005 
014:         * @author James Dixon
015:         */
016:
017:        package org.pentaho.core.subscribe;
018:
019:        import java.io.InputStream;
020:        import java.io.OutputStream;
021:        import java.util.ArrayList;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        import org.pentaho.core.repository.IContentItem;
028:        import org.pentaho.core.repository.ISolutionRepository;
029:        import org.pentaho.core.runtime.IRuntimeContext;
030:        import org.pentaho.core.session.IPentahoSession;
031:        import org.pentaho.core.solution.HttpRequestParameterProvider;
032:        import org.pentaho.core.solution.HttpSessionParameterProvider;
033:        import org.pentaho.core.solution.IActionSequence;
034:        import org.pentaho.core.solution.IOutputHandler;
035:        import org.pentaho.core.solution.IParameterProvider;
036:        import org.pentaho.core.solution.IParameterSetter;
037:        import org.pentaho.core.solution.ISolutionEngine;
038:        import org.pentaho.core.solution.SimpleOutputHandler;
039:        import org.pentaho.core.solution.SimpleParameterProvider;
040:        import org.pentaho.core.solution.SimpleParameterSetter;
041:        import org.pentaho.core.solution.SolutionEngine;
042:        import org.pentaho.core.system.ISystemSettings;
043:        import org.pentaho.core.system.PentahoSystem;
044:        import org.pentaho.core.ui.SimpleUrlFactory;
045:        import org.pentaho.core.util.UIUtil;
046:        import org.pentaho.messages.Messages;
047:        import org.pentaho.plugin.quartz.QuartzExecute;
048:        import org.pentaho.plugin.quartz.QuartzSystemListener;
049:        import org.pentaho.plugin.quartz.SecurityAwareBackgroundSubscriptionHelper;
050:        import org.pentaho.repository.content.ContentItemFile;
051:        import org.pentaho.util.UUIDUtil;
052:        import org.quartz.CronTrigger;
053:        import org.quartz.JobDetail;
054:        import org.quartz.Scheduler;
055:        import org.quartz.Trigger;
056:
057:        import com.pentaho.repository.subscribe.ISubscriptionRepository;
058:        import com.pentaho.repository.subscribe.Schedule;
059:        import com.pentaho.repository.subscribe.SubscribeContent;
060:        import com.pentaho.repository.subscribe.Subscription;
061:
062:        public class SubscriptionHelper {
063:
064:            public static void editSubscription(String subscriptionName,
065:                    IPentahoSession session, SimpleUrlFactory urlFactory,
066:                    OutputStream outputStream) {
067:
068:                ISubscriptionRepository subscriptionRepository = PentahoSystem
069:                        .getSubscriptionRepository(session);
070:                Subscription subscription = subscriptionRepository
071:                        .getSubscription(subscriptionName, session);
072:                if (subscription == null) {
073:                    // TODO surface an error
074:                    return;
075:                }
076:                SubscribeContent content = subscription.getContent();
077:                Map contentParameters = content.getParameters();
078:                SimpleParameterSetter parameters = new SimpleParameterSetter();
079:                parameters.setParameters(contentParameters);
080:                getSubscriptionParameters(subscriptionName, parameters, session);
081:                // SimpleParameterProvider parameterProvider = new SimpleParameterProvider(
082:                // contentParameters );
083:
084:                //Proposed fix for bug BISERVER-97 by Ezequiel Cuellar
085:                //Changed to set parameterXsl from the value specified specified in the Pentaho.xml tag "default-parameter-xsl"
086:
087:                //Proposed fix for bug BISERVER-238 by Ezequiel Cuellar
088:                //Took away reference to SubscribeForm.xsl and changed it to DefaultParameterForm.xsl
089:                ISystemSettings systemSettings = PentahoSystem
090:                        .getSystemSettings();
091:                String defaultParameterXsl = systemSettings.getSystemSetting(
092:                        "default-parameter-xsl", "DefaultParameterForm.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
093:
094:                SolutionEngine solutionEngine = (SolutionEngine) PentahoSystem
095:                        .getSolutionEngineInstance(session);
096:                solutionEngine.setLoggingLevel(PentahoSystem.loggingLevel);
097:                solutionEngine.init(session);
098:                solutionEngine.setParameterXsl(defaultParameterXsl);
099:                solutionEngine.setForcePrompt(true);
100:
101:                Map parameterProviderMap = new HashMap();
102:                parameterProviderMap.put("PRO_EDIT_SUBSCRIPTION", parameters); //$NON-NLS-1$	
103:                HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(
104:                        session);
105:                parameterProviderMap.put(
106:                        HttpSessionParameterProvider.SCOPE_SESSION,
107:                        sessionParameters);
108:
109:                SimpleOutputHandler outputHandler = null;
110:                if (outputStream != null) {
111:                    outputHandler = new SimpleOutputHandler(outputStream, true);
112:                }
113:
114:                outputHandler
115:                        .setOutputPreference(IOutputHandler.OUTPUT_TYPE_PARAMETERS);
116:                ArrayList messages = new ArrayList();
117:                IRuntimeContext runtime = null;
118:                String instanceId = null;
119:                boolean persisted = false;
120:                PentahoSystem.ActionInfo contentInfo = PentahoSystem
121:                        .parseActionString(content.getActionReference());
122:
123:                try {
124:                    runtime = solutionEngine
125:                            .execute(
126:                                    contentInfo.getSolutionName(),
127:                                    contentInfo.getPath(),
128:                                    contentInfo.getActionName(),
129:                                    "Subscriptions", false, true, instanceId, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages); //$NON-NLS-1$
130:                } finally {
131:                    runtime.dispose();
132:                }
133:            }
134:
135:            /*
136:             * The regular save subscription
137:             */
138:            public static String saveSubscription(
139:                    IParameterProvider parameterProvider,
140:                    String actionReference, IPentahoSession userSession) {
141:                return saveSubscription(parameterProvider, actionReference,
142:                        userSession, false);
143:            }
144:
145:            /*
146:             * Pass in boolean true to save subscription information without requiring a content to be defined - Used for JPovot views  
147:             */
148:            public static String saveSubscription(
149:                    IParameterProvider parameterProvider,
150:                    String actionReference, IPentahoSession userSession,
151:                    boolean saveOnly) {
152:
153:                if (userSession == null || userSession.getName() == null) {
154:                    return Messages
155:                            .getString("SubscriptionHelper.USER_LOGIN_NEEDED"); //$NON-NLS-1$
156:                }
157:
158:                String subscriptionId = (String) parameterProvider
159:                        .getParameter("subscribe-id"); //$NON-NLS-1$
160:                boolean editing = (subscriptionId != null)
161:                        && (subscriptionId.length() > 0);
162:                String subscriptionName = (String) parameterProvider
163:                        .getParameter("subscribe-name"); //$NON-NLS-1$
164:
165:                String destination = parameterProvider.getStringParameter(
166:                        "destination", null); //$NON-NLS-1$
167:                ISubscriptionRepository subscriptionRepository = PentahoSystem
168:                        .getSubscriptionRepository(userSession);
169:
170:                if (!editing) {
171:                    boolean isUniqueName = subscriptionRepository
172:                            .checkUniqueSubscriptionName(subscriptionName,
173:                                    userSession.getName(), actionReference);
174:                    if (!isUniqueName) {
175:                        return Messages
176:                                .getString(
177:                                        "SubscriptionHelper.USER_SUBSCRIPTION_NAME_ALREADY_EXISTS", subscriptionName); //$NON-NLS-1$
178:                    }
179:                }
180:
181:                ISolutionRepository solutionRepository = PentahoSystem
182:                        .getSolutionRepository(userSession);
183:                PentahoSystem.ActionInfo contentInfo = PentahoSystem
184:                        .parseActionString(actionReference);
185:                IActionSequence actionSequence = solutionRepository
186:                        .getActionSequence(contentInfo.getSolutionName(),
187:                                contentInfo.getPath(), contentInfo
188:                                        .getActionName(),
189:                                PentahoSystem.loggingLevel,
190:                                ISolutionRepository.ACTION_SUBSCRIBE);
191:                if (actionSequence == null) {
192:                    // TODO log an error
193:                    return Messages
194:                            .getString("SubscriptionHelper.USER_SUBSCRIPTION_NOT_CREATE"); //$NON-NLS-1$
195:                }
196:                Map inputs = actionSequence
197:                        .getInputDefinitionsForParameterProvider(HttpRequestParameterProvider.SCOPE_REQUEST);
198:                SubscribeContent content = subscriptionRepository
199:                        .getContentByActionReference(actionReference);
200:                if (content == null) {
201:                    if (saveOnly) {
202:                        String subContId = UUIDUtil.getUUIDAsString();
203:                        content = new SubscribeContent(subContId,
204:                                actionReference, SubscribeContent.TYPE_REPORT);
205:                        subscriptionRepository.addContent(content);
206:                    } else {
207:                        return (Messages
208:                                .getString(
209:                                        "SubscriptionHelper.ACTION_SEQUENCE_NOT_ALLOWED", contentInfo.getActionName())); //$NON-NLS-1$
210:                    }
211:                }
212:
213:                HashMap parameters = new HashMap();
214:
215:                // we need to grab the parameters
216:                // TODO load the action sequence from the repository so we can limit this
217:                // to just the required parameters or the action name
218:                Iterator inputsIterator = inputs.keySet().iterator();
219:                while (inputsIterator.hasNext()) {
220:                    String parameterName = (String) inputsIterator.next();
221:                    Object parameterValue = parameterProvider
222:                            .getParameter(parameterName);
223:                    if (parameterValue != null) {
224:                        parameters.put(parameterName, parameterValue);
225:                    }
226:                }
227:
228:                // Just in case it's a PivotView Subscription 
229:                if (saveOnly) {
230:                    String parameterValue = (String) parameterProvider
231:                            .getParameter("mdx"); //$NON-NLS-1$
232:                    if (parameterValue != null) {
233:                        parameters.put("mdx", parameterValue); //$NON-NLS-1$
234:                    }
235:                }
236:
237:                String parameterValue = (String) parameterProvider
238:                        .getParameter("action2"); //$NON-NLS-1$
239:                if (parameterValue != null) {
240:                    parameters.put("action", parameterValue); //$NON-NLS-1$
241:                }
242:                Subscription subscription = null;
243:                if (editing) {
244:                    // update an existing subscription
245:                    subscription = subscriptionRepository.getSubscription(
246:                            subscriptionId, userSession);
247:                    if (subscription == null) {
248:                        editing = false;
249:                    } else {
250:                        subscription.setTitle(subscriptionName);
251:                        subscription.setDestination(destination);
252:                        subscription.getParameters().clear();
253:                        subscription.getParameters().putAll(parameters);
254:                        subscription.getSchedules().clear();
255:                    }
256:                }
257:                if (!editing) {
258:                    // create a new subscription
259:                    subscriptionId = UUIDUtil.getUUIDAsString();
260:                    subscription = new Subscription(subscriptionId, userSession
261:                            .getName(), subscriptionName, content, destination,
262:                            Subscription.TYPE_PERSONAL, parameters);
263:                }
264:
265:                // now add the schedules
266:                List schedules = subscriptionRepository.getSchedules();
267:                for (int i = 0; i < schedules.size(); i++) {
268:                    Schedule schedule = (Schedule) schedules.get(i);
269:                    String scheduleId = schedule.getId();
270:                    String scheduleValue = (String) parameterProvider
271:                            .getParameter("schedule-" + scheduleId); //$NON-NLS-1$
272:                    if ("true".equals(scheduleValue)) { //$NON-NLS-1$
273:                        subscription.addSchedule(schedule);
274:                    }
275:                }
276:
277:                if (subscriptionRepository.addSubscription(subscription)) {
278:                    return Messages
279:                            .getString("SubscriptionHelper.USER_SUBSCRIPTION_CREATED"); //$NON-NLS-1$
280:                } else {
281:                    // TODO log an error
282:                    return Messages
283:                            .getString("SubscriptionHelper.USER_SUBSCRIPTION_NOT_CREATE"); //$NON-NLS-1$
284:                }
285:            }
286:
287:            public static boolean scheduleSubscription(Subscription subscription) {
288:
289:                try {
290:                    Scheduler scheduler = QuartzSystemListener
291:                            .getSchedulerInstance();
292:
293:                    // String jobAction = null;
294:                    SubscribeContent subContent = subscription.getContent();
295:                    String solutionName = subContent.getActionReference();
296:                    String solution = solutionName.substring(0, solutionName
297:                            .indexOf('/'));
298:                    String action = solutionName.substring(solutionName
299:                            .lastIndexOf('/') + 1);
300:                    String path = solutionName.substring(solution.length() + 1,
301:                            solutionName.length() - action.length() - 1);
302:
303:                    String jobName = subscription.getUser()
304:                            + " : " + subscription.getTitle(); //$NON-NLS-1$
305:                    JobDetail jobDetail = new JobDetail(jobName,
306:                            "Subscription Group", QuartzExecute.class); //$NON-NLS-1$
307:                    jobDetail.getJobDataMap().put("solution", solution); //$NON-NLS-1$
308:                    jobDetail.getJobDataMap().put("path", path); //$NON-NLS-1$
309:                    jobDetail.getJobDataMap().put("action", action); //$NON-NLS-1$
310:
311:                    jobDetail.getJobDataMap().putAll(
312:                            subscription.getParameters());
313:
314:                    List scheduleList = subscription.getSchedules();
315:                    for (int i = 0; i < scheduleList.size(); ++i) {
316:                        Schedule schedule = (Schedule) scheduleList.get(i);
317:                        Trigger trigger = new CronTrigger(schedule
318:                                .getScheduleReference(),
319:                                "Subscription Group", schedule.getCronString()); //$NON-NLS-1$
320:                        trigger
321:                                .setMisfireInstruction(Trigger.MISFIRE_INSTRUCTION_SMART_POLICY);
322:                        if (scheduler.getJobDetail(jobDetail.getName(),
323:                                "Subscription Group") != null) { //$NON-NLS-1$
324:                            scheduler.deleteJob(jobDetail.getName(),
325:                                    "Subscription Group"); //$NON-NLS-1$
326:                        }
327:                        scheduler.scheduleJob(jobDetail, trigger);
328:                    }
329:                } catch (Throwable t) {
330:                    t.printStackTrace();
331:                    return (false);
332:                }
333:                return (true);
334:            }
335:
336:            public static String deleteSubscription(String subscriptionId,
337:                    IPentahoSession userSession) {
338:                ISubscriptionRepository subscriptionRepository = PentahoSystem
339:                        .getSubscriptionRepository(userSession);
340:
341:                Subscription subscription = subscriptionRepository
342:                        .getSubscription(subscriptionId, userSession);
343:                if (subscription == null) {
344:                    // TODO send an error message
345:                    try {
346:                        return Messages
347:                                .getString("SubscriptionHelper.USER_SUBSCRIPTION_NOT_DELETED"); //$NON-NLS-1$
348:                    } catch (Exception e) {
349:                    }
350:                }
351:
352:                try {
353:                    subscriptionRepository.deleteSubscription(subscriptionId,
354:                            userSession);
355:                    try {
356:                        return Messages
357:                                .getString("SubscriptionHelper.USER_SUBSCRIPTION_DELETED"); //$NON-NLS-1$
358:                    } catch (Exception e) {
359:                    }
360:                } catch (Exception e) {
361:                    try {
362:                        return Messages
363:                                .getString("SubscriptionHelper.USER_SUBSCRIPTION_NOT_DELETED"); //$NON-NLS-1$
364:                    } catch (Exception e2) {
365:                    }
366:                }
367:                return Messages
368:                        .getString("SubscriptionHelper.USER_SUBSCRIPTION_NOT_DELETED"); //$NON-NLS-1$
369:
370:            }
371:
372:            public static void runSubscription(String subscriptionName,
373:                    IPentahoSession session,
374:                    IParameterProvider sessionParameters,
375:                    SimpleUrlFactory urlFactory, IOutputHandler outputHandler) {
376:
377:                ISubscriptionRepository subscriptionRepository = PentahoSystem
378:                        .getSubscriptionRepository(session);
379:                Subscription subscription = subscriptionRepository
380:                        .getSubscription(subscriptionName, session);
381:                if (subscription == null) {
382:                    // TODO surface an error
383:                    return;
384:                }
385:                SubscribeContent content = subscription.getContent();
386:                Map contentParameters = content.getParameters();
387:                Map subscriptionParameters = subscription.getParameters();
388:                SimpleParameterProvider parameterProvider = new SimpleParameterProvider(
389:                        contentParameters);
390:                parameterProvider.setParameters(subscriptionParameters);
391:
392:                ISolutionEngine solutionEngine = PentahoSystem
393:                        .getSolutionEngineInstance(session);
394:                solutionEngine.setLoggingLevel(PentahoSystem.loggingLevel);
395:                solutionEngine.init(session);
396:
397:                Map parameterProviderMap = new HashMap();
398:                parameterProviderMap.put(
399:                        HttpRequestParameterProvider.SCOPE_REQUEST,
400:                        parameterProvider);
401:                parameterProviderMap.put(
402:                        HttpSessionParameterProvider.SCOPE_SESSION,
403:                        sessionParameters);
404:
405:                ArrayList messages = new ArrayList();
406:                IRuntimeContext runtime = null;
407:                String instanceId = null;
408:                boolean persisted = false;
409:                PentahoSystem.ActionInfo contentInfo = PentahoSystem
410:                        .parseActionString(content.getActionReference());
411:                String actionName = (String) subscriptionParameters
412:                        .get("action"); //$NON-NLS-1$
413:                if (actionName == null) {
414:                    actionName = contentInfo.getActionName();
415:                }
416:                try {
417:                    runtime = solutionEngine
418:                            .execute(
419:                                    contentInfo.getSolutionName(),
420:                                    contentInfo.getPath(),
421:                                    actionName,
422:                                    "Subscriptions", false, true, instanceId, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages); //$NON-NLS-1$
423:                    // see if we need to provide feedback to the caller
424:
425:                    try {
426:                        if (!outputHandler.contentDone()) {
427:                            IContentItem contentItem = outputHandler
428:                                    .getFeedbackContentItem();
429:                            OutputStream outputStream = contentItem
430:                                    .getOutputStream(subscriptionName);
431:
432:                            if (runtime == null) {
433:                                // we need an error message...
434:                                StringBuffer buffer = new StringBuffer();
435:                                UIUtil.formatFailureMessage(
436:                                        "text/html", runtime, buffer); //$NON-NLS-1$
437:                                outputStream
438:                                        .write(buffer.toString().getBytes());
439:                                contentItem.closeOutputStream();
440:                            } else if (runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
441:                                StringBuffer buffer = new StringBuffer();
442:                                UIUtil.formatSuccessMessage(
443:                                        "text/html", runtime, buffer, false); //$NON-NLS-1$
444:                                outputStream
445:                                        .write(buffer.toString().getBytes());
446:                                contentItem.closeOutputStream();
447:                            } else {
448:                                // we need an error message...
449:                                StringBuffer buffer = new StringBuffer();
450:                                UIUtil.formatFailureMessage(
451:                                        "text/html", runtime, buffer); //$NON-NLS-1$
452:                                outputStream
453:                                        .write(buffer.toString().getBytes());
454:                                contentItem.closeOutputStream();
455:                            }
456:                        }
457:                    } catch (Throwable t) {
458:                        // TODO
459:                    }
460:
461:                } finally {
462:                    if (runtime != null) {
463:                        runtime.dispose();
464:                    }
465:                }
466:            }
467:
468:            public static void getArchived(String subscriptionName,
469:                    String fileId, IPentahoSession session,
470:                    IOutputHandler outputHandler) {
471:
472:                ISubscriptionRepository subscriptionRepository = PentahoSystem
473:                        .getSubscriptionRepository(session);
474:                Subscription subscription = subscriptionRepository
475:                        .getSubscription(subscriptionName, session);
476:                if (subscription == null) {
477:                    // TODO surface an error
478:                    return;
479:                }
480:                IContentItem contentItem = subscriptionRepository
481:                        .getContentItem(subscriptionName, session);
482:                List files = contentItem.getFileVersions();
483:                Iterator fileIterator = files.iterator();
484:                ContentItemFile file = null;
485:                while (fileIterator.hasNext()) {
486:                    file = (ContentItemFile) fileIterator.next();
487:                    if (fileId.equals(file.getId())) {
488:                        break;
489:                    }
490:                }
491:
492:                try {
493:                    IContentItem outoutContentItem = outputHandler
494:                            .getOutputContentItem(IOutputHandler.RESPONSE,
495:                                    IOutputHandler.CONTENT, null, null,
496:                                    contentItem.getMimeType());
497:                    OutputStream outputStream = outoutContentItem
498:                            .getOutputStream(subscriptionName);
499:                    if (file == null) {
500:                        // TODO surface an error
501:                        outputStream
502:                                .write(Messages
503:                                        .getString(
504:                                                "SubscriptionHelper.USER_ARCHIVE_NOT_FOUND").getBytes()); //$NON-NLS-1$
505:                        outoutContentItem.closeOutputStream();
506:                        return;
507:                    }
508:                    outoutContentItem.setMimeType(contentItem.getMimeType());
509:                    InputStream inputStream = file.getInputStream();
510:                    byte buffer[] = new byte[2048];
511:                    int n = inputStream.read(buffer);
512:                    while (n > 0) {
513:                        outputStream.write(buffer, 0, n);
514:                        n = inputStream.read(buffer);
515:                    }
516:                    outoutContentItem.closeOutputStream();
517:                } catch (Exception e) {
518:                    // TODO surface an error
519:                }
520:
521:            }
522:
523:            public static String getSubscriptionParameters(
524:                    String subscriptionName, IParameterSetter parameters,
525:                    IPentahoSession session) {
526:
527:                ISubscriptionRepository subscriptionRepository = PentahoSystem
528:                        .getSubscriptionRepository(session);
529:                Subscription subscription = subscriptionRepository
530:                        .getSubscription(subscriptionName, session);
531:                if (subscription == null) {
532:                    // TODO surface an error
533:                    return Messages
534:                            .getString("SubscriptionHelper.USER_SUBSCRIPTION_DOES_NOT_EXIST"); //$NON-NLS-1$
535:                }
536:
537:                // handle the parameters for the subscription
538:                Map subscriptionParameters = subscription.getParameters();
539:                Iterator parameterIterator = subscriptionParameters.keySet()
540:                        .iterator();
541:                while (parameterIterator.hasNext()) {
542:                    String key = (String) parameterIterator.next();
543:                    Object value = subscriptionParameters.get(key);
544:                    parameters.setParameter(key, value);
545:                }
546:
547:                // handle the main subscription info
548:                parameters.setParameter(
549:                        "subscribe-title", subscription.getTitle()); //$NON-NLS-1$
550:                parameters.setParameter(
551:                        "destination", subscription.getDestination()); //$NON-NLS-1$
552:                parameters.setParameter(
553:                        "action", subscription.getContent().getId()); //$NON-NLS-1$
554:                // parameters.setParameter( "editing", "true" ); //$NON-NLS-1$ //$NON-NLS-2$
555:                // add the subscription id so that we can update the object when the user
556:                // saves
557:                parameters.setParameter("subscribe-id", subscription.getId()); //$NON-NLS-1$
558:                String actionReference = subscription.getContent()
559:                        .getActionReference();
560:                PentahoSystem.ActionInfo actionInfo = PentahoSystem
561:                        .parseActionString(actionReference);
562:                parameters.setParameter(
563:                        "solution", actionInfo.getSolutionName()); //$NON-NLS-1$
564:                parameters.setParameter("path", actionInfo.getPath()); //$NON-NLS-1$
565:                parameters.setParameter("action", actionInfo.getActionName()); //$NON-NLS-1$
566:                // parameters.setParameter( "subscribe", "edit" );
567:                // handle the schedules
568:                List schedules = subscription.getSchedules();
569:                Schedule schedule;
570:                for (int i = 0; i < schedules.size(); i++) {
571:                    schedule = (Schedule) schedules.get(i);
572:                    parameters.setParameter(
573:                            "schedule-" + schedule.getId(), "true"); //$NON-NLS-1$ //$NON-NLS-2$      
574:                }
575:
576:                return null;
577:            }
578:
579:            public static String deleteSubscriptionArchive(
580:                    String subscriptionName, String fileId,
581:                    IPentahoSession session) {
582:
583:                ISubscriptionRepository subscriptionRepository = PentahoSystem
584:                        .getSubscriptionRepository(session);
585:                Subscription subscription = subscriptionRepository
586:                        .getSubscription(subscriptionName, session);
587:                if (subscription == null) {
588:                    // TODO surface an error
589:                    return Messages
590:                            .getString("SubscriptionHelper.USER_SUBSCRIPTION_DOES_NOT_EXIST"); //$NON-NLS-1$
591:                }
592:                IContentItem contentItem = subscriptionRepository
593:                        .getContentItem(subscriptionName, session);
594:                if (contentItem == null) {
595:                    // TODO surface an error
596:                    return Messages
597:                            .getString("SubscriptionHelper.USER_CONTENT_ITEM_DOES_NOT_EXIST"); //$NON-NLS-1$
598:                }
599:                contentItem.removeVersion(fileId);
600:                return Messages
601:                        .getString("SubscriptionHelper.USER_ARCHIVE_DELETED"); //$NON-NLS-1$
602:
603:            }
604:
605:            public static String createSubscriptionArchive(
606:                    String subscriptionName, IPentahoSession session,
607:                    SimpleUrlFactory urlFactory,
608:                    IParameterProvider sessionParameters) {
609:                ISubscriptionRepository subscriptionRepository = PentahoSystem
610:                        .getSubscriptionRepository(session);
611:                Subscription subscription = subscriptionRepository
612:                        .getSubscription(subscriptionName, session);
613:                if (subscription == null) {
614:                    // TODO surface an error
615:                    return Messages
616:                            .getString("SubscriptionHelper.USER_SUBSCRIPTION_DOES_NOT_EXIST"); //$NON-NLS-1$
617:                }
618:                SubscribeContent content = subscription.getContent();
619:                if (content == null) {
620:                    // TODO surface an error
621:                    return Messages
622:                            .getString("SubscriptionHelper.USER_CONTENT_ITEM_DOES_NOT_EXIST"); //$NON-NLS-1$
623:                }
624:                Map contentParameters = content.getParameters();
625:                Map subscriptionParameters = subscription.getParameters();
626:                SimpleParameterProvider parameterProvider = new SimpleParameterProvider(
627:                        contentParameters);
628:                parameterProvider.setParameters(subscriptionParameters);
629:                String subsName = parameterProvider.getStringParameter(
630:                        "subscribe-name", null); //$NON-NLS-1$
631:                if (subsName == null) {
632:                    parameterProvider.setParameter(
633:                            "subscribe-name", subscriptionName); //$NON-NLS-1$
634:                }
635:                PentahoSystem.ActionInfo contentInfo = PentahoSystem
636:                        .parseActionString(content.getActionReference());
637:
638:                String actionName = (String) subscriptionParameters
639:                        .get("action"); //$NON-NLS-1$
640:                if (actionName == null) {
641:                    actionName = contentInfo.getActionName();
642:                }
643:                parameterProvider.setParameter(
644:                        "solution", contentInfo.getSolutionName()); //$NON-NLS-1$
645:                parameterProvider.setParameter("path", contentInfo.getPath()); //$NON-NLS-1$
646:                parameterProvider.setParameter("action", actionName); //$NON-NLS-1$
647:
648:                SecurityAwareBackgroundSubscriptionHelper pbsh = new SecurityAwareBackgroundSubscriptionHelper();
649:                return pbsh.backgroundExecuteAction(session, parameterProvider);
650:            }
651:
652:            public static String getSubscriptionOutputLocation(
653:                    String solutionName, String actionPath, String actionName) {
654:                String outputFolder = actionName.substring(0, actionName
655:                        .lastIndexOf('.'));
656:                return solutionName
657:                        + "/" + actionPath + "/" + outputFolder + "/subscriptions"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
658:            }
659:
660:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.