fixes bug#11452

dev:Claudio
qua:Renato


git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@83114 d1611594-4594-4d17-8e1d-87c2c4800839
master
aristides 2018-07-04 13:45:40 +00:00
parent 69fb9713ff
commit 482d09a055
1 changed files with 45 additions and 30 deletions

View File

@ -6,12 +6,14 @@ import java.util.Locale;
import java.util.ResourceBundle;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRParagraph;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JExcelApiExporter;
import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
import net.sf.jasperreports.engine.util.JRProperties;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@ -27,13 +29,13 @@ import com.rjconsultores.ventaboletos.utilerias.LocaleUtil;
*
*/
public class RenderRelatorioJasper {
private static Logger log = Logger.getLogger(Relatorio.class);
protected JasperPrint jasperPrint;
private Relatorio relatorio;
/**
* @param relatorio
* Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios
@ -46,7 +48,7 @@ public class RenderRelatorioJasper {
public RenderRelatorioJasper(Relatorio relatorio) throws Exception {
this.relatorio = relatorio;
}
public void preRender() {
this.initBundler();
this.initLocale();
@ -55,22 +57,22 @@ public class RenderRelatorioJasper {
private void initBundler() {
// TODO Alterar para injeção de acordo com usuário logado ou outro meio para obter o Locale correto
Locale locale = LocaleUtil.getLocale();
try {
ResourceBundle resource = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNome(), locale);
this.relatorio.getParametros().put(JRParameter.REPORT_RESOURCE_BUNDLE, resource);
/* Adicionar o arquivo de internacionalização para o subreporte quando informado */
if(this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 0) {
if(this.relatorio.getNomeSubReporte().length == 1 && StringUtils.isNotBlank(this.relatorio.getNomeSubReporte()[0])) {
if (this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 0) {
if (this.relatorio.getNomeSubReporte().length == 1 && StringUtils.isNotBlank(this.relatorio.getNomeSubReporte()[0])) {
ResourceBundle resourceSubReporte = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNomeSubReporte()[0], locale);
this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE", resourceSubReporte);
} else if(this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 1) {
} else if (this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 1) {
int indice = 0;
for (String nomeSubReporte : this.relatorio.getNomeSubReporte()) {
if(StringUtils.isNotBlank(nomeSubReporte)) {
if (StringUtils.isNotBlank(nomeSubReporte)) {
ResourceBundle resourceSubReporte = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + nomeSubReporte, locale);
this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE" + "_" + (++indice), resourceSubReporte);
}
@ -78,7 +80,7 @@ public class RenderRelatorioJasper {
}
}
} catch (Exception e) {
log.error(e.getMessage(),e);
log.error(e.getMessage(), e);
}
}
@ -108,29 +110,42 @@ public class RenderRelatorioJasper {
this.preRender();
byte[] conteudo = null;
if (this.jasperPrint == null) {
try {
if (this.jasperPrint == null) {
if (this.relatorio.isCollectionDataSource()) {
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getCollectionDataSource());
} else {
if (this.relatorio.isCustomDataSource())
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), (JRDataSource) this.relatorio.getCustomDataSource());
else
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getConexao());
if (this.relatorio.isCollectionDataSource()) {
if (!StringUtils.isBlank(this.relatorio.getNome()) && this.relatorio.getNome().equalsIgnoreCase("RelatorioGratuidade")) {
JRProperties.setProperty(JRParagraph.DEFAULT_TAB_STOP_WIDTH, "10");
}
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getCollectionDataSource());
} else {
if (this.relatorio.isCustomDataSource())
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), (JRDataSource) this.relatorio.getCustomDataSource());
else
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getConexao());
}
}
}
switch (saida) {
switch (saida) {
case PDF:
conteudo = this.renderPdf();
break;
case PDF:
conteudo = this.renderPdf();
break;
case XLS:
conteudo = this.renderXls(isCustomXls);
break;
case XLS:
conteudo = this.renderXls(isCustomXls);
break;
}
} catch (Exception e) {
// TODO: handle exception
throw new Exception();
} finally {
if (!StringUtils.isBlank(this.relatorio.getNome()) && this.relatorio.getNome().equalsIgnoreCase("RelatorioGratuidade")) {
JRProperties.setProperty(JRParagraph.DEFAULT_TAB_STOP_WIDTH, "40");
}
}
return conteudo;
@ -139,11 +154,11 @@ public class RenderRelatorioJasper {
protected byte[] renderXls(boolean isCustomXls) throws Exception {
JExcelApiExporter exporterXLS = new JExcelApiExporter();
ByteArrayOutputStream output = new ByteArrayOutputStream();
//As duas propriedades são para quando o arquivo xls chegar no máximo de linhas pular para a próxima aba do arquivo mantis #11294
// As duas propriedades são para quando o arquivo xls chegar no máximo de linhas pular para a próxima aba do arquivo mantis #11294
exporterXLS.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporterXLS.setParameter(JExcelApiExporterParameter.MAXIMUM_ROWS_PER_SHEET, 65500);
exporterXLS.setParameter(JExcelApiExporterParameter.JASPER_PRINT, this.jasperPrint);
exporterXLS.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, output);