Search in sources :

Example 1 with IAdminContentConditionalLogic

use of org.pentaho.platform.plugin.services.pluginmgr.IAdminContentConditionalLogic 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)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Facet (org.codehaus.enunciate.Facet)1 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)1 IAdminContentConditionalLogic (org.pentaho.platform.plugin.services.pluginmgr.IAdminContentConditionalLogic)1