Ejemplo n.º 1
0
 public void resetAxisSelections(QueryAxis axis) {
   for (QueryDimension dim : axis.getDimensions()) {
     dim.clearInclusions();
     dim.clearExclusions();
     dim.clearSort();
   }
 }
Ejemplo n.º 2
0
  private IQuery applyTag(IQuery query, OlapConnection con, SaikuTag t) throws Exception {
    String xml = query.toXml();
    QueryDeserializer qd = new QueryDeserializer();
    query = qd.unparse(xml, con);

    List<SimpleCubeElement> doneDimension = new ArrayList<SimpleCubeElement>();
    Map<String, QueryDimension> dimensionMap = new HashMap<String, QueryDimension>();
    if (t.getSaikuTupleDimensions() != null) {
      for (SimpleCubeElement st : t.getSaikuTupleDimensions()) {
        if (!doneDimension.contains(st)) {
          QueryDimension dim = query.getDimension(st.getName());
          dimensionMap.put(st.getUniqueName(), dim);
          dim.clearExclusions();
          dim.clearInclusions();
          query.moveDimension(dim, null);
          doneDimension.add(st);
        }
      }
      if (t.getSaikuTupleDimensions().size() > 0) {
        SimpleCubeElement rootDim = t.getSaikuTupleDimensions().get(0);
        QueryDimension dim = query.getDimension(rootDim.getName());
        query.moveDimension(dim, Axis.COLUMNS);

        for (SaikuTuple tuple : t.getSaikuTuples()) {
          SaikuMember m = tuple.getSaikuMember(rootDim.getUniqueName());
          List<SaikuMember> others = tuple.getOtherSaikuMembers(rootDim.getUniqueName());
          Selection sel = dim.createSelection(IdentifierParser.parseIdentifier(m.getUniqueName()));
          for (SaikuMember context : others) {
            QueryDimension otherDim = dimensionMap.get(context.getDimensionUniqueName());
            query.moveDimension(otherDim, Axis.COLUMNS);
            Selection ctxSel =
                otherDim.createSelection(IdentifierParser.parseIdentifier(context.getUniqueName()));
            sel.addContext(ctxSel);
          }
          dim.getInclusions().add(sel);
        }
      }
    }
    if (t.getSaikuDimensionSelections() != null) {
      for (SaikuDimensionSelection dimsel : t.getSaikuDimensionSelections()) {
        if (!dimsel.getName().equals("Measures")) {
          QueryDimension filterDim = query.getDimension(dimsel.getName());
          query.moveDimension(filterDim, Axis.FILTER);
          filterDim.clearInclusions();
          for (SaikuSelection ss : dimsel.getSelections()) {
            if (ss.getType() == SaikuSelection.Type.MEMBER) {
              Selection sel =
                  filterDim.createSelection(IdentifierParser.parseIdentifier(ss.getUniqueName()));
              if (!filterDim.getInclusions().contains(sel)) {
                filterDim.getInclusions().add(sel);
              }
            }
          }
          // TODO: Move it to columns since drilling through with 2 filter items of the same
          // dimension doesn't work
          //					if (filterDim.getInclusions().size() > 1) {
          //						query.moveDimension(filterDim, Axis.COLUMNS);
          //					}
        }
      }
    }

    return query;
  }