コード例 #1
0
ファイル: QueryUtils.java プロジェクト: yokoboy/bi-platform
 /**
  * @param area
  * @param schema
  * @return
  */
 private static List<String> getOlapElementNames(Item[] items, String cubeId, Schema schema) {
   List<String> tmp = Lists.newArrayList();
   if (items == null || items.length == 0) {
     return tmp;
   }
   for (Item item : items) {
     OlapElement olapElement =
         ReportDesignModelUtils.getDimOrIndDefineWithId(schema, cubeId, item.getOlapElementId());
     tmp.add(olapElement.getCaption());
   }
   return tmp;
 }
コード例 #2
0
ファイル: QueryUtils.java プロジェクト: yokoboy/bi-platform
 /**
  * @param area
  * @param schema
  * @param item
  * @return String
  */
 private static OlapElement getOlapElement(ExtendArea area, Schema schema, Item item) {
   OlapElement olapElement =
       ReportDesignModelUtils.getDimOrIndDefineWithId(
           schema, area.getCubeId(), item.getOlapElementId());
   if (olapElement != null) {
     return olapElement;
   }
   return null;
 }
コード例 #3
0
ファイル: QueryUtils.java プロジェクト: yokoboy/bi-platform
 /**
  * @param schema
  * @param area
  * @param items
  * @param axisType
  * @return
  * @throws QueryModelBuildException
  */
 private static AxisMeta buildAxisMeta(
     Schema schema, ExtendArea area, Map<Item, Object> items, AxisType axisType)
     throws QueryModelBuildException {
   AxisMeta meta = new AxisMeta(axisType);
   for (Map.Entry<Item, Object> entry : items.entrySet()) {
     Item item = entry.getKey();
     OlapElement olapElement =
         ReportDesignModelUtils.getDimOrIndDefineWithId(
             schema, area.getCubeId(), item.getOlapElementId());
     if (olapElement == null) {
       continue;
     }
     if (olapElement instanceof Dimension) {
       meta.getCrossjoinDims().add(olapElement.getName());
     } else {
       meta.getQueryMeasures().add(olapElement.getName());
     }
   }
   return meta;
 }
コード例 #4
0
ファイル: QueryUtils.java プロジェクト: yokoboy/bi-platform
  /**
   * 获取扩展区域包含的立方体定义
   *
   * @param reportModel 报表模型
   * @param area 扩展区域
   * @return 立方体定义
   * @throws QueryModelBuildException
   */
  public static Cube getCubeWithExtendArea(ReportDesignModel reportModel, ExtendArea area)
      throws QueryModelBuildException {
    Cube oriCube = getCubeFromReportModel(reportModel, area);
    // 对于可选指标,默认将事实表包含的所有列作为查询条件
    if ("true".equals(area.getOtherSetting().get(Constants.CAN_CHANGED_MEASURE))) {
      Cube rs = transformCube(oriCube);
      modifyMeasures(rs.getMeasures(), rs);
      return rs;
    }
    Map<String, List<Dimension>> filterDims = collectFilterDim(reportModel);
    MiniCube cube = new MiniCube(area.getCubeId());
    String areaId = area.getId();
    LogicModel logicModel = area.getLogicModel();
    if (area.getType() == ExtendAreaType.SELECTION_AREA
        || area.getType() == ExtendAreaType.LITEOLAP_CHART
        || area.getType() == ExtendAreaType.LITEOLAP_TABLE) {
      LiteOlapExtendArea liteOlapArea =
          (LiteOlapExtendArea) reportModel.getExtendById(area.getReferenceAreaId());
      logicModel = liteOlapArea.getLogicModel();
      areaId = area.getReferenceAreaId();
    }
    if (logicModel == null) {
      throw new QueryModelBuildException("logic model is empty");
    }
    Item[] items = logicModel.getItems(area.getType() != ExtendAreaType.TABLE);
    Map<String, Dimension> dimensions = new HashMap<String, Dimension>();
    Map<String, Measure> measures = new HashMap<String, Measure>();

    for (Item item : items) {
      OlapElement olapElement = oriCube.getDimensions().get(item.getOlapElementId());
      if (olapElement == null) { // 维度不存在或者可能是指标信息
        olapElement = oriCube.getMeasures().get(item.getOlapElementId());
        if (olapElement != null) {
          Measure measure = (Measure) olapElement;
          measures.put(measure.getName(), measure);
        }
      } else {
        MiniCubeDimension dim = (MiniCubeDimension) DeepcopyUtils.deepCopy(olapElement);
        dim.setLevels(Maps.newLinkedHashMap());
        ;
        ((Dimension) olapElement)
            .getLevels()
            .values()
            .forEach(
                level -> {
                  level.setDimension(dim);
                  dim.getLevels().put(level.getName(), level);
                });
        dimensions.put(dim.getName(), dim);
      }
    }
    if (area.getType() == ExtendAreaType.LITEOLAP) {
      /** TODO 把liteOlap中候选的维度和指标加入到items里面 */
      Map<String, Item> candDims = ((LiteOlapExtendArea) area).getCandDims();
      Schema schema = reportModel.getSchema();
      String cubeId = area.getCubeId();
      for (String elementId : candDims.keySet()) {
        OlapElement element =
            ReportDesignModelUtils.getDimOrIndDefineWithId(schema, cubeId, elementId);
        MiniCubeDimension dim = (MiniCubeDimension) DeepcopyUtils.deepCopy(element);
        dim.setLevels(Maps.newLinkedHashMap());
        ((Dimension) element)
            .getLevels()
            .values()
            .forEach(
                level -> {
                  level.setDimension(dim);
                  dim.getLevels().put(level.getName(), level);
                });
        dimensions.put(element.getName(), (Dimension) element);
      }
      Map<String, Item> candInds = ((LiteOlapExtendArea) area).getCandInds();
      for (String elementId : candInds.keySet()) {
        OlapElement element =
            ReportDesignModelUtils.getDimOrIndDefineWithId(schema, cubeId, elementId);
        if (element instanceof CallbackMeasure) {
          CallbackMeasure m = DeepcopyUtils.deepCopy((CallbackMeasure) element);
          String url = ((CallbackMeasure) element).getCallbackUrl();
          m.setCallbackUrl(HttpUrlUtils.getBaseUrl(url));
          m.setCallbackParams(HttpUrlUtils.getParams(url));
          measures.put(m.getName(), m);
        } else {
          measures.put(element.getName(), (Measure) element);
        }
      }
    }
    if (filterDims != null) {
      List<Dimension> dims = filterDims.get(area.getCubeId());
      if (dims != null) {
        for (Dimension dim : dims) {
          if (dim != null) {
            dimensions.put(dim.getName(), dim);
          }
        }
      }

      // TODO 处理不同cube共用同一查询条件情况
      filterDims.forEach(
          (key, dimArray) -> {
            if (key != null && !key.equals(area.getCubeId())) {
              dimArray
                  .stream()
                  .filter(
                      dim -> {
                        return dim instanceof TimeDimension;
                      })
                  .forEach(
                      dim -> {
                        for (Dimension tmp : oriCube.getDimensions().values()) {
                          if (dim.getName().equals(tmp.getName())) {
                            MiniCubeDimension tmpDim =
                                (MiniCubeDimension) DeepcopyUtils.deepCopy(dim);
                            tmpDim.setLevels((LinkedHashMap<String, Level>) tmp.getLevels());
                            tmpDim.setFacttableColumn(tmp.getFacttableColumn());
                            tmpDim.setFacttableCaption(tmp.getFacttableCaption());
                            dimensions.put(tmpDim.getName(), tmpDim);
                          }
                        }
                      });
            }
          });
    }
    cube.setDimensions(dimensions);
    modifyMeasures(measures, oriCube);
    cube.setMeasures(measures);
    cube.setSource(((MiniCube) oriCube).getSource());
    cube.setPrimaryKey(((MiniCube) oriCube).getPrimaryKey());
    cube.setId(oriCube.getId() + "_" + areaId);
    return cube;
  }