use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.
the class PentahoPlatformExporter method exportUsersAndRoles.
protected void exportUsersAndRoles() {
log.debug("export users & roles");
IUserRoleListService userRoleListService = PentahoSystem.get(IUserRoleListService.class);
UserDetailsService userDetailsService = PentahoSystem.get(UserDetailsService.class);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get(IRoleAuthorizationPolicyRoleBindingDao.class);
ITenant tenant = TenantUtils.getCurrentTenant();
// get the user settings for this user
IUserSettingService service = getUserSettingService();
// User Export
List<String> userList = userRoleListService.getAllUsers(tenant);
for (String user : userList) {
UserExport userExport = new UserExport();
userExport.setUsername(user);
userExport.setPassword(userDetailsService.loadUserByUsername(user).getPassword());
for (String role : userRoleListService.getRolesForUser(tenant, user)) {
userExport.setRole(role);
}
if (service != null && service instanceof IAnyUserSettingService) {
IAnyUserSettingService userSettings = (IAnyUserSettingService) service;
List<IUserSetting> settings = userSettings.getUserSettings(user);
if (settings != null) {
for (IUserSetting setting : settings) {
userExport.addUserSetting(new ExportManifestUserSetting(setting));
}
}
}
this.getExportManifest().addUserExport(userExport);
}
// export the global user settings
if (service != null) {
List<IUserSetting> globalUserSettings = service.getGlobalUserSettings();
if (globalUserSettings != null) {
for (IUserSetting setting : globalUserSettings) {
getExportManifest().addGlobalUserSetting(new ExportManifestUserSetting(setting));
}
}
}
// RoleExport
List<String> roles = userRoleListService.getAllRoles();
for (String role : roles) {
RoleExport roleExport = new RoleExport();
roleExport.setRolename(role);
roleExport.setPermission(roleBindingDao.getRoleBindingStruct(null).bindingMap.get(role));
exportManifest.addRoleExport(roleExport);
}
}
use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportGlobalUserSetting_noOverwrite.
@Test
public void testImportGlobalUserSetting_noOverwrite() throws Exception {
importHandler.setOverwriteFile(false);
List<ExportManifestUserSetting> settings = new ArrayList<>();
settings.add(new ExportManifestUserSetting("language", "en_US"));
settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
IUserSettingService userSettingService = Mockito.mock(IUserSettingService.class);
PentahoSystem.registerObject(userSettingService);
IUserSetting setting = Mockito.mock(IUserSetting.class);
Mockito.when(userSettingService.getGlobalUserSetting("language", null)).thenReturn(null);
Mockito.when(userSettingService.getGlobalUserSetting("showHiddenFiles", null)).thenReturn(setting);
importHandler.importGlobalUserSettings(settings);
Mockito.verify(userSettingService).setGlobalUserSetting("language", "en_US");
Mockito.verify(userSettingService, Mockito.never()).setGlobalUserSetting(Mockito.eq("showHiddenFiles"), Mockito.anyString());
Mockito.verify(userSettingService).getGlobalUserSetting("language", null);
Mockito.verify(userSettingService).getGlobalUserSetting("showHiddenFiles", null);
}
use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportGlobalUserSetting.
@Test
public void testImportGlobalUserSetting() throws Exception {
importHandler.setOverwriteFile(true);
List<ExportManifestUserSetting> settings = new ArrayList<>();
settings.add(new ExportManifestUserSetting("language", "en_US"));
settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
IUserSettingService userSettingService = Mockito.mock(IUserSettingService.class);
PentahoSystem.registerObject(userSettingService);
importHandler.importGlobalUserSettings(settings);
Mockito.verify(userSettingService).setGlobalUserSetting("language", "en_US");
Mockito.verify(userSettingService).setGlobalUserSetting("showHiddenFiles", "false");
Mockito.verify(userSettingService, Mockito.never()).getGlobalUserSetting(Mockito.anyString(), Mockito.anyString());
}
use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.
the class ThemeServlet method handleRequest.
public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// look for a passed in theme context (content generator, other named area)
String moduleName = req.getParameter("context");
OutputStream out = resp.getOutputStream();
// $NON-NLS-1$
resp.setContentType("text/javascript");
// $NON-NLS-1$
resp.setHeader("Cache-Control", "no-cache");
IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, getPentahoSession(req));
// NOTE: this code should be kept in sync with that of PentahoWebContextFilter.java
String activeTheme = (String) getPentahoSession(req).getAttribute("pentaho-user-theme");
String ua = req.getHeader("User-Agent");
// check if we're coming from a mobile device, if so, lock to system default (ruby)
if (!StringUtils.isEmpty(ua) && ua.matches(".*(?i)(iPad|iPod|iPhone|Android).*")) {
activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
}
if (activeTheme == null) {
try {
activeTheme = settingsService.getUserSetting("pentaho-user-theme", null).getSettingValue();
} catch (Exception ignored) {
// the user settings service is not valid in the agile-bi deployment of the
// server
}
if (activeTheme == null) {
activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
}
}
out.write(("\n\n// Theming scripts. This file is generated by (" + getClass().getName() + ") and cannot be found on disk\n").getBytes());
out.write(("var active_theme = \"" + activeTheme + "\";\n\n").getBytes());
// Build-up JSON graph for system theme.
JSONObject root = new JSONObject();
JSONObject themeObject;
for (String systemThemeName : themeManager.getSystemThemeIds()) {
Theme theme = themeManager.getSystemTheme(systemThemeName);
themeObject = new JSONObject();
root.put(theme.getId(), themeObject);
themeObject.put("rootDir", theme.getThemeRootDir());
for (ThemeResource res : theme.getResources()) {
themeObject.append("resources", res.getLocation());
}
}
out.write(("var core_theme_tree = " + root.toString() + ";\n\n").getBytes());
out.write("// Inject the theme script to handle the insertion of requested theme resources\n\n".getBytes());
ModuleThemeInfo moduleThemeinfo = themeManager.getModuleThemeInfo(moduleName);
if (moduleThemeinfo != null) {
// Build-up JSON graph for module theme.
root = new JSONObject();
for (Theme theme : moduleThemeinfo.getModuleThemes()) {
themeObject = new JSONObject();
root.put(theme.getName(), themeObject);
themeObject.put("rootDir", theme.getThemeRootDir());
for (ThemeResource res : theme.getResources()) {
themeObject.append("resources", res.getLocation());
}
}
out.write(("var module_theme_tree = " + root.toString() + ";\n\n").getBytes());
}
// createElement & insertBefore
out.write(("(function() {\n" + "var script = document.createElement('script');\n" + "script.type = 'text/javascript';\n" + // "script.async = false;\n" +
"script.src = CONTEXT_PATH + 'js/themeResources.js';\n" + "var existing = document.getElementsByTagName('script')[0];\n" + "existing.parentNode.insertBefore(script, existing);\n" + "}());").getBytes());
} catch (IOException e) {
logger.debug("IO exception creating Theme info", e);
throw new ServletException(e);
} catch (JSONException e) {
logger.debug("JSON exception creating Theme info", e);
throw new ServletException(e);
}
}
use of org.pentaho.platform.api.usersettings.IUserSettingService in project pentaho-platform by pentaho.
the class UserSettingsResource method getUserSetting.
/**
* Retrieve a particular user setting for the current user
*
* @param setting (Name of the setting)
*
* @return value of the setting for the user
*/
@GET
@Path("{setting : .+}")
@Facet(name = "Unsupported")
public Response getUserSetting(@PathParam("setting") String setting) {
IUserSettingService settingsService = getUserSettingService();
IUserSetting userSetting = settingsService.getUserSetting(setting, null);
return Response.ok(userSetting != null ? userSetting.getSettingValue() : null).build();
}
Aggregations