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);
}
}
}
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();
}
}
Aggregations