コード例 #1
0
ファイル: OlapQueryService.java プロジェクト: ra2085/saiku
  public SaikuFilter getFilter(
      String queryName,
      String filtername,
      String dimensionName,
      String hierarchyName,
      String levelName) {
    IQuery query = getIQuery(queryName);
    CellSet cs = query.getCellset();
    List<SimpleCubeElement> members = new ArrayList<SimpleCubeElement>();
    SimpleCubeElement dimension = null;
    SimpleCubeElement hierarchy = null;
    Set<MetadataElement> mset = new HashSet<MetadataElement>();

    if (cs != null) {
      List<CellSetAxis> axes = new ArrayList<CellSetAxis>();
      axes.addAll(cs.getAxes());
      axes.add(cs.getFilterAxis());
      for (CellSetAxis axis : axes) {
        int posIndex = 0;
        for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) {
          if (h.getName().equals(hierarchyName)) {
            if (hierarchy == null) {
              hierarchy = new SimpleCubeElement(h.getName(), h.getUniqueName(), h.getCaption());
              Dimension d = h.getDimension();
              dimension = new SimpleCubeElement(d.getName(), d.getUniqueName(), d.getCaption());
            }
            if (h.getLevels().size() == 1) {
              break;
            }

            for (Position pos : axis.getPositions()) {
              Member m = pos.getMembers().get(posIndex);
              if (m.getLevel().getName().equals(levelName)) {
                mset.add(m);
              }
            }
            break;
          }
          posIndex++;
        }
      }
      if (mset.size() == 0) {
        QueryDimension qd = query.getDimension(dimensionName);
        if (qd != null && qd.getAxis().getLocation() != null) {
          for (Selection sel : qd.getInclusions()) {
            if ((sel.getRootElement() instanceof Member)) {
              Member m = ((Member) sel.getRootElement());
              if (m.getLevel().getName().equals(levelName)) {
                mset.add(m);
              }
            }
          }
        }
      }
      members = ObjectUtil.convert2Simple(mset);
      Collections.sort(members, new SaikuUniqueNameComparator());
      log.debug("Create Filters: Found members in the result or query: " + members.size());
    }
    return new SaikuFilter(filtername, null, dimension, hierarchy, members);
  }
コード例 #2
0
ファイル: FilterHandler.java プロジェクト: rcpgithub/pivot4j
  /** @return the filterNode */
  public TreeNode getFilterNode() {
    if (model != null && model.isInitialized()) {
      Hierarchy hierarchy = getHierarchy();

      if (filterNode == null && hierarchy != null) {
        this.filterNode = new DefaultTreeNode();

        filterNode.setExpanded(true);

        List<Member> members;
        boolean isMeasure;

        try {
          members = hierarchy.getRootMembers();
          isMeasure = hierarchy.getDimension().getDimensionType() == Type.MEASURE;
        } catch (OlapException e) {
          throw new FacesException(e);
        }

        for (Member member : members) {
          if (isMeasure && !member.isVisible()) {
            continue;
          }

          MemberNode node = new MemberNode(member);

          node.setNodeFilter(this);
          node.setExpanded(true);
          node.setSelectable(true);
          node.setSelected(isSelected(member));

          filterNode.getChildren().add(node);
        }

        List<TreeNode> initialSelection =
            ((DefaultTreeNode) filterNode)
                .collectNodes(
                    new NodeCollector() {

                      @Override
                      public boolean collectNode(TreeNode node) {
                        return node.isSelected();
                      }

                      @Override
                      public boolean searchNode(TreeNode node) {
                        return node.isExpanded();
                      }
                    });

        this.selection = initialSelection.toArray(new TreeNode[initialSelection.size()]);
      }
    } else {
      this.filterNode = null;
    }

    return filterNode;
  }
コード例 #3
0
 public List<Hierarchy> getHierarchies() {
   if (queryAxis.getAxisOrdinal().isFilter()) {
     // Slicer contains all dimensions not mentioned on other axes.
     // The list contains the default hierarchy of
     // each dimension not already in the slicer or in another axes.
     Set<Dimension> dimensionSet = new HashSet<Dimension>();
     for (CellSetAxisMetaData cellSetAxisMetaData : cellSetMetaData.getAxesMetaData()) {
       for (Hierarchy hierarchy : cellSetAxisMetaData.getHierarchies()) {
         dimensionSet.add(hierarchy.getDimension());
       }
     }
     List<Hierarchy> hierarchyList = new ArrayList<Hierarchy>();
     for (Dimension dimension : cellSetMetaData.getCube().getDimensions()) {
       if (dimensionSet.add(dimension)) {
         hierarchyList.add(dimension.getDefaultHierarchy());
       }
     }
     // In case a dimension has multiple hierarchies, return the
     // declared type of the slicer expression. For example, if the
     // WHERE clause contains [Time].[Weekly].[1997].[Week 6], the
     // slicer should contain [Time].[Weekly] not the default hierarchy
     // [Time].
     for (Hierarchy hierarchy : getHierarchiesNonFilter()) {
       if (hierarchy.getDimension().getHierarchies().size() == 1) {
         continue;
       }
       for (int i = 0; i < hierarchyList.size(); i++) {
         Hierarchy hierarchy1 = hierarchyList.get(i);
         if (hierarchy1.getDimension().equals(hierarchy.getDimension())
             && hierarchy1 != hierarchy) {
           hierarchyList.set(i, hierarchy);
         }
       }
     }
     return hierarchyList;
   } else {
     return getHierarchiesNonFilter();
   }
 }