Package org.saiku.olap.query

Examples of org.saiku.olap.query.IQuery


  }

  @NotNull
  public SaikuTag createTag(String queryName, String tagName, @NotNull List<List<Integer>> cellPositions) {
    try {
      IQuery query = getIQuery(queryName);
      CellSet cs = query.getCellset();
      List<SaikuTuple> tuples = new ArrayList<SaikuTuple>();
      List<SimpleCubeElement> dimensions = new ArrayList<SimpleCubeElement>();
      for (List<Integer> cellPosition : cellPositions) {
        List<Member> members = new ArrayList<Member>();
        for (int i = 0; i < cellPosition.size(); i++) {
View Full Code Here


  }


  public IQuery zoomIn(String queryName, @Nullable List<List<Integer>> realPositions) {
    try {
      IQuery query = getIQuery(queryName);
      CellSet cs = query.getCellset();
      if (cs == null) {
        throw new SaikuServiceException("Cannot zoom in if last cellset is null");
      }
      if (realPositions == null || realPositions.size() == 0) {
        throw new SaikuServiceException("Cannot zoom in if zoom in position is empty");
      }

      Map<Dimension, Set<Member>> memberSelection = new HashMap<Dimension, Set<Member>>();
      for (List<Integer> position : realPositions) {
        for (int k = 0; k < position.size(); k++) {
          Position p = cs.getAxes().get(k).getPositions().get(position.get(k));
          List<Member> members = p.getMembers();
          for (Member m : members) {
            Dimension d = m.getDimension();
            if (!memberSelection.containsKey(d)) {
              Set<Member> mset = new HashSet<Member>();
              memberSelection.put(d, mset);
            }
            memberSelection.get(d).add(m);
          }
        }
      }

      for (Dimension d : memberSelection.keySet()) {
        QueryDimension a = query.getDimension(d.getName());
        a.clearInclusions();
        for (Member m : memberSelection.get(d)) {
          a.include(m);
        }
      }
View Full Code Here

  public SaikuFilter getFilter(String queryName, String filtername, String dimensionName, String hierarchyName,
                               String levelName) {
    try {


      IQuery query = getIQuery(queryName);
      CellSet cs = query.getCellset();
      if (cs == null) {
        throw new SaikuServiceException("Cannot get filter of result if last cellset is null");
      }

      CellDataSet result = OlapResultSetUtil.cellSet2Matrix(cs, query.getFormatter());

      List<SimpleCubeElement> members = new ArrayList<SimpleCubeElement>();
      Set<MetadataElement> mset = new HashSet<MetadataElement>();

      Cube cube = query.getCube();
      Hierarchy h = cube.getHierarchies().get(hierarchyName);
      if (h == null) {
        throw new Exception("Cannot find hierarchy in cube " + cube.getName() + " with name " + hierarchyName);
      }
      Dimension d = h.getDimension();
      Level l = h.getLevels().get(levelName);
      if (l == null) {
        throw new Exception("Cannot find level in hierarchy " + h.getName() + " with name " + levelName);
      }
      SimpleCubeElement hierarchy = new SimpleCubeElement(h.getName(), h.getUniqueName(), h.getCaption());
      SimpleCubeElement dimension = new SimpleCubeElement(d.getName(), d.getUniqueName(), d.getCaption());

      Long start = new Date().getTime();

      // try headers first
      AbstractBaseCell[][] headers = result.getCellSetHeaders();
      if (headers != null && headers.length > 0 && headers[0].length > 0) {
        for (AbstractBaseCell[] header : headers) {
          for (int k = 0; k < headers[0].length; k++) {
            if (header[k] == null) {
              continue;
            }
            MemberCell mc = (MemberCell) header[k];
            if (mc.getUniqueName() != null) {
              if (mc.getHierarchy().equals(hierarchy.getUniqueName()) && mc.getLevel().equals(l.getUniqueName())) {
                String mu = mc.getUniqueName();
                List<IdentifierSegment> memberList = IdentifierNode.parseIdentifier(mu).getSegmentList();
                Member m = cube.lookupMember(memberList);
                mset.add(m);
              }
            }
          }
        }
      }
      Long header = new Date().getTime();

      if (mset.size() == 0) {
        // try body next
        AbstractBaseCell[][] body = result.getCellSetBody();
        if (body != null && body.length > 0 && body[0].length > 0) {
          for (AbstractBaseCell[] aBody : body) {
            for (int k = 0; k < body[0].length; k++) {
              if (aBody[k] == null) {
                continue;
              }
              AbstractBaseCell ac = aBody[k];
              if (ac instanceof DataCell) {
                break;
              }
              if (ac instanceof MemberCell) {
                MemberCell mc = (MemberCell) aBody[k];
                if (mc.getUniqueName() != null) {
                  if (mc.getHierarchy().equals(hierarchy.getUniqueName()) && mc.getLevel().equals(l.getUniqueName())) {
                    String mu = mc.getUniqueName();
                    List<IdentifierSegment> memberList = IdentifierNode.parseIdentifier(mu).getSegmentList();
                    Member m = cube.lookupMember(memberList);
                    mset.add(m);
                  }
                }
              }
            }
          }
        }
      }
      Long body = new Date().getTime();


      // fallback - check inclusions (probably they are only on filter)
      if (mset.size() == 0) {
//List<CellSetAxis> axes = new ArrayList<CellSetAxis>();
//axes.addAll(cs.getAxes());
//axes.add(cs.getFilterAxis());
//for (CellSetAxis axis : axes) {
//int posIndex = 0;
//for (Hierarchy he : axis.getAxisMetaData().getHierarchies()) {
//if (he.getName().equals(hierarchyName)) {
//if (hierarchy == null) {
//hierarchy = new SimpleCubeElement(he.getName(),
// he.getUniqueName(),  he.getCaption());
//dimension = new SimpleCubeElement(d.getName(),
// d.getUniqueName(), d.getCaption());
//}
//if (he.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)) {
View Full Code Here

    }
  }

  @NotNull
  public Map<String, SaikuFilter> getValidFilters(String queryName, @NotNull Map<String, SaikuFilter> allFilters) {
    IQuery query = getIQuery(queryName);
    Cube c = query.getCube();
    Map<String, SaikuFilter> filteredMap = new HashMap<String, SaikuFilter>();
    for (SaikuFilter sf : allFilters.values()) {
      if (StringUtils.isBlank(sf.getName()) || sf.getDimension() == null) {
        continue;
      }
View Full Code Here

    return filteredMap;
  }

  @NotNull
  public SaikuQuery applyFilter(String queryname, @Nullable SaikuFilter filter) throws Exception {
    IQuery query = getIQuery(queryname);
    if (filter != null && filter.getName() != null && filter.getDimension() != null && filter.getMembers() != null) {
      query.setFilter(filter);
      QueryDimension qDim = query.getDimension(filter.getDimension().getName());

      if (qDim != null) {
        qDim.clearInclusions();
        query.moveDimension(qDim, Axis.FILTER);
        for (SimpleCubeElement member : filter.getMembers()) {
          List<IdentifierSegment> memberList = IdentifierNode.parseIdentifier(member.getUniqueName()).getSegmentList();
          qDim.include(memberList);
        }
      }
View Full Code Here

    return ObjectUtil.convert(query);
  }

  @NotNull
  public SaikuQuery removeFilter(String queryname) {
    IQuery query = getIQuery(queryname);
    if (query != null && query.getFilter() != null) {
      SaikuFilter filter = query.getFilter();
      QueryDimension qDim = query.getDimension(filter.getDimension().getName());
      if (qDim != null) {
        qDim.clearInclusions();
        query.moveDimension(qDim, null);
      }
      query.removeFilter();
    }
    return ObjectUtil.convert(query);
  }
View Full Code Here

    return ObjectUtil.convert(query);
  }


  public void setTag(String queryName, SaikuTag tag) {
    IQuery query = getIQuery(queryName);
    query.setTag(tag);
  }
View Full Code Here

    IQuery query = getIQuery(queryName);
    query.setTag(tag);
  }

  public void disableTag(String queryName) {
    IQuery query = getIQuery(queryName);
    query.removeTag();
  }
View Full Code Here

    queries.put(queryName, query);
  }

  private void removeIQuery(String queryName) {
    if (queries.containsKey(queryName)) {
      IQuery q = queries.remove(queryName);
      try {
        q.cancel();
      } catch (Exception e) {
        LOG.error("Cannot remove query", e);
      }
      q = null;
    }
View Full Code Here

      if (LOG.isDebugEnabled()) {
        LOG.debug("TRACK\t" + "\t/query/" + queryName + "/axis/" + axisName + "\tDELETE");
      }
      axisName = StringUtils.isNotBlank(axisName) ? axisName.toUpperCase() : null;
      if (axisName != null) {
        IQuery query = olapQueryService.clearAxis(queryName, axisName);
        return Response.ok().entity(ObjectUtil.convert(query)).build();

      }
      throw new Exception("Clear Axis: Axis name cannot be null");
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.saiku.olap.query.IQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.