KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > solution > SolutionHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jan 13, 2006
14  * @author James Dixon
15  */

16
17 package org.pentaho.core.solution;
18
19 import java.io.ByteArrayOutputStream JavaDoc;
20 import java.io.OutputStream JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.pentaho.core.runtime.IRuntimeContext;
27 import org.pentaho.core.session.IPentahoSession;
28 import org.pentaho.core.session.StandaloneSession;
29 import org.pentaho.core.system.PentahoSystem;
30 import org.pentaho.core.ui.IPentahoUrlFactory;
31 import org.pentaho.core.ui.SimpleUrlFactory;
32
33 public class SolutionHelper {
34
35     /**
36      *
37      *
38      * Runs an action sequence. This method uses the base URL set by the
39      * Application Context
40      *
41      * @param description
42      * An identifier for this process. This is used for auditing and
43      * logging purposes only.
44      * @param userId
45      * The user (or user agent) that is requesting this execution.
46      * This is used for auditing and logging and also can be used in
47      * action sequences (for example to filter data)
48      * @param actionSequence
49      * Path to the action sequence file
50      * @param parameters
51      * Parameters to be passed to the action sequence
52      * @param outputStream
53      * The output stream for content generated by the action
54      * sequence. Can be null.
55      * @return
56      */

57     public static ISolutionEngine execute(String JavaDoc description, String JavaDoc userId, String JavaDoc actionSequence, Map JavaDoc parameters, OutputStream JavaDoc outputStream) {
58
59         PentahoSystem.systemEntryPoint();
60         ISolutionEngine solutionEngine = null;
61         try {
62             // create a generic session object
63
StandaloneSession session = new StandaloneSession(userId);
64
65             solutionEngine = PentahoSystem.getSolutionEngineInstance(session);
66             solutionEngine.init(session);
67
68             SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
69
70             String JavaDoc baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
71             HashMap JavaDoc parameterProviderMap = new HashMap JavaDoc();
72             parameterProviderMap.put("request", parameterProvider); //$NON-NLS-1$
73

74             IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
75
76             String JavaDoc solutionRef[] = PentahoSystem.parseActionString(actionSequence);
77
78             String JavaDoc solution = solutionRef[0];
79             String JavaDoc solutionPath = solutionRef[1];
80             String JavaDoc action = solutionRef[2];
81             String JavaDoc processName = description;
82             boolean persisted = false;
83             List JavaDoc messages = new ArrayList JavaDoc();
84
85             if (outputStream == null) {
86                 outputStream = new ByteArrayOutputStream JavaDoc(0);
87             }
88             SimpleOutputHandler outputHandler = null;
89             if (outputStream != null) {
90                 outputHandler = new SimpleOutputHandler(outputStream, false);
91                 outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
92             }
93             solutionEngine.execute(solution, solutionPath, action, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
94
95         } finally {
96             PentahoSystem.systemExitPoint();
97         }
98         return solutionEngine;
99     }
100
101     public static ISolutionEngine execute(String JavaDoc description, IPentahoSession session, String JavaDoc actionSequence, Map JavaDoc parameters, OutputStream JavaDoc outputStream) {
102
103         PentahoSystem.systemEntryPoint();
104         ISolutionEngine solutionEngine = null;
105         try {
106
107             solutionEngine = PentahoSystem.getSolutionEngineInstance(session);
108             solutionEngine.init(session);
109
110             SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
111
112             String JavaDoc baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
113             HashMap JavaDoc parameterProviderMap = new HashMap JavaDoc();
114             parameterProviderMap.put("request", parameterProvider); //$NON-NLS-1$
115

116             IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
117
118             String JavaDoc solutionRef[] = PentahoSystem.parseActionString(actionSequence);
119
120             String JavaDoc solution = solutionRef[0];
121             String JavaDoc solutionPath = solutionRef[1];
122             String JavaDoc action = solutionRef[2];
123             String JavaDoc processName = description;
124             boolean persisted = false;
125             List JavaDoc messages = new ArrayList JavaDoc();
126
127             if (outputStream == null) {
128                 outputStream = new ByteArrayOutputStream JavaDoc(0);
129             }
130             SimpleOutputHandler outputHandler = null;
131             if (outputStream != null) {
132                 outputHandler = new SimpleOutputHandler(outputStream, false);
133                 outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
134             }
135             solutionEngine.execute(solution, solutionPath, action, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
136
137         } finally {
138             PentahoSystem.systemExitPoint();
139         }
140         return solutionEngine;
141     }
142
143     public static void execute(IRuntimeContext context, String JavaDoc actionSequence, Map JavaDoc parameters, OutputStream JavaDoc outputStream) {
144
145         PentahoSystem.systemEntryPoint();
146         try {
147             // create a generic session object
148
IPentahoSession session = context.getSession();
149
150             ISolutionEngine solutionEngine = PentahoSystem.getSolutionEngineInstance(session);
151             solutionEngine.init(session);
152
153             SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
154
155             HashMap JavaDoc parameterProviderMap = new HashMap JavaDoc();
156             parameterProviderMap.put("request", parameterProvider); //$NON-NLS-1$
157

158             String JavaDoc solutionRef[] = PentahoSystem.parseActionString(actionSequence);
159
160             String JavaDoc solution = solutionRef[0];
161             String JavaDoc solutionPath = solutionRef[1];
162             String JavaDoc action = solutionRef[2];
163             String JavaDoc processName = context.getProcessId();
164
165             if (outputStream == null) {
166                 outputStream = new ByteArrayOutputStream JavaDoc(0);
167             }
168             SimpleOutputHandler outputHandler = null;
169             if (outputStream != null) {
170                 outputHandler = new SimpleOutputHandler(outputStream, false);
171                 outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
172             }
173             context = solutionEngine.execute(context, solution, solutionPath, action, processName, false, true, parameterProviderMap, outputHandler);
174
175         } finally {
176             PentahoSystem.systemExitPoint();
177         }
178
179     }
180
181     public static void execute(ISolutionEngine solutionEngine, String JavaDoc actionSequence, Map JavaDoc parameters, OutputStream JavaDoc outputStream) {
182
183         PentahoSystem.systemEntryPoint();
184         try {
185
186             if (solutionEngine == null) {
187                 return;
188             }
189
190             IRuntimeContext context = solutionEngine.getExecutionContext();
191
192             // create a generic session object
193
IPentahoSession session = context.getSession();
194
195             solutionEngine.init(session);
196
197             if (parameters == null) {
198                 parameters = new HashMap JavaDoc();
199             }
200             SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
201
202             HashMap JavaDoc parameterProviderMap = new HashMap JavaDoc();
203             parameterProviderMap.put("request", parameterProvider); //$NON-NLS-1$
204

205             String JavaDoc solutionRef[] = PentahoSystem.parseActionString(actionSequence);
206
207             String JavaDoc solution = solutionRef[0];
208             String JavaDoc solutionPath = solutionRef[1];
209             String JavaDoc action = solutionRef[2];
210             String JavaDoc processName = context.getProcessId();
211
212             if (outputStream == null) {
213                 outputStream = new ByteArrayOutputStream JavaDoc(0);
214             }
215             SimpleOutputHandler outputHandler = null;
216             if (outputStream != null) {
217                 outputHandler = new SimpleOutputHandler(outputStream, false);
218                 outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
219             }
220             context = solutionEngine.execute(context, solution, solutionPath, action, processName, false, true, parameterProviderMap, outputHandler);
221
222         } finally {
223             PentahoSystem.systemExitPoint();
224         }
225         return;
226
227     }
228
229 }
230
Popular Tags