use of mondrian.olap.MondrianException in project pentaho-platform by pentaho.
the class PentahoXmlaServletTest method testInvalidDataSourceInfo.
@Test
public void testInvalidDataSourceInfo() throws Exception {
ISecurityHelper securityHelper = mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(securityHelper);
when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<DataSources>\n" + "<DataSource>\n" + "<DataSourceName>Pentaho</DataSourceName>\n" + "<DataSourceDescription>Pentaho BI Platform Datasources</DataSourceDescription>\n" + "<URL>http://localhost:8080/pentaho/Xmla</URL>\n" + "<DataSourceInfo>Provider=mondrian</DataSourceInfo>\n" + "<ProviderName>PentahoXMLA</ProviderName>\n" + "<ProviderType>MDP</ProviderType>\n" + "<AuthenticationMode>Unauthenticated</AuthenticationMode>\n" + "<Catalogs>\n" + "<Catalog name=\"SampleData\">\n" + "<DataSourceInfo></DataSourceInfo>\n" + "<Definition>mondrian:/SampleData</Definition>\n" + "</Catalog>\n" + "</Catalogs>\n" + "</DataSource>\n" + "</DataSources>\n");
try {
// should throw
new PentahoXmlaServlet().makeContentFinder("fakeurl").getContent();
} catch (MondrianException e) {
assertTrue(e.getCause().getCause().getMessage().contains("DataSourceInfo not defined for SampleData"));
return;
}
fail("Did not throw expected exception.");
}
use of mondrian.olap.MondrianException in project pentaho-platform by pentaho.
the class MondrianModelComponent method getInitialQuery.
public static String getInitialQuery(final Properties properties, final String cubeName, IPentahoSession session) throws Throwable {
// Apply any properties for this catalog specified in datasource.xml
IMondrianCatalogService mondrianCatalogService = PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession());
List<MondrianCatalog> catalogs = mondrianCatalogService.listCatalogs(PentahoSessionHolder.getSession(), true);
String propCat = properties.getProperty(RolapConnectionProperties.Catalog.name());
for (MondrianCatalog cat : catalogs) {
if (cat.getDefinition().equalsIgnoreCase(propCat)) {
Util.PropertyList connectProperties = Util.parseConnectString(cat.getDataSourceInfo());
Iterator<Pair<String, String>> iter = connectProperties.iterator();
while (iter.hasNext()) {
Pair<String, String> pair = iter.next();
if (// Only set if not set already
!properties.containsKey(pair.getKey())) {
properties.put(pair.getKey(), pair.getValue());
}
}
break;
}
}
MDXConnection mdxConnection = (MDXConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, properties, session, null);
// mdxConnection.setProperties( properties );
Connection connection = mdxConnection.getConnection();
if (connection == null) {
Logger.error("MondrianModelComponent", Messages.getInstance().getErrorString("MondrianModel.ERROR_0001_INVALID_CONNECTION", // $NON-NLS-1$ //$NON-NLS-2$
properties.toString()));
return null;
}
try {
return MondrianModelComponent.getInitialQuery(connection, cubeName);
} catch (Throwable t) {
if (t instanceof MondrianException) {
// pull the cause out, otherwise it never gets logged
Throwable cause = ((MondrianException) t).getCause();
if (cause != null) {
throw cause;
} else {
throw t;
}
} else {
throw t;
}
}
}
use of mondrian.olap.MondrianException 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 mondrian.olap.MondrianException 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);
}
use of mondrian.olap.MondrianException in project mondrian by pentaho.
the class SegmentLoader method loadImpl.
private Map<Segment, SegmentWithData> loadImpl(int cellRequestCount, List<GroupingSet> groupingSets, List<StarPredicate> compoundPredicateList) {
SqlStatement stmt = null;
GroupingSetsList groupingSetsList = new GroupingSetsList(groupingSets);
RolapStar.Column[] defaultColumns = groupingSetsList.getDefaultColumns();
final Map<Segment, SegmentWithData> segmentMap = new HashMap<Segment, SegmentWithData>();
Throwable throwable = null;
try {
int arity = defaultColumns.length;
SortedSet<Comparable>[] axisValueSets = getDistinctValueWorkspace(arity);
stmt = createExecuteSql(cellRequestCount, groupingSetsList, compoundPredicateList);
if (stmt == null) {
// Nothing to do. We're done here.
return segmentMap;
}
boolean[] axisContainsNull = new boolean[arity];
RowList rows = processData(stmt, axisContainsNull, axisValueSets, groupingSetsList);
boolean sparse = setAxisDataAndDecideSparseUse(axisValueSets, axisContainsNull, groupingSetsList, rows);
final Map<BitKey, GroupingSetsList.Cohort> groupingDataSetsMap = createDataSetsForGroupingSets(groupingSetsList, sparse, rows.getTypes().subList(arity, rows.getTypes().size()));
loadDataToDataSets(groupingSetsList, rows, groupingDataSetsMap);
setDataToSegments(groupingSetsList, groupingDataSetsMap, segmentMap);
return segmentMap;
} catch (Throwable e) {
throwable = e;
if (stmt == null) {
throw new MondrianException(e);
}
throw stmt.handle(e);
} finally {
if (stmt != null) {
stmt.close();
}
setFailOnStillLoadingSegments(segmentMap, groupingSetsList, throwable);
}
}
Aggregations