private Map<String, Object> discoverAndSetParameters(
      IReportRunnable report, HttpServletRequest request) throws Throwable {

    Map<String, Object> parms = new HashMap<String, Object>();
    IGetParameterDefinitionTask task = birtEngine.createGetParameterDefinitionTask(report);
    @SuppressWarnings("unchecked")
    Collection<IParameterDefnBase> params = task.getParameterDefns(true);
    for (IParameterDefnBase param : params) {
      Assert.isInstanceOf(
          IScalarParameterDefn.class,
          param,
          "the parameter must be assignable to " + IScalarParameterDefn.class.getName());
      IScalarParameterDefn scalar = (IScalarParameterDefn) param;
      if (this.reportParameters != null && this.reportParameters.get(param.getName()) != null) {
        String format = scalar.getDisplayFormat();
        // todo will this step on the Spring MVC converters?
        ReportParameterConverter converter =
            new ReportParameterConverter(format, request.getLocale());

        Object value = this.reportParameters.get(param.getName());
        parms.put(param.getName(), value);

        //                       /* converter.parse(*/  this.reportParameters.get(param.getName()),
        // scalar.getDataType()/*)*/);
      } else if (StringUtils.hasText(getParameter(request, param.getName()))) {
        parms.put(param.getName(), getParamValueObject(request, scalar));
      }
    }
    task.close();
    return parms;
  }
 /** Test passing reportContext */
 @SuppressWarnings("unchecked")
 @Test
 public void testExecute1() {
   try {
     final IReportEngine reportEngine = ReportEngine.getReportEngine();
     final InputStream is =
         this.getClass().getResourceAsStream("/reports/test_display_parameters.rptdesign");
     final IReportRunnable design = reportEngine.openReportDesign(is);
     final IGetParameterDefinitionTask paramTask =
         reportEngine.createGetParameterDefinitionTask(design);
     List<EngineException> errors = null;
     try {
       final IRunAndRenderTask rrTask = reportEngine.createRunAndRenderTask(design);
       final Map<String, Object> appContext = rrTask.getAppContext();
       final ClassLoader classLoader = getClass().getClassLoader();
       appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, classLoader);
       // rrTask.setAppContext(appContext);
       try {
         final ByteArrayOutputStream os = new ByteArrayOutputStream();
         final RenderOption options = new HTMLRenderOption();
         options.setOutputFormat("HTML");
         options.setOutputStream(os);
         rrTask.setRenderOption(options);
         rrTask.run();
         errors = rrTask.getErrors();
         String output = os.toString("utf-8");
         System.out.println(output);
         Assert.assertTrue(output.indexOf("Australian Collectors, Co.") >= 0);
         Assert.assertTrue(output.indexOf("NewParameter") >= 0);
         Assert.assertTrue(output.indexOf("abc") >= 0);
       } finally {
         rrTask.close();
       }
     } finally {
       paramTask.close();
     }
     if (errors != null) {
       Iterator<EngineException> iterator = errors.iterator();
       if (iterator.hasNext()) {
         EngineException error = iterator.next();
         Assert.fail("Engine exception: " + error.getMessage());
       }
     }
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     Assert.fail(e.toString());
   } catch (BirtException e) {
     e.printStackTrace();
     Assert.fail(e.toString());
   }
 }
예제 #3
0
  @SuppressWarnings("unchecked")
  private void prepareReportParams(RptProperties properties) {
    externalParams = new HashSet<String>();
    reportParams =
        new LinkedHashMap<
            String,
            ReportParameter>(); // use LinkedHashMap
                                // http://issues.m-g.ru/bugzilla/show_bug.cgi?id=4577
    IGetParameterDefinitionTask paramTask = engine.createGetParameterDefinitionTask(design);
    try {
      Collection<IParameterDefnBase> paramsC = paramTask.getParameterDefns(true);
      for (IParameterDefnBase param : paramsC) {
        if (param instanceof IParameterGroupDefn)
          addGroupReportParameter(
              properties, param.getName(), (IParameterGroupDefn) param, paramTask);
        else if (param instanceof IScalarParameterDefn)
          addReportParameter(
              properties,
              param.getName(),
              (IScalarParameterDefn) param,
              null,
              paramTask.getDefaultValue(param));
      }
    } finally {
      paramTask.close();
    }

    /*
     * BIRT не даёт работать с поименованными параметрами, приходится
     * обходить
     */
    List<DataSetHandle> dshL =
        (List<DataSetHandle>) design.getDesignHandle().getModuleHandle().getAllDataSets();

    for (DataSetHandle dsH : dshL) {
      if (dsH instanceof OdaDataSetHandle
          && MERP_DATASET_ID.equals(((OdaDataSetHandle) dsH).getExtensionID())) {
        ArrayList<String> paramNames = new ArrayList<String>();
        ArrayList<DataSetParameter> prms =
            (ArrayList<DataSetParameter>) dsH.getListProperty("parameters");
        if (prms != null) {
          for (DataSetParameter prm : prms) paramNames.add(prm.getName());

          datasetParams.put(dsH.getStringProperty(BAI_CODE), paramNames);
        }
      }
    }
    // *********************************************************//
  }
예제 #4
0
  /**
   * загрузить список значений параметра отчета
   *
   * @param paramName имя параметра
   * @return список значений
   */
  public List<SelectionChoice> getParameterSelectionList(String paramName) {
    IGetParameterDefinitionTask task = null;
    try {
      task = engine.createGetParameterDefinitionTask(design);
      if (task != null) {
        setupEngineTask(task, rptProperties);
        return SelectionChoiceImpl.convertEngineParameterSelectionChoice(
            task.getSelectionList(paramName));
      }
    } finally {
      if (task != null) task.close();
    }

    return null;
  }
예제 #5
0
  /**
   * загрузить список значений каскадного параметра
   *
   * @param paramName имя параметра
   * @param groupName имя каскадной группы
   * @param groupKeys список значений параметров находящихся выше по иерархии в каскадной группе
   * @return список значений
   */
  @SuppressWarnings("deprecation")
  public List<SelectionChoice> getSelectionListForCascadingGroup(
      String paramName, String groupName, Object[] groupKeys) {
    IGetParameterDefinitionTask task = null;
    try {
      task = engine.createGetParameterDefinitionTask(design);
      if (task != null) {
        setupEngineTask(task, rptProperties);
        task.evaluateQuery(groupName);
        return SelectionChoiceImpl.convertEngineParameterSelectionChoice(
            task.getSelectionListForCascadingGroup(groupName, groupKeys));
      }
    } finally {
      if (task != null) task.close();
    }

    return null;
  }
예제 #6
0
 @SuppressWarnings("unchecked")
 private void addGroupReportParameter(
     RptProperties properties,
     String name,
     IParameterGroupDefn param,
     IGetParameterDefinitionTask paramTask) {
   Collection<IParameterDefnBase> elements = ((IParameterGroupDefn) param).getContents();
   for (IParameterDefnBase param2 : elements)
     if (param2 instanceof IParameterGroupDefn)
       addGroupReportParameter(
           properties, param2.getName(), (IParameterGroupDefn) param2, paramTask);
     else if (param2 instanceof IScalarParameterDefn)
       addReportParameter(
           properties,
           param2.getName(),
           (IScalarParameterDefn) param2,
           (IParameterGroupDefn) param,
           paramTask.getDefaultValue(param2));
 }