use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingsResource method getUserSettings.
/**
* Retrieve the global settings and the user settings for the current user
*
* @return list of settings for the platform
*/
@GET
@Path("/list")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public ArrayList<Setting> getUserSettings() {
try {
IUserSettingService settingsService = getUserSettingService();
List<IUserSetting> userSettings = settingsService.getUserSettings();
ArrayList<Setting> settings = new ArrayList<Setting>();
for (IUserSetting userSetting : userSettings) {
settings.add(new Setting(userSetting.getSettingName(), userSetting.getSettingValue()));
}
return settings;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class PentahoWebContextFilterTest method setup.
@Before
public void setup() throws IOException, ServletException {
this.serverScheme = "https";
String serverName = "di.pentaho.local";
int port = 9055;
this.serverAddress = this.serverScheme + "://" + serverName + ":" + port;
this.contextRoot = "/the/context/root/";
this.fullyQualifiedServerURL = this.serverAddress + this.contextRoot;
this.mockRequest = mock(HttpServletRequest.class);
ServletContext mockServletContext = mock(ServletContext.class);
ServletRegistration mockServletRegistration = mock(ServletRegistration.class);
Collection<String> mappings = new ArrayList<>(1);
mappings.add(PentahoWebContextFilter.DEFAULT_OSGI_BRIDGE);
when(mockServletRegistration.getMappings()).thenReturn(mappings);
when(mockServletContext.getServletRegistration(PentahoWebContextFilter.PLATFORM_OSGI_BRIDGE_ID)).thenReturn(mockServletRegistration);
when(this.mockRequest.getServletContext()).thenReturn(mockServletContext);
when(this.mockRequest.getRequestURI()).thenReturn("/somewhere/" + PentahoWebContextFilter.WEB_CONTEXT_JS);
when(this.mockRequest.getScheme()).thenReturn(this.serverScheme);
when(this.mockRequest.getServerName()).thenReturn(serverName);
when(this.mockRequest.getServerPort()).thenReturn(port);
when(this.mockRequest.getHeader("referer")).thenReturn(this.serverAddress + "/some/app");
this.mockResponse = mock(HttpServletResponse.class);
this.mockResponseOutputStream = new java.io.ByteArrayOutputStream();
when(this.mockResponse.getOutputStream()).thenReturn(new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
PentahoWebContextFilterTest.this.mockResponseOutputStream.write(b);
}
});
FilterConfig mockFilterConfig = mock(FilterConfig.class);
this.pentahoWebContextFilter = spy(new PentahoWebContextFilter());
IApplicationContext mockApplicationContext = mock(IApplicationContext.class);
when(mockApplicationContext.getFullyQualifiedServerURL()).thenReturn(this.fullyQualifiedServerURL);
doReturn(mockApplicationContext).when(this.pentahoWebContextFilter).getApplicationContext();
IPentahoRequestContext mockRequestContext = mock(IPentahoRequestContext.class);
when(mockRequestContext.getContextPath()).thenReturn(this.contextRoot);
doReturn(mockRequestContext).when(this.pentahoWebContextFilter).getRequestContext();
this.activeTheme = "xptoTheme";
IUserSetting mockUserSetting = mock(IUserSetting.class);
when(mockUserSetting.getSettingValue()).thenReturn(this.activeTheme);
IUserSettingService mockUserSettingsService = mock(IUserSettingService.class);
when(mockUserSettingsService.getUserSetting("pentaho-user-theme", null)).thenReturn(mockUserSetting);
doReturn(mockUserSettingsService).when(this.pentahoWebContextFilter).getUserSettingsService();
this.sessionName = "testSession";
IPentahoSession mockSession = mock(IPentahoSession.class);
when(mockSession.getName()).thenReturn(this.sessionName);
doReturn(mockSession).when(this.pentahoWebContextFilter).getSession();
this.reservedChars = new ArrayList<>(2);
this.reservedChars.add('r');
this.reservedChars.add('c');
doReturn(this.reservedChars).when(this.pentahoWebContextFilter).getRepositoryReservedChars();
IPluginManager mockPluginManager = mock(IPluginManager.class);
doReturn(mockPluginManager).when(this.pentahoWebContextFilter).getPluginManager();
doReturn(PentahoWebContextFilter.DEFAULT_SERVICES_ROOT).when(this.pentahoWebContextFilter).initializeServicesPath();
this.pentahoWebContextFilter.init(mockFilterConfig);
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingService method getUserSettings.
@Override
public List<IUserSetting> getUserSettings(String username) throws SecurityException {
// if the user does not have the setting, check if a global setting exists
List<IUserSetting> userSettings = new ArrayList<>();
if (canAdminister()) {
try {
String homePath = ClientRepositoryPaths.getUserHomeFolderPath(username);
Serializable userHomeId = repository.getFile(homePath).getId();
Map<String, Serializable> userMetadata = repository.getFileMetadata(userHomeId);
for (Map.Entry<String, Serializable> entry : userMetadata.entrySet()) {
String key = entry.getKey();
if (key.startsWith(SETTING_PREFIX)) {
String settingFromKey = key.substring(SETTING_PREFIX.length());
userSettings.add(createSetting(settingFromKey, entry.getValue()));
}
}
} catch (Throwable ignored) {
// if anything goes wrong with authentication (anonymous user) or permissions
// just return the default value, if we continue to log these errors (like on before Login)
// we'll see *many* errors in the logs which are not helpful
}
} else {
throw new SecurityException("Unauthorized User");
}
return userSettings;
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.
the class UserSettingService method getGlobalUserSettings.
public List<IUserSetting> getGlobalUserSettings() {
String tentantHomePath = ClientRepositoryPaths.getEtcFolderPath();
Serializable tenantHomeId = repository.getFile(tentantHomePath).getId();
Map<String, Serializable> tenantMetadata = repository.getFileMetadata(tenantHomeId);
List<IUserSetting> userSettings = new ArrayList<IUserSetting>(tenantMetadata.size());
for (Map.Entry<String, Serializable> entry : tenantMetadata.entrySet()) {
String key = entry.getKey();
if (key.startsWith(SETTING_PREFIX)) {
userSettings.add(createSetting(key.substring(SETTING_PREFIX.length()), entry.getValue()));
}
}
return userSettings;
}
use of org.pentaho.platform.api.usersettings.pojo.IUserSetting 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) {
log.error(Messages.getInstance().getString("ERROR.ImportingUserSetting", user.getUsername()));
log.debug(Messages.getInstance().getString("ERROR.ImportingUserSetting", user.getUsername()), e);
}
}
}
Aggregations