@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); } } } // *********************************************************// }
@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)); }
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; }