Commit 0bcb60a6b01eecaa269bfa6ca1acc96a154f89b5
1 parent
35cf4af1
Exists in
master
Implementação dos recursos de relatório
Showing
10 changed files
with
152 additions
and
25 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/dao/impl/ReportVersionDaoHibernate.java
... | ... | @@ -2,8 +2,11 @@ package br.com.centralit.esi.api.resource.dao.impl; |
2 | 2 | |
3 | 3 | import org.springframework.stereotype.Repository; |
4 | 4 | |
5 | +import br.com.centralit.esi.api.enumerated.ResourceTypeEnum; | |
5 | 6 | import br.com.centralit.esi.api.resource.dao.ReportVersionDao; |
6 | 7 | import br.com.centralit.esi.api.resource.model.ReportVersion; |
8 | +import br.com.centralit.esi.api.resource.model.ResourceVersion; | |
9 | +import br.com.centralit.framework.dao.arquitetura.SearchSeven; | |
7 | 10 | |
8 | 11 | @Repository("reportVersionDao") |
9 | 12 | public class ReportVersionDaoHibernate extends ResourceVersionDaoHibernate implements ReportVersionDao { |
... | ... | @@ -12,4 +15,20 @@ public class ReportVersionDaoHibernate extends ResourceVersionDaoHibernate imple |
12 | 15 | super(ReportVersion.class); |
13 | 16 | } |
14 | 17 | |
18 | + @Override | |
19 | + public ResourceVersion findByName(String resourceName) { | |
20 | + SearchSeven search = new SearchSeven(); | |
21 | + | |
22 | + search.addFilterEqual("resource.name", resourceName); | |
23 | + | |
24 | + search.addFilterEqual("resource.type", ResourceTypeEnum.REPORT); | |
25 | + | |
26 | + search.addFilterEmpty("resource.dataInativo"); | |
27 | + search.addFilterEmpty("dataInativo"); | |
28 | + | |
29 | + search.setMaxResults(1); | |
30 | + | |
31 | + return this.searchUnique(search, ReportVersion.class); | |
32 | + } | |
33 | + | |
15 | 34 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportVersion.java
... | ... | @@ -37,7 +37,7 @@ public class ReportVersion extends ResourceVersion { |
37 | 37 | @JsonView({ Views.EsiResourceEditView.class}) |
38 | 38 | protected Resource form; |
39 | 39 | |
40 | - @ManyToOne(fetch=FetchType.LAZY, optional=false) | |
40 | + @ManyToOne(cascade = { CascadeType.ALL }, fetch=FetchType.LAZY, optional=false) | |
41 | 41 | @JsonView({ Views.EsiResourceEditView.class, Views.EsiPackageExportView.class}) |
42 | 42 | protected ReportDataSource dataSource; |
43 | 43 | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ResourceVersion.java
... | ... | @@ -48,7 +48,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
48 | 48 | @JsonSubTypes.Type(value=ImageVersion.class, name="ImageVersion"), |
49 | 49 | @JsonSubTypes.Type(value=FileVersion.class, name="FileVersion"), |
50 | 50 | @JsonSubTypes.Type(value=PageVersion.class, name="PageVersion"), |
51 | - @JsonSubTypes.Type(value=PageVersion.class, name="PageVersion"), | |
51 | + @JsonSubTypes.Type(value=ReportVersion.class, name="ReportVersion"), | |
52 | 52 | }) |
53 | 53 | public class ResourceVersion extends PersistentObject { |
54 | 54 | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/JasperReportManagerImpl.java
1 | 1 | package br.com.centralit.esi.api.resource.service.impl; |
2 | 2 | |
3 | +import java.io.File; | |
4 | +import java.io.FileOutputStream; | |
3 | 5 | import java.sql.Connection; |
4 | 6 | import java.util.HashMap; |
5 | 7 | import java.util.List; |
6 | 8 | |
7 | 9 | import net.sf.jasperreports.engine.JRDataSource; |
8 | 10 | import net.sf.jasperreports.engine.JRException; |
11 | +import net.sf.jasperreports.engine.JasperCompileManager; | |
9 | 12 | import net.sf.jasperreports.engine.JasperExportManager; |
10 | 13 | import net.sf.jasperreports.engine.JasperFillManager; |
11 | 14 | import net.sf.jasperreports.engine.JasperPrint; |
12 | 15 | import net.sf.jasperreports.engine.data.JRBeanArrayDataSource; |
13 | 16 | import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; |
17 | +import net.sf.json.JSONArray; | |
14 | 18 | |
15 | 19 | import org.springframework.stereotype.Component; |
16 | 20 | |
... | ... | @@ -36,12 +40,25 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper |
36 | 40 | JasperPrint print = null; |
37 | 41 | byte[] buffer = null; |
38 | 42 | |
43 | + String path = report.buildBasePath(); | |
44 | + | |
45 | + String pathReport = servletContext.getRealPath(path+"/"+report.getFileName()); | |
46 | + | |
47 | + String pathReportJasper = pathReport.replaceAll(".jrxml", ".jasper"); | |
48 | + | |
49 | + try { | |
50 | + JasperCompileManager.compileReportToFile(pathReport, pathReportJasper); | |
51 | + } catch (JRException e1) { | |
52 | + e1.printStackTrace(); | |
53 | + throw new EsiExecutionException(e1); | |
54 | + } | |
55 | + | |
39 | 56 | switch (report.getDataSource().getType()) { |
40 | 57 | case CONNECTION: |
41 | 58 | Connection connection = dataSourceService.connect(report.getDataSource().getConnection()); |
42 | 59 | |
43 | 60 | try { |
44 | - print = JasperFillManager.fillReport(report.getFileName(), this.buildParams(report, inputMap), connection); | |
61 | + print = JasperFillManager.fillReport(pathReportJasper, this.buildParams(report, inputMap), connection); | |
45 | 62 | } catch (JRException e) { |
46 | 63 | e.printStackTrace(); |
47 | 64 | try { |
... | ... | @@ -55,7 +72,7 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper |
55 | 72 | |
56 | 73 | default: |
57 | 74 | try { |
58 | - print = JasperFillManager.fillReport(report.getFileName(), this.buildParams(report, inputMap), this.buildDataSource(report, inputMap)); | |
75 | + print = JasperFillManager.fillReport(pathReportJasper, this.buildParams(report, inputMap), this.buildDataSource(report, inputMap)); | |
59 | 76 | } catch (JRException e) { |
60 | 77 | throw new EsiExecutionException(e); |
61 | 78 | } |
... | ... | @@ -65,7 +82,15 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper |
65 | 82 | if (print != null) { |
66 | 83 | try { |
67 | 84 | buffer = JasperExportManager.exportReportToPdf(print); |
68 | - } catch (JRException e) { | |
85 | + | |
86 | + String pathPDF = pathReport.replaceAll(".jrxml", ".pdf"); | |
87 | + | |
88 | + File file = new File(pathPDF); | |
89 | + FileOutputStream in = new FileOutputStream(file); | |
90 | + in.write(buffer); | |
91 | + in.close(); | |
92 | + | |
93 | + } catch (Exception e) { | |
69 | 94 | e.printStackTrace(); |
70 | 95 | throw new EsiExecutionException(e); |
71 | 96 | } |
... | ... | @@ -92,7 +117,8 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper |
92 | 117 | if (output.getOutputVariables() != null) { |
93 | 118 | Object value = output.getValue(reportDataSource.getOutputAttributeName()); |
94 | 119 | if (value != null) { |
95 | - dataSource = new JRBeanArrayDataSource(new Object[]{value}); | |
120 | + JSONArray array = JSONArray.fromObject(value); | |
121 | + dataSource = new JRBeanCollectionDataSource(array); | |
96 | 122 | } |
97 | 123 | } |
98 | 124 | break; | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ReportManagerImpl.java
... | ... | @@ -4,6 +4,8 @@ import java.util.HashMap; |
4 | 4 | import java.util.List; |
5 | 5 | import java.util.Map; |
6 | 6 | |
7 | +import javax.servlet.ServletContext; | |
8 | + | |
7 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
8 | 10 | import org.springframework.stereotype.Component; |
9 | 11 | |
... | ... | @@ -34,6 +36,9 @@ public abstract class ReportManagerImpl implements ReportManager { |
34 | 36 | |
35 | 37 | @Autowired |
36 | 38 | protected RuntimeManager runtimeManager; |
39 | + | |
40 | + @Autowired | |
41 | + protected ServletContext servletContext; | |
37 | 42 | |
38 | 43 | protected abstract Object buildDataSource(ReportVersion report, HashMap<String, Object> inputMap); |
39 | 44 | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ReportVersionServiceImpl.java
... | ... | @@ -6,21 +6,28 @@ import java.util.List; |
6 | 6 | |
7 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | +import org.springframework.web.multipart.MultipartFile; | |
9 | 10 | |
10 | -import br.com.centralit.api.service.MenuService; | |
11 | +import br.com.centralit.esi.api.data.service.CustomSQLService; | |
12 | +import br.com.centralit.esi.api.data.service.DataObjectService; | |
13 | +import br.com.centralit.esi.api.data.service.DataSourceService; | |
14 | +import br.com.centralit.esi.api.design.service.FlowService; | |
11 | 15 | import br.com.centralit.esi.api.enumerated.ReportEngineEnum; |
12 | 16 | import br.com.centralit.esi.api.enumerated.ResourceTypeEnum; |
13 | 17 | import br.com.centralit.esi.api.resource.dao.ReportVersionDao; |
18 | +import br.com.centralit.esi.api.resource.model.FormVersion; | |
14 | 19 | import br.com.centralit.esi.api.resource.model.ReportDataSource; |
15 | 20 | import br.com.centralit.esi.api.resource.model.ReportParameter; |
16 | 21 | import br.com.centralit.esi.api.resource.model.ReportVersion; |
17 | 22 | import br.com.centralit.esi.api.resource.model.Resource; |
18 | 23 | import br.com.centralit.esi.api.resource.model.ResourceVersion; |
24 | +import br.com.centralit.esi.api.resource.service.FormVersionService; | |
19 | 25 | import br.com.centralit.esi.api.resource.service.JasperReportManager; |
20 | 26 | import br.com.centralit.esi.api.resource.service.PentahoReportManager; |
21 | 27 | import br.com.centralit.esi.api.resource.service.ReportDataSourceService; |
22 | 28 | import br.com.centralit.esi.api.resource.service.ReportParameterService; |
23 | 29 | import br.com.centralit.esi.api.resource.service.ReportVersionService; |
30 | +import br.com.centralit.esi.exception.EsiBusinessException; | |
24 | 31 | |
25 | 32 | @Service("reportVersionService") |
26 | 33 | public class ReportVersionServiceImpl extends ResourceVersionServiceImpl implements ReportVersionService { |
... | ... | @@ -38,7 +45,19 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme |
38 | 45 | private ReportParameterService reportParameterService; |
39 | 46 | |
40 | 47 | @Autowired |
41 | - private MenuService menuService; | |
48 | + private FormVersionService formVersionService; | |
49 | + | |
50 | + @Autowired | |
51 | + private DataSourceService dataSourceService; | |
52 | + | |
53 | + @Autowired | |
54 | + private DataObjectService dataObjectService; | |
55 | + | |
56 | + @Autowired | |
57 | + private FlowService flowService; | |
58 | + | |
59 | + @Autowired | |
60 | + private CustomSQLService customSQLService; | |
42 | 61 | |
43 | 62 | @Autowired |
44 | 63 | public ReportVersionServiceImpl(ReportVersionDao reportVersionDao) { |
... | ... | @@ -68,13 +87,60 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme |
68 | 87 | for (ReportParameter parameter : reportVersion.getParameters()) { |
69 | 88 | parameter.setId(null); |
70 | 89 | parameter.setReport(reportVersion); |
90 | + switch (parameter.getType()) { | |
91 | + case DATAOBJECT: | |
92 | + parameter.setDataObject(dataObjectService.find(parameter.getDataObject().getId())); | |
93 | + if (parameter.getCustomSQL() != null) { | |
94 | + parameter.setCustomSQL(customSQLService.find(parameter.getCustomSQL().getId())); | |
95 | + } | |
96 | + parameter.setFlow(null); | |
97 | + break; | |
98 | + case FLOW: | |
99 | + parameter.setFlow(flowService.find(parameter.getFlow().getId())); | |
100 | + parameter.setDataObject(null); | |
101 | + break; | |
102 | + default: | |
103 | + break; | |
104 | + } | |
71 | 105 | } |
72 | 106 | } |
73 | 107 | |
74 | 108 | if (reportVersion.getDataSource() != null) { |
75 | - reportVersion.getDataSource().setId(null); | |
109 | + ReportDataSource reportDataSource = reportVersion.getDataSource(); | |
110 | + reportDataSource.setId(null); | |
111 | + switch (reportDataSource.getType()) { | |
112 | + case CONNECTION: | |
113 | + reportDataSource.setConnection(dataSourceService.find(reportDataSource.getConnection().getId())); | |
114 | + reportDataSource.setDataObject(null); | |
115 | + reportDataSource.setFlow(null); | |
116 | + break; | |
117 | + case DATAOBJECT: | |
118 | + reportDataSource.setDataObject(dataObjectService.find(reportDataSource.getDataObject().getId())); | |
119 | + if (reportDataSource.getCustomSQL() != null) { | |
120 | + reportDataSource.setCustomSQL(customSQLService.find(reportDataSource.getCustomSQL().getId())); | |
121 | + } | |
122 | + reportDataSource.setConnection(null); | |
123 | + reportDataSource.setFlow(null); | |
124 | + break; | |
125 | + case FLOW: | |
126 | + reportDataSource.setFlow(flowService.find(reportDataSource.getFlow().getId())); | |
127 | + reportDataSource.setDataObject(null); | |
128 | + reportDataSource.setConnection(null); | |
129 | + break; | |
130 | + default: | |
131 | + break; | |
132 | + } | |
76 | 133 | } |
77 | - | |
134 | + | |
135 | + FormVersion formVersion = reportVersion.getFormVersion(); | |
136 | + formVersion.setPath(reportVersion.getPath()); | |
137 | + if (formVersion.isNew()) { | |
138 | + formVersion = (FormVersion) formVersionService.save(reportVersion.getFormVersion()); | |
139 | + }else{ | |
140 | + formVersion = (FormVersion) formVersionService.merge(reportVersion.getFormVersion()); | |
141 | + } | |
142 | + | |
143 | + reportVersion.setForm(formVersion.getResource()); | |
78 | 144 | } |
79 | 145 | |
80 | 146 | @Override |
... | ... | @@ -126,4 +192,20 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme |
126 | 192 | } |
127 | 193 | } |
128 | 194 | |
195 | + @Override | |
196 | + public ResourceVersion save(Long id, String name, String description, String path, MultipartFile file, Boolean replace) { | |
197 | + ResourceVersion resourceVersion = null; | |
198 | + | |
199 | + resourceVersion = (ResourceVersion) this.getReference(id); | |
200 | + if (resourceVersion == null) { | |
201 | + throw new EsiBusinessException("Arquivo não encontrado"); | |
202 | + } | |
203 | + | |
204 | + this.loadFile(resourceVersion, file); | |
205 | + | |
206 | + this.upload(resourceVersion); | |
207 | + | |
208 | + return resourceVersion; | |
209 | + } | |
210 | + | |
129 | 211 | } |
130 | 212 | \ No newline at end of file | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ResourceVersionServiceImpl.java
... | ... | @@ -294,7 +294,7 @@ public class ResourceVersionServiceImpl extends GenericServiceImpl<ResourceVersi |
294 | 294 | return file; |
295 | 295 | } |
296 | 296 | |
297 | - private void loadFile(ResourceVersion resourceVersion, MultipartFile file) { | |
297 | + protected void loadFile(ResourceVersion resourceVersion, MultipartFile file) { | |
298 | 298 | try { |
299 | 299 | resourceVersion.setFile(file.getBytes()); |
300 | 300 | resourceVersion.setFileName(file.getOriginalFilename()); | ... | ... |
cit-esi-web/src/main/java/br/com/centralit/controller/ReportController.java
... | ... | @@ -29,7 +29,7 @@ public class ReportController extends ResourceController{ |
29 | 29 | |
30 | 30 | byte[] response = reportVersionService.execute(report, report.getInputMap()); |
31 | 31 | |
32 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(response, this.getListView()); | |
32 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(response, null); | |
33 | 33 | |
34 | 34 | return responseBody; |
35 | 35 | } | ... | ... |
cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java
... | ... | @@ -773,7 +773,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen |
773 | 773 | |
774 | 774 | parameter = parameterService.findByName(Parameter.RESOURCE_REPORT_CONTROLLER); |
775 | 775 | if (parameter == null) { |
776 | - String fileName = servletContext.getRealPath("WEB-INF/classes/templates/resource_task_controller.js"); | |
776 | + String fileName = servletContext.getRealPath("WEB-INF/classes/templates/resource_report_controller.js"); | |
777 | 777 | |
778 | 778 | parameter = new Parameter(); |
779 | 779 | parameter.setName(Parameter.RESOURCE_REPORT_CONTROLLER); |
... | ... | @@ -800,7 +800,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen |
800 | 800 | |
801 | 801 | parameter = parameterService.findByName(Parameter.RESOURCE_REPORT_HTML); |
802 | 802 | if (parameter == null) { |
803 | - String fileName = servletContext.getRealPath("WEB-INF/classes/templates/resource_task_html.html"); | |
803 | + String fileName = servletContext.getRealPath("WEB-INF/classes/templates/resource_report_html.html"); | |
804 | 804 | |
805 | 805 | parameter = new Parameter(); |
806 | 806 | parameter.setName(Parameter.RESOURCE_REPORT_HTML); | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js
... | ... | @@ -319,6 +319,7 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
319 | 319 | } |
320 | 320 | |
321 | 321 | if ($scope.isValidProperties($scope.report.formVersion)) { |
322 | + $scope.setFormAttributes(); | |
322 | 323 | $scope.removeComponentWorkspace(); |
323 | 324 | |
324 | 325 | if (oldVersion == undefined) { |
... | ... | @@ -342,7 +343,7 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
342 | 343 | $scope.uploadFile(); |
343 | 344 | }); |
344 | 345 | }else{ |
345 | - FormBuilderRepository.save($scope.report).then(function(result) { | |
346 | + ReportRepository.save($scope.report).then(function(result) { | |
346 | 347 | $scope.report = result.originalElement; |
347 | 348 | $scope.uploadFile(); |
348 | 349 | }); |
... | ... | @@ -359,14 +360,8 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
359 | 360 | $scope.uploader.url += 'name=' + $scope.report.resource.name; |
360 | 361 | $scope.uploader.url += '&description=' + $scope.report.resource.description; |
361 | 362 | $scope.uploader.url += '&path=' + $scope.report.path; |
362 | - | |
363 | - if (oldVersion) { | |
364 | - $scope.uploader.url += '&replace=true'; | |
365 | - } | |
366 | - | |
367 | - if ($scope.report.id) { | |
368 | - $scope.uploader.url += '&id=' + $scope.report.id; | |
369 | - } | |
363 | + $scope.uploader.url += '&replace=true'; | |
364 | + $scope.uploader.url += '&id=' + $scope.report.id; | |
370 | 365 | |
371 | 366 | $scope.uploader.queue[0].url = $scope.uploader.url; |
372 | 367 | $scope.uploader.uploadAll(); |
... | ... | @@ -434,7 +429,7 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
434 | 429 | $scope.uploader.filters.push({ |
435 | 430 | name: 'reportFilter', |
436 | 431 | fn: function(item /*{File|FileLikeObject}*/, options) { |
437 | - return item.name.indexOf(".jasper") !== -1; | |
432 | + return item.name.indexOf(".jasper") !== -1 || item.name.indexOf(".jrxml") !== -1; | |
438 | 433 | } |
439 | 434 | }); |
440 | 435 | |
... | ... | @@ -490,7 +485,7 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
490 | 485 | |
491 | 486 | $scope.view = function(){ |
492 | 487 | if ($scope.report && $scope.report.fileName) { |
493 | - $scope.url = '/cit-esi-web/reports/'+$scope.report.fileName; | |
488 | + $scope.url = '/cit-esi-web/reports/'+$scope.report.path+'/'+$scope.report.fileName; | |
494 | 489 | |
495 | 490 | $scope.openModal('viewFile', 'lg'); |
496 | 491 | } | ... | ... |