Search in sources :

Example 11 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.

the class SolutionImportHandler method importUserSettings.

protected void importUserSettings(UserExport user) {
    IUserSettingService settingService = PentahoSystem.get(IUserSettingService.class);
    IAnyUserSettingService userSettingService = null;
    if (settingService != null && settingService instanceof IAnyUserSettingService) {
        userSettingService = (IAnyUserSettingService) settingService;
    }
    if (userSettingService != null) {
        List<ExportManifestUserSetting> exportedSettings = user.getUserSettings();
        try {
            for (ExportManifestUserSetting exportedSetting : exportedSettings) {
                if (isOverwriteFile()) {
                    userSettingService.setUserSetting(user.getUsername(), exportedSetting.getName(), exportedSetting.getValue());
                } else {
                    // see if it's there first before we set this setting
                    IUserSetting userSetting = userSettingService.getUserSetting(user.getUsername(), exportedSetting.getName(), null);
                    if (userSetting == null) {
                        // only set it if we didn't find that it exists already
                        userSettingService.setUserSetting(user.getUsername(), exportedSetting.getName(), exportedSetting.getValue());
                    }
                }
            }
        } catch (SecurityException e) {
            String errorMsg = Messages.getInstance().getString("ERROR.ImportingUserSetting", user.getUsername());
            getLogger().error(errorMsg);
            getLogger().debug(errorMsg, e);
        }
    }
}
Also used : IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting)

Example 12 with IUserSettingService

use of org.pentaho.platform.api.usersettings.IUserSettingService 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)

Aggregations

IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)12 IUserSetting (org.pentaho.platform.api.usersettings.pojo.IUserSetting)6 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Facet (org.codehaus.enunciate.Facet)4 ExportManifestUserSetting (org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting)4 IOException (java.io.IOException)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Test (org.junit.Test)2 Mockito.anyString (org.mockito.Mockito.anyString)2 IThemeManager (org.pentaho.platform.api.ui.IThemeManager)2 Theme (org.pentaho.platform.api.ui.Theme)2 OutputStream (java.io.OutputStream)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1