Skip to content

Commit 1591ff0

Browse files
hiberus-osmysticfall
authored andcommitted
Added option to include 'All member' when place hierarchy
1 parent 39a31fd commit 1591ff0

File tree

2 files changed

+82
-29
lines changed

2 files changed

+82
-29
lines changed

pivot4j-core/src/main/java/org/pivot4j/transform/PlaceHierarchiesOnAxes.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
* <li>The GUI will examine the result of the olap query to find out which
2222
* hierarchies are currently displayed on what axes. It will use
2323
* Axis.getHierarchies() for this.</li>
24-
*
24+
*
2525
* <li>Then it will find out what Hierarchies exist by calling
2626
* OlapModel.getDimensions() and Dimension.getHierarchies().</li>
27-
*
27+
*
2828
* <li>The Information will be presented to the user and he will be allowed to
2929
* change the mapping between axes and hierarchies.</li>
30-
*
30+
*
3131
* <li>For every Hierarchy that the user selected for display on an axis, the
3232
* GUI will call createMemberExpression().</li>
33-
*
33+
*
3434
* <li>For each axis the system will build the the array of memberExpressions
3535
* and call setAxis once.</li>
3636
* </ul>
@@ -45,9 +45,22 @@ public interface PlaceHierarchiesOnAxes extends Transform {
4545
* @param expandAllMember
4646
* If this flag is set and an "All" member is put onto an axis,
4747
* the children of the All member will be added as well.
48+
* @param includeAllMember
49+
* If this flag is set and an "All" member is put onto axis,
50+
* include Union (All + Children). If it's false, only includes Children.
4851
*/
49-
void placeHierarchies(Axis axis, List<Hierarchy> hierarchies,
50-
boolean expandAllMember);
52+
void placeHierarchies(Axis axis, List<Hierarchy> hierarchies, boolean expandAllMember, boolean includeAllMember);
53+
54+
/**
55+
* @param axis
56+
* The target axis
57+
* @param hierarchies
58+
* The hierarchies to put
59+
* @param expandAllMember
60+
* If this flag is set and an "All" member is put onto an axis,
61+
* the children of the All member will be added as well.
62+
*/
63+
void placeHierarchies(Axis axis, List<Hierarchy> hierarchies, boolean expandAllMember);
5164

5265
/**
5366
* @param axis
@@ -60,7 +73,24 @@ void placeHierarchies(Axis axis, List<Hierarchy> hierarchies,
6073
* than ZERO will put the hierarchy at the end of the axis.
6174
*/
6275
void addHierarchy(Axis axis, Hierarchy hierarchy, boolean expandAllMember,
63-
int position);
76+
int position);
77+
78+
/**
79+
* @param axis
80+
* The target axis
81+
* @param hierarchy
82+
* The hierarchy to add
83+
* @param expandAllMember
84+
*
85+
* @param includeAllMember
86+
* If this flag is set and an "All" member is put onto axis,
87+
* include Union (All + Children). If it's false, only includes Children.
88+
* @param position
89+
* The position index where to add the hierarchy. Any value less
90+
* than ZERO will put the hierarchy at the end of the axis.
91+
*/
92+
void addHierarchy(Axis axis, Hierarchy hierarchy, boolean expandAllMember, boolean includeAllMember,
93+
int position);
6494

6595
/**
6696
* @param axis
@@ -83,7 +113,7 @@ void addHierarchy(Axis axis, Hierarchy hierarchy, boolean expandAllMember,
83113
/**
84114
* Collects all hierarchies on a given axis in the result. If no hierarchies
85115
* are visible, it returns an empty list.
86-
*
116+
*
87117
* @param axis
88118
* the axis to use
89119
* @return A list of hierarchies

pivot4j-core/src/main/java/org/pivot4j/transform/impl/PlaceHierarchiesOnAxesImpl.java

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,26 @@ public class PlaceHierarchiesOnAxesImpl extends AbstractTransform implements
4242
* @param connection
4343
*/
4444
public PlaceHierarchiesOnAxesImpl(QueryAdapter queryAdapter,
45-
OlapConnection connection) {
45+
OlapConnection connection) {
4646
super(queryAdapter, connection);
4747
}
4848

49+
public void placeHierarchies(Axis axis, List<Hierarchy> hierarchies,
50+
boolean expandAllMember) {
51+
placeHierarchies(axis, hierarchies, expandAllMember, true);
52+
}
4953
/**
5054
* @see org.pivot4j.transform.PlaceHierarchiesOnAxes#placeHierarchies(org.olap4j.Axis,
51-
* java.util.List, boolean)
55+
* java.util.List, boolean, boolean)
5256
*/
5357
public void placeHierarchies(Axis axis, List<Hierarchy> hierarchies,
54-
boolean expandAllMember) {
58+
boolean expandAllMember, boolean includeAllMember) {
5559
QueryAdapter adapter = getQueryAdapter();
5660

5761
List<Exp> memberExpressions = new ArrayList<Exp>();
5862
for (Hierarchy hierarchy : hierarchies) {
5963
memberExpressions.add(createMemberExpression(hierarchy,
60-
expandAllMember));
64+
expandAllMember, includeAllMember));
6165
}
6266

6367
Quax quax = adapter.getQuax(axis);
@@ -100,7 +104,17 @@ public void placeHierarchies(Axis axis, List<Hierarchy> hierarchies,
100104
*/
101105
@Override
102106
public void addHierarchy(Axis axis, Hierarchy hierarchy,
103-
boolean expandAllMember, int position) {
107+
boolean expandAllMember, int position) {
108+
addHierarchy(axis, hierarchy, expandAllMember, true, position);
109+
}
110+
111+
/**
112+
* @see org.pivot4j.transform.PlaceHierarchiesOnAxes#addHierarchy(org.olap4j.Axis,
113+
* org.olap4j.metadata.Hierarchy, boolean, boolean, int)
114+
*/
115+
@Override
116+
public void addHierarchy(Axis axis, Hierarchy hierarchy,
117+
boolean expandAllMember, boolean includeAllMember, int position) {
104118
List<Hierarchy> hierarchies = findVisibleHierarchies(axis);
105119

106120
if (hierarchies.contains(hierarchy)) {
@@ -116,7 +130,7 @@ public void addHierarchy(Axis axis, Hierarchy hierarchy,
116130
hierarchies.add(position, hierarchy);
117131
}
118132

119-
placeHierarchies(axis, hierarchies, expandAllMember);
133+
placeHierarchies(axis, hierarchies, expandAllMember, includeAllMember);
120134
}
121135

122136
/**
@@ -199,7 +213,7 @@ public List<Hierarchy> findVisibleHierarchies(Axis axis) {
199213
* @return
200214
*/
201215
protected Exp createMemberExpression(Hierarchy hierarchy,
202-
boolean expandAllMember) {
216+
boolean expandAllMember, boolean includeAllMember) {
203217
// if the query does not contain the hierarchy,
204218
// just return the highest level
205219
QueryAdapter adapter = getQueryAdapter();
@@ -209,7 +223,7 @@ protected Exp createMemberExpression(Hierarchy hierarchy,
209223
if (quax == null) {
210224
adapter.getCurrentMdx(true);
211225
// the hierarchy was not found on any axis
212-
return topLevelMembers(hierarchy, expandAllMember);
226+
return topLevelMembers(hierarchy, expandAllMember, includeAllMember);
213227
// return top level members of the hierarchy
214228
}
215229

@@ -222,12 +236,12 @@ protected Exp createMemberExpression(Hierarchy hierarchy,
222236

223237
/**
224238
* TODO Merge with {@link QuaxUtil#topLevelMembers(Hierarchy, boolean)}
225-
*
239+
*
226240
* @param hierarchy
227241
* @param expandAllMember
228242
* @return
229243
*/
230-
protected Exp topLevelMembers(Hierarchy hierarchy, boolean expandAllMember) {
244+
protected Exp topLevelMembers(Hierarchy hierarchy, boolean expandAllMember, boolean includeAllMember) {
231245
try {
232246
if (hierarchy.hasAll()) {
233247
// an "All" member is present -get it
@@ -260,20 +274,29 @@ protected Exp topLevelMembers(Hierarchy hierarchy, boolean expandAllMember) {
260274

261275
// must expand
262276
// create Union({AllMember}, AllMember.children)
263-
Exp allExp = new MemberExp(allMember);
277+
if (includeAllMember) {
278+
Exp allExp = new MemberExp(allMember);
264279

265-
FunCall allSet = new FunCall("{}", Syntax.Braces);
266-
allSet.getArgs().add(allExp);
280+
FunCall allSet = new FunCall("{}", Syntax.Braces);
281+
allSet.getArgs().add(allExp);
267282

268-
FunCall mAllChildren = new FunCall("Children",
269-
Syntax.Property);
270-
mAllChildren.getArgs().add(allExp);
283+
FunCall mAllChildren = new FunCall("Children",
284+
Syntax.Property);
285+
mAllChildren.getArgs().add(allExp);
271286

272-
FunCall union = new FunCall("Union", Syntax.Function);
273-
union.getArgs().add(allSet);
274-
union.getArgs().add(mAllChildren);
287+
FunCall union = new FunCall("Union", Syntax.Function);
288+
union.getArgs().add(allSet);
289+
union.getArgs().add(mAllChildren);
275290

276-
return union;
291+
return union;
292+
} else {
293+
Exp allExp = new MemberExp(allMember);
294+
295+
FunCall mAllChildren = new FunCall("Children",
296+
Syntax.Property);
297+
mAllChildren.getArgs().add(allExp);
298+
return mAllChildren;
299+
}
277300
}
278301
}
279302

@@ -304,4 +327,4 @@ protected Exp topLevelMembers(Hierarchy hierarchy, boolean expandAllMember) {
304327
throw new PivotException(e);
305328
}
306329
}
307-
}
330+
}

0 commit comments

Comments
 (0)