@Test public void testStringInputType() { ReportParameters reportParameters; try { reportParameters = m_reportService.getParameters(REPORTID); ReportStringParm stringParm2 = reportParameters.getStringParms().get(1); Assert.assertEquals("onmsCategorySelector", stringParm2.getInputType()); } catch (ReportException e) { e.printStackTrace(); } }
public ReportParameters getParameters(String reportId) throws ReportException { ReportParameters reportParameters = new ReportParameters(); ArrayList<ReportIntParm> intParms; ArrayList<ReportFloatParm> floatParms; ArrayList<ReportDoubleParm> doubleParms; ArrayList<ReportStringParm> stringParms; ArrayList<ReportDateParm> dateParms; JRParameter[] reportParms; JasperReport jasperReport = null; Map<?, ?> defaultValues = null; try { jasperReport = JasperCompileManager.compileReport(m_globalReportRepository.getTemplateStream(reportId)); defaultValues = JRParameterDefaultValuesEvaluator.evaluateParameterDefaultValues(jasperReport, null); } catch (JRException e) { log.error("unable to compile jasper report", e); throw new ReportException("unable to compile jasperReport", e); } reportParms = jasperReport.getParameters(); intParms = new ArrayList<ReportIntParm>(); reportParameters.setIntParms(intParms); floatParms = new ArrayList<ReportFloatParm>(); reportParameters.setFloatParms(floatParms); doubleParms = new ArrayList<ReportDoubleParm>(); reportParameters.setDoubleParms(doubleParms); stringParms = new ArrayList<ReportStringParm>(); reportParameters.setStringParms(stringParms); dateParms = new ArrayList<ReportDateParm>(); reportParameters.setDateParms(dateParms); for (JRParameter reportParm : reportParms) { if (reportParm.isSystemDefined() == false) { if (reportParm.isForPrompting() == false) { log.debug("report parm " + reportParm.getName() + " is not for prompting - continuing"); continue; } else { log.debug("found promptable report parm " + reportParm.getName()); } if (reportParm.getValueClassName().equals("java.lang.String")) { log.debug("adding a string parm name " + reportParm.getName()); ReportStringParm stringParm = new ReportStringParm(); if (reportParm.getDescription() != null) { stringParm.setDisplayName(reportParm.getDescription()); } else { stringParm.setDisplayName(reportParm.getName()); } if (reportParm.getPropertiesMap().containsProperty(STRING_INPUT_TYPE)) { stringParm.setInputType(reportParm.getPropertiesMap().getProperty(STRING_INPUT_TYPE)); } stringParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { stringParm.setValue((String) defaultValues.get(reportParm.getName())); } else { stringParm.setValue(new String()); } stringParms.add(stringParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Integer")) { log.debug("adding a Integer parm name " + reportParm.getName()); ReportIntParm intParm = new ReportIntParm(); if (reportParm.getDescription() != null) { intParm.setDisplayName(reportParm.getDescription()); } else { intParm.setDisplayName(reportParm.getName()); } intParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { intParm.setValue((Integer) defaultValues.get(reportParm.getName())); } else { intParm.setValue(new Integer(0)); } intParms.add(intParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Float")) { log.debug("adding a Float parm name " + reportParm.getName()); ReportFloatParm floatParm = new ReportFloatParm(); if (reportParm.getDescription() != null) { floatParm.setDisplayName(reportParm.getDescription()); } else { floatParm.setDisplayName(reportParm.getName()); } floatParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { floatParm.setValue((Float) defaultValues.get(reportParm.getName())); } else { floatParm.setValue(new Float(0)); } floatParms.add(floatParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Double")) { log.debug("adding a Double parm name " + reportParm.getName()); ReportDoubleParm doubleParm = new ReportDoubleParm(); if (reportParm.getDescription() != null) { doubleParm.setDisplayName(reportParm.getDescription()); } else { doubleParm.setDisplayName(reportParm.getName()); } doubleParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { doubleParm.setValue((Double) defaultValues.get(reportParm.getName())); } else { doubleParm.setValue(new Double(0)); } doubleParms.add(doubleParm); continue; } if (reportParm.getValueClassName().equals("java.util.Date")) { log.debug("adding a java.util.Date parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } if (reportParm.getValueClassName().equals("java.sql.Date") || reportParm.getValueClassName().equals("java.sql.Timestamp")) { log.debug("adding a java.sql.Date or Timestamp parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } throw new ReportException( "Unsupported report parameter type " + reportParm.getValueClassName()); } } return reportParameters; }
JasperReportService implements ReportService { public ReportParameters getParameters(String reportId) throws ReportException { ReportParameters reportParameters = new ReportParameters(); ArrayList<ReportIntParm> intParms; ArrayList<ReportFloatParm> floatParms; ArrayList<ReportDoubleParm> doubleParms; ArrayList<ReportStringParm> stringParms; ArrayList<ReportDateParm> dateParms; JRParameter[] reportParms; JasperReport jasperReport = null; Map<?, ?> defaultValues = null; try { jasperReport = JasperCompileManager.compileReport(m_globalReportRepository.getTemplateStream(reportId)); defaultValues = JRParameterDefaultValuesEvaluator.evaluateParameterDefaultValues(jasperReport, null); } catch (JRException e) { log.error("unable to compile jasper report", e); throw new ReportException("unable to compile jasperReport", e); } reportParms = jasperReport.getParameters(); intParms = new ArrayList<ReportIntParm>(); reportParameters.setIntParms(intParms); floatParms = new ArrayList<ReportFloatParm>(); reportParameters.setFloatParms(floatParms); doubleParms = new ArrayList<ReportDoubleParm>(); reportParameters.setDoubleParms(doubleParms); stringParms = new ArrayList<ReportStringParm>(); reportParameters.setStringParms(stringParms); dateParms = new ArrayList<ReportDateParm>(); reportParameters.setDateParms(dateParms); for (JRParameter reportParm : reportParms) { if (reportParm.isSystemDefined() == false) { if (reportParm.isForPrompting() == false) { log.debug("report parm " + reportParm.getName() + " is not for prompting - continuing"); continue; } else { log.debug("found promptable report parm " + reportParm.getName()); } if (reportParm.getValueClassName().equals("java.lang.String")) { log.debug("adding a string parm name " + reportParm.getName()); ReportStringParm stringParm = new ReportStringParm(); if (reportParm.getDescription() != null) { stringParm.setDisplayName(reportParm.getDescription()); } else { stringParm.setDisplayName(reportParm.getName()); } if (reportParm.getPropertiesMap().containsProperty(STRING_INPUT_TYPE)) { stringParm.setInputType(reportParm.getPropertiesMap().getProperty(STRING_INPUT_TYPE)); } stringParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { stringParm.setValue((String) defaultValues.get(reportParm.getName())); } else { stringParm.setValue(new String()); } stringParms.add(stringParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Integer")) { log.debug("adding a Integer parm name " + reportParm.getName()); ReportIntParm intParm = new ReportIntParm(); if (reportParm.getDescription() != null) { intParm.setDisplayName(reportParm.getDescription()); } else { intParm.setDisplayName(reportParm.getName()); } intParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { intParm.setValue((Integer) defaultValues.get(reportParm.getName())); } else { intParm.setValue(new Integer(0)); } intParms.add(intParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Float")) { log.debug("adding a Float parm name " + reportParm.getName()); ReportFloatParm floatParm = new ReportFloatParm(); if (reportParm.getDescription() != null) { floatParm.setDisplayName(reportParm.getDescription()); } else { floatParm.setDisplayName(reportParm.getName()); } floatParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { floatParm.setValue((Float) defaultValues.get(reportParm.getName())); } else { floatParm.setValue(new Float(0)); } floatParms.add(floatParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Double")) { log.debug("adding a Double parm name " + reportParm.getName()); ReportDoubleParm doubleParm = new ReportDoubleParm(); if (reportParm.getDescription() != null) { doubleParm.setDisplayName(reportParm.getDescription()); } else { doubleParm.setDisplayName(reportParm.getName()); } doubleParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { doubleParm.setValue((Double) defaultValues.get(reportParm.getName())); } else { doubleParm.setValue(new Double(0)); } doubleParms.add(doubleParm); continue; } if (reportParm.getValueClassName().equals("java.util.Date")) { log.debug("adding a java.util.Date parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } if (reportParm.getValueClassName().equals("java.sql.Date") || reportParm.getValueClassName().equals("java.sql.Timestamp")) { log.debug("adding a java.sql.Date or Timestamp parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } throw new ReportException( "Unsupported report parameter type " + reportParm.getValueClassName()); } } return reportParameters; } }
JasperReportService implements ReportService { public ReportParameters getParameters(String reportId) throws ReportException { ReportParameters reportParameters = new ReportParameters(); ArrayList<ReportIntParm> intParms; ArrayList<ReportFloatParm> floatParms; ArrayList<ReportDoubleParm> doubleParms; ArrayList<ReportStringParm> stringParms; ArrayList<ReportDateParm> dateParms; JRParameter[] reportParms; JasperReport jasperReport = null; Map<?, ?> defaultValues = null; try { jasperReport = JasperCompileManager.compileReport(m_globalReportRepository.getTemplateStream(reportId)); defaultValues = JRParameterDefaultValuesEvaluator.evaluateParameterDefaultValues(jasperReport, null); } catch (JRException e) { log.error("unable to compile jasper report", e); throw new ReportException("unable to compile jasperReport", e); } reportParms = jasperReport.getParameters(); intParms = new ArrayList<ReportIntParm>(); reportParameters.setIntParms(intParms); floatParms = new ArrayList<ReportFloatParm>(); reportParameters.setFloatParms(floatParms); doubleParms = new ArrayList<ReportDoubleParm>(); reportParameters.setDoubleParms(doubleParms); stringParms = new ArrayList<ReportStringParm>(); reportParameters.setStringParms(stringParms); dateParms = new ArrayList<ReportDateParm>(); reportParameters.setDateParms(dateParms); for (JRParameter reportParm : reportParms) { if (reportParm.isSystemDefined() == false) { if (reportParm.isForPrompting() == false) { log.debug("report parm " + reportParm.getName() + " is not for prompting - continuing"); continue; } else { log.debug("found promptable report parm " + reportParm.getName()); } if (reportParm.getValueClassName().equals("java.lang.String")) { log.debug("adding a string parm name " + reportParm.getName()); ReportStringParm stringParm = new ReportStringParm(); if (reportParm.getDescription() != null) { stringParm.setDisplayName(reportParm.getDescription()); } else { stringParm.setDisplayName(reportParm.getName()); } if (reportParm.getPropertiesMap().containsProperty(STRING_INPUT_TYPE)) { stringParm.setInputType(reportParm.getPropertiesMap().getProperty(STRING_INPUT_TYPE)); } stringParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { stringParm.setValue((String) defaultValues.get(reportParm.getName())); } else { stringParm.setValue(new String()); } stringParms.add(stringParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Integer")) { log.debug("adding a Integer parm name " + reportParm.getName()); ReportIntParm intParm = new ReportIntParm(); if (reportParm.getDescription() != null) { intParm.setDisplayName(reportParm.getDescription()); } else { intParm.setDisplayName(reportParm.getName()); } intParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { intParm.setValue((Integer) defaultValues.get(reportParm.getName())); } else { intParm.setValue(new Integer(0)); } intParms.add(intParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Float")) { log.debug("adding a Float parm name " + reportParm.getName()); ReportFloatParm floatParm = new ReportFloatParm(); if (reportParm.getDescription() != null) { floatParm.setDisplayName(reportParm.getDescription()); } else { floatParm.setDisplayName(reportParm.getName()); } floatParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { floatParm.setValue((Float) defaultValues.get(reportParm.getName())); } else { floatParm.setValue(new Float(0)); } floatParms.add(floatParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Double")) { log.debug("adding a Double parm name " + reportParm.getName()); ReportDoubleParm doubleParm = new ReportDoubleParm(); if (reportParm.getDescription() != null) { doubleParm.setDisplayName(reportParm.getDescription()); } else { doubleParm.setDisplayName(reportParm.getName()); } doubleParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { doubleParm.setValue((Double) defaultValues.get(reportParm.getName())); } else { doubleParm.setValue(new Double(0)); } doubleParms.add(doubleParm); continue; } if (reportParm.getValueClassName().equals("java.util.Date")) { log.debug("adding a java.util.Date parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } if (reportParm.getValueClassName().equals("java.sql.Date") || reportParm.getValueClassName().equals("java.sql.Timestamp")) { log.debug("adding a java.sql.Date or Timestamp parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } throw new ReportException( "Unsupported report parameter type " + reportParm.getValueClassName()); } } return reportParameters; } JasperReportService(); }
JasperReportService implements ReportService { public ReportParameters getParameters(String reportId) throws ReportException { ReportParameters reportParameters = new ReportParameters(); ArrayList<ReportIntParm> intParms; ArrayList<ReportFloatParm> floatParms; ArrayList<ReportDoubleParm> doubleParms; ArrayList<ReportStringParm> stringParms; ArrayList<ReportDateParm> dateParms; JRParameter[] reportParms; JasperReport jasperReport = null; Map<?, ?> defaultValues = null; try { jasperReport = JasperCompileManager.compileReport(m_globalReportRepository.getTemplateStream(reportId)); defaultValues = JRParameterDefaultValuesEvaluator.evaluateParameterDefaultValues(jasperReport, null); } catch (JRException e) { log.error("unable to compile jasper report", e); throw new ReportException("unable to compile jasperReport", e); } reportParms = jasperReport.getParameters(); intParms = new ArrayList<ReportIntParm>(); reportParameters.setIntParms(intParms); floatParms = new ArrayList<ReportFloatParm>(); reportParameters.setFloatParms(floatParms); doubleParms = new ArrayList<ReportDoubleParm>(); reportParameters.setDoubleParms(doubleParms); stringParms = new ArrayList<ReportStringParm>(); reportParameters.setStringParms(stringParms); dateParms = new ArrayList<ReportDateParm>(); reportParameters.setDateParms(dateParms); for (JRParameter reportParm : reportParms) { if (reportParm.isSystemDefined() == false) { if (reportParm.isForPrompting() == false) { log.debug("report parm " + reportParm.getName() + " is not for prompting - continuing"); continue; } else { log.debug("found promptable report parm " + reportParm.getName()); } if (reportParm.getValueClassName().equals("java.lang.String")) { log.debug("adding a string parm name " + reportParm.getName()); ReportStringParm stringParm = new ReportStringParm(); if (reportParm.getDescription() != null) { stringParm.setDisplayName(reportParm.getDescription()); } else { stringParm.setDisplayName(reportParm.getName()); } if (reportParm.getPropertiesMap().containsProperty(STRING_INPUT_TYPE)) { stringParm.setInputType(reportParm.getPropertiesMap().getProperty(STRING_INPUT_TYPE)); } stringParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { stringParm.setValue((String) defaultValues.get(reportParm.getName())); } else { stringParm.setValue(new String()); } stringParms.add(stringParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Integer")) { log.debug("adding a Integer parm name " + reportParm.getName()); ReportIntParm intParm = new ReportIntParm(); if (reportParm.getDescription() != null) { intParm.setDisplayName(reportParm.getDescription()); } else { intParm.setDisplayName(reportParm.getName()); } intParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { intParm.setValue((Integer) defaultValues.get(reportParm.getName())); } else { intParm.setValue(new Integer(0)); } intParms.add(intParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Float")) { log.debug("adding a Float parm name " + reportParm.getName()); ReportFloatParm floatParm = new ReportFloatParm(); if (reportParm.getDescription() != null) { floatParm.setDisplayName(reportParm.getDescription()); } else { floatParm.setDisplayName(reportParm.getName()); } floatParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { floatParm.setValue((Float) defaultValues.get(reportParm.getName())); } else { floatParm.setValue(new Float(0)); } floatParms.add(floatParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Double")) { log.debug("adding a Double parm name " + reportParm.getName()); ReportDoubleParm doubleParm = new ReportDoubleParm(); if (reportParm.getDescription() != null) { doubleParm.setDisplayName(reportParm.getDescription()); } else { doubleParm.setDisplayName(reportParm.getName()); } doubleParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { doubleParm.setValue((Double) defaultValues.get(reportParm.getName())); } else { doubleParm.setValue(new Double(0)); } doubleParms.add(doubleParm); continue; } if (reportParm.getValueClassName().equals("java.util.Date")) { log.debug("adding a java.util.Date parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } if (reportParm.getValueClassName().equals("java.sql.Date") || reportParm.getValueClassName().equals("java.sql.Timestamp")) { log.debug("adding a java.sql.Date or Timestamp parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } throw new ReportException( "Unsupported report parameter type " + reportParm.getValueClassName()); } } return reportParameters; } JasperReportService(); List<ReportFormat> getFormats(String reportId); ReportParameters getParameters(String reportId); void render(String ReportId, String location, ReportFormat format,
                       OutputStream outputStream); String run(HashMap<String, Object> reportParms, String reportId); void runAndRender(HashMap<String, Object> reportParms,
                             String reportId, ReportFormat format, OutputStream outputStream); boolean validate(HashMap<String, Object> reportParms,
                            String reportId); void setGlobalReportRepository(GlobalReportRepository globalReportRepository); }
JasperReportService implements ReportService { public ReportParameters getParameters(String reportId) throws ReportException { ReportParameters reportParameters = new ReportParameters(); ArrayList<ReportIntParm> intParms; ArrayList<ReportFloatParm> floatParms; ArrayList<ReportDoubleParm> doubleParms; ArrayList<ReportStringParm> stringParms; ArrayList<ReportDateParm> dateParms; JRParameter[] reportParms; JasperReport jasperReport = null; Map<?, ?> defaultValues = null; try { jasperReport = JasperCompileManager.compileReport(m_globalReportRepository.getTemplateStream(reportId)); defaultValues = JRParameterDefaultValuesEvaluator.evaluateParameterDefaultValues(jasperReport, null); } catch (JRException e) { log.error("unable to compile jasper report", e); throw new ReportException("unable to compile jasperReport", e); } reportParms = jasperReport.getParameters(); intParms = new ArrayList<ReportIntParm>(); reportParameters.setIntParms(intParms); floatParms = new ArrayList<ReportFloatParm>(); reportParameters.setFloatParms(floatParms); doubleParms = new ArrayList<ReportDoubleParm>(); reportParameters.setDoubleParms(doubleParms); stringParms = new ArrayList<ReportStringParm>(); reportParameters.setStringParms(stringParms); dateParms = new ArrayList<ReportDateParm>(); reportParameters.setDateParms(dateParms); for (JRParameter reportParm : reportParms) { if (reportParm.isSystemDefined() == false) { if (reportParm.isForPrompting() == false) { log.debug("report parm " + reportParm.getName() + " is not for prompting - continuing"); continue; } else { log.debug("found promptable report parm " + reportParm.getName()); } if (reportParm.getValueClassName().equals("java.lang.String")) { log.debug("adding a string parm name " + reportParm.getName()); ReportStringParm stringParm = new ReportStringParm(); if (reportParm.getDescription() != null) { stringParm.setDisplayName(reportParm.getDescription()); } else { stringParm.setDisplayName(reportParm.getName()); } if (reportParm.getPropertiesMap().containsProperty(STRING_INPUT_TYPE)) { stringParm.setInputType(reportParm.getPropertiesMap().getProperty(STRING_INPUT_TYPE)); } stringParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { stringParm.setValue((String) defaultValues.get(reportParm.getName())); } else { stringParm.setValue(new String()); } stringParms.add(stringParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Integer")) { log.debug("adding a Integer parm name " + reportParm.getName()); ReportIntParm intParm = new ReportIntParm(); if (reportParm.getDescription() != null) { intParm.setDisplayName(reportParm.getDescription()); } else { intParm.setDisplayName(reportParm.getName()); } intParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { intParm.setValue((Integer) defaultValues.get(reportParm.getName())); } else { intParm.setValue(new Integer(0)); } intParms.add(intParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Float")) { log.debug("adding a Float parm name " + reportParm.getName()); ReportFloatParm floatParm = new ReportFloatParm(); if (reportParm.getDescription() != null) { floatParm.setDisplayName(reportParm.getDescription()); } else { floatParm.setDisplayName(reportParm.getName()); } floatParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { floatParm.setValue((Float) defaultValues.get(reportParm.getName())); } else { floatParm.setValue(new Float(0)); } floatParms.add(floatParm); continue; } if (reportParm.getValueClassName().equals("java.lang.Double")) { log.debug("adding a Double parm name " + reportParm.getName()); ReportDoubleParm doubleParm = new ReportDoubleParm(); if (reportParm.getDescription() != null) { doubleParm.setDisplayName(reportParm.getDescription()); } else { doubleParm.setDisplayName(reportParm.getName()); } doubleParm.setName(reportParm.getName()); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { doubleParm.setValue((Double) defaultValues.get(reportParm.getName())); } else { doubleParm.setValue(new Double(0)); } doubleParms.add(doubleParm); continue; } if (reportParm.getValueClassName().equals("java.util.Date")) { log.debug("adding a java.util.Date parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } if (reportParm.getValueClassName().equals("java.sql.Date") || reportParm.getValueClassName().equals("java.sql.Timestamp")) { log.debug("adding a java.sql.Date or Timestamp parm name " + reportParm.getName()); ReportDateParm dateParm = new ReportDateParm(); dateParm.setUseAbsoluteDate(false); if (reportParm.getDescription() != null) { dateParm.setDisplayName(reportParm.getDescription()); } else { dateParm.setDisplayName(reportParm.getName()); } dateParm.setName(reportParm.getName()); dateParm.setCount(new Integer(1)); dateParm.setInterval("day"); dateParm.setHours(0); dateParm.setMinutes(0); if (defaultValues.containsKey(reportParm.getName()) && (defaultValues.get(reportParm.getName()) != null)) { dateParm.setDate((Date) defaultValues.get(reportParm.getName())); Calendar cal = Calendar.getInstance(); cal.setTime(dateParm.getDate()); dateParm.setMinutes(cal.get(Calendar.MINUTE)); dateParm.setHours(cal.get(Calendar.HOUR_OF_DAY)); } else { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dateParm.setDate(cal.getTime()); } dateParms.add(dateParm); continue; } throw new ReportException( "Unsupported report parameter type " + reportParm.getValueClassName()); } } return reportParameters; } JasperReportService(); List<ReportFormat> getFormats(String reportId); ReportParameters getParameters(String reportId); void render(String ReportId, String location, ReportFormat format,
                       OutputStream outputStream); String run(HashMap<String, Object> reportParms, String reportId); void runAndRender(HashMap<String, Object> reportParms,
                             String reportId, ReportFormat format, OutputStream outputStream); boolean validate(HashMap<String, Object> reportParms,
                            String reportId); void setGlobalReportRepository(GlobalReportRepository globalReportRepository);  }