Search in sources :

Example 66 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class XQConnectionIT method testXQConnection.

public void testXQConnection() {
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream("DatasourceTest.XQ_Datasource", ".html");
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
    IRuntimeContext context = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    run("/test/datasource/XQ_Datasource.xaction", null, false, parameterProvider, outputHandler, session);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
// TODO need some validation of success
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 67 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class XQConnectionIT method testJFreeReportParameterPage2.

/*
   * public void testXQConnection_JFreeXQuery() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ OutputStream
   * outputStream = getOutputStream("DatasourceTest.XQ_Datasource", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context =
   * run("test", "reporting", "JFree_XQuery_report.xaction", null, false, parameterProvider, outputHandler, session);
   * //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success }
   */
public void testJFreeReportParameterPage2() {
    startTest();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$
    parameterProvider.setParameter("type", "html");
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream("ReportingTest.testJFreeReportParameterPage2", ".html");
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    IRuntimeContext context = run("/test/reporting/jfreereport-reports-test-param2.xaction", null, false, parameterProvider, outputHandler, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    session);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // TODO need some validation of success
    finishTest();
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 68 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class FilterDefinitionIT method getParameterProviders.

private Map getParameterProviders() {
    SimpleParameterProvider simplePP = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$
    simplePP.setParameter("empty", "empty");
    Map parameterProviders = new HashMap();
    parameterProviders.put(HttpSessionParameterProvider.SCOPE_SESSION, simplePP);
    simplePP = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$
    simplePP.setParameter("empty", "empty");
    parameterProviders.put(HttpRequestParameterProvider.SCOPE_REQUEST, simplePP);
    return parameterProviders;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 69 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class FileResource method doIsParameterizable.

/**
 * Determines whether a selected file supports parameters or not
 *
 * @param pathId Colon separated path for the repository file.
 *
 * @return ("true" or "false")
 * @throws FileNotFoundException
 */
@GET
@Path("{pathId : .+}/parameterizable")
@Produces(MediaType.TEXT_PLAIN)
@Facet(name = "Unsupported")
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully get the file or directory."), @ResponseCode(code = 404, condition = "Failed to find the file or resource.") })
public // have to accept anything for browsers to work
String doIsParameterizable(@PathParam("pathId") String pathId) throws FileNotFoundException {
    boolean hasParameterUi = false;
    RepositoryFile repositoryFile = getRepository().getFile(fileService.idToPath(pathId));
    if (repositoryFile != null) {
        try {
            hasParameterUi = hasParameterUi(repositoryFile);
        } catch (NoSuchBeanDefinitionException e) {
        // Do nothing.
        }
    }
    boolean hasParameters = false;
    if (hasParameterUi) {
        try {
            IContentGenerator parameterContentGenerator = getContentGenerator(repositoryFile);
            if (parameterContentGenerator != null) {
                ByteArrayOutputStream outputStream = getByteArrayOutputStream();
                parameterContentGenerator.setOutputHandler(new SimpleOutputHandler(outputStream, false));
                parameterContentGenerator.setMessagesList(new ArrayList<String>());
                Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
                SimpleParameterProvider parameterProvider = getSimpleParameterProvider();
                parameterProvider.setParameter("path", encode(repositoryFile.getPath()));
                parameterProvider.setParameter("renderMode", "PARAMETER");
                parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
                parameterContentGenerator.setParameterProviders(parameterProviders);
                parameterContentGenerator.setSession(getSession());
                parameterContentGenerator.createContent();
                if (outputStream.size() > 0) {
                    Document document = parseText(outputStream.toString());
                    // exclude all parameters that are of type "system", xactions set system params that have to be ignored.
                    @SuppressWarnings("rawtypes") List nodes = document.selectNodes("parameters/parameter");
                    for (int i = 0; i < nodes.size() && !hasParameters; i++) {
                        Element elem = (Element) nodes.get(i);
                        if (elem.attributeValue("name").equalsIgnoreCase("output-target") && elem.attributeValue("is-mandatory").equalsIgnoreCase("true")) {
                            hasParameters = true;
                            continue;
                        }
                        Element attrib = (Element) elem.selectSingleNode("attribute[@namespace='http://reporting.pentaho" + ".org/namespaces/engine/parameter-attributes/core' and @name='role']");
                        if (attrib == null || !"system".equals(attrib.attributeValue("value"))) {
                            hasParameters = true;
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error(getMessagesInstance().getString("FileResource.PARAM_FAILURE", e.getMessage()), e);
        }
    }
    return Boolean.toString(hasParameters);
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) DocumentException(org.dom4j.DocumentException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) Facet(org.codehaus.enunciate.Facet)

Example 70 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class GeneratorStreamingOutput method createHeaderParamProvider.

protected IParameterProvider createHeaderParamProvider() {
    SimpleParameterProvider headerParams = new SimpleParameterProvider();
    Enumeration<?> names = httpServletRequest.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String value = httpServletRequest.getHeader(name);
        headerParams.setParameter(name, value);
    }
    return headerParams;
}
Also used : SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)72 HashMap (java.util.HashMap)32 ArrayList (java.util.ArrayList)23 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)23 OutputStream (java.io.OutputStream)21 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)21 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)21 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)16 Test (org.junit.Test)13 IOException (java.io.IOException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 Map (java.util.Map)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)5 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)5 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5 Iterator (java.util.Iterator)4