Search in sources :

Example 36 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class SystemResource method getAuthenticationProvider.

/**
 * Return JSON string reporting which authentication provider is currently in use
 *
 * Response sample: { "authenticationType": "JCR_BASED_AUTHENTICATION" }
 *
 * @return AuthenticationProvider represented as JSON response
 * @throws Exception
 */
@GET
@Path("/authentication-provider")
@Produces({ MediaType.APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response getAuthenticationProvider() throws Exception {
    try {
        if (canAdminister()) {
            IConfiguration config = this.systemConfig.getConfiguration("security");
            String provider = config.getProperties().getProperty("provider");
            return Response.ok(new AuthenticationProvider(provider)).type(MediaType.APPLICATION_JSON).build();
        } else {
            return Response.status(UNAUTHORIZED).build();
        }
    } catch (Throwable t) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getString("SystemResource.GENERAL_ERROR"), t);
        throw new Exception(t);
    }
}
Also used : IConfiguration(org.pentaho.platform.api.engine.IConfiguration) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 37 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class SystemResource method setLocaleOverride.

/**
 * Apply the selected locale to the user console
 *
 * @param locale (user console's locale)
 *
 * @return
 */
@POST
@Path("/locale")
@Facet(name = "Unsupported")
public Response setLocaleOverride(String locale) {
    IPentahoSession session = PentahoSessionHolder.getSession();
    Locale newLocale = null;
    if (session != null) {
        if (!StringUtils.isEmpty(locale)) {
            // Clean up "en-US" and "en/GB"
            String localeTmp = locale.replaceAll("-|/", "_");
            try {
                newLocale = LocaleUtils.toLocale(localeTmp);
                session.setAttribute("locale_override", localeTmp);
                LocaleHelper.setLocaleOverride(newLocale);
            } catch (IllegalArgumentException ex) {
                return Response.serverError().entity(ex.getMessage()).build();
            }
        } else {
            // empty string or null passed in, unset locale_override variable.
            session.setAttribute("locale_override", null);
            LocaleHelper.setLocaleOverride(null);
        }
    } else {
        LocaleHelper.setLocaleOverride(null);
    }
    return getLocale();
}
Also used : Locale(java.util.Locale) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Facet(org.codehaus.enunciate.Facet)

Example 38 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class ThemeResource method setTheme.

/**
 * Set the current theme to the one provided in this request
 *
 * @param theme (theme to be changed to)
 *
 * @return
 */
@POST
@Path("/set")
@Consumes({ WILDCARD })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully set theme."), @ResponseCode(code = 403, condition = "Illegal set operation.") })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response setTheme(String theme) {
    IThemeManager themeManager = PentahoSystem.get(IThemeManager.class);
    List<String> ids = themeManager.getSystemThemeIds();
    if ((ids != null) && (ids.indexOf(theme) >= 0)) {
        getPentahoSession().setAttribute("pentaho-user-theme", theme);
        IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, getPentahoSession());
        settingsService.setUserSetting("pentaho-user-theme", theme);
        return getActiveTheme();
    } else {
        // Prevent log forging/injection
        String cleanTheme = theme.replace('\n', ' ').replace('\r', ' ');
        // We do not want to NLS-ize this message
        logger.error("Attempt to set invalid theme: " + cleanTheme);
        return Response.status(Response.Status.FORBIDDEN).entity("").build();
    }
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) Facet(org.codehaus.enunciate.Facet)

Example 39 with Facet

use of org.codehaus.enunciate.Facet in project pentaho-platform by pentaho.

the class UserConsoleResource method getMondrianCatalogs.

/**
 * Return the list of mondrian cubes in the platform
 *
 * @return list of cubes
 */
@GET
@Path("/cubes")
@Facet(name = "Unsupported")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
public List<Cube> getMondrianCatalogs() {
    ArrayList<Cube> cubes = new ArrayList<Cube>();
    IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", UserConsoleService.getPentahoSession());
    List<MondrianCatalog> catalogs = catalogService.listCatalogs(UserConsoleService.getPentahoSession(), true);
    for (MondrianCatalog cat : catalogs) {
        for (MondrianCube cube : cat.getSchema().getCubes()) {
            cubes.add(new Cube(cat.getName(), cube.getName(), cube.getId()));
        }
    }
    return cubes;
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianCube(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCube) ArrayList(java.util.ArrayList) MondrianCube(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCube) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 40 with Facet

use of org.codehaus.enunciate.Facet 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

Facet (org.codehaus.enunciate.Facet)48 Path (javax.ws.rs.Path)43 Produces (javax.ws.rs.Produces)33 GET (javax.ws.rs.GET)29 ArrayList (java.util.ArrayList)12 Consumes (javax.ws.rs.Consumes)12 POST (javax.ws.rs.POST)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 PUT (javax.ws.rs.PUT)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)6 Response (javax.ws.rs.core.Response)5 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)5 HashSet (java.util.HashSet)4 StringTokenizer (java.util.StringTokenizer)4 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)4 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)4 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3