use of net.sf.jasperreports.engine.data.JRBeanCollectionDataSource in project Asqatasun by Asqatasun.
the class ExportService method export.
/**
* Processes the download for Excel format
* @param response
* @param resourceId
* @param auditStatistics
* @param dataSource
* @param locale
* @param format
* @throws ColumnBuilderException
* @throws ClassNotFoundException
* @throws JRException
* @throws NotSupportedExportFormatException
*/
@SuppressWarnings("unchecked")
public void export(HttpServletResponse response, long resourceId, AuditStatistics auditStatistics, Collection<?> dataSource, Locale locale, String format) throws ColumnBuilderException, ClassNotFoundException, JRException, NotSupportedExportFormatException {
if (!exportFormatMap.containsKey(format)) {
throw new NotSupportedExportFormatException(format);
}
ExportFormat exportFormat = exportFormatMap.get(format);
DynamicReport dr = LayoutFactory.getInstance().buildReportLayout(locale, auditStatistics, format);
// Retrieve our data source
JRDataSource ds = new JRBeanCollectionDataSource(dataSource);
// params is used for passing extra parameters
JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds);
// Create our output byte stream
// This is the stream where the data will be written
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRExporter exporter;
try {
exporter = (JRExporter) Class.forName(exportFormat.getExporterClassName()).newInstance();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();
response.setHeader(CONTENT_DISPOSITION, INLINE_FILENAME + getFileName(resourceId, exportFormat.getFileExtension()));
// Make sure to set the correct content type
// Each format has its own content type
response.setContentType(exportFormat.getFileType());
response.setContentLength(baos.size());
// Write to reponse stream
writeReportToResponseStream(response, baos);
} catch (InstantiationException | IllegalAccessException ex) {
LOGGER.warn(ex);
}
}
use of net.sf.jasperreports.engine.data.JRBeanCollectionDataSource in project midpoint by Evolveum.
the class MidPointQueryExecutor method createDatasource.
@Override
public JRDataSource createDatasource() throws JRException {
try {
if (query == null && script == null) {
throw new JRException("Neither query, nor script defined in the report.");
}
if (query != null) {
Collection<PrismObject<? extends ObjectType>> results;
results = searchObjects(query, SelectorOptions.createCollection(GetOperationOptions.createRaw()));
return createDataSourceFromObjects(results);
} else {
if (script.contains("AuditEventRecord")) {
Collection<AuditEventRecord> audtiEventRecords = searchAuditRecords(script, getPromptingParameters());
Collection<AuditEventRecordType> auditEventRecordsType = new ArrayList<>();
for (AuditEventRecord aer : audtiEventRecords) {
AuditEventRecordType aerType = aer.createAuditEventRecordType(true);
auditEventRecordsType.add(aerType);
}
return new JRBeanCollectionDataSource(auditEventRecordsType);
} else {
Collection<PrismContainerValue<? extends Containerable>> results;
results = evaluateScript(script, getParameters());
return createDataSourceFromContainerValues(results);
}
}
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
// TODO Auto-generated catch block
throw new JRException(e);
}
}
use of net.sf.jasperreports.engine.data.JRBeanCollectionDataSource in project sic by belluccifranco.
the class ProductoServiceImpl method getReporteListaDePreciosPorEmpresa.
@Override
public byte[] getReporteListaDePreciosPorEmpresa(List<Producto> productos, long idEmpresa) {
ClassLoader classLoader = FacturaServiceImpl.class.getClassLoader();
InputStream isFileReport = classLoader.getResourceAsStream("sic/vista/reportes/ListaPreciosProductos.jasper");
Map params = new HashMap();
params.put("empresa", empresaService.getEmpresaPorId(idEmpresa));
params.put("logo", Utilidades.convertirByteArrayIntoImage(empresaService.getEmpresaPorId(idEmpresa).getLogo()));
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(productos);
try {
return JasperExportManager.exportReportToPdf(JasperFillManager.fillReport(isFileReport, params, ds));
} catch (JRException ex) {
throw new ServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_reporte"), ex);
}
}
use of net.sf.jasperreports.engine.data.JRBeanCollectionDataSource in project sic by belluccifranco.
the class FacturaServiceImpl method getReporteFacturaVenta.
@Override
public byte[] getReporteFacturaVenta(Factura factura) {
ClassLoader classLoader = FacturaServiceImpl.class.getClassLoader();
InputStream isFileReport = classLoader.getResourceAsStream("sic/vista/reportes/FacturaVenta.jasper");
Map params = new HashMap();
ConfiguracionDelSistema cds = configuracionDelSistemaService.getConfiguracionDelSistemaPorEmpresa(factura.getEmpresa());
params.put("preImpresa", cds.isUsarFacturaVentaPreImpresa());
String formasDePago = "";
formasDePago = pagoService.getPagosDeLaFactura(factura.getId_Factura()).stream().map((pago) -> pago.getFormaDePago().getNombre() + " -").reduce(formasDePago, String::concat);
params.put("formasDePago", formasDePago);
if (factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_B) || factura.getTipoComprobante().equals(TipoDeComprobante.PRESUPUESTO)) {
factura.setSubTotal_bruto(factura.getSubTotal());
factura.setIva_105_neto(0);
factura.setIva_21_neto(0);
}
params.put("facturaVenta", factura);
if (factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_A) || factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_B) || factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_C)) {
if (factura.getNumSerieAfip() != 0 && factura.getNumFacturaAfip() != 0) {
params.put("nroComprobante", factura.getNumSerieAfip() + " - " + factura.getNumFacturaAfip());
} else {
params.put("nroComprobante", "");
}
} else {
params.put("nroComprobante", factura.getNumSerie() + " - " + factura.getNumFactura());
}
params.put("logo", Utilidades.convertirByteArrayIntoImage(factura.getEmpresa().getLogo()));
List<RenglonFactura> renglones = this.getRenglonesDeLaFactura(factura.getId_Factura());
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(renglones);
try {
return JasperExportManager.exportReportToPdf(JasperFillManager.fillReport(isFileReport, params, ds));
} catch (JRException ex) {
throw new ServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_reporte"), ex);
}
}
use of net.sf.jasperreports.engine.data.JRBeanCollectionDataSource in project sic by belluccifranco.
the class PedidoServiceImpl method getReportePedido.
@Override
public byte[] getReportePedido(Pedido pedido) {
ClassLoader classLoader = PedidoServiceImpl.class.getClassLoader();
InputStream isFileReport = classLoader.getResourceAsStream("sic/vista/reportes/Pedido.jasper");
Map params = new HashMap();
params.put("pedido", pedido);
params.put("logo", Utilidades.convertirByteArrayIntoImage(pedido.getEmpresa().getLogo()));
List<RenglonPedido> renglones = this.getRenglonesDelPedido(pedido.getId_Pedido());
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(renglones);
try {
return JasperExportManager.exportReportToPdf(JasperFillManager.fillReport(isFileReport, params, ds));
} catch (JRException ex) {
throw new ServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_reporte"), ex);
}
}
Aggregations