def parse_drilldown(cube, drilldown)
      # check if the drilldown is a named set
      named_sets = cube.named_sets
      if (ns = named_sets.find { |ns| ns.name == drilldown })
        return ns
      end

      begin
        s = org.olap4j.mdx.IdentifierNode.parseIdentifier(drilldown).getSegmentList
      rescue Java::JavaLang::IllegalArgumentException
        error!("Illegal drilldown specification: #{drilldown}", 400)
      end

      if s.size > 3 || s.map(&:quoting).any? { |q| q.name == 'KEY' }
        error!("Illegal drilldown specification: #{drilldown}", 400)
        return
      end

      dimension = get_dimension(cube, s.first.name)
      hierarchy = dimension.hierarchies.first
      level = hierarchy.levels[hierarchy.has_all? ? 1 : 0]

      if s.size > 1
        if s.size == 3 # 3 parts, means that a hierarchy was provided
          hierarchy = dimension.hierarchies.find { |h_| h_.name == s[1].name }
          if hierarchy.nil?
            error!("Hierarchy `#{s[1].name}` does not exist in dimension #{dimension.name}", 404)
          end
        end
        level = hierarchy.levels.find { |l_| l_.name == s[s.size - 1].name }
        if level.nil?
          error!("Level `#{s[1].name}` does not exist in #{dimension.name}", 404)
        end
      end

      level
    end
def parse_drilldown(cube, drilldown)
      # check if the drilldown is a named set
      named_sets = cube.named_sets
      if (ns = named_sets.find { |ns| ns.name == drilldown })
        return ns
      end

      begin
        s = org.olap4j.mdx.IdentifierNode.parseIdentifier(drilldown).getSegmentList
      rescue Java::JavaLang::IllegalArgumentException
        error!("Illegal drilldown specification: #{drilldown}", 400)
      end

      if s.size > 3 || s.map(&:quoting).any? { |q| q.name == 'KEY' }
        error!("Illegal drilldown specification: #{drilldown}", 400)
        return
      end

      dimension = get_dimension(cube, s.first.name)
      hierarchy = dimension.hierarchies.first
      level = hierarchy.levels[hierarchy.has_all? ? 1 : 0]

      if s.size > 1
        if s.size == 3 # 3 parts, means that a hierarchy was provided
          hierarchy = dimension.hierarchies.find { |h_| h_.name == s[1].name }
          if hierarchy.nil?
            error!("Hierarchy `#{s[1].name}` does not exist in dimension #{dimension.name}", 404)
          end
        end
        level = hierarchy.levels.find { |l_| l_.name == s[s.size - 1].name }
        if level.nil?
          error!("Level `#{s[1].name}` does not exist in #{dimension.name}", 404)
        end
      end

      level
    end
Parses a drilldown specification
 XXX TODO write doc