Search in sources :

Example 1 with JRBeanCollectionDataSource

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);
    }
}
Also used : ClassicLayoutManager(ar.com.fdvs.dj.core.layout.ClassicLayoutManager) DynamicReport(ar.com.fdvs.dj.domain.DynamicReport) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) NotSupportedExportFormatException(org.asqatasun.webapp.report.service.exception.NotSupportedExportFormatException) ExportFormat(org.asqatasun.webapp.report.format.ExportFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with JRBeanCollectionDataSource

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) JRException(net.sf.jasperreports.engine.JRException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ArrayList(java.util.ArrayList) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Containerable(com.evolveum.midpoint.prism.Containerable) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord)

Example 3 with JRBeanCollectionDataSource

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);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) ServiceException(sic.service.ServiceException) BusinessServiceException(sic.service.BusinessServiceException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with JRBeanCollectionDataSource

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);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) ServiceException(sic.service.ServiceException) BusinessServiceException(sic.service.BusinessServiceException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ConfiguracionDelSistema(sic.modelo.ConfiguracionDelSistema) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) RenglonFactura(sic.modelo.RenglonFactura) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with JRBeanCollectionDataSource

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);
    }
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) JRException(net.sf.jasperreports.engine.JRException) ServiceException(sic.service.ServiceException) BusinessServiceException(sic.service.BusinessServiceException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JRBeanCollectionDataSource (net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)5 JRException (net.sf.jasperreports.engine.JRException)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BusinessServiceException (sic.service.BusinessServiceException)3 ServiceException (sic.service.ServiceException)3 ClassicLayoutManager (ar.com.fdvs.dj.core.layout.ClassicLayoutManager)1 DynamicReport (ar.com.fdvs.dj.domain.DynamicReport)1 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 Containerable (com.evolveum.midpoint.prism.Containerable)1 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)1