Search in sources :

Example 41 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler 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 42 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler 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 43 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler 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)

Aggregations

SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)43 OutputStream (java.io.OutputStream)25 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)24 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)22 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)17 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)15 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)12 IOException (java.io.IOException)8 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)8 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)6 IContentItem (org.pentaho.platform.api.repository.IContentItem)6 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)6 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)5 Iterator (java.util.Iterator)4 List (java.util.List)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)4