Search in sources :

Example 31 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class SolutionEngine method init.

public void init(final IPentahoSession pSession) {
    parameterProviders = new HashMap<String, IParameterProvider>();
    this.session = pSession;
    this.setParameterProvider(SolutionEngine.JVM_PARAMETER_PROVIDER, new JVMParameterProvider());
    setForcePrompt(false);
    // Provide the security parameter provider to the parameter provider map in the super class
    SecurityParameterProvider provider = new SecurityParameterProvider(pSession);
    this.setParameterProvider(SecurityParameterProvider.SCOPE_SECURITY, provider);
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) JVMParameterProvider(org.pentaho.platform.util.JVMParameterProvider) SecurityParameterProvider(org.pentaho.platform.engine.security.SecurityParameterProvider)

Example 32 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class SolutionEngineAgent method execute.

public int execute() {
    PentahoSystem.systemEntryPoint();
    try {
        // create a generic session object
        StandaloneSession session = new StandaloneSession(userId);
        solutionEngine = PentahoSystem.get(SolutionEngine.class, session);
        solutionEngine.init(session);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        // $NON-NLS-1$
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath());
        String processName = description;
        boolean persisted = false;
        List messages = new ArrayList();
        outputStream = new ByteArrayOutputStream(0);
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            outputHandler = new SimpleOutputHandler(outputStream, false);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        PentahoSystem.systemExitPoint();
    }
    return solutionEngine.getStatus();
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 33 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class SolutionHelper method execute.

/**
 * Runs an action sequence. This method uses the base URL set by the Application Context
 *
 * @param description
 *          An identifier for this process. This is used for auditing and logging purposes only.
 * @param session
 *          The user session that is requesting this execution. This is used for auditing and logging and also
 *          can be used in action sequences (for example to filter data)
 * @param actionSequence
 *          Path to the action sequence file
 * @param parameters
 *          Parameters to be passed to the action sequence
 * @param outputStream
 *          The output stream for content generated by the action sequence. Can be null.
 * @param execListener
 *          An execution listener for feedback during execution. Can be null.
 * @return
 */
public static ISolutionEngine execute(final String description, final IPentahoSession session, final String actionSequence, final Map parameters, OutputStream outputStream, final IExecutionListener execListener, final boolean collateMessages, final boolean manageHibernate) {
    if (manageHibernate) {
        PentahoSystem.systemEntryPoint();
    }
    ISolutionEngine solutionEngine = null;
    try {
        solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
        solutionEngine.init(session);
        solutionEngine.setlistener(execListener);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        String url = requestContext.getContextPath();
        // Modifications by Ezequiel Cuellar
        // Old code.
        // String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
        // New code. Since the SubActionComponent is being instantiated below to return feedback
        // it is necesary to configure the baseUrl to include the ViewAction.
        Object actionUrlComponent = parameters.get(StandardSettings.ACTION_URL_COMPONENT);
        if ((actionUrlComponent != null) && (actionUrlComponent.toString().length() > 0)) {
            url += actionUrlComponent.toString();
        } else {
            // $NON-NLS-1$
            url += "ViewAction?";
        }
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(url);
        String processName = description;
        boolean persisted = false;
        // for now, the messages list needs to be untyped since we may put exceptions as well as strings in it
        List<?> messages = null;
        if (collateMessages) {
            messages = new ArrayList();
        }
        if (outputStream == null) {
            outputStream = new ByteArrayOutputStream(0);
        }
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            // Modifications by Ezequiel Cuellar
            // Old code.
            // outputHandler = new SimpleOutputHandler(outputStream, false);
            // New code. Without setting the allowFeedback parameter to true it is assumed that SubActionComponent
            // instances
            // are never capable of returning feedback which may not always be the case.
            outputHandler = new SimpleOutputHandler(outputStream, true);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        if (manageHibernate) {
            PentahoSystem.systemExitPoint();
        }
    }
    return solutionEngine;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 34 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class SolutionEngineInteractivityService method doGet.

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    PentahoSystem.systemEntryPoint();
    try {
        IPentahoSession userSession = getPentahoSession(request);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // $NON-NLS-1$
        String solutionName = request.getParameter("solution");
        // $NON-NLS-1$
        String actionPath = request.getParameter("path");
        // $NON-NLS-1$
        String actionName = request.getParameter("action");
        IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
        String fileName = null;
        if (actionSequence != null) {
            String title = actionSequence.getTitle();
            if ((title != null) && (title.length() > 0)) {
                fileName = title;
            } else {
                String sequenceName = actionSequence.getSequenceName();
                if ((sequenceName != null) && (sequenceName.length() > 0)) {
                    fileName = sequenceName;
                } else {
                    List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
                    int i = 0;
                    boolean done = false;
                    while ((actionDefinitionsList.size() > i) && !done) {
                        IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
                        String componentName = actionDefinition.getComponentName();
                        if ((componentName != null) && (componentName.length() > 0)) {
                            fileName = componentName;
                            done = true;
                        } else {
                            i++;
                        }
                    }
                }
            }
        }
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        HttpOutputHandler outputHandler = createOutputHandler(response, outputStream);
        outputHandler.setSession(userSession);
        IMimeTypeListener listener = new HttpMimeTypeListener(request, response);
        listener.setName(fileName);
        outputHandler.setMimeTypeListener(listener);
        SimpleUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath() + // $NON-NLS-1$
        "SolutionEngineInteractivityService?");
        IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
        setupOutputHandler(outputHandler, requestParameters);
        HttpServletRequestHandler requestHandler = getRequestHandler(request, response, userSession, requestParameters, outputStream, outputHandler, urlFactory);
        handleActionRequest(request, response, outputHandler, requestHandler, requestParameters, outputStream, null);
    } finally {
        PentahoSystem.systemExitPoint();
    }
}
Also used : IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) HttpOutputHandler(org.pentaho.platform.web.http.HttpOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory)

Example 35 with IParameterProvider

use of org.pentaho.platform.api.engine.IParameterProvider in project pentaho-platform by pentaho.

the class ViewAction method doGet.

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    PentahoSystem.systemEntryPoint();
    try {
        IPentahoSession userSession = getPentahoSession(request);
        if (!doBackgroundExecution(request, response, userSession)) {
            OutputStream outputStream = getOutputStream(response, doMessages(request));
            ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(userSession);
            // $NON-NLS-1$
            String actionPath = request.getParameter("path");
            IActionSequence actionSequence = actionHelper.getActionSequence(actionPath, PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
            String fileName = null;
            if (actionSequence != null) {
                String title = actionSequence.getTitle();
                if ((title != null) && (title.length() > 0)) {
                    fileName = title;
                } else {
                    String sequenceName = actionSequence.getSequenceName();
                    if ((sequenceName != null) && (sequenceName.length() > 0)) {
                        fileName = sequenceName;
                    } else {
                        List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
                        int i = 0;
                        boolean done = false;
                        while ((actionDefinitionsList.size() > i) && !done) {
                            IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
                            String componentName = actionDefinition.getComponentName();
                            if ((componentName != null) && (componentName.length() > 0)) {
                                fileName = componentName;
                                done = true;
                            } else {
                                i++;
                            }
                        }
                    }
                }
            }
            IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
            HttpOutputHandler outputHandler = createOutputHandler(response, outputStream);
            outputHandler.setSession(userSession);
            IMimeTypeListener listener = new HttpMimeTypeListener(request, response, fileName);
            outputHandler.setMimeTypeListener(listener);
            // $NON-NLS-1$
            SimpleUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath() + "ViewAction?");
            IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
            HttpServletRequestHandler requestHandler = getRequestHandler(request, response, userSession, requestParameters, outputStream, outputHandler, urlFactory);
            handleActionRequest(request, response, outputHandler, requestHandler, outputStream, null);
        }
    } finally {
        PentahoSystem.systemExitPoint();
    }
}
Also used : IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) HttpOutputHandler(org.pentaho.platform.web.http.HttpOutputHandler) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory)

Aggregations

IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)57 HashMap (java.util.HashMap)27 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 ArrayList (java.util.ArrayList)14 List (java.util.List)11 Test (org.junit.Test)11 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 IOException (java.io.IOException)9 Iterator (java.util.Iterator)8 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)8 HttpRequestParameterProvider (org.pentaho.platform.web.http.request.HttpRequestParameterProvider)8 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 SimpleParameterSetter (org.pentaho.platform.engine.services.solution.SimpleParameterSetter)6 OutputStream (java.io.OutputStream)5