Search in sources :

Example 41 with IParameterProvider

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

the class WsdlPageTest method testMissingPathParamProvider.

@Test
public void testMissingPathParamProvider() throws Exception {
    // $NON-NLS-1$
    assertNotNull("Logger is null", contentGenerator.getLogger());
    Map<String, IParameterProvider> parameterProviders = Collections.<String, IParameterProvider>singletonMap(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider());
    contentGenerator.setParameterProviders(parameterProviders);
    contentGenerator.createContent();
    String content = new String(out.toByteArray());
    assertTrue(content, content.contains(Messages.getInstance().getErrorString(// $NON-NLS-1$
    "WebServiceContentGenerator.ERROR_0004_PATH_PARAMS_IS_MISSING")));
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 42 with IParameterProvider

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

the class WsdlPageTest method testMissingServiceName.

@Test
public void testMissingServiceName() throws Exception {
    // $NON-NLS-1$
    assertNotNull("Logger is null", contentGenerator.getLogger());
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider());
    // $NON-NLS-1$
    parameterProviders.put("path", new SimpleParameterProvider());
    contentGenerator.setParameterProviders(parameterProviders);
    contentGenerator.createContent();
    String content = new String(out.toByteArray());
    assertTrue(content, content.contains(Messages.getInstance().getErrorString(// $NON-NLS-1$
    "WebServiceContentGenerator.ERROR_0005_SERVICE_NAME_IS_MISSING")));
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 43 with IParameterProvider

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

the class ContentGeneratorUtil method getContentAsString.

/**
 * Convenience method for executing a content generator and getting back it's output as a string. Useful for
 * testing.
 *
 * @param cg
 *          the content generator to execute
 * @return the output of the content generator
 * @throws Exception
 *           if there was a problem creating the content
 */
public static String getContentAsString(IContentGenerator cg) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParams);
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("?");
    List<String> messages = new ArrayList<String>();
    cg.setOutputHandler(outputHandler);
    IMimeTypeListener mimeTypeListener = new IMimeTypeListener() {

        @SuppressWarnings("unused")
        public String mimeType = null;

        @SuppressWarnings("unused")
        public String name = null;

        public void setMimeType(String mimeType) {
            this.mimeType = mimeType;
        }

        public void setName(String name) {
            this.name = name;
        }
    };
    outputHandler.setMimeTypeListener(mimeTypeListener);
    cg.setMessagesList(messages);
    cg.setParameterProviders(parameterProviders);
    cg.setSession(PentahoSessionHolder.getSession());
    cg.setUrlFactory(urlFactory);
    cg.createContent();
    String content = new String(out.toByteArray());
    return content;
}
Also used : IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 44 with IParameterProvider

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

the class DefaultChartBeansGenerator method runActionSequence.

/**
 * Executes an action sequence from an <code>ActionSequenceDocument</code>.
 *
 * @param pentahoSession
 *          current <code>IPentahoSession</code>
 * @param parameterProviders
 *          map of parameter providers; there should a single entry with "request" as the key
 * @param outputHandler
 *          output handler
 * @param doc
 *          action sequence document
 * @throws RuntimeException
 *           if anything goes wrong
 */
protected void runActionSequence(final IPentahoSession pentahoSession, final Map<String, IParameterProvider> parameterProviders, final IOutputHandler outputHandler, final ActionSequenceDocument doc) throws RuntimeException {
    // Get the solution engine
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, pentahoSession);
    if (solutionEngine == null) {
        // $NON-NLS-1$
        throw new RuntimeException("solutionEngine is null");
    }
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(pentahoSession);
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    String contextPath = requestContext.getContextPath();
    // $NON-NLS-1$
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory(contextPath);
    IRuntimeContext runtime;
    IParameterProvider requestParmProvider = parameterProviders.get("request");
    if (requestParmProvider.hasParameter("obj_id")) {
        final String obj_id = (String) requestParmProvider.getParameter("obj_id");
        final String msg_name = (String) requestParmProvider.getParameter("message_name");
        final String job_id = (String) requestParmProvider.getParameter("job_id");
        runtime = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        doc.toString(), // $NON-NLS-1$ //$NON-NLS-2$
        obj_id, // $NON-NLS-1$ //$NON-NLS-2$
        job_id, // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, msg_name, true, parameterProviders, outputHandler, null, urlFactory, // $NON-NLS-1$
        new ArrayList());
    } else {
        runtime = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        doc.toString(), // $NON-NLS-1$ //$NON-NLS-2$
        "chartbeans_mql", // $NON-NLS-1$ //$NON-NLS-2$
        "myprocessid", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, "myinstanceid", true, parameterProviders, outputHandler, null, urlFactory, // $NON-NLS-1$
        new ArrayList());
    }
    if ((runtime != null) && (runtime.getStatus() != IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
        StringBuilder buf = new StringBuilder();
        boolean firstIteration = true;
        for (Object /* String */
        message : runtime.getMessages()) {
            if (message instanceof Exception) {
                Exception ex = (Exception) message;
                if (ex.getCause() instanceof RuntimeException) {
                    throw (RuntimeException) ex.getCause();
                }
            }
            if (!firstIteration) {
                // $NON-NLS-1$
                buf.append(" \\\\ ");
            }
            buf.append(message);
        }
        String errorStr;
        if (buf.indexOf("action_sequence_failed") > -1 && buf.indexOf("MQLRelationalDataComponent") > -1) {
            errorStr = Messages.getInstance().getString("DefaultChartBeansGenerator.ERROR_0001_SECURITY_ERROR");
        } else {
            errorStr = Messages.getInstance().getString("DefaultChartBeansGenerator.ERROR_0002_UNKNOWN_ERROR");
        }
        throw new RuntimeException(errorStr);
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 45 with IParameterProvider

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

the class PentahoReportConfiguration method lookupVariable.

@Override
protected String lookupVariable(final String property) {
    final IApplicationContext context = PentahoSystem.getApplicationContext();
    if (context != null) {
        final String contextParam = context.getProperty(property);
        if (contextParam != null) {
            return contextParam;
        }
    }
    final IParameterProvider globalParameters = PentahoSystem.getGlobalParameters();
    if (globalParameters != null) {
        final String globalParam = globalParameters.getStringParameter(property, null);
        if (globalParam != null) {
            return globalParam;
        }
    }
    final String systemSetting = PentahoSystem.getSystemSetting(property, null);
    if (systemSetting != null) {
        return systemSetting;
    }
    if (context != null) {
        if ("base-url".equals(property)) {
            // $NON-NLS-1$
            return context.getFullyQualifiedServerURL();
        }
    }
    return null;
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext)

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