Commit a1745259ff005065f276c09a449d61a81474eceb

Authored by Carlos Alberto
1 parent e8e56ec0
Exists in master

Implementação de recursos de relatório PENTAHO

cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportDataSource.java
... ... @@ -75,6 +75,7 @@ public class ReportDataSource extends PersistentObject {
75 75  
76 76 public ReportDataSource(ReportDataSource reportDataSource) {
77 77 this.type = reportDataSource.getType();
  78 + this.connection = reportDataSource.getConnection();
78 79 this.dataObject = reportDataSource.getDataObject();
79 80 this.flow = reportDataSource.getFlow();
80 81 this.scriptCode = reportDataSource.getScriptCode();
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/PentahoReportManagerImpl.java
1 1 package br.com.centralit.esi.api.resource.service.impl;
2 2  
  3 +import java.io.FileInputStream;
  4 +import java.io.IOException;
  5 +import java.net.MalformedURLException;
  6 +import java.sql.Connection;
3 7 import java.util.HashMap;
  8 +import java.util.Map;
4 9  
  10 +import org.pentaho.reporting.engine.classic.core.MasterReport;
  11 +import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
  12 +import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory;
  13 +import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
  14 +import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
  15 +import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil;
  16 +import org.pentaho.reporting.libraries.resourceloader.ResourceException;
5 17 import org.springframework.stereotype.Component;
6 18  
  19 +import br.com.centralit.esi.api.data.core.DataObjectUtil;
  20 +import br.com.centralit.esi.api.enumerated.ReportFormatTypeEnum;
  21 +import br.com.centralit.esi.api.enumerated.ResourceTypeEnum;
  22 +import br.com.centralit.esi.api.resource.model.ReportDataSource;
7 23 import br.com.centralit.esi.api.resource.model.ReportVersion;
8 24 import br.com.centralit.esi.api.resource.service.PentahoReportManager;
  25 +import br.com.centralit.esi.api.util.DefaultConvertUtils;
  26 +import br.com.centralit.esi.api.util.PentahooReportUtil;
  27 +import br.com.centralit.esi.exception.EsiExecutionException;
9 28  
10 29 @Component("pentahoReportManager")
11 30 public class PentahoReportManagerImpl extends ReportManagerImpl implements PentahoReportManager {
... ... @@ -16,21 +35,104 @@ public class PentahoReportManagerImpl extends ReportManagerImpl implements Penta
16 35 private static final long serialVersionUID = 1L;
17 36  
18 37 @Override
19   - protected Object buildDataSource(ReportVersion report, HashMap<String, Object> parameters) {
20   - // TODO Auto-generated method stub
21   - return null;
  38 + protected SQLReportDataFactory buildDataSource(ReportVersion report, HashMap<String, Object> parameters) {
  39 + ReportDataSource reportDataSource = report.getDataSource();
  40 + SQLReportDataFactory dataSource = null;
  41 + Connection connection = null;
  42 +
  43 + switch (reportDataSource.getType()) {
  44 + case CONNECTION:
  45 + connection = dataSourceService.connect(report.getDataSource().getConnection());
  46 + dataSource = new SQLReportDataFactory(connection);
  47 + break;
  48 +
  49 + case DATAOBJECT:
  50 + connection = dataSourceService.connect(reportDataSource.getDataObject().getDataSource());
  51 + dataSource = new SQLReportDataFactory(connection);
  52 + if (reportDataSource.getCustomSQL() != null) {
  53 + dataSource.setQuery(reportDataSource.getDataObject().getName(), reportDataSource.getCustomSQL().getSql());
  54 + }else{
  55 + dataSource.setQuery(reportDataSource.getDataObject().getName(), DataObjectUtil.buildSelectSQL(reportDataSource.getDataObject()));
  56 + }
  57 + break;
  58 +
  59 + default:
  60 + break;
  61 + }
  62 +
  63 + return dataSource;
22 64 }
23 65  
24 66 @Override
25   - public byte[] execute(ReportVersion reportVersion, HashMap<String, Object> parameters) {
26   - // TODO Auto-generated method stub
27   - return null;
  67 + public byte[] execute(ReportVersion report, HashMap<String, Object> inputMap) {
  68 + byte[] buffer = null;
  69 +
  70 + String path = ResourceTypeEnum.REPORT.getPath();
  71 +
  72 + String pathReport = servletContext.getRealPath(path+"/"+report.getFileName());
  73 +
  74 + Map<String, Object> params = this.buildParams(report, inputMap);
  75 +
  76 + ReportFormatTypeEnum outType = ReportFormatTypeEnum.PDF;
  77 +
  78 + DefaultConvertUtils.registerDefaultConverts();
  79 + PentahooReportUtil pentahooReportUtil = new PentahooReportUtil();
  80 + MasterReport masterReport = null;
  81 + try {
  82 + SQLReportDataFactory dataSource = this.buildDataSource(report, inputMap);
  83 + masterReport = pentahooReportUtil.getCompleteReportDefinition(pathReport, params, dataSource);
  84 + } catch (MalformedURLException e) {
  85 + e.printStackTrace();
  86 + throw new EsiExecutionException(e);
  87 + } catch (ResourceException e) {
  88 + e.printStackTrace();
  89 + throw new EsiExecutionException(e);
  90 + }
  91 +
  92 + String outputPath = "";
  93 + try{
  94 + switch (outType) {
  95 + case HTML:
  96 + outputPath = pathReport.replaceAll(".prpt", ".html");
  97 + HtmlReportUtil.createDirectoryHTML(masterReport, outputPath);
  98 + break;
  99 +
  100 + case PDF:
  101 + outputPath = pathReport.replaceAll(".prpt", ".pdf");
  102 + PdfReportUtil.createPDF(masterReport, outputPath);
  103 + break;
  104 +
  105 + case EXCEL:
  106 + outputPath = pathReport.replaceAll(".prpt", ".xlsx");
  107 + ExcelReportUtil.createXLSX(masterReport, outputPath);
  108 + break;
  109 +
  110 + default:
  111 + break;
  112 + }
  113 + } catch (IOException e) {
  114 + e.printStackTrace();
  115 + throw new EsiExecutionException(e);
  116 + } catch (ReportProcessingException e) {
  117 + e.printStackTrace();
  118 + throw new EsiExecutionException(e);
  119 + }
  120 +
  121 + String fullPath = servletContext.getRealPath(outputPath);
  122 + try {
  123 + FileInputStream is = new FileInputStream(fullPath);
  124 + buffer = new byte[is.available()];
  125 + is.read(buffer);
  126 + is.close();
  127 + } catch (Exception e) {
  128 + e.printStackTrace();
  129 + }
  130 +
  131 + return buffer;
28 132 }
29 133  
30 134 @Override
31   - public void compile(ReportVersion reportVersion) {
32   - // TODO Auto-generated method stub
33   -
  135 + public void compile(ReportVersion reportVersion) {
34 136 }
35 137  
36 138 }
37 139 \ No newline at end of file
... ...
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js
... ... @@ -32,8 +32,16 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
32 32 $scope.reportEngineList = result;
33 33 });
34 34  
  35 + $scope.dataSourceList = {};
  36 + $scope.dataSourceList.JASPER = [];
  37 + $scope.dataSourceList.PENTAHO = [];
35 38 DomainRepository.getEnumeratedDomain('ReportDataSourceEnum').then(function(result) {
36   - $scope.reportDataSourceList = result;
  39 + angular.forEach(result, function (type) {
  40 + $scope.dataSourceList.JASPER.push(type);
  41 + if (type.chave != 'FLOW' && type.chave != 'SCRIPT') {
  42 + $scope.dataSourceList.PENTAHO.push(type);
  43 + }
  44 + });
37 45 });
38 46  
39 47 DomainRepository.getEnumeratedDomain('ReportParameterTypeEnum').then(function(result) {
... ... @@ -430,6 +438,8 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
430 438 $scope.appController.activeWorkspace($scope.workspace);
431 439 }
432 440  
  441 + $scope.reportDataSourceList = $scope.dataSourceList[$scope.report.engine];
  442 +
433 443 $scope.edit = edit;
434 444  
435 445 $scope.newReport = false;
... ...
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js
... ... @@ -117,7 +117,7 @@ citApp.controller(&#39;ReportFileController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportReposi
117 117 $scope.uploader.filters.push({
118 118 name: 'reportFilter',
119 119 fn: function(item /*{File|FileLikeObject}*/, options) {
120   - return item.name.indexOf(".jrxml") !== -1;
  120 + return item.name.indexOf(".jrxml") !== -1 || item.name.indexOf(".prpt") !== -1;
121 121 }
122 122 });
123 123  
... ... @@ -156,6 +156,8 @@ citApp.controller(&#39;ReportFileController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportReposi
156 156 $scope.report.engine = undefined;
157 157 if (fileName.indexOf(".jrxml") > 0) {;
158 158 $scope.report.engine = 'JASPER';
  159 + }else{
  160 + $scope.report.engine = 'PENTAHO';
159 161 }
160 162 };
161 163  
... ...