Search in sources :

Example 6 with IContentGenerator

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

the class PentahoSystemPluginManager method getContentGenerator.

@Override
public IContentGenerator getContentGenerator(String type, String perspectiveName) {
    IContentGenerator cg = null;
    String beanId;
    if (perspectiveName == null || perspectiveName.equals(DEFAULT_PERSPECTIVE)) {
        beanId = type;
    } else {
        beanId = type + "." + perspectiveName;
    }
    IContentGenerator contentGenerator = PentahoSystem.get(IContentGenerator.class, PentahoSessionHolder.getSession(), Collections.singletonMap(CONTENT_TYPE, beanId));
    if (contentGenerator == null) {
        contentGenerator = PentahoSystem.get(IContentGenerator.class, PentahoSessionHolder.getSession(), Collections.singletonMap(CONTENT_TYPE, perspectiveName));
    }
    return contentGenerator;
}
Also used : IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator)

Example 7 with IContentGenerator

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

the class AxisWebServiceManagerIT method testMetaInf.

@Test
public void testMetaInf() throws Exception {
    IContentGenerator serviceLister = new StyledHtmlAxisServiceLister();
    String html = ContentGeneratorUtil.getContentAsString(serviceLister);
    System.out.println(html);
    assertTrue("title is not displayed", html.contains("junit echo service"));
}
Also used : IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) StyledHtmlAxisServiceLister(org.pentaho.platform.plugin.services.webservices.content.StyledHtmlAxisServiceLister) Test(org.junit.Test)

Example 8 with IContentGenerator

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

the class AxisWebServiceManagerIT method testExecuteUrlListed.

/*
   * The following tests are checking that the HtmlServiceLister (content generator) outputs the correct meta
   * information about the services defined in the test plugin. They are integration tests in the sense that all the
   * work of registering the plugin that defines the services and content generators is done by actual platform modules
   * as it would normally happen, and is not mocked for these tests.
   */
@Test
public void testExecuteUrlListed() throws Exception {
    IContentGenerator serviceLister = new StyledHtmlAxisServiceLister();
    String html = ContentGeneratorUtil.getContentAsString(serviceLister);
    System.out.println(html);
    assertTrue("Run URL is missing", html.contains("/content/ws-run/echoService"));
}
Also used : IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) StyledHtmlAxisServiceLister(org.pentaho.platform.plugin.services.webservices.content.StyledHtmlAxisServiceLister) Test(org.junit.Test)

Example 9 with IContentGenerator

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

the class AxisWebServiceManagerIT method testWsdlUrlListed.

@Test
public void testWsdlUrlListed() throws Exception {
    IContentGenerator serviceLister = new StyledHtmlAxisServiceLister();
    String html = ContentGeneratorUtil.getContentAsString(serviceLister);
    System.out.println(html);
    assertTrue("WSDL URL is missing", html.contains("/content/ws-wsdl/echoService"));
}
Also used : IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) StyledHtmlAxisServiceLister(org.pentaho.platform.plugin.services.webservices.content.StyledHtmlAxisServiceLister) Test(org.junit.Test)

Example 10 with IContentGenerator

use of org.pentaho.platform.api.engine.IContentGenerator 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

IContentGenerator (org.pentaho.platform.api.engine.IContentGenerator)11 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 StyledHtmlAxisServiceLister (org.pentaho.platform.plugin.services.webservices.content.StyledHtmlAxisServiceLister)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)3 IOException (java.io.IOException)2 List (java.util.List)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 MockServletContext (com.mockrunner.mock.web.MockServletContext)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1