use of net.sf.jasperreports.engine.JRParameter in project midpoint by Evolveum.
the class JasperReportDto method initFileds.
private void initFileds(boolean onlyForPromptingParams) {
if (jasperReportXml == null) {
return;
}
try {
design = ReportTypeUtil.loadJasperDesign(jasperReportXml);
query = design.getQuery().getText();
fields = new ArrayList<JasperReportFieldDto>();
for (JRField field : design.getFieldsList()) {
fields.add(new JasperReportFieldDto(field.getName(), field.getValueClass(), field.getValueClassName()));
}
for (JasperReportFieldDto field : fields) {
design.removeField(field.getName());
}
parameters = new ArrayList<JasperReportParameterDto>();
for (JRParameter parameter : design.getParametersList()) {
if (parameter.isSystemDefined()) {
continue;
}
if (onlyForPromptingParams && !parameter.isForPrompting()) {
continue;
}
JasperReportParameterDto p = new JasperReportParameterDto(parameter);
parameters.add(p);
}
for (JasperReportParameterDto param : parameters) {
design.removeParameter(param.getName());
}
detail = new String(Base64.decodeBase64(jasperReportXml));
} catch (SchemaException e) {
// TODO Auto-generated catch block
throw new IllegalArgumentException(e);
}
}
use of net.sf.jasperreports.engine.JRParameter in project midpoint by Evolveum.
the class MidPointQueryExecutor method getParameters.
protected Map<QName, Object> getParameters() {
JRParameter[] params = dataset.getParameters();
Map<QName, Object> expressionParameters = new HashMap<QName, Object>();
for (JRParameter param : params) {
if (param.isSystemDefined()) {
continue;
}
//LOGGER.trace(((JRBaseParameter)param).getName());
Object v = getParameterValue(param.getName());
try {
expressionParameters.put(new QName(param.getName()), new PrismPropertyValue(v));
} catch (Exception e) {
//just skip properties that are not important for midpoint
}
LOGGER.trace("p.val: {}", v);
}
return expressionParameters;
}
use of net.sf.jasperreports.engine.JRParameter in project mots by motech-implementations.
the class JasperTemplateServiceTest method shouldValidateFileAndSetDataIfDefaultValueExpressionIsNull.
@Test
public void shouldValidateFileAndSetDataIfDefaultValueExpressionIsNull() throws Exception {
MultipartFile file = mock(MultipartFile.class);
when(file.getOriginalFilename()).thenReturn(NAME_OF_FILE);
mockStatic(JasperCompileManager.class);
JasperReport report = mock(JasperReport.class);
InputStream inputStream = mock(InputStream.class);
when(file.getInputStream()).thenReturn(inputStream);
JRParameter param1 = mock(JRParameter.class);
JRParameter param2 = mock(JRParameter.class);
JRPropertiesMap propertiesMap = mock(JRPropertiesMap.class);
JRExpression jrExpression = mock(JRExpression.class);
String[] propertyNames = { DISPLAY_NAME };
when(report.getParameters()).thenReturn(new JRParameter[] { param1, param2 });
when(JasperCompileManager.compileReport(inputStream)).thenReturn(report);
when(propertiesMap.getPropertyNames()).thenReturn(propertyNames);
when(propertiesMap.getProperty(DISPLAY_NAME)).thenReturn(PARAM_DISPLAY_NAME);
when(param1.getPropertiesMap()).thenReturn(propertiesMap);
when(param1.getValueClassName()).thenReturn("java.lang.String");
when(param1.isForPrompting()).thenReturn(true);
when(param1.getDefaultValueExpression()).thenReturn(jrExpression);
when(jrExpression.getText()).thenReturn("text");
when(param2.getPropertiesMap()).thenReturn(propertiesMap);
when(param2.getValueClassName()).thenReturn("java.lang.Integer");
when(param2.isForPrompting()).thenReturn(true);
when(param2.getDefaultValueExpression()).thenReturn(null);
ByteArrayOutputStream byteOutputStream = mock(ByteArrayOutputStream.class);
whenNew(ByteArrayOutputStream.class).withAnyArguments().thenReturn(byteOutputStream);
ObjectOutputStream objectOutputStream = spy(new ObjectOutputStream(byteOutputStream));
whenNew(ObjectOutputStream.class).withArguments(byteOutputStream).thenReturn(objectOutputStream);
doNothing().when(objectOutputStream).writeObject(report);
byte[] byteData = new byte[1];
when(byteOutputStream.toByteArray()).thenReturn(byteData);
JasperTemplate jasperTemplate = new JasperTemplate();
jasperTemplateService.validateFileAndInsertTemplate(jasperTemplate, file);
verify(jasperTemplateRepository).save(jasperTemplate);
assertThat(jasperTemplate.getTemplateParameters().get(0).getDisplayName(), is(PARAM_DISPLAY_NAME));
}
use of net.sf.jasperreports.engine.JRParameter in project mots by motech-implementations.
the class JasperTemplateService method validateFileAndSetData.
/**
* Validate ".jrxml" report file with JasperCompileManager. If report is valid create additional
* report parameters. Save additional report parameters as JasperTemplateParameter list. Save
* report file as ".jasper" in byte array in Template class. If report is not valid throw
* exception.
*/
private void validateFileAndSetData(JasperTemplate jasperTemplate, MultipartFile file) throws ReportingException {
ReportingValidationHelper.throwIfFileIsNull(file);
ReportingValidationHelper.throwIfIncorrectFileType(file, ALLOWED_FILETYPES);
ReportingValidationHelper.throwIfFileIsEmpty(file);
try {
JasperReport report = JasperCompileManager.compileReport(file.getInputStream());
String reportType = report.getProperty(REPORT_TYPE_PROPERTY);
if (reportType != null) {
jasperTemplate.setType(reportType);
}
String formats = report.getProperty(SUPPORTED_FORMATS_PROPERTY);
if (formats != null) {
jasperTemplate.setSupportedFormats(extractListProperties(formats));
}
JRParameter[] jrParameters = report.getParameters();
if (jrParameters != null && jrParameters.length > 0) {
processJrParameters(jasperTemplate, jrParameters);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(report);
jasperTemplate.setData(bos.toByteArray());
} catch (JRException ex) {
throw new ReportingException(ex, ERROR_REPORTING_FILE_INVALID);
} catch (IOException ex) {
throw new ReportingException(ex, ex.getMessage());
}
}
use of net.sf.jasperreports.engine.JRParameter in project opennms by OpenNMS.
the class JasperReportService method buildJRparameters.
private Map<String, Object> buildJRparameters(final Map<String, Object> onmsReportParms, final JRParameter[] reportParms) throws ReportException {
final Map<String, Object> jrReportParms = new HashMap<String, Object>();
for (final JRParameter reportParm : reportParms) {
if (apply(getParameterFilters(), reportParm)) {
final String parmName = reportParm.getName();
if (!onmsReportParms.containsKey(parmName)) {
throw new ReportException("Required parameter " + parmName + " not supplied to JasperReports by OpenNMS");
}
if (reportParm.getValueClassName().equals("java.lang.String")) {
jrReportParms.put(parmName, (String) onmsReportParms.get(parmName));
continue;
}
if (reportParm.getValueClassName().equals("java.lang.Integer")) {
jrReportParms.put(parmName, (Integer) onmsReportParms.get(parmName));
continue;
}
if (reportParm.getValueClassName().equals("java.lang.Float")) {
jrReportParms.put(parmName, (Float) onmsReportParms.get(parmName));
continue;
}
if (reportParm.getValueClassName().equals("java.lang.Double")) {
jrReportParms.put(parmName, (Double) onmsReportParms.get(parmName));
continue;
}
if (reportParm.getValueClassName().equals("java.util.Date")) {
jrReportParms.put(parmName, (Date) onmsReportParms.get(parmName));
continue;
}
if (reportParm.getValueClassName().equals("java.sql.Date")) {
final Date date = (Date) onmsReportParms.get(parmName);
jrReportParms.put(parmName, new java.sql.Date(date.getTime()));
continue;
}
if (reportParm.getValueClassName().equals("java.sql.Timestamp")) {
final Date date = (Date) onmsReportParms.get(parmName);
jrReportParms.put(parmName, new java.sql.Timestamp(date.getTime()));
continue;
}
throw new ReportException("Unsupported report parameter type " + reportParm.getValueClassName());
}
}
return jrReportParms;
}
Aggregations