use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting 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.plugin.services.importexport.ExportManifestUserSetting in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportUserSettings_NoOverwrite.
@Test
public void testImportUserSettings_NoOverwrite() throws Exception {
UserExport user = new UserExport();
user.setUsername("pentaho");
user.addUserSetting(new ExportManifestUserSetting("theme", "crystal"));
user.addUserSetting(new ExportManifestUserSetting("language", "en_US"));
IAnyUserSettingService userSettingService = Mockito.mock(IAnyUserSettingService.class);
PentahoSystem.registerObject(userSettingService);
importHandler.setOverwriteFile(false);
IUserSetting existingSetting = Mockito.mock(IUserSetting.class);
Mockito.when(userSettingService.getUserSetting("pentaho", "theme", null)).thenReturn(existingSetting);
Mockito.when(userSettingService.getUserSetting("pentaho", "language", null)).thenReturn(null);
importHandler.importUserSettings(user);
Mockito.verify(userSettingService, Mockito.never()).setUserSetting("pentaho", "theme", "crystal");
Mockito.verify(userSettingService).setUserSetting("pentaho", "language", "en_US");
Mockito.verify(userSettingService).getUserSetting("pentaho", "theme", null);
Mockito.verify(userSettingService).getUserSetting("pentaho", "language", null);
}
use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportUserSettings.
@Test
public void testImportUserSettings() throws Exception {
UserExport user = new UserExport();
user.setUsername("pentaho");
user.addUserSetting(new ExportManifestUserSetting("theme", "crystal"));
user.addUserSetting(new ExportManifestUserSetting("language", "en_US"));
IAnyUserSettingService userSettingService = Mockito.mock(IAnyUserSettingService.class);
PentahoSystem.registerObject(userSettingService);
importHandler.setOverwriteFile(true);
importHandler.importUserSettings(user);
Mockito.verify(userSettingService).setUserSetting("pentaho", "theme", "crystal");
Mockito.verify(userSettingService).setUserSetting("pentaho", "language", "en_US");
}
use of org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting 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.plugin.services.importexport.ExportManifestUserSetting 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());
}
Aggregations