Commit 6213bab0c2a1a776acb7821fa82602f2aa5d5a91

Authored by Carlos Alberto
1 parent 7f080a63
Exists in master

Implementação dos recursos de relatório

cit-esi-api/src/main/java/br/com/centralit/esi/api/enumerated/ReportDataSourceEnum.java
1 1 package br.com.centralit.esi.api.enumerated;
2 2  
3 3 public enum ReportDataSourceEnum {
  4 + NONE("ESI.ENUMERADO.DATASOURCE_NENHUM"),
4 5 CONNECTION("ESI.ENUMERADO.DATASOURCE_CONEXAO"),
5 6 DATAOBJECT("ESI.ENUMERADO.DATASOURCE_OBJETO_DADOS"),
6 7 FLOW("ESI.ENUMERADO.DATASOURCE_FLUXO_ESI"),
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/ReportManager.java
... ... @@ -9,4 +9,6 @@ public interface ReportManager extends Serializable {
9 9  
10 10 public byte[] execute(ReportVersion reportVersion, HashMap<String, Object> inputMap);
11 11  
  12 + public void compile(ReportVersion reportVersion);
  13 +
12 14 }
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/JasperReportManagerImpl.java
... ... @@ -34,15 +34,13 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper
34 34 *
35 35 */
36 36 private static final long serialVersionUID = 1L;
  37 +
37 38  
38 39 @Override
39   - public byte[] execute(ReportVersion report, HashMap<String, Object> inputMap) {
40   - JasperPrint print = null;
41   - byte[] buffer = null;
42   -
43   - String path = report.buildBasePath();
  40 + public void compile(ReportVersion reportVersion) {
  41 + String path = reportVersion.buildBasePath();
44 42  
45   - String pathReport = servletContext.getRealPath(path+"/"+report.getFileName());
  43 + String pathReport = servletContext.getRealPath(path+"/"+reportVersion.getFileName());
46 44  
47 45 String pathReportJasper = pathReport.replaceAll(".jrxml", ".jasper");
48 46  
... ... @@ -52,6 +50,18 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper
52 50 e1.printStackTrace();
53 51 throw new EsiExecutionException(e1);
54 52 }
  53 + }
  54 +
  55 + @Override
  56 + public byte[] execute(ReportVersion report, HashMap<String, Object> inputMap) {
  57 + JasperPrint print = null;
  58 + byte[] buffer = null;
  59 +
  60 + String path = report.buildBasePath();
  61 +
  62 + String pathReport = servletContext.getRealPath(path+"/"+report.getFileName());
  63 +
  64 + pathReport = pathReport.replaceAll(".jrxml", ".jasper");
55 65  
56 66 Map<String, Object> params = this.buildParams(report, inputMap);
57 67 params.put("SUBREPORT_DIR", servletContext.getRealPath(path)+"/");
... ... @@ -61,7 +71,7 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper
61 71 Connection connection = dataSourceService.connect(report.getDataSource().getConnection());
62 72  
63 73 try {
64   - print = JasperFillManager.fillReport(pathReportJasper, params, connection);
  74 + print = JasperFillManager.fillReport(pathReport, params, connection);
65 75 } catch (JRException e) {
66 76 e.printStackTrace();
67 77 try {
... ... @@ -75,7 +85,7 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper
75 85  
76 86 default:
77 87 try {
78   - print = JasperFillManager.fillReport(pathReportJasper, params, this.buildDataSource(report, inputMap));
  88 + print = JasperFillManager.fillReport(pathReport, params, this.buildDataSource(report, inputMap));
79 89 } catch (JRException e) {
80 90 throw new EsiExecutionException(e);
81 91 }
... ... @@ -86,7 +96,7 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper
86 96 try {
87 97 buffer = JasperExportManager.exportReportToPdf(print);
88 98  
89   - String pathPDF = pathReport.replaceAll(".jrxml", ".pdf");
  99 + String pathPDF = pathReport.replaceAll(".jasper", ".pdf");
90 100  
91 101 File file = new File(pathPDF);
92 102 FileOutputStream in = new FileOutputStream(file);
... ... @@ -140,6 +150,5 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper
140 150  
141 151 return dataSource;
142 152 }
143   -
144 153  
145 154 }
146 155 \ No newline at end of file
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/PentahoReportManagerImpl.java
... ... @@ -27,5 +27,10 @@ public class PentahoReportManagerImpl extends ReportManagerImpl implements Penta
27 27 return null;
28 28 }
29 29  
30   -
  30 + @Override
  31 + public void compile(ReportVersion reportVersion) {
  32 + // TODO Auto-generated method stub
  33 +
  34 + }
  35 +
31 36 }
32 37 \ No newline at end of file
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ReportVersionServiceImpl.java
... ... @@ -77,6 +77,7 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
77 77  
78 78 oldReportVersion.setParameters(null);
79 79 }
  80 + reportDataSourceService.remove(oldReportVersion.getDataSource());
80 81 }
81 82  
82 83 @Override
... ... @@ -140,6 +141,8 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
140 141 }
141 142 }
142 143  
  144 + this.compile(reportVersion);
  145 +
143 146 FormVersion formVersion = reportVersion.getFormVersion();
144 147 formVersion.setPath(reportVersion.getPath());
145 148 formVersion.setGenerateDefaultPage(true);
... ... @@ -150,7 +153,7 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
150 153 }
151 154 reportVersion.setForm(formVersion.getResource());
152 155 }
153   -
  156 +
154 157 @Override
155 158 protected ResourceVersion clone(ResourceVersion resourceVersion) {
156 159 ReportVersion oldResourceVersion = (ReportVersion) resourceVersion;
... ... @@ -216,4 +219,12 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
216 219 return resourceVersion;
217 220 }
218 221  
  222 +
  223 + private void compile(ReportVersion reportVersion) {
  224 + if (reportVersion.getEngine().equals(ReportEngineEnum.JASPER)) {
  225 + jasperReportManager.compile(reportVersion);
  226 + }else if (reportVersion.getEngine().equals(ReportEngineEnum.PENTAHO)) {
  227 + pentahoReportManager.compile(reportVersion);
  228 + }
  229 + }
219 230 }
220 231 \ No newline at end of file
... ...
cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java
... ... @@ -2169,6 +2169,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen
2169 2169 internacionalizacaoList.add(new Internacionalizacao("ESI.DATASOURCE", "Data source", dominio, modulo));
2170 2170 internacionalizacaoList.add(new Internacionalizacao("ESI.DATAOBJECT", "Objeto de dados", dominio, modulo));
2171 2171  
  2172 + internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_NENHUM", "Nenhum", dominio, modulo));
2172 2173 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_CONEXAO", "Conexão de dados", dominio, modulo));
2173 2174 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_OBJETO_DADOS", "Objeto de dados", dominio, modulo));
2174 2175 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_FLUXO_ESI", "Fluxo ESI", dominio, modulo));
... ...
cit-esi-web/src/main/resources/reports/empregado.jrxml
... ... @@ -3,20 +3,18 @@
3 3 <property name="ireport.zoom" value="1.0"/>
4 4 <property name="ireport.x" value="0"/>
5 5 <property name="ireport.y" value="0"/>
  6 + <subDataset name="telefones" uuid="f01c39a3-0b2c-4ff2-88b2-680f489cfa35"/>
6 7 <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
7 8 <defaultValueExpression><![CDATA[]]></defaultValueExpression>
8 9 </parameter>
9   - <queryString language="JSON">
10   - <![CDATA[]]>
  10 + <queryString>
  11 + <![CDATA[select id, nome, matricula from rh_empregado]]>
11 12 </queryString>
12 13 <field name="id" class="java.lang.Integer">
13 14 <fieldDescription><![CDATA[id]]></fieldDescription>
14 15 </field>
15 16 <field name="nome" class="java.lang.String"/>
16 17 <field name="matricula" class="java.lang.String"/>
17   - <field name="telefones" class="java.util.Collection">
18   - <property name="numero" value=""/>
19   - </field>
20 18 <background>
21 19 <band splitType="Stretch"/>
22 20 </background>
... ... @@ -59,7 +57,10 @@
59 57 </textField>
60 58 <subreport>
61 59 <reportElement x="434" y="0" width="110" height="22" uuid="10ec63c0-9a3b-4c31-bb52-8e3a6296b10b"/>
62   - <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{telefones})]]></dataSourceExpression>
  60 + <subreportParameter name="empregado_id">
  61 + <subreportParameterExpression><![CDATA[$F{id}]]></subreportParameterExpression>
  62 + </subreportParameter>
  63 + <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
63 64 <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "empregado_telefone.jasper"]]></subreportExpression>
64 65 </subreport>
65 66 </band>
... ...
cit-esi-web/src/main/resources/reports/empregado_telefone.jrxml
... ... @@ -10,9 +10,9 @@
10 10 <band splitType="Stretch"/>
11 11 </background>
12 12 <detail>
13   - <band height="23" splitType="Stretch">
  13 + <band height="42" splitType="Stretch">
14 14 <textField>
15   - <reportElement x="0" y="0" width="100" height="20" uuid="2b62387e-af3c-4c0c-81b8-e211519c1d4a"/>
  15 + <reportElement x="11" y="12" width="100" height="20" uuid="42865c6c-27a5-48de-9549-8c87e20aa594"/>
16 16 <textFieldExpression><![CDATA[$F{numero}]]></textFieldExpression>
17 17 </textField>
18 18 </band>
... ...
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js
... ... @@ -401,7 +401,7 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
401 401 // Limpa o formulario preenchido
402 402 $scope.limparReport = function(){
403 403 $scope.report = {resource: {type: "REPORT"}, className: className, majorVersion: 1, minorVersion: 0
404   - , formVersion: $scope.createFormVersion(), dataSource: {}, parameters: []};
  404 + , formVersion: $scope.createFormVersion(), dataSource: {type: 'NONE'}, parameters: []};
405 405 $scope.uploader.clearQueue();
406 406 };
407 407  
... ...