001/* 002// $Id: RollUpLevelTransform.java 482 2012-01-05 23:27:27Z jhyde $ 003// 004// Licensed to Julian Hyde under one or more contributor license 005// agreements. See the NOTICE file distributed with this work for 006// additional information regarding copyright ownership. 007// 008// Julian Hyde licenses this file to you under the Apache License, 009// Version 2.0 (the "License"); you may not use this file except in 010// compliance with the License. You may obtain a copy of the License at: 011// 012// http://www.apache.org/licenses/LICENSE-2.0 013// 014// Unless required by applicable law or agreed to in writing, software 015// distributed under the License is distributed on an "AS IS" BASIS, 016// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017// See the License for the specific language governing permissions and 018// limitations under the License. 019*/ 020package org.olap4j.transform; 021 022import org.olap4j.Axis; 023import org.olap4j.CellSet; 024import org.olap4j.mdx.ParseTreeNode; 025import org.olap4j.metadata.Member; 026 027/** 028 * Roll-up level transformation 029 * 030 * <p>Description: Replaces a member at a specific position on an axis by all 031 * the members of its parent's level. The member to roll-up is identified from 032 * a CellSet with the axis, positionOrdinalInAxis and memberOrdinalInPosition 033 * arguments. 034 * 035 * <p>Example of use: the user clicks on a member in a crosstab axis, in order 036 * to roll up to the members of the upper level. 037 * 038 * <p>Applicability: this transform is applicable only to members in a query 039 * that are have a parent. (Note: how would this work in parent-child 040 * hierarchies?) 041 * 042 * @author etdub 043 * @version $Id: RollUpLevelTransform.java 482 2012-01-05 23:27:27Z jhyde $ 044 * @since Aug 4, 2008 045 */ 046public class RollUpLevelTransform extends AxisTransform { 047 048 // private final int positionOrdinalInAxis; 049 // private final int memberOrdinalInPosition; 050 // private final CellSet cellSet; 051 052 // private final Position positionToDrill; 053 private final Member memberToDrill; 054 // private final List<Member> pathToMember; 055 056 /** 057 * ctor 058 * 059 * @param axis 060 * @param positionOrdinalInAxis 061 * @param memberOrdinalInPosition 062 * @param cellSet 063 */ 064 public RollUpLevelTransform( 065 Axis axis, 066 int positionOrdinalInAxis, 067 int memberOrdinalInPosition, 068 CellSet cellSet) 069 { 070 super(axis); 071 072 // this.positionOrdinalInAxis = positionOrdinalInAxis; 073 // this.memberOrdinalInPosition = memberOrdinalInPosition; 074 // this.cellSet = cellSet; 075 076 // Position positionToDrill = 077 // TransformUtil.getPositionFromCellSet(axis, positionOrdinalInAxis, 078 // cellSet); 079 memberToDrill = TransformUtil.getMemberFromCellSet( 080 axis, positionOrdinalInAxis, memberOrdinalInPosition, cellSet); 081 // pathToMember = getPathToMember(positionToDrill, 082 // memberOrdinalInPosition); 083 } 084 085 public String getName() { 086 return "Roll member up a level"; 087 } 088 089 public String getDescription() { 090 return "Replaces the member expression on the axis by all members " 091 + "on its parent level"; 092 } 093 094 @Override 095 protected ParseTreeNode processAxisExp(ParseTreeNode exp) { 096 // FIXME: for now only 1 dimension on an axis is supported, 097 // (naive implementation only used for proof of concept) 098 return MdxHelper.makeSetCallNode( 099 MdxHelper.makeMembersCallNode( 100 MdxHelper.makeLevelCallNode( 101 MdxHelper.makeParentCallNode( 102 MdxHelper.makeMemberNode(memberToDrill))))); 103 } 104 105} 106 107// End RollUpLevelTransform.java