use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class MondrianAbstractPlatformUserRoleMapper method getMondrianRolesFromCatalog.
/**
* This method returns the role names as found in the Mondrian schema. The returned names must be ordered (sorted) or
* code down-stream will not work.
*
* @param userSession
* Users' session
* @param catalogName
* The name of the catalog
* @return Array of role names from the schema file
*/
protected String[] getMondrianRolesFromCatalog(IPentahoSession userSession, String context) {
String[] rtn = null;
// Get the catalog service
IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class);
if (catalogService != null) {
// Get the catalog by name
MondrianCatalog catalog = catalogService.getCatalog(context, userSession);
if (catalog != null) {
// The roles are in the schema object
MondrianSchema schema = catalog.getSchema();
if (schema != null) {
// Ask the schema for the role names array
String[] roleNames = schema.getRoleNames();
if ((roleNames != null) && (roleNames.length > 0)) {
// Return the roles from the schema
Arrays.sort(roleNames);
return roleNames;
}
}
}
}
// Check with the IOlapService and try to get a list of roles there.
IOlapService olapService = PentahoSystem.get(IOlapService.class);
if (olapService != null) {
MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(PentahoSystem.get(IUnifiedRepository.class));
String serverName = null;
for (String name : helper.getOlap4jServers()) {
PropertyList props = Util.parseConnectString(helper.getOlap4jServerInfo(name).URL);
if (props.get(RolapConnectionProperties.Catalog.name(), "").equals(context)) {
serverName = name;
}
}
if (serverName != null) {
OlapConnection conn = null;
try {
// Use a null session for root access.
conn = olapService.getConnection(serverName, null);
List<String> roleList = conn.getAvailableRoleNames();
String[] roleArray = roleList.toArray(new String[roleList.size()]);
Arrays.sort(roleArray);
return roleArray;
} catch (OlapException e) {
log.error("Failed to get a list of roles from olap connection " + context, e);
throw new RuntimeException(e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// OK to squash this one.
log.error("Failed to get a list of roles from olap connection " + context, e);
}
}
}
}
}
// Sort the returned list of roles.
return rtn;
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class OlapServiceImpl method addHostedCatalog.
public void addHostedCatalog(String name, String dataSourceInfo, InputStream inputStream, boolean overwrite, IPentahoSession session) {
// Access
if (!hasAccess(name, EnumSet.of(RepositoryFilePermission.WRITE), session)) {
// $NON-NLS-1$
LOG.debug("user does not have access; throwing exception");
throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"OlapServiceImpl.ERROR_0003_INSUFFICIENT_PERMISSION"), IOlapServiceException.Reason.ACCESS_DENIED);
}
// check for existing vs. the overwrite flag.
if (getCatalogNames(session).contains(name) && !overwrite) {
throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"OlapServiceImpl.ERROR_0004_ALREADY_EXISTS"), IOlapServiceException.Reason.ALREADY_EXISTS);
}
try {
MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(getRepository());
helper.addHostedCatalog(inputStream, name, dataSourceInfo);
} catch (Exception e) {
throw new IOlapServiceException(e, IOlapServiceException.Reason.convert(e));
}
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class OlapServiceImpl method addOlap4jCatalog.
public void addOlap4jCatalog(String name, String className, String URL, String user, String password, Properties props, boolean overwrite, IPentahoSession session) {
// Access
if (!hasAccess(name, EnumSet.of(RepositoryFilePermission.WRITE), session)) {
// $NON-NLS-1$
LOG.debug("user does not have access; throwing exception");
throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"OlapServiceImpl.ERROR_0003_INSUFFICIENT_PERMISSION"), IOlapServiceException.Reason.ACCESS_DENIED);
}
// check for existing vs. the overwrite flag.
if (getCatalogNames(session).contains(name) && !overwrite) {
throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"OlapServiceImpl.ERROR_0004_ALREADY_EXISTS"), IOlapServiceException.Reason.ALREADY_EXISTS);
}
MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(getRepository());
helper.addOlap4jServer(name, className, URL, user, password, props);
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method addCatalog.
/**
* new method to pass the input stream directly from data access put and post schema
*
* @param schemaInputStream
* @param catalog
* @param overwrite
* @param acl catalog ACL
* @param pentahoSession
* @throws MondrianCatalogServiceException
*/
@Override
public synchronized void addCatalog(InputStream schemaInputStream, final MondrianCatalog catalog, final boolean overwrite, RepositoryFileAcl acl, final IPentahoSession pentahoSession) throws MondrianCatalogServiceException {
if (MondrianCatalogHelper.logger.isDebugEnabled()) {
// $NON-NLS-1$
MondrianCatalogHelper.logger.debug("addCatalog");
}
init(pentahoSession);
// check for existing dataSourceInfo+catalog
final boolean catalogExistsWithSameDatasource = catalogExists(catalog, pentahoSession);
if (catalogExistsWithSameDatasource && !overwrite) {
throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0004_ALREADY_EXISTS"), // $NON-NLS-1$
Reason.ALREADY_EXISTS);
}
// Checks if a catalog of the same name but with a different file
// path exists.
MondrianCatalog fileLocationCatalogTest = null;
for (MondrianCatalog currentCatalogCheck : getCatalogs(pentahoSession)) {
if (currentCatalogCheck.getName().equals(catalog.getName())) {
fileLocationCatalogTest = currentCatalogCheck;
break;
}
}
// compare the catalog names and throw exception if same and NOT ovewrite
final boolean catalogExistsWithDifferentDatasource;
try {
catalogExistsWithDifferentDatasource = fileLocationCatalogTest != null && definitionEquals(fileLocationCatalogTest.getDefinition(), "mondrian:/" + URLEncoder.encode(catalog.getName(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new MondrianCatalogServiceException(e);
}
if (catalogExistsWithDifferentDatasource && !overwrite) {
throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"MondrianCatalogHelper.ERROR_0004_ALREADY_EXISTS"), Reason.XMLA_SCHEMA_NAME_EXISTS);
}
MondrianCatalogRepositoryHelper helper = getMondrianCatalogRepositoryHelper();
try {
helper.addHostedCatalog(schemaInputStream, catalog.getName(), catalog.getDataSourceInfo());
} catch (Exception e) {
throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"MondrianCatalogHelper.ERROR_0008_ERROR_OCCURRED"), Reason.valueOf(e.getMessage()));
}
if (MondrianCatalogHelper.logger.isDebugEnabled()) {
MondrianCatalogHelper.logger.debug(// $NON-NLS-1$ //$NON-NLS-2$
"refreshing from dataSourcesConfig (" + dataSourcesConfig + ")");
}
try {
reInit(pentahoSession);
setAclFor(catalog.getName(), acl);
if (catalogExistsWithSameDatasource || catalogExistsWithDifferentDatasource) {
flushCacheForCatalog(catalog.getName(), pentahoSession);
}
} catch (MondrianException e) {
helper.deleteHostedCatalog(catalog.getName());
reInit(pentahoSession);
throw e;
}
}
use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method testAddCatalogWithException.
@Test(expected = MondrianException.class)
public void testAddCatalogWithException() {
initMondrianCatalogsCache();
MondrianCatalogHelper helperSpy = spy(helper);
doThrow(new MondrianException()).when(helperSpy).reInit(any(IPentahoSession.class));
IPentahoSession session = mock(IPentahoSession.class);
doNothing().when(helperSpy).init(session);
MondrianCatalog cat = createTestCatalog();
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
try {
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
} catch (MondrianException e) {
// verifying the repository rolled back and the cache reinitialized
verify(repositoryHelper, times(1)).deleteHostedCatalog(anyString());
verify(helperSpy, times(2)).reInit(any(IPentahoSession.class));
}
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
}
Aggregations