*
* :[paramName] - where paramName will be replaced by the value passed as parameter to the jasper
* report with the same name as [paramName]
*/
// add to missingParameter
ReportDefinition missed = new ReportDefinition();
// set the name
missed.setName(name.getValue());
// set the class
Attribute clazz = elem.attribute("class");
missed.setClazz(clazz.getValue());
List<Element> props =elem.elements("property");
Properties property = new SortedProperties();
for (Element prop:props) {
String propName = prop.attributeValue("name");
String propValue = prop.attributeValue("value");
if ("prompt.type".equals(propName)) {
missed.setType(propValue);
} else if ("prompt.query".equals(propName)) {
// extract the native query to database
String queryName = propValue;
if(!StringUtil.isEmpty(queryName)){
//try to match :[paramName]
Matcher matcher = Pattern.compile(":(\\w+)").matcher(queryName);
while (matcher.find()) {
String paramName = matcher.group(0).substring(1);
if (!StringUtil.isEmpty(paramName) && requestParams.get(paramName)!=null){
String[] paramValueArr = requestParams.get(paramName);
String paramValue = StringUtil.explode(',', paramValueArr);
queryName = queryName.replaceAll(":" + paramName, paramValue);
}
}
}
List<Object[]> rs = ((ReportDAO) getDao()).getParamOptionResults(queryName);
for (Object[] option : rs) {
property.put(Long.valueOf(option[1].toString()), option[0].toString());
}
}else if("prompt.command".equals(propName)){
missed.setType(propName);
property.put(propValue, dynamicParameters.get(propValue));
}else
property.put(propName, propValue);
}
missed.setProperties(property);
missing.add(missed);
}
}
if (!requestParams.containsKey(DynamicReport.REPORT_FORMAT)) {
ReportDefinition missed = new ReportDefinition();
missed.setName("reportFormat");
missed.setClazz("java.lang.String");
missed.setType("dropdown");
Properties props = new Properties();
props.put(DynamicReport.FORMAT_EXCEL, "Excel");
props.put(DynamicReport.FORMAT_HTML, "Html");
props.put(DynamicReport.FORMAT_IMAGE, "Graph Image");
props.put(DynamicReport.FORMAT_PDF, "PDF");
missed.setProperties(props);
missing.add(missed);
}
} catch (DocumentException e) {
_log.error(e,e);
}