Exemple #1
0
 /**
  * trans cube
  *
  * @param cube
  * @return new Cube
  */
 public static Cube transformCube(Cube cube) {
   MiniCube newCube = (MiniCube) DeepcopyUtils.deepCopy(cube);
   final Map<String, Measure> measures = Maps.newConcurrentMap();
   cube.getMeasures()
       .values()
       .forEach(
           m -> {
             measures.put(m.getName(), m);
           });
   newCube.setMeasures(measures);
   final Map<String, Dimension> dimensions = Maps.newLinkedHashMap();
   cube.getDimensions()
       .values()
       .forEach(
           dim -> {
             MiniCubeDimension tmp = (MiniCubeDimension) DeepcopyUtils.deepCopy(dim);
             LinkedHashMap<String, Level> tmpLevel = Maps.newLinkedHashMap();
             dim.getLevels()
                 .values()
                 .forEach(
                     level -> {
                       level.setDimension(dim);
                       tmpLevel.put(level.getName(), level);
                     });
             tmp.setLevels(tmpLevel);
             dimensions.put(tmp.getName(), tmp);
           });
   newCube.setDimensions(dimensions);
   return newCube;
 }
Exemple #2
0
 /**
  * @param model
  * @return Map<String, List<Dimension>>
  */
 private static Map<String, List<Dimension>> collectFilterDim(ReportDesignModel model) {
   Map<String, List<Dimension>> rs = Maps.newHashMap();
   for (ExtendArea area : model.getExtendAreaList()) {
     if (isFilterArea(area.getType())) {
       Cube cube = model.getSchema().getCubes().get(area.getCubeId());
       if (rs.get(area.getCubeId()) == null) {
         List<Dimension> dims = Lists.newArrayList();
         area.listAllItems()
             .values()
             .forEach(
                 key -> {
                   MiniCubeDimension dim =
                       (MiniCubeDimension)
                           DeepcopyUtils.deepCopy(cube.getDimensions().get(key.getId()));
                   dim.setLevels(Maps.newLinkedHashMap());
                   cube.getDimensions()
                       .get(key.getId())
                       .getLevels()
                       .values()
                       .forEach(
                           level -> {
                             dim.getLevels().put(level.getName(), level);
                           });
                   dims.add(dim);
                 });
         rs.put(area.getCubeId(), dims);
       } else {
         area.listAllItems()
             .values()
             .forEach(
                 key -> {
                   MiniCubeDimension dim =
                       (MiniCubeDimension)
                           DeepcopyUtils.deepCopy(cube.getDimensions().get(key.getId()));
                   dim.setLevels(Maps.newLinkedHashMap());
                   ;
                   cube.getDimensions()
                       .get(key.getId())
                       .getLevels()
                       .values()
                       .forEach(
                           level -> {
                             dim.getLevels().put(level.getName(), level);
                           });
                   rs.get(area.getCubeId()).add(dim);
                 });
       }
     }
   }
   return rs;
 }
 /** {@inheritDoc} */
 @Override
 public boolean updateReportModel(ReportDesignModel model, boolean modelInCache) {
   ReportDesignModel persModel = DeepcopyUtils.deepCopy(model);
   // 如果当前model在编辑状态,需要更新持久化的model的name
   if (isNameExist(model.getName(), model.getId())) {
     return false;
   }
   if (modelInCache) {
     persModel = getModelByIdOrName(model.getId(), false);
   }
   try {
     try {
       this.deleteModel(persModel, true);
     } catch (Exception e) {
       try {
         fileService.rm(generateOriDevReportLocation(persModel));
       } catch (FileServiceException e1) {
         throw new ReportModelOperationException(e1);
       }
     }
     persModel.setName(model.getName());
     this.saveOrUpdateModel(persModel);
   } catch (ReportModelOperationException e) {
     logger.error(e.getMessage(), e);
     return false;
   }
   return true;
 }
Exemple #4
0
  /**
   * 修正报表区域模型参数
   *
   * @param request
   * @param model
   */
  public static Map<String, Object> resetContextParam(
      final HttpServletRequest request, ReportDesignModel model) {
    Map<String, Object> rs = Maps.newHashMap();
    Collection<ReportParam> params = DeepcopyUtils.deepCopy(model.getParams()).values();
    // modify by jiangyichao at 2015-05-19
    Collection<PlaneTableCondition> planeTableConditions =
        DeepcopyUtils.deepCopy(model.getPlaneTableConditions()).values();
    if (params.size() == 0 && planeTableConditions.size() == 0) {
      return rs;
    }
    LOG.info("context params ============== " + ContextManager.getParams());
    // 当前请求参数
    Map<String, String> requestParams = collectRequestParams(params, request);
    rs.putAll(requestParams);
    LOG.info("current request params ============== " + requestParams);

    // TODO 先处理P功能对应的参数
    if (params.size() != 0) {
      params.forEach(
          param -> {
            LOG.info("current param define ============== " + param.toString());
            if (param.isNeeded() && StringUtils.isEmpty(requestParams.get(param.getName()))) {
              if (StringUtils.isEmpty(param.getDefaultValue())) {
                throw new RuntimeException("必要参数未赋值");
              }
              rs.put(param.getElementId(), param.getDefaultValue());
              rs.put(param.getName(), param.getDefaultValue());
            } else if (!StringUtils.isEmpty(requestParams.get(param.getName()))) {
              rs.put(param.getElementId(), requestParams.get(param.getName()));
            } else if (!StringUtils.isEmpty(param.getDefaultValue())) {
              rs.put(param.getElementId(), param.getDefaultValue());
              rs.put(param.getName(), param.getDefaultValue());
            }
          });
    }

    // 处理平面表对应的条件
    if (planeTableConditions.size() != 0) {
      planeTableConditions.forEach(
          condition -> {
            LOG.info("current planeTable condition define ============== " + condition.toString());
            // 如果请求参数中没有条件对应的参数,则使用默认值对应的参数值
            if (StringUtils.isEmpty(requestParams.get(condition.getName()))) {
              rs.put(condition.getElementId(), condition.getDefaultValue());
              rs.put(condition.getName(), condition.getDefaultValue());
            } else if (!StringUtils.isEmpty(requestParams.get(condition.getName()))) {
              // 如果请求参数中有条件对应的参数,则取请求参数中的参数值
              // TODO 对时间条件和层级条件做特殊处理
              String requestParam = requestParams.get(condition.getName());
              // 处理时间条件
              //                    requestParam =
              // PlaneTableUtils.handleTimeCondition(requestParam);
              // 处理层级条件
              //                    requestParam =
              // PlaneTableUtils.handleLayerCondition(requestParam);
              rs.put(condition.getElementId(), requestParam);
            }
          });
    }

    LOG.info("after reset params is : " + rs);
    return rs;
  }
Exemple #5
0
  /**
   * 获取扩展区域包含的立方体定义
   *
   * @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;
  }