Search in sources :

Example 1 with IPluginOperation

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

the class SystemPathPluginProviderIT method testLoadContentGenerators.

@SuppressWarnings("deprecation")
@Test
public void testLoadContentGenerators() throws PlatformPluginRegistrationException {
    microPlatform.init();
    List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
    IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("content-generator-plugin"));
    assertNotNull("content-generator-plugin should have been found", plugin);
    List<IContentInfo> contentTypes = plugin.getContentInfos();
    Object contentType = CollectionUtils.find(contentTypes, new Predicate() {

        public boolean evaluate(Object object) {
            IContentInfo type = (IContentInfo) object;
            return type.getTitle().equals("Good Test Type");
        }
    });
    assertNotNull("\"Good Test Type\" should have been loaded", contentType);
    assertNotNull("\"Good Test Type\" extension definition is incorrect", ((IContentInfo) contentType).getExtension().equals("good-content-type"));
    IContentInfo contentInfo = (IContentInfo) contentType;
    IPluginOperation operation = contentInfo.getOperations().listIterator().next();
    assertEquals("Missing perspective", "custom-perspective", operation.getPerspective());
    assertEquals("\"Test Type Missing type\" should not have been loaded", 0, CollectionUtils.countMatches(contentTypes, new Predicate() {

        public boolean evaluate(Object object) {
            IContentInfo type = (IContentInfo) object;
            return type.getTitle().equals("Test Type Missing type");
        }
    }));
    assertEquals("\"test-type-missing-title\" should not have been loaded", 0, CollectionUtils.countMatches(contentTypes, new Predicate() {

        public boolean evaluate(Object object) {
            IContentInfo type = (IContentInfo) object;
            return type.getExtension().equals("test-type-missing-title");
        }
    }));
}
Also used : IContentInfo(org.pentaho.platform.api.engine.IContentInfo) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPluginOperation(org.pentaho.platform.api.engine.IPluginOperation) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Predicate(org.apache.commons.collections.Predicate) Test(org.junit.Test)

Example 2 with IPluginOperation

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

the class DefaultPluginManagerIT method test10_ContentTypeRegistration.

@Test
public void test10_ContentTypeRegistration() throws PlatformInitializationException {
    microPlatform.define(IPluginProvider.class, Tst10PluginProvider.class).start();
    pluginManager.reload();
    Set<String> types = pluginManager.getContentTypes();
    // FIXME: getContentTypes returns the list of types configured by content generators, not the list
    // of types defined by IContentInfo's. Is this really what we want? If a type has no content
    // generator configured, then it is invisible through this API.
    assertTrue("test10type1 should be registered", types.contains("test10type1-ext"));
    assertTrue("test10type2 should be registered", types.contains("test10type2-ext"));
    IContentInfo contentInfo = pluginManager.getContentTypeInfo("test10type1-ext");
    assertNotNull("type should be registered for extension test10type1-ext", contentInfo);
    assertEquals("test10type1-title", contentInfo.getTitle());
    assertEquals("test10type1-description", contentInfo.getDescription());
    assertEquals("test10type1-ext", contentInfo.getExtension());
    assertEquals("test10type1-url", contentInfo.getIconUrl());
    List<IPluginOperation> ops = contentInfo.getOperations();
    assertNotNull("Operations are null", ops);
    assertEquals("Wrong number of ops", 2, ops.size());
    assertEquals("Operation name is wrong", "test10type1-oper1-id", ops.get(0).getId());
    assertEquals("Operation name is wrong", "test10type1-oper2-id", ops.get(1).getId());
    assertEquals("Operation command is wrong", "test10type1-oper2-perspective", ops.get(1).getPerspective());
}
Also used : IContentInfo(org.pentaho.platform.api.engine.IContentInfo) IPluginOperation(org.pentaho.platform.api.engine.IPluginOperation) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) Test(org.junit.Test)

Example 3 with IPluginOperation

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

the class RepositoryResource method doExecuteDefault.

/**
 * Takes a pathId to a file and generates a URI that represents the URL to call to generate content from that file.
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho/api/repos/public:steel%20wheels:Invoice%20(report).prpt/default
 * </p>
 *
 * @param pathId @param pathId
 *
 * @return URI that represents a forwarding URL to execute to generate content from the file {pathId}.
 *
 * <p><b>Example Response:</b></p>
 *  <pre function="syntax.xml">
 *    This response does not contain data.
 *  </pre>
 */
@GET
@Path("{pathId : .+}/default")
@Produces({ WILDCARD })
@StatusCodes({ @ResponseCode(code = 303, condition = "Successfully get the resource."), @ResponseCode(code = 404, condition = "Failed to find the resource.") })
public Response doExecuteDefault(@PathParam("pathId") String pathId) throws FileNotFoundException, MalformedURLException, URISyntaxException {
    String perspective = null;
    StringBuffer buffer = null;
    String url = null;
    String path = FileResource.idToPath(pathId);
    String extension = path.substring(path.lastIndexOf('.') + 1);
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, PentahoSessionHolder.getSession());
    IContentInfo info = pluginManager.getContentTypeInfo(extension);
    for (IPluginOperation operation : info.getOperations()) {
        if (operation.getId().equalsIgnoreCase("RUN")) {
            // $NON-NLS-1$
            perspective = operation.getPerspective();
            break;
        }
    }
    if (perspective == null) {
        perspective = GENERATED_CONTENT_PERSPECTIVE;
    }
    buffer = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    url = // $NON-NLS-1$
    buffer.substring(0, buffer.lastIndexOf("/") + 1) + perspective + ((queryString != null && queryString.length() > 0) ? "?" + httpServletRequest.getQueryString() : "");
    return Response.seeOther((new URL(url)).toURI()).build();
}
Also used : IContentInfo(org.pentaho.platform.api.engine.IContentInfo) IPluginOperation(org.pentaho.platform.api.engine.IPluginOperation) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) URL(java.net.URL) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes)

Example 4 with IPluginOperation

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

the class UserConsoleResource method getMantleSettings.

/**
 * Return the current user console settings
 *
 * @return current settings
 */
@GET
@Path("/settings")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public List<Setting> getMantleSettings() {
    ArrayList<Setting> settings = new ArrayList<Setting>();
    settings.add(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    new Setting("login-show-users-list", PentahoSystem.getSystemSetting("login-show-users-list", "")));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(new Setting("documentation-url", PentahoSystem.getSystemSetting("documentation-url", "")));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(new Setting("submit-on-enter-key", PentahoSystem.getSystemSetting("submit-on-enter-key", "true")));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(new Setting("user-console-revision", PentahoSystem.getSystemSetting("user-console-revision", "")));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(new Setting("startupPerspective", PentahoSystem.getSystemSetting("startup-perspective", "")));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(new Setting("showOnlyPerspective", PentahoSystem.getSystemSetting("show-only-perspective", "")));
    int startupUrls = Integer.parseInt(PentahoSystem.getSystemSetting("num-startup-urls", "0"));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    settings.add(new Setting("num-startup-urls", PentahoSystem.getSystemSetting("num-startup-urls", "0")));
    for (int i = 1; i <= startupUrls; i++) {
        // $NON-NLS-1$
        settings.add(new Setting("startup-url-" + i, PentahoSystem.getSystemSetting("startup-url-" + i, "")));
        // $NON-NLS-1$
        settings.add(new Setting("startup-name-" + i, PentahoSystem.getSystemSetting("startup-name-" + i, "")));
    }
    // Check for override of New Analysis View via pentaho.xml
    // Poked in via pentaho.xml entries
    // <new-analysis-view>
    // <command-url>http://www.google.com</command-url>
    // <command-title>Marc Analysis View</command-title>
    // </new-analysis-view>
    // <new-report>
    // <command-url>http://www.yahoo.com</command-url>
    // <command-title>Marc New Report</command-title>
    // </new-report>
    // 
    // $NON-NLS-1$
    String overrideNewAnalysisViewCommmand = PentahoSystem.getSystemSetting("new-analysis-view/command-url", null);
    // $NON-NLS-1$
    String overrideNewAnalysisViewTitle = PentahoSystem.getSystemSetting("new-analysis-view/command-title", null);
    if ((overrideNewAnalysisViewCommmand != null) && (overrideNewAnalysisViewTitle != null)) {
        // $NON-NLS-1$
        settings.add(new Setting("new-analysis-view-command-url", overrideNewAnalysisViewCommmand));
        // $NON-NLS-1$
        settings.add(new Setting("new-analysis-view-command-title", overrideNewAnalysisViewTitle));
    }
    // $NON-NLS-1$
    String overrideNewReportCommmand = PentahoSystem.getSystemSetting("new-report/command-url", null);
    // $NON-NLS-1$
    String overrideNewReportTitle = PentahoSystem.getSystemSetting("new-report/command-title", null);
    if ((overrideNewReportCommmand != null) && (overrideNewReportTitle != null)) {
        // $NON-NLS-1$
        settings.add(new Setting("new-report-command-url", overrideNewReportCommmand));
        // $NON-NLS-1$
        settings.add(new Setting("new-report-command-title", overrideNewReportTitle));
    }
    // $NON-NLS-1$
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, UserConsoleService.getPentahoSession());
    if (pluginManager != null) {
        // load content types from IPluginSettings
        int i = 0;
        for (String contentType : pluginManager.getContentTypes()) {
            IContentInfo info = pluginManager.getContentTypeInfo(contentType);
            if (info != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                settings.add(new Setting("plugin-content-type-" + i, "." + contentType));
                // $NON-NLS-1$
                settings.add(new Setting("plugin-content-type-icon-" + i, info.getIconUrl()));
                int j = 0;
                for (IPluginOperation operation : info.getOperations()) {
                    // $NON-NLS-1$
                    settings.add(new Setting("plugin-content-type-" + i + "-command-" + j, operation.getId()));
                    settings.add(new Setting("plugin-content-type-" + i + "-command-perspective-" + j, // $NON-NLS-1$
                    operation.getPerspective()));
                    j++;
                }
                i++;
            }
        }
    }
    return settings;
}
Also used : IContentInfo(org.pentaho.platform.api.engine.IContentInfo) IPluginOperation(org.pentaho.platform.api.engine.IPluginOperation) ArrayList(java.util.ArrayList) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

IContentInfo (org.pentaho.platform.api.engine.IContentInfo)4 IPluginOperation (org.pentaho.platform.api.engine.IPluginOperation)4 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Predicate (org.apache.commons.collections.Predicate)1 Facet (org.codehaus.enunciate.Facet)1 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)1 IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)1 IPluginProvider (org.pentaho.platform.api.engine.IPluginProvider)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1