diff --git a/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportDataSource.java b/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportDataSource.java index 1d8650d..aff9ba1 100644 --- a/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportDataSource.java +++ b/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportDataSource.java @@ -75,6 +75,7 @@ public class ReportDataSource extends PersistentObject { public ReportDataSource(ReportDataSource reportDataSource) { this.type = reportDataSource.getType(); + this.connection = reportDataSource.getConnection(); this.dataObject = reportDataSource.getDataObject(); this.flow = reportDataSource.getFlow(); this.scriptCode = reportDataSource.getScriptCode(); diff --git a/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/PentahoReportManagerImpl.java b/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/PentahoReportManagerImpl.java index 91c3592..e0316e9 100644 --- a/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/PentahoReportManagerImpl.java +++ b/cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/PentahoReportManagerImpl.java @@ -1,11 +1,30 @@ package br.com.centralit.esi.api.resource.service.impl; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.sql.Connection; import java.util.HashMap; +import java.util.Map; +import org.pentaho.reporting.engine.classic.core.MasterReport; +import org.pentaho.reporting.engine.classic.core.ReportProcessingException; +import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory; +import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil; +import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil; +import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil; +import org.pentaho.reporting.libraries.resourceloader.ResourceException; import org.springframework.stereotype.Component; +import br.com.centralit.esi.api.data.core.DataObjectUtil; +import br.com.centralit.esi.api.enumerated.ReportFormatTypeEnum; +import br.com.centralit.esi.api.enumerated.ResourceTypeEnum; +import br.com.centralit.esi.api.resource.model.ReportDataSource; import br.com.centralit.esi.api.resource.model.ReportVersion; import br.com.centralit.esi.api.resource.service.PentahoReportManager; +import br.com.centralit.esi.api.util.DefaultConvertUtils; +import br.com.centralit.esi.api.util.PentahooReportUtil; +import br.com.centralit.esi.exception.EsiExecutionException; @Component("pentahoReportManager") public class PentahoReportManagerImpl extends ReportManagerImpl implements PentahoReportManager { @@ -16,21 +35,104 @@ public class PentahoReportManagerImpl extends ReportManagerImpl implements Penta private static final long serialVersionUID = 1L; @Override - protected Object buildDataSource(ReportVersion report, HashMap parameters) { - // TODO Auto-generated method stub - return null; + protected SQLReportDataFactory buildDataSource(ReportVersion report, HashMap parameters) { + ReportDataSource reportDataSource = report.getDataSource(); + SQLReportDataFactory dataSource = null; + Connection connection = null; + + switch (reportDataSource.getType()) { + case CONNECTION: + connection = dataSourceService.connect(report.getDataSource().getConnection()); + dataSource = new SQLReportDataFactory(connection); + break; + + case DATAOBJECT: + connection = dataSourceService.connect(reportDataSource.getDataObject().getDataSource()); + dataSource = new SQLReportDataFactory(connection); + if (reportDataSource.getCustomSQL() != null) { + dataSource.setQuery(reportDataSource.getDataObject().getName(), reportDataSource.getCustomSQL().getSql()); + }else{ + dataSource.setQuery(reportDataSource.getDataObject().getName(), DataObjectUtil.buildSelectSQL(reportDataSource.getDataObject())); + } + break; + + default: + break; + } + + return dataSource; } @Override - public byte[] execute(ReportVersion reportVersion, HashMap parameters) { - // TODO Auto-generated method stub - return null; + public byte[] execute(ReportVersion report, HashMap inputMap) { + byte[] buffer = null; + + String path = ResourceTypeEnum.REPORT.getPath(); + + String pathReport = servletContext.getRealPath(path+"/"+report.getFileName()); + + Map params = this.buildParams(report, inputMap); + + ReportFormatTypeEnum outType = ReportFormatTypeEnum.PDF; + + DefaultConvertUtils.registerDefaultConverts(); + PentahooReportUtil pentahooReportUtil = new PentahooReportUtil(); + MasterReport masterReport = null; + try { + SQLReportDataFactory dataSource = this.buildDataSource(report, inputMap); + masterReport = pentahooReportUtil.getCompleteReportDefinition(pathReport, params, dataSource); + } catch (MalformedURLException e) { + e.printStackTrace(); + throw new EsiExecutionException(e); + } catch (ResourceException e) { + e.printStackTrace(); + throw new EsiExecutionException(e); + } + + String outputPath = ""; + try{ + switch (outType) { + case HTML: + outputPath = pathReport.replaceAll(".prpt", ".html"); + HtmlReportUtil.createDirectoryHTML(masterReport, outputPath); + break; + + case PDF: + outputPath = pathReport.replaceAll(".prpt", ".pdf"); + PdfReportUtil.createPDF(masterReport, outputPath); + break; + + case EXCEL: + outputPath = pathReport.replaceAll(".prpt", ".xlsx"); + ExcelReportUtil.createXLSX(masterReport, outputPath); + break; + + default: + break; + } + } catch (IOException e) { + e.printStackTrace(); + throw new EsiExecutionException(e); + } catch (ReportProcessingException e) { + e.printStackTrace(); + throw new EsiExecutionException(e); + } + + String fullPath = servletContext.getRealPath(outputPath); + try { + FileInputStream is = new FileInputStream(fullPath); + buffer = new byte[is.available()]; + is.read(buffer); + is.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + return buffer; } @Override - public void compile(ReportVersion reportVersion) { - // TODO Auto-generated method stub - + public void compile(ReportVersion reportVersion) { } } \ No newline at end of file diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js index b6ca0d3..778e9b9 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js @@ -32,8 +32,16 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository $scope.reportEngineList = result; }); + $scope.dataSourceList = {}; + $scope.dataSourceList.JASPER = []; + $scope.dataSourceList.PENTAHO = []; DomainRepository.getEnumeratedDomain('ReportDataSourceEnum').then(function(result) { - $scope.reportDataSourceList = result; + angular.forEach(result, function (type) { + $scope.dataSourceList.JASPER.push(type); + if (type.chave != 'FLOW' && type.chave != 'SCRIPT') { + $scope.dataSourceList.PENTAHO.push(type); + } + }); }); DomainRepository.getEnumeratedDomain('ReportParameterTypeEnum').then(function(result) { @@ -430,6 +438,8 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository $scope.appController.activeWorkspace($scope.workspace); } + $scope.reportDataSourceList = $scope.dataSourceList[$scope.report.engine]; + $scope.edit = edit; $scope.newReport = false; diff --git a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js index 997becf..e90c2af 100644 --- a/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js +++ b/cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportFileController.js @@ -117,7 +117,7 @@ citApp.controller('ReportFileController', ["$scope", "appService", "ReportReposi $scope.uploader.filters.push({ name: 'reportFilter', fn: function(item /*{File|FileLikeObject}*/, options) { - return item.name.indexOf(".jrxml") !== -1; + return item.name.indexOf(".jrxml") !== -1 || item.name.indexOf(".prpt") !== -1; } }); @@ -156,6 +156,8 @@ citApp.controller('ReportFileController', ["$scope", "appService", "ReportReposi $scope.report.engine = undefined; if (fileName.indexOf(".jrxml") > 0) {; $scope.report.engine = 'JASPER'; + }else{ + $scope.report.engine = 'PENTAHO'; } }; -- libgit2 0.21.2