Exemple #1
0
  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);
  }
 /**
  * Prints a cell set.
  *
  * @param cellSet Cell set
  * @param pw Writer
  */
 private static void print(CellSet cellSet, PrintWriter pw) {
   pw.println("Axis #0:");
   printAxis(pw, cellSet.getFilterAxis());
   final List<CellSetAxis> axes = cellSet.getAxes();
   final int axisCount = axes.size();
   for (int i = 0; i < axisCount; i++) {
     CellSetAxis axis = axes.get(i);
     pw.println("Axis #" + (i + 1) + ":");
     printAxis(pw, axis);
   }
   // Usually there are 3 axes: {filter, columns, rows}. Position is a
   // {column, row} pair. We call printRows with axis=2. When it
   // recurses to axis=-1, it prints.
   List<Integer> pos = new ArrayList<Integer>(axisCount);
   for (int i = 0; i < axisCount; i++) {
     pos.add(-1);
   }
   if (axisCount == 0) {
     printCell(cellSet, pw, pos);
   } else {
     printRows(cellSet, pw, axisCount - 1, pos);
   }
 }