Search in sources :

Example 6 with IPluginManager

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

the class PluginFileContentGenerator method createContent.

@Override
public void createContent(OutputStream outputStream) throws Exception {
    IPluginResourceLoader pluginResourceLoader = PentahoSystem.get(IPluginResourceLoader.class);
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    ClassLoader classLoader = pluginManager.getClassLoader(pluginId);
    String filePath = !relativeFilePath.startsWith("/") ? "/" + relativeFilePath : relativeFilePath;
    InputStream inputStream = pluginResourceLoader.getResourceAsStream(classLoader, filePath);
    int val;
    while ((val = inputStream.read()) != -1) {
        outputStream.write(val);
    }
    outputStream.flush();
}
Also used : InputStream(java.io.InputStream) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader)

Example 7 with IPluginManager

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

the class UserConsoleResource method getAdminContent.

/**
 * Returns the list of admin related settings
 *
 * @return list of settings
 */
@GET
@Path("/getAdminContent")
@Facet(name = "Unsupported")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public List<Setting> getAdminContent() {
    ArrayList<Setting> settings = new ArrayList<Setting>();
    try {
        IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, UserConsoleService.getPentahoSession());
        List<String> pluginIds = pluginManager.getRegisteredPlugins();
        nextPlugin: for (String pluginId : pluginIds) {
            String adminContentInfo = (String) pluginManager.getPluginSetting(pluginId, "admin-content-info", null);
            String exceptionMessage = (String) pluginManager.getPluginSetting(pluginId, "exception-message", null);
            if (adminContentInfo != null) {
                StringTokenizer nameValuePairs = new StringTokenizer(adminContentInfo, ";");
                while (nameValuePairs.hasMoreTokens()) {
                    String currentToken = nameValuePairs.nextToken().trim();
                    if (currentToken.startsWith("conditional-logic-validator=")) {
                        String validatorName = currentToken.substring("conditional-logic-validator=".length());
                        Class<?> validatorClass = pluginManager.getClassLoader(pluginId).loadClass(validatorName);
                        IAdminContentConditionalLogic validator = (IAdminContentConditionalLogic) validatorClass.newInstance();
                        int status = validator.validate();
                        if (status == IAdminContentConditionalLogic.DISPLAY_ADMIN_CONTENT) {
                            settings.add(new Setting("admin-content-info", adminContentInfo));
                        }
                        if (status == IAdminContentConditionalLogic.DISPLAY_EXCEPTION_MESSAGE && exceptionMessage != null) {
                            settings.add(new Setting("exception-message", exceptionMessage));
                        }
                        if (status == IAdminContentConditionalLogic.AVOID_ADMIN_CONTENT) {
                            continue nextPlugin;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return settings;
}
Also used : StringTokenizer(java.util.StringTokenizer) IAdminContentConditionalLogic(org.pentaho.platform.plugin.services.pluginmgr.IAdminContentConditionalLogic) ArrayList(java.util.ArrayList) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 8 with IPluginManager

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

the class PentahoWebContextFilterTest method setup.

@Before
public void setup() throws IOException, ServletException {
    this.serverScheme = "https";
    String serverName = "di.pentaho.local";
    int port = 9055;
    this.serverAddress = this.serverScheme + "://" + serverName + ":" + port;
    this.contextRoot = "/the/context/root/";
    this.fullyQualifiedServerURL = this.serverAddress + this.contextRoot;
    this.mockRequest = mock(HttpServletRequest.class);
    ServletContext mockServletContext = mock(ServletContext.class);
    ServletRegistration mockServletRegistration = mock(ServletRegistration.class);
    Collection<String> mappings = new ArrayList<>(1);
    mappings.add(PentahoWebContextFilter.DEFAULT_OSGI_BRIDGE);
    when(mockServletRegistration.getMappings()).thenReturn(mappings);
    when(mockServletContext.getServletRegistration(PentahoWebContextFilter.PLATFORM_OSGI_BRIDGE_ID)).thenReturn(mockServletRegistration);
    when(this.mockRequest.getServletContext()).thenReturn(mockServletContext);
    when(this.mockRequest.getRequestURI()).thenReturn("/somewhere/" + PentahoWebContextFilter.WEB_CONTEXT_JS);
    when(this.mockRequest.getScheme()).thenReturn(this.serverScheme);
    when(this.mockRequest.getServerName()).thenReturn(serverName);
    when(this.mockRequest.getServerPort()).thenReturn(port);
    when(this.mockRequest.getHeader("referer")).thenReturn(this.serverAddress + "/some/app");
    this.mockResponse = mock(HttpServletResponse.class);
    this.mockResponseOutputStream = new java.io.ByteArrayOutputStream();
    when(this.mockResponse.getOutputStream()).thenReturn(new ServletOutputStream() {

        @Override
        public void write(int b) throws IOException {
            PentahoWebContextFilterTest.this.mockResponseOutputStream.write(b);
        }
    });
    FilterConfig mockFilterConfig = mock(FilterConfig.class);
    this.pentahoWebContextFilter = spy(new PentahoWebContextFilter());
    IApplicationContext mockApplicationContext = mock(IApplicationContext.class);
    when(mockApplicationContext.getFullyQualifiedServerURL()).thenReturn(this.fullyQualifiedServerURL);
    doReturn(mockApplicationContext).when(this.pentahoWebContextFilter).getApplicationContext();
    IPentahoRequestContext mockRequestContext = mock(IPentahoRequestContext.class);
    when(mockRequestContext.getContextPath()).thenReturn(this.contextRoot);
    doReturn(mockRequestContext).when(this.pentahoWebContextFilter).getRequestContext();
    this.activeTheme = "xptoTheme";
    IUserSetting mockUserSetting = mock(IUserSetting.class);
    when(mockUserSetting.getSettingValue()).thenReturn(this.activeTheme);
    IUserSettingService mockUserSettingsService = mock(IUserSettingService.class);
    when(mockUserSettingsService.getUserSetting("pentaho-user-theme", null)).thenReturn(mockUserSetting);
    doReturn(mockUserSettingsService).when(this.pentahoWebContextFilter).getUserSettingsService();
    this.sessionName = "testSession";
    IPentahoSession mockSession = mock(IPentahoSession.class);
    when(mockSession.getName()).thenReturn(this.sessionName);
    doReturn(mockSession).when(this.pentahoWebContextFilter).getSession();
    this.reservedChars = new ArrayList<>(2);
    this.reservedChars.add('r');
    this.reservedChars.add('c');
    doReturn(this.reservedChars).when(this.pentahoWebContextFilter).getRepositoryReservedChars();
    IPluginManager mockPluginManager = mock(IPluginManager.class);
    doReturn(mockPluginManager).when(this.pentahoWebContextFilter).getPluginManager();
    doReturn(PentahoWebContextFilter.DEFAULT_SERVICES_ROOT).when(this.pentahoWebContextFilter).initializeServicesPath();
    this.pentahoWebContextFilter.init(mockFilterConfig);
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRegistration(javax.servlet.ServletRegistration) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ServletContext(javax.servlet.ServletContext) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) FilterConfig(javax.servlet.FilterConfig) Before(org.junit.Before)

Example 9 with IPluginManager

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

the class PojoComponent method validateAction.

@Override
protected boolean validateAction() {
    boolean ok = false;
    if (pojo == null && isDefinedInput("class")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String className = getInputStringValue("class");
        // try to load the class from a plugin
        IPluginManager pluginMgr = PentahoSystem.get(IPluginManager.class, getSession());
        if (pluginMgr != null && pluginMgr.isBeanRegistered(className)) {
            try {
                // "className" is actually the plugin bean id in this case
                pojo = pluginMgr.getBean(className);
            } catch (PluginBeanException e) {
                // $NON-NLS-1$
                error("Could not load bean class from plugin", e);
                return false;
            }
        }
        // the bean class was not found in a plugin, so try the default classloader
        if (pojo == null) {
            try {
                // TODO support loading classes from the solution repository
                Class<?> aClass = getClass().getClassLoader().loadClass(className);
                pojo = aClass.newInstance();
            } catch (Exception ex) {
                // $NON-NLS-1$
                error("Could not load bean class", ex);
                return false;
            }
        }
    }
    if (pojo != null) {
        // By the time we get here, we've got our class
        try {
            Method[] methods = pojo.getClass().getMethods();
            // create a method map
            for (Method method : methods) {
                String name = method.getName();
                Class<?>[] paramTypes = method.getParameterTypes();
                if (name.equals("getOutputs")) {
                    // $NON-NLS-1$
                    runtimeOutputsMethod = method;
                } else if (name.equals("setInputs")) {
                    // $NON-NLS-1$
                    runtimeInputsMethod = method;
                } else if (name.equals("setResources")) {
                    // $NON-NLS-1$
                    resourcesMethod = method;
                } else if (name.equals("setLogger")) {
                    // $NON-NLS-1$
                    if (paramTypes.length == 1 && paramTypes[0] == Log.class) {
                        loggerMethod = method;
                    }
                } else if (name.equals("setSession")) {
                    // $NON-NLS-1$
                    if (paramTypes.length == 1 && paramTypes[0] == IPentahoSession.class) {
                        sessionMethod = method;
                    }
                } else if (name.equalsIgnoreCase("configure")) {
                    // $NON-NLS-1$
                    configureMethod = method;
                } else if (name.startsWith("set")) {
                    // $NON-NLS-1$
                    name = name.substring(3).toUpperCase();
                    if (name.equals("CLASS")) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        warn(Messages.getInstance().getString("PojoComponent.CANNOT_USE_SETCLASS"));
                    } else {
                        if (!setMethods.containsKey(name)) {
                            setMethods.put(name, new ArrayList<Method>());
                        }
                        setMethods.get(name).add(method);
                    }
                } else if (name.startsWith("get")) {
                    // $NON-NLS-1$
                    name = name.substring(3).toUpperCase();
                    getMethods.put(name, method);
                } else if (name.equalsIgnoreCase("execute")) {
                    // $NON-NLS-1$
                    executeMethod = method;
                } else if (name.equalsIgnoreCase("validate")) {
                    // $NON-NLS-1$
                    validateMethod = method;
                } else if (name.equalsIgnoreCase("done")) {
                    // $NON-NLS-1$
                    doneMethod = method;
                }
            }
            ok = true;
        } catch (Throwable ex) {
            // $NON-NLS-1$
            error("Could not load object class", ex);
        }
    }
    return ok;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Method(java.lang.reflect.Method) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IPluginManager(org.pentaho.platform.api.engine.IPluginManager)

Example 10 with IPluginManager

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

the class PluggableUploadFileServlet method getUploaderBean.

protected IUploadFileServletPlugin getUploaderBean(String uploaderBeanId, HttpServletResponse response) throws PluginBeanException, IOException {
    if (StringUtils.isEmpty(uploaderBeanId)) {
        response.getWriter().write(// $NON-NLS-1$
        Messages.getInstance().getErrorString("PluggableUploadFileServlet.ERROR_0006_NO_UPLOADER_FOUND"));
        return null;
    }
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    if (!pluginManager.isBeanRegistered(uploaderBeanId)) {
        response.getWriter().write(Messages.getInstance().getErrorString("PluggableUploadFileServlet.ERROR_0008_NO_UPLOADER_BY_ID", // $NON-NLS-1$
        Encode.forHtml(uploaderBeanId)));
        return null;
    }
    Object uploaderBean = pluginManager.getBean(uploaderBeanId);
    if (!(uploaderBean instanceof IUploadFileServletPlugin)) {
        response.getWriter().write(Messages.getInstance().getErrorString("PluggableUploadFileServlet.ERROR_0007_UPLOADER_WRONG_TYPE", // $NON-NLS-1$
        IUploadFileServletPlugin.class.getName()));
        return null;
    }
    IUploadFileServletPlugin uploaderPlugin = (IUploadFileServletPlugin) uploaderBean;
    return uploaderPlugin;
}
Also used : IPluginManager(org.pentaho.platform.api.engine.IPluginManager)

Aggregations

IPluginManager (org.pentaho.platform.api.engine.IPluginManager)24 ArrayList (java.util.ArrayList)7 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 IOException (java.io.IOException)4 Facet (org.codehaus.enunciate.Facet)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)2 IContentInfo (org.pentaho.platform.api.engine.IContentInfo)2 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)2 IPluginOperation (org.pentaho.platform.api.engine.IPluginOperation)2 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)2 PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1