示例#1
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}
   *
   * @throws DataSourceOperationException
   */
  @Override
  public boolean publishReport(ReportDesignModel model, String securityKey)
      throws ReportModelOperationException, DataSourceOperationException {

    boolean result = false;
    String devReportLocation = this.generateDevReportLocation(model);
    String realeaseLocation = this.getReleaseReportLocation(model);
    try {
      // 删除原来已经发布的报表,如果不存在,忽略此处异常
      ReportDesignModel tmp = this.getModelByIdOrName(model.getId(), true);
      if (tmp != null) {
        try {
          fileService.rm(getReleaseReportLocation(tmp));
        } catch (Exception e) {
          fileService.rm(getOriReleaseReportLocation(tmp));
        }
      }
    } catch (FileServiceException e1) {
      logger.info(e1.getMessage(), e1);
    }
    try {
      result = this.fileService.copy(devReportLocation, realeaseLocation);
    } catch (FileServiceException e) {
      logger.error(e.getMessage(), e);
      throw new ReportModelOperationException("发布报表失败!");
    }
    if (!result) {
      logger.error("拷贝报表失败!");
      throw new ReportModelOperationException("发布报表失败!");
    }
    /** 发布 */
    DataSourceDefine dsDefine;
    DataSourceInfo dsInfo;
    try {
      dsDefine = dsService.getDsDefine(model.getDsId());
      DataSourceConnectionService<?> dsConnService =
          DataSourceConnectionServiceFactory.getDataSourceConnectionServiceInstance(
              dsDefine.getDataSourceType().name());
      dsInfo = dsConnService.parseToDataSourceInfo(dsDefine, securityKey);
    } catch (DataSourceOperationException e) {
      logger.error("Fail in Finding datasource define. ", e);
      throw e;
    } catch (DataSourceConnectionException e) {
      logger.error("Fail in parse datasource to datasourceInfo.", e);
      throw new DataSourceOperationException(e);
    }
    List<Cube> cubes = Lists.newArrayList();
    for (ExtendArea area : model.getExtendAreaList()) {
      try {
        if ((area.getType() != ExtendAreaType.TABLE
                && area.getType() != ExtendAreaType.LITEOLAP_TABLE
                && area.getType() != ExtendAreaType.CHART
                && area.getType() != ExtendAreaType.LITEOLAP_CHART)
            || area.getType() == ExtendAreaType.PLANE_TABLE
            || QueryUtils.isFilterArea(area.getType())) {
          continue;
        }
        Cube cube = QueryUtils.getCubeWithExtendArea(model, area);
        cubes.add(cube);
      } catch (QueryModelBuildException e) {
        logger.warn("It seems that logicmodel of area is null. Ingore this area. ");
        continue;
      }
    }
    if (cubes.size() == 0) {
      logger.info("cube is empty, don't need to create index!");
      return true;
    }
    new Thread() {
      public void run() {
        MiniCubeConnection connection = MiniCubeDriverManager.getConnection(dsInfo);
        connection.publishCubes(cubes, dsInfo);
      }
    }.start();
    return true;
  }