Skip to content

Commit

Permalink
MONDRIAN: [MONDRIAN-1079] Allow turning off drillthrough.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 14987]
  • Loading branch information
lucboudreau committed Mar 2, 2012
1 parent 607f71d commit b9c58c5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/mondrian/olap/MondrianProperties.xml
Expand Up @@ -784,6 +784,16 @@ unrecognized action is specified)</li>
<Type>String</Type>
<Default>OFF</Default>
</PropertyDefinition>
<PropertyDefinition>
<Name>EnableDrillThrough</Name>
<Path>mondrian.drillthrough.enable</Path>
<Description>
If disabled, Mondrian will throw an exception if someone attempts to
perform a drillthrough of any kind.
</Description>
<Type>boolean</Type>
<Default>true</Default>
</PropertyDefinition>
<PropertyDefinition>
<Name>EnableTotalCount</Name>
<Path>mondrian.xmla.drillthroughTotalCount.enable</Path>
Expand Down
4 changes: 4 additions & 0 deletions src/main/mondrian/resource/MondrianResource.xml
Expand Up @@ -280,6 +280,10 @@
<text>Don''t know how to rollup aggregator ''avg'' because the cube doesn''t contain at least one ''count'' and one ''sum'' measures based on the same column.</text>
</exception>

<exception id="350650" name="DrillthroughDisabled">
<text>Can''t perform drillthrough operations because ''{0}'' is set to false.</text>
</exception>bacon

<!-- ====================================================================== -->
<!-- Connectivity errors -->

Expand Down
14 changes: 14 additions & 0 deletions src/main/mondrian/rolap/RolapCell.java
Expand Up @@ -13,6 +13,7 @@
import mondrian.olap.*;
import mondrian.olap.fun.AggregateFunDef;
import mondrian.olap.fun.SetFunDef;
import mondrian.resource.MondrianResource;
import mondrian.rolap.agg.*;
import mondrian.server.*;
import mondrian.server.monitor.SqlStatementEvent;
Expand Down Expand Up @@ -103,6 +104,14 @@ public String getDrillThroughSQL(
List<Exp> fields,
boolean extendedContext)
{
if (!MondrianProperties.instance()
.EnableDrillThrough.get())
{
throw MondrianResource.instance()
.DrillthroughDisabled.ex(
MondrianProperties.instance()
.EnableDrillThrough.getPath());
}
final Member[] currentMembers = getMembersForDrillThrough();
// Create a StarPredicate to represent the compound slicer
// (if necessary)
Expand Down Expand Up @@ -305,6 +314,11 @@ private StarPredicate buildDrillthroughSlicerPredicate(
* @return true if can drill through
*/
public boolean canDrillThrough() {
if (!MondrianProperties.instance()
.EnableDrillThrough.get())
{
return false;
}
// get current members
final Member[] currentMembers = getMembersForDrillThrough();
if (containsCalcMembers(currentMembers)) {
Expand Down
35 changes: 35 additions & 0 deletions testsrc/main/mondrian/test/DrillThroughTest.java
Expand Up @@ -12,6 +12,7 @@
package mondrian.test;

import mondrian.olap.*;
import mondrian.resource.MondrianResource;
import mondrian.rolap.*;
import mondrian.spi.Dialect;

Expand Down Expand Up @@ -1189,6 +1190,40 @@ public void testDrillThroughMultiPositionCompoundSlicer() {
}
getTestContext().assertSqlEquals(expectedSql, sql, 27402);
}

public void testDrillthroughDisable() {
propSaver.set(
MondrianProperties.instance().EnableDrillThrough,
true);
Result result =
executeQuery(
"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\n"
+ " {[Product].[All Products]} ON ROWS\n"
+ "FROM [Sales]\n"
+ "WHERE {[Time].[1997].[Q1], [Time].[1997].[Q2]}");
Cell cell = result.getCell(new int[]{0, 0});
assertTrue(cell.canDrillThrough());

propSaver.set(
MondrianProperties.instance().EnableDrillThrough,
false);
result =
executeQuery(
"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\n"
+ " {[Product].[All Products]} ON ROWS\n"
+ "FROM [Sales]\n"
+ "WHERE {[Time].[1997].[Q1], [Time].[1997].[Q2]}");
cell = result.getCell(new int[]{0, 0});
assertFalse(cell.canDrillThrough());
try {
cell.getDrillThroughSQL(false);
fail();
} catch (MondrianException e) {
assertTrue(
e.getMessage().contains(
"Can't perform drillthrough operations because"));
}
}
}

// End DrillThroughTest.java

0 comments on commit b9c58c5

Please sign in to comment.