Skip to content

Commit

Permalink
MONDRIAN/3.1: Change rules for generating captions and descriptions of
Browse files Browse the repository at this point in the history
    hierarchies in shared dimensions that are used multiple times within the
    same cube. If the <DimensionUsage> has a name and that name is different
    from the name of the shared dimension, prefix the caption and description of
    the hierarchy with the caption of the dimension usage (which can be
    specified directly, or defaults to the name of the dimension usage).

[git-p4: depot-paths = "//open/mondrian-release/3.1/": change = 13226]
  • Loading branch information
julianhyde committed Dec 11, 2009
1 parent d7f34fb commit bbb6bff
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 20 deletions.
61 changes: 44 additions & 17 deletions src/main/mondrian/rolap/RolapCubeHierarchy.java
Expand Up @@ -61,8 +61,8 @@ public RolapCubeHierarchy(
super(
dimension,
subName,
rolapHierarchy.getCaption(),
rolapHierarchy.getDescription(),
applyPrefix(cubeDim, rolapHierarchy.getCaption()),
applyPrefix(cubeDim, rolapHierarchy.getDescription()),
rolapHierarchy.hasAll(),
rolapHierarchy.getAnnotationMap());

Expand Down Expand Up @@ -137,6 +137,48 @@ public RolapCubeHierarchy(
}
}

/**
* Applies a prefix to a caption or description of a hierarchy in a shared
* dimension. Ensures that if a dimension is used more than once in the same
* cube then the hierarchies are distinguishable.
*
* <p>For example, if the [Time] dimension is imported as [Order Time] and
* [Ship Time], then the [Time].[Weekly] hierarchy would have caption
* "Order Time.Weekly caption" and description "Order Time.Weekly
* description".
*
* <p>If the dimension usage has a caption, it overrides.
*
* <p>If the dimension usage has a null name, or the name is the same
* as the dimension, and no caption, then no prefix is applied.
*
* @param cubeDim Cube dimension (maybe a usage of a shared dimension)
* @param caption Caption or description
* @return Caption or description, possibly prefixed by dimension role name
*/
private static String applyPrefix(
MondrianDef.CubeDimension cubeDim,
String caption)
{
if (caption == null) {
return null;
}
if (cubeDim instanceof MondrianDef.DimensionUsage) {
final MondrianDef.DimensionUsage dimensionUsage =
(MondrianDef.DimensionUsage) cubeDim;
if (dimensionUsage.name != null
&& !dimensionUsage.name.equals(dimensionUsage.source))
{
if (dimensionUsage.caption != null) {
return dimensionUsage.caption + "." + caption;
} else {
return dimensionUsage.name + "." + caption;
}
}
}
return caption;
}

public String getAllMemberName() {
return rolapHierarchy.getAllMemberName();
}
Expand Down Expand Up @@ -297,21 +339,6 @@ public RolapCubeMember getAllMember() {
return currentAllMember;
}

/**
* Returns the display name of this catalog element.
* If no caption is defined, the name is returned.
*/
public String getCaption() {
return rolapHierarchy.getCaption();
}

/**
* Sets the display name of this catalog element.
*/
public void setCaption(String caption) {
rolapHierarchy.setCaption(caption);
}

void setMemberReader(MemberReader memberReader) {
rolapHierarchy.setMemberReader(memberReader);
}
Expand Down
43 changes: 40 additions & 3 deletions testsrc/main/mondrian/test/SchemaTest.java
Expand Up @@ -2590,7 +2590,9 @@ public void testCaptionDescriptionAndAnnotation() {
+ " caption=\"Time shared caption\"\n"
+ " description=\"Time shared description\">\n"
+ " <Annotations><Annotation name=\"a\">Time shared</Annotation></Annotations>\n"
+ " <Hierarchy hasAll=\"false\" primaryKey=\"time_id\">\n"
+ " <Hierarchy hasAll=\"false\" primaryKey=\"time_id\"\n"
+ " caption=\"Time shared hierarchy caption\"\n"
+ " description=\"Time shared hierarchy description\">\n"
+ " <Table name=\"time_by_day\"/>\n"
+ " <Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\"\n"
+ " levelType=\"TimeYears\"/>\n"
Expand Down Expand Up @@ -2690,8 +2692,6 @@ public void testCaptionDescriptionAndAnnotation() {
assertEquals("Canada", member.getName());
assertEquals("Canada", member.getCaption());
assertNull(member.getDescription());
final Map<String, Object> emptyAnnotationMap =
Collections.<String, Object>emptyMap();
checkAnnotations(member.getAnnotationMap());

// All member. Caption defaults to name; description is null.
Expand All @@ -2715,6 +2715,26 @@ public void testCaptionDescriptionAndAnnotation() {
assertEquals("Time usage caption", timeDimension.getCaption());
checkAnnotations(timeDimension.getAnnotationMap(), "a", "Time usage");

// Time1 is a usage of a shared dimension Time.
// Now look at the hierarchy usage within that dimension usage.
// Because the dimension usage has a name, use that as a prefix for
// name, caption and description of the hierarchy usage.
final Hierarchy timeHierarchy = timeDimension.getHierarchies()[0];
// The hierarchy in the shared dimension does not have a name, so the
// hierarchy usage inherits the name of the dimension usage, Time1.
assertEquals("Time1", timeHierarchy.getName());
// The description is prefixed by the dimension usage name.
assertEquals(
"Time usage caption.Time shared hierarchy description",
timeHierarchy.getDescription());
// The hierarchy caption is prefixed by the caption of the dimension
// usage.
assertEquals(
"Time usage caption.Time shared hierarchy caption",
timeHierarchy.getCaption());
// No annotations.
checkAnnotations(timeHierarchy.getAnnotationMap());

// the second time dimension does not overrides caption and description
final Dimension time2Dimension = cube.getDimensions()[3];
assertEquals("Time2", time2Dimension.getName());
Expand All @@ -2723,6 +2743,23 @@ public void testCaptionDescriptionAndAnnotation() {
assertEquals("Time shared caption", time2Dimension.getCaption());
checkAnnotations(time2Dimension.getAnnotationMap());

final Hierarchy time2Hierarchy = time2Dimension.getHierarchies()[0];
// The hierarchy in the shared dimension does not have a name, so the
// hierarchy usage inherits the name of the dimension usage, Time2.
assertEquals("Time2", time2Hierarchy.getName());
// The description is prefixed by the dimension usage name (because
// dimension usage has no caption).
assertEquals(
"Time2.Time shared hierarchy description",
time2Hierarchy.getDescription());
// The hierarchy caption is prefixed by the dimension usage name
// (because the dimension usage has no caption.
assertEquals(
"Time2.Time shared hierarchy caption",
time2Hierarchy.getCaption());
// No annotations.
checkAnnotations(time2Hierarchy.getAnnotationMap());

final Dimension measuresDimension = cube.getDimensions()[0];
final Hierarchy measuresHierarchy =
measuresDimension.getHierarchies()[0];
Expand Down

0 comments on commit bbb6bff

Please sign in to comment.