예제 #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);
  }
예제 #2
0
  public List<SaikuMember> getResultMetadataMembers(
      String queryName,
      boolean preferResult,
      String dimensionName,
      String hierarchyName,
      String levelName) {
    IQuery query = getIQuery(queryName);
    CellSet cs = query.getCellset();
    List<SaikuMember> members = new ArrayList<SaikuMember>();
    Set<Level> levels = new HashSet<Level>();

    if (cs != null && preferResult) {
      for (CellSetAxis axis : cs.getAxes()) {
        int posIndex = 0;
        for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) {
          if (h.getUniqueName().equals(hierarchyName)) {
            log.debug("Found hierarchy in the result: " + hierarchyName);
            if (h.getLevels().size() == 1) {
              break;
            }
            Set<Member> mset = new HashSet<Member>();
            for (Position pos : axis.getPositions()) {
              Member m = pos.getMembers().get(posIndex);
              if (!m.getLevel().getLevelType().equals(Type.ALL)) {
                levels.add(m.getLevel());
              }
              if (m.getLevel().getUniqueName().equals(levelName)) {
                mset.add(m);
              }
            }

            members = ObjectUtil.convertMembers(mset);
            Collections.sort(members, new SaikuUniqueNameComparator());

            break;
          }
          posIndex++;
        }
      }
      log.debug("Found members in the result: " + members.size());
    }
    if (cs == null || !preferResult || members.size() == 0 || levels.size() == 1) {
      members =
          olapDiscoverService.getLevelMembers(
              query.getSaikuCube(), dimensionName, hierarchyName, levelName);
    }

    return members;
  }
예제 #3
0
 /**
  * Computes a description of an axis.
  *
  * @param axis Axis
  * @return Description of axis
  */
 private AxisInfo computeAxisInfo(final CellSetAxis axis) {
   if (axis == null) {
     return new AxisInfo(0);
   }
   final AxisInfo axisInfo = new AxisInfo(axis.getAxisMetaData().getHierarchies().size());
   int p = -1;
   for (final Position position : axis.getPositions()) {
     ++p;
     int k = -1;
     for (final Member member : position.getMembers()) {
       ++k;
       final AxisOrdinalInfo axisOrdinalInfo = axisInfo.ordinalInfos.get(k);
       if (!axisOrdinalInfo.getDepths().contains(member.getDepth())) {
         axisOrdinalInfo.getDepths().add(member.getDepth());
         axisOrdinalInfo.addLevel(member.getDepth(), member.getLevel());
         Collections.sort(axisOrdinalInfo.depths);
       }
     }
   }
   return axisInfo;
 }