Search in sources :

Example 6 with IParameterProvider

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

the class MessageFormatterTest method makeParameterProviders.

private Map<String, IParameterProvider> makeParameterProviders(final IPentahoSession session) {
    final Map<String, IParameterProvider> res = new HashMap<>();
    res.put("jvm", new JVMParameterProvider());
    res.put(SecurityParameterProvider.SCOPE_SECURITY, new SecurityParameterProvider(session));
    return res;
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) JVMParameterProvider(org.pentaho.platform.util.JVMParameterProvider) SecurityParameterProvider(org.pentaho.platform.engine.security.SecurityParameterProvider)

Example 7 with IParameterProvider

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

the class GlobalListPublisherTest method test1.

public void test1() throws ObjectFactoryException {
    StandaloneSession session = new StandaloneSession("test");
    StandaloneApplicationContext appContext = new StandaloneApplicationContext("src/test/resources/solution", "");
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.GlobalListPublisherTest.spring.xml", null);
    PentahoSystem.init(appContext);
    PentahoSystem.registerObjectFactory(factory);
    PentahoSystem.setSystemSettingsService(factory.get(ISystemSettings.class, "systemSettingsService", session));
    List<ISessionStartupAction> actions = new ArrayList<ISessionStartupAction>();
    SessionStartupAction startupAction1 = new SessionStartupAction();
    startupAction1.setSessionType(PentahoSystem.SCOPE_GLOBAL);
    startupAction1.setActionPath("testsolution/testpath/test.xaction");
    startupAction1.setActionOutputScope(PentahoSystem.SCOPE_GLOBAL);
    actions.add(startupAction1);
    TestRuntimeContext context = new TestRuntimeContext();
    context.status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
    TestSolutionEngine engine = PentahoSystem.get(TestSolutionEngine.class, "ISolutionEngine", session);
    engine.testRuntime = context;
    Map<String, IActionParameter> outputs = new HashMap<String, IActionParameter>();
    TestActionParameter param = new TestActionParameter();
    param.setValue("testvalue");
    outputs.put("testoutput", param);
    context.outputParameters = outputs;
    engine.executeCount = 0;
    GlobalListsPublisher globals = new GlobalListsPublisher();
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS"), globals.getName());
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_DESCRIPTION"), globals.getDescription());
    assertTrue(!globals.getName().startsWith("!"));
    assertTrue(!globals.getDescription().startsWith("!"));
    assertNotNull(globals.getLogger());
    String resultMsg = globals.publish(session);
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"), resultMsg);
    assertEquals(0, engine.executeCount);
    PentahoSystem.setSessionStartupActions(actions);
    IParameterProvider globalParams = PentahoSystem.getGlobalParameters();
    resultMsg = globals.publish(session);
    assertEquals(1, engine.executeCount);
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"), resultMsg);
    // check that we made it all the way to executing the startup action
    assertEquals(session, engine.initSession);
    assertEquals(startupAction1.getActionPath(), engine.actionPath);
    assertEquals("testvalue", globalParams.getParameter("testoutput"));
    param.setValue("testvalue2");
    resultMsg = globals.publish(session);
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"), resultMsg);
    assertEquals(2, engine.executeCount);
    assertNotNull(globalParams);
    assertEquals("testvalue2", globalParams.getParameter("testoutput"));
    assertEquals(2, engine.executeCount);
}
Also used : ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) SessionStartupAction(org.pentaho.platform.engine.core.system.SessionStartupAction) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) GlobalListsPublisher(org.pentaho.platform.engine.core.system.GlobalListsPublisher) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 8 with IParameterProvider

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

the class XactionUtil method executeXml.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeXml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession) throws Exception {
    try {
        HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
        HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
        Map parameterProviders = new HashMap();
        // $NON-NLS-1$
        parameterProviders.put("request", requestParameters);
        // $NON-NLS-1$
        parameterProviders.put("session", sessionParameters);
        List messages = new ArrayList();
        IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
        // $NON-NLS-1$
        httpServletResponse.setContentType("text/xml");
        httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
        OutputStream contentStream = new ByteArrayOutputStream();
        SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
        IRuntimeContext runtime = null;
        try {
            runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
            Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, messages);
            OutputFormat format = OutputFormat.createCompactFormat();
            format.setSuppressDeclaration(true);
            // $NON-NLS-1$
            format.setEncoding("utf-8");
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(outputStream, format);
            writer.write(responseDoc);
            writer.flush();
            // $NON-NLS-1$
            return outputStream.toString("utf-8");
        } finally {
            if (runtime != null) {
                runtime.dispose();
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        logger.warn(Messages.getInstance().getString("XactionUtil.XML_OUTPUT_NOT_SUPPORTED"));
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) OutputFormat(org.dom4j.io.OutputFormat) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 9 with IParameterProvider

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

the class XactionUtil method executeScheduleUi.

/**
 * This method executes an xaction with forcePrompt=true and outputPreference=PARAMETERS, allowing for the xaction to
 * render the secure filter appropriately when being executed in the background or while being scheduled.
 *
 * @param file                the location of the xaction
 * @param httpServletRequest  the request object
 * @param httpServletResponse the response object
 * @param userSession         the user session
 * @return potential response message
 * @throws Exception
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeScheduleUi(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession, IMimeTypeListener mimeTypeListener) throws Exception {
    IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
    IRuntimeContext runtime = null;
    try {
        HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
        HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        boolean doMessages = "true".equalsIgnoreCase(requestParams.getStringParameter("debug", "false"));
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        boolean doWrapper = "true".equalsIgnoreCase(requestParams.getStringParameter("wrapper", "true"));
        IOutputHandler outputHandler = createOutputHandler(httpServletResponse, getOutputStream(httpServletResponse, doMessages));
        if (mimeTypeListener == null) {
            mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
        }
        outputHandler.setMimeTypeListener(mimeTypeListener);
        outputHandler.setSession(userSession);
        Map parameterProviders = new HashMap();
        // $NON-NLS-1$
        parameterProviders.put("request", requestParameters);
        // $NON-NLS-1$
        parameterProviders.put("session", sessionParameters);
        createOutputFileName(file, outputHandler);
        int outputPreference = IOutputHandler.OUTPUT_TYPE_PARAMETERS;
        outputHandler.setOutputPreference(outputPreference);
        List messages = new ArrayList();
        // forcePrompt=true when displaying the scheduling UI
        runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, true, messages);
        String str = postExecute(runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest, httpServletResponse, messages, false);
        return str;
    } catch (Exception e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
        throw e;
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpMimeTypeListener(org.pentaho.platform.web.servlet.HttpMimeTypeListener) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ArrayList(java.util.ArrayList) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with IParameterProvider

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

the class XactionUtil method executeHtml.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeHtml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession, IMimeTypeListener mimeTypeListener) throws Exception {
    IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
    IRuntimeContext runtime = null;
    try {
        HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
        HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        boolean doMessages = "true".equalsIgnoreCase(requestParams.getStringParameter("debug", "false"));
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        boolean doWrapper = "true".equalsIgnoreCase(requestParams.getStringParameter("wrapper", "true"));
        IOutputHandler outputHandler = createOutputHandler(httpServletResponse, getOutputStream(httpServletResponse, doMessages));
        // disposition is set on the response header
        if (mimeTypeListener == null) {
            mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
        }
        outputHandler.setMimeTypeListener(mimeTypeListener);
        outputHandler.setSession(userSession);
        Map parameterProviders = new HashMap();
        // $NON-NLS-1$
        parameterProviders.put("request", requestParameters);
        // $NON-NLS-1$
        parameterProviders.put("session", sessionParameters);
        createOutputFileName(file, outputHandler);
        int outputPreference = IOutputHandler.OUTPUT_TYPE_DEFAULT;
        outputHandler.setOutputPreference(outputPreference);
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
        List messages = new ArrayList();
        runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
        String str = postExecute(runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest, httpServletResponse, messages, true);
        return str;
    } catch (Exception e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
        throw e;
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpMimeTypeListener(org.pentaho.platform.web.servlet.HttpMimeTypeListener) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ArrayList(java.util.ArrayList) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Map(java.util.Map) HashMap(java.util.HashMap)

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