Commit d71291b8e591a33315fa60fea85760966931dacc

Authored by Carlos Alberto
1 parent 6b65a5c0
Exists in master

Implementação dos recursos de relatório

cit-esi-api/src/main/java/br/com/centralit/esi/api/data/model/CustomSQL.java
@@ -36,7 +36,7 @@ public class CustomSQL extends PersistentObject { @@ -36,7 +36,7 @@ public class CustomSQL extends PersistentObject {
36 36
37 @Id 37 @Id
38 @GeneratedValue(strategy = GenerationType.AUTO) 38 @GeneratedValue(strategy = GenerationType.AUTO)
39 - @JsonView({Views.EsiDataObjectListView.class, Views.EsiDataObjectEditView.class }) 39 + @JsonView({Views.GenericView.class })
40 protected Long id; 40 protected Long id;
41 41
42 @ManyToOne(fetch=FetchType.LAZY, optional=false) 42 @ManyToOne(fetch=FetchType.LAZY, optional=false)
@@ -44,15 +44,15 @@ public class CustomSQL extends PersistentObject { @@ -44,15 +44,15 @@ public class CustomSQL extends PersistentObject {
44 protected DataObject dataObject; 44 protected DataObject dataObject;
45 45
46 @Column(nullable = false) 46 @Column(nullable = false)
47 - @JsonView({ Views.EsiDataObjectListView.class, Views.EsiDataObjectEditView.class, Views.EsiPackageExportView.class}) 47 + @JsonView({ Views.GenericView.class})
48 private SqlClauseTypeEnum type; 48 private SqlClauseTypeEnum type;
49 49
50 @Column(nullable = true, length=100) 50 @Column(nullable = true, length=100)
51 - @JsonView({ Views.EsiDataObjectListView.class, Views.EsiDataObjectEditView.class, Views.EsiPackageExportView.class}) 51 + @JsonView({ Views.GenericView.class})
52 private String name; 52 private String name;
53 53
54 @Column(nullable = true, length=255) 54 @Column(nullable = true, length=255)
55 - @JsonView({ Views.EsiDataObjectListView.class, Views.EsiDataObjectEditView.class, Views.EsiPackageExportView.class}) 55 + @JsonView({ Views.GenericView.class})
56 private String description; 56 private String description;
57 57
58 @Column(nullable = false) 58 @Column(nullable = false)
cit-esi-api/src/main/java/br/com/centralit/esi/api/data/model/DataObject.java
@@ -71,7 +71,7 @@ public class DataObject extends PersistentObjectAudit { @@ -71,7 +71,7 @@ public class DataObject extends PersistentObjectAudit {
71 protected Resource form; 71 protected Resource form;
72 72
73 @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataObject", fetch = FetchType.LAZY) 73 @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataObject", fetch = FetchType.LAZY)
74 - @JsonView({ Views.EsiDataObjectEditView.class, Views.EsiPackageExportView.class}) 74 + @JsonView({ Views.EsiResourceEditView.class, Views.EsiDataObjectEditView.class, Views.EsiPackageExportView.class})
75 private List<CustomSQL> sqls; 75 private List<CustomSQL> sqls;
76 76
77 @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataObject", fetch = FetchType.LAZY) 77 @OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataObject", fetch = FetchType.LAZY)
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportDataSource.java
@@ -81,6 +81,7 @@ public class ReportDataSource extends PersistentObject { @@ -81,6 +81,7 @@ public class ReportDataSource extends PersistentObject {
81 this.outputAttributeName = reportDataSource.getOutputAttributeName(); 81 this.outputAttributeName = reportDataSource.getOutputAttributeName();
82 this.restoreManyToOne = reportDataSource.getRestoreManyToOne(); 82 this.restoreManyToOne = reportDataSource.getRestoreManyToOne();
83 this.restoreOneToMany = reportDataSource.getRestoreOneToMany(); 83 this.restoreOneToMany = reportDataSource.getRestoreOneToMany();
  84 + this.customSQL = reportDataSource.getCustomSQL();
84 } 85 }
85 86
86 @Override 87 @Override
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/ReportParameter.java
@@ -23,10 +23,12 @@ import br.com.centralit.framework.json.Views; @@ -23,10 +23,12 @@ import br.com.centralit.framework.json.Views;
23 import br.com.centralit.framework.model.arquitetura.PersistentObject; 23 import br.com.centralit.framework.model.arquitetura.PersistentObject;
24 24
25 import com.fasterxml.jackson.annotation.JsonIgnore; 25 import com.fasterxml.jackson.annotation.JsonIgnore;
  26 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
26 import com.fasterxml.jackson.annotation.JsonView; 27 import com.fasterxml.jackson.annotation.JsonView;
27 28
28 @Entity 29 @Entity
29 @Table(name="RES_ReportParameter") 30 @Table(name="RES_ReportParameter")
  31 +@JsonIgnoreProperties({ "$index" })
30 public class ReportParameter extends PersistentObject { 32 public class ReportParameter extends PersistentObject {
31 33
32 /** 34 /**
@@ -86,14 +88,16 @@ public class ReportParameter extends PersistentObject { @@ -86,14 +88,16 @@ public class ReportParameter extends PersistentObject {
86 } 88 }
87 89
88 public ReportParameter(ReportVersion report, ReportParameter reportParameter) { 90 public ReportParameter(ReportVersion report, ReportParameter reportParameter) {
89 - this.name = reportParameter.name; 91 + this.name = reportParameter.getName();
90 this.report = report; 92 this.report = report;
91 - this.type = reportParameter.type;  
92 - this.dataObject = reportParameter.dataObject;  
93 - this.flow = reportParameter.flow;  
94 - this.image = reportParameter.image;  
95 - this.scriptCode = reportParameter.scriptCode;  
96 - this.outputAttributeName = reportParameter.outputAttributeName; 93 + this.type = reportParameter.getType();
  94 + this.dataObject = reportParameter.getDataObject();
  95 + this.flow = reportParameter.getFlow();
  96 + this.image = reportParameter.getImage();
  97 + this.scriptCode = reportParameter.getScriptCode();
  98 + this.outputAttributeName = reportParameter.getOutputAttributeName();
  99 + this.constant = reportParameter.getConstant();
  100 + this.customSQL = reportParameter.getCustomSQL();
97 } 101 }
98 102
99 public ReportVersion getReport() { 103 public ReportVersion getReport() {
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/model/Resource.java
@@ -50,6 +50,10 @@ public class Resource extends PersistentObject { @@ -50,6 +50,10 @@ public class Resource extends PersistentObject {
50 @JsonView({ Views.GenericView.class}) 50 @JsonView({ Views.GenericView.class})
51 private HashMap<String, Object> inputMap; 51 private HashMap<String, Object> inputMap;
52 52
  53 + @Transient
  54 + @JsonView({ Views.GenericView.class})
  55 + private String path;
  56 +
53 public Resource() { 57 public Resource() {
54 } 58 }
55 59
@@ -125,5 +129,13 @@ public class Resource extends PersistentObject { @@ -125,5 +129,13 @@ public class Resource extends PersistentObject {
125 129
126 public void setInputMap(HashMap<String, Object> inputMap) { 130 public void setInputMap(HashMap<String, Object> inputMap) {
127 this.inputMap = inputMap; 131 this.inputMap = inputMap;
  132 + }
  133 +
  134 + public String getPath() {
  135 + return path;
  136 + }
  137 +
  138 + public void setPath(String path) {
  139 + this.path = path;
128 } 140 }
129 } 141 }
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ReportManagerImpl.java
@@ -12,8 +12,10 @@ import org.springframework.stereotype.Component; @@ -12,8 +12,10 @@ import org.springframework.stereotype.Component;
12 import br.com.centralit.esi.api.data.service.DataSourceService; 12 import br.com.centralit.esi.api.data.service.DataSourceService;
13 import br.com.centralit.esi.api.data.service.impl.DataManager; 13 import br.com.centralit.esi.api.data.service.impl.DataManager;
14 import br.com.centralit.esi.api.execution.component.ExecuteScript; 14 import br.com.centralit.esi.api.execution.component.ExecuteScript;
  15 +import br.com.centralit.esi.api.resource.model.ImageVersion;
15 import br.com.centralit.esi.api.resource.model.ReportParameter; 16 import br.com.centralit.esi.api.resource.model.ReportParameter;
16 import br.com.centralit.esi.api.resource.model.ReportVersion; 17 import br.com.centralit.esi.api.resource.model.ReportVersion;
  18 +import br.com.centralit.esi.api.resource.service.ImageVersionService;
17 import br.com.centralit.esi.api.resource.service.ReportManager; 19 import br.com.centralit.esi.api.resource.service.ReportManager;
18 import br.com.centralit.esi.api.runtime.RuntimeEnvironment; 20 import br.com.centralit.esi.api.runtime.RuntimeEnvironment;
19 import br.com.centralit.esi.api.runtime.RuntimeEnvironmentImpl; 21 import br.com.centralit.esi.api.runtime.RuntimeEnvironmentImpl;
@@ -39,11 +41,14 @@ public abstract class ReportManagerImpl implements ReportManager { @@ -39,11 +41,14 @@ public abstract class ReportManagerImpl implements ReportManager {
39 41
40 @Autowired 42 @Autowired
41 protected ServletContext servletContext; 43 protected ServletContext servletContext;
  44 +
  45 + @Autowired
  46 + protected ImageVersionService imageVersionService;
42 47
43 protected abstract Object buildDataSource(ReportVersion report, HashMap<String, Object> inputMap); 48 protected abstract Object buildDataSource(ReportVersion report, HashMap<String, Object> inputMap);
44 49
45 protected Map<String, Object> buildParams(ReportVersion report, HashMap<String, Object> inputMap) { 50 protected Map<String, Object> buildParams(ReportVersion report, HashMap<String, Object> inputMap) {
46 - HashMap<String, Object> outputMap = new HashMap<String, Object>(); 51 + HashMap<String, Object> outputMap = inputMap;
47 52
48 if (report.getParameters() != null) { 53 if (report.getParameters() != null) {
49 for (ReportParameter parameter : report.getParameters()) { 54 for (ReportParameter parameter : report.getParameters()) {
@@ -54,6 +59,14 @@ public abstract class ReportManagerImpl implements ReportManager { @@ -54,6 +59,14 @@ public abstract class ReportManagerImpl implements ReportManager {
54 return outputMap; 59 return outputMap;
55 } 60 }
56 61
  62 + protected void addMapValue(HashMap<String, Object> map, String name, Object value) {
  63 + if (map.containsKey(name)) {
  64 + map.remove(map.get(name));
  65 + }
  66 +
  67 + map.put(name, value);
  68 + }
  69 +
57 protected void buildParam(ReportParameter parameter, HashMap<String, Object> inputMap, HashMap<String, Object> outputMap) { 70 protected void buildParam(ReportParameter parameter, HashMap<String, Object> inputMap, HashMap<String, Object> outputMap) {
58 switch (parameter.getType()) { 71 switch (parameter.getType()) {
59 case DATAOBJECT: 72 case DATAOBJECT:
@@ -63,7 +76,7 @@ public abstract class ReportManagerImpl implements ReportManager { @@ -63,7 +76,7 @@ public abstract class ReportManagerImpl implements ReportManager {
63 for (HashMap<String, Object> map : resultSet) { 76 for (HashMap<String, Object> map : resultSet) {
64 Object value = map.get(parameter.getOutputAttributeName()); 77 Object value = map.get(parameter.getOutputAttributeName());
65 if (value != null) { 78 if (value != null) {
66 - outputMap.put(parameter.getOutputAttributeName(), value); 79 + addMapValue(outputMap, parameter.getName(), value);
67 break; 80 break;
68 } 81 }
69 } 82 }
@@ -75,7 +88,7 @@ public abstract class ReportManagerImpl implements ReportManager { @@ -75,7 +88,7 @@ public abstract class ReportManagerImpl implements ReportManager {
75 if (output.getOutputVariables() != null) { 88 if (output.getOutputVariables() != null) {
76 Object value = output.getValue(parameter.getOutputAttributeName()); 89 Object value = output.getValue(parameter.getOutputAttributeName());
77 if (value != null) { 90 if (value != null) {
78 - outputMap.put(parameter.getOutputAttributeName(), value); 91 + addMapValue(outputMap, parameter.getName(), value);
79 } 92 }
80 } 93 }
81 break; 94 break;
@@ -84,13 +97,21 @@ public abstract class ReportManagerImpl implements ReportManager { @@ -84,13 +97,21 @@ public abstract class ReportManagerImpl implements ReportManager {
84 RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironmentImpl(null, inputMap); 97 RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironmentImpl(null, inputMap);
85 Object value = ExecuteScript.execute(runtimeEnvironment, parameter.getName(), parameter.getScriptCode()); 98 Object value = ExecuteScript.execute(runtimeEnvironment, parameter.getName(), parameter.getScriptCode());
86 if (value != null) { 99 if (value != null) {
87 - outputMap.put(parameter.getName(), value); 100 + addMapValue(outputMap, parameter.getName(), value);
88 } 101 }
89 break; 102 break;
90 103
91 case IMAGE: 104 case IMAGE:
  105 + ImageVersion imageVersion = (ImageVersion) imageVersionService.findByName(parameter.getImage().getName());
  106 +
  107 + String path = servletContext.getRealPath(imageVersion.getFullPath());
  108 + addMapValue(outputMap, parameter.getName(), path);
92 break; 109 break;
93 110
  111 + case CONSTANT:
  112 + addMapValue(outputMap, parameter.getName(), parameter.getConstant());
  113 + break;
  114 +
94 default: 115 default:
95 break; 116 break;
96 } 117 }
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ReportVersionServiceImpl.java
@@ -88,7 +88,7 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme @@ -88,7 +88,7 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
88 protected void build(ResourceVersion resourceVersion) { 88 protected void build(ResourceVersion resourceVersion) {
89 ReportVersion reportVersion = (ReportVersion) resourceVersion; 89 ReportVersion reportVersion = (ReportVersion) resourceVersion;
90 90
91 - if (reportVersion.getEngine() == null && !UtilString.isNullOrEmpty(reportVersion.getFileName())) { 91 + if (!UtilString.isNullOrEmpty(reportVersion.getFileName())) {
92 if (reportVersion.getFileName().toUpperCase().indexOf(".JRXML") > 0) { 92 if (reportVersion.getFileName().toUpperCase().indexOf(".JRXML") > 0) {
93 reportVersion.setEngine(ReportEngineEnum.JASPER); 93 reportVersion.setEngine(ReportEngineEnum.JASPER);
94 }else{ 94 }else{
@@ -102,7 +102,9 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme @@ -102,7 +102,9 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
102 parameter.setReport(reportVersion); 102 parameter.setReport(reportVersion);
103 switch (parameter.getType()) { 103 switch (parameter.getType()) {
104 case DATAOBJECT: 104 case DATAOBJECT:
105 - parameter.setDataObject(dataObjectService.find(parameter.getDataObject().getId())); 105 + if (parameter.getDataObject() != null) {
  106 + parameter.setDataObject(dataObjectService.find(parameter.getDataObject().getId()));
  107 + }
106 if (parameter.getCustomSQL() != null) { 108 if (parameter.getCustomSQL() != null) {
107 parameter.setCustomSQL(customSQLService.find(parameter.getCustomSQL().getId())); 109 parameter.setCustomSQL(customSQLService.find(parameter.getCustomSQL().getId()));
108 } 110 }
@@ -110,7 +112,9 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme @@ -110,7 +112,9 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
110 parameter.setImage(null); 112 parameter.setImage(null);
111 break; 113 break;
112 case FLOW: 114 case FLOW:
113 - parameter.setFlow(flowService.find(parameter.getFlow().getId())); 115 + if (parameter.getFlow() != null) {
  116 + parameter.setFlow(flowService.find(parameter.getFlow().getId()));
  117 + }
114 parameter.setDataObject(null); 118 parameter.setDataObject(null);
115 parameter.setCustomSQL(null); 119 parameter.setCustomSQL(null);
116 parameter.setImage(null); 120 parameter.setImage(null);
@@ -118,8 +122,10 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme @@ -118,8 +122,10 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
118 case IMAGE: 122 case IMAGE:
119 parameter.setFlow(null); 123 parameter.setFlow(null);
120 parameter.setDataObject(null); 124 parameter.setDataObject(null);
121 - parameter.setCustomSQL(null);  
122 - parameter.setImage(resourceService.find(parameter.getImage().getId())); 125 + parameter.setCustomSQL(null);
  126 + if (parameter.getImage() != null) {
  127 + parameter.setImage(resourceService.find(parameter.getImage().getId()));
  128 + }
123 break; 129 break;
124 default: 130 default:
125 parameter.setFlow(null); 131 parameter.setFlow(null);
@@ -191,7 +197,9 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme @@ -191,7 +197,9 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
191 newResourceVersion.setForm(oldResourceVersion.getForm()); 197 newResourceVersion.setForm(oldResourceVersion.getForm());
192 newResourceVersion.setFormVersion(oldResourceVersion.getFormVersion()); 198 newResourceVersion.setFormVersion(oldResourceVersion.getFormVersion());
193 199
194 - newResourceVersion.setDataSource(new ReportDataSource(oldResourceVersion.getDataSource())); 200 + if (oldResourceVersion.getDataSource() != null) {
  201 + newResourceVersion.setDataSource(new ReportDataSource(oldResourceVersion.getDataSource()));
  202 + }
195 203
196 if (oldResourceVersion.getParameters() != null) { 204 if (oldResourceVersion.getParameters() != null) {
197 List<ReportParameter> parameters = new ArrayList<ReportParameter>(); 205 List<ReportParameter> parameters = new ArrayList<ReportParameter>();
@@ -239,10 +247,25 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme @@ -239,10 +247,25 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme
239 } 247 }
240 248
241 private void compile(ReportVersion reportVersion) { 249 private void compile(ReportVersion reportVersion) {
242 - if (reportVersion.getEngine().equals(ReportEngineEnum.JASPER)) {  
243 - jasperReportManager.compile(reportVersion);  
244 - }else if (reportVersion.getEngine().equals(ReportEngineEnum.PENTAHO)) {  
245 - pentahoReportManager.compile(reportVersion); 250 + if (reportVersion != null && reportVersion.getFile() != null) {
  251 + if (reportVersion.getEngine().equals(ReportEngineEnum.JASPER)) {
  252 + jasperReportManager.compile(reportVersion);
  253 + }else if (reportVersion.getEngine().equals(ReportEngineEnum.PENTAHO)) {
  254 + pentahoReportManager.compile(reportVersion);
  255 + }
246 } 256 }
247 } 257 }
  258 +
  259 + @Override
  260 + public void uploadAll() {
  261 + List<ResourceVersion> resources = this.findAll();
  262 + if (resources != null) {
  263 + for (ResourceVersion resourceVersion : resources) {
  264 + upload(resourceVersion);
  265 + }
  266 + for (ResourceVersion resourceVersion : resources) {
  267 + compile((ReportVersion) resourceVersion);
  268 + }
  269 + }
  270 + }
248 } 271 }
249 \ No newline at end of file 272 \ No newline at end of file
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ResourceVersionServiceImpl.java
@@ -155,8 +155,6 @@ public class ResourceVersionServiceImpl extends GenericServiceImpl&lt;ResourceVersi @@ -155,8 +155,6 @@ public class ResourceVersionServiceImpl extends GenericServiceImpl&lt;ResourceVersi
155 if (path.charAt(path.length() - 1) == '/') { 155 if (path.charAt(path.length() - 1) == '/') {
156 path = path.substring(0,path.length() - 1); 156 path = path.substring(0,path.length() - 1);
157 } 157 }
158 - }else{  
159 -  
160 } 158 }
161 resourceVersion.setPath(path); 159 resourceVersion.setPath(path);
162 160
@@ -331,15 +329,15 @@ public class ResourceVersionServiceImpl extends GenericServiceImpl&lt;ResourceVersi @@ -331,15 +329,15 @@ public class ResourceVersionServiceImpl extends GenericServiceImpl&lt;ResourceVersi
331 329
332 this.save(resourceVersion); 330 this.save(resourceVersion);
333 }else{ 331 }else{
334 - ResourceVersion resourceVersionAux = (ResourceVersion) this.getReference(id);  
335 - if (resourceVersionAux == null) { 332 + resourceVersion = (ResourceVersion) this.getReference(id);
  333 + if (resourceVersion == null) {
336 throw new EsiBusinessException("Arquivo não encontrado"); 334 throw new EsiBusinessException("Arquivo não encontrado");
337 } 335 }
338 336
339 - resourceVersion = this.create(name, description, path); 337 + resourceVersion.getResource().setName(name);
  338 + resourceVersion.getResource().setDescription(description);
  339 + resourceVersion.setPath(path);
340 this.loadFile(resourceVersion, file); 340 this.loadFile(resourceVersion, file);
341 - resourceVersion.setId(id);  
342 - resourceVersion.getResource().setId(resourceVersionAux.getResource().getId());  
343 this.merge(resourceVersion); 341 this.merge(resourceVersion);
344 } 342 }
345 343
cit-esi-web/src/main/java/br/com/centralit/controller/ReportController.java
1 package br.com.centralit.controller; 1 package br.com.centralit.controller;
2 2
  3 +import java.io.File;
  4 +import java.io.FileInputStream;
  5 +import java.io.FileOutputStream;
  6 +import java.io.IOException;
  7 +import java.util.UUID;
  8 +
  9 +import javax.servlet.ServletContext;
  10 +import javax.servlet.http.HttpServletResponse;
  11 +
3 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller; 13 import org.springframework.stereotype.Controller;
5 import org.springframework.web.bind.annotation.RequestBody; 14 import org.springframework.web.bind.annotation.RequestBody;
6 import org.springframework.web.bind.annotation.RequestMapping; 15 import org.springframework.web.bind.annotation.RequestMapping;
7 import org.springframework.web.bind.annotation.RequestMethod; 16 import org.springframework.web.bind.annotation.RequestMethod;
  17 +import org.springframework.web.bind.annotation.RequestParam;
8 import org.springframework.web.bind.annotation.ResponseBody; 18 import org.springframework.web.bind.annotation.ResponseBody;
9 19
10 import br.com.centralit.esi.api.resource.model.Resource; 20 import br.com.centralit.esi.api.resource.model.Resource;
11 import br.com.centralit.esi.api.resource.service.ReportVersionService; 21 import br.com.centralit.esi.api.resource.service.ReportVersionService;
  22 +import br.com.centralit.esi.exception.EsiBusinessException;
12 import br.com.centralit.framework.json.ResponseBodyWrapper; 23 import br.com.centralit.framework.json.ResponseBodyWrapper;
  24 +import br.com.centralit.framework.json.Views;
13 25
14 @Controller 26 @Controller
15 @RequestMapping("/rest/esi/resource/report") 27 @RequestMapping("/rest/esi/resource/report")
@@ -18,6 +30,9 @@ public class ReportController extends ResourceController{ @@ -18,6 +30,9 @@ public class ReportController extends ResourceController{
18 @Autowired 30 @Autowired
19 private ReportVersionService reportVersionService; 31 private ReportVersionService reportVersionService;
20 32
  33 + @Autowired
  34 + protected ServletContext servletContext;
  35 +
21 @Autowired 36 @Autowired
22 public ReportController(ReportVersionService reportVersionService) { 37 public ReportController(ReportVersionService reportVersionService) {
23 super(reportVersionService); 38 super(reportVersionService);
@@ -27,12 +42,56 @@ public class ReportController extends ResourceController{ @@ -27,12 +42,56 @@ public class ReportController extends ResourceController{
27 @ResponseBody 42 @ResponseBody
28 public ResponseBodyWrapper execute(@RequestBody Resource report) { 43 public ResponseBodyWrapper execute(@RequestBody Resource report) {
29 44
30 - byte[] response = reportVersionService.execute(report, report.getInputMap()); 45 + byte[] buffer = reportVersionService.execute(report, report.getInputMap());
  46 +
  47 + String path = "reports/report_" + UUID.randomUUID().toString() + ".pdf";
  48 +
  49 + String pathname = servletContext.getRealPath(path);
  50 +
  51 + try {
  52 + File file = new File(pathname);
  53 + FileOutputStream in = new FileOutputStream(file);
  54 + in.write(buffer);
  55 + in.close();
  56 + } catch (Exception e) {
  57 + e.printStackTrace();
  58 + throw new EsiBusinessException(e);
  59 + }
  60 +
  61 + report.setInputMap(null);
  62 + report.setPath(path);
31 63
32 - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(response, null); 64 + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(report, Views.GenericView.class);
33 65
34 return responseBody; 66 return responseBody;
35 } 67 }
36 68
  69 + @RequestMapping(value = "/view", method = RequestMethod.GET)
  70 + public @ResponseBody
  71 + void view(@RequestParam(value = "path") String path, HttpServletResponse response) {
  72 + byte[] buffer = null;
  73 + try {
  74 + FileInputStream is = new FileInputStream(servletContext.getRealPath(path));
  75 + buffer = new byte[is.available()];
  76 + is.read(buffer);
  77 + is.close();
  78 + } catch (Exception e) {
  79 + e.printStackTrace();
  80 + }
  81 +
  82 + response.setContentType("application/octet-stream");
  83 +
  84 + response.setHeader("Content-Disposition", "inline;filename=\"" + path + "\"");
  85 +
  86 + try {
  87 + response.getOutputStream().write(buffer);
  88 + } catch (IOException e) {
  89 + // TODO Auto-generated catch block
  90 + e.printStackTrace();
  91 + }
  92 +
  93 +// return resp;
  94 +
  95 + }
37 96
38 } 97 }
cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java
@@ -56,6 +56,7 @@ import br.com.centralit.esi.api.resource.service.FormWidgetService; @@ -56,6 +56,7 @@ import br.com.centralit.esi.api.resource.service.FormWidgetService;
56 import br.com.centralit.esi.api.resource.service.ImageVersionService; 56 import br.com.centralit.esi.api.resource.service.ImageVersionService;
57 import br.com.centralit.esi.api.resource.service.JavaScriptVersionService; 57 import br.com.centralit.esi.api.resource.service.JavaScriptVersionService;
58 import br.com.centralit.esi.api.resource.service.PageVersionService; 58 import br.com.centralit.esi.api.resource.service.PageVersionService;
  59 +import br.com.centralit.esi.api.resource.service.ReportVersionService;
59 import br.com.centralit.esi.api.resource.service.ResourceService; 60 import br.com.centralit.esi.api.resource.service.ResourceService;
60 import br.com.centralit.esi.api.util.EsiAppUtils; 61 import br.com.centralit.esi.api.util.EsiAppUtils;
61 import br.com.centralit.esi.exception.EsiBusinessException; 62 import br.com.centralit.esi.exception.EsiBusinessException;
@@ -182,6 +183,9 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen @@ -182,6 +183,9 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen
182 183
183 @Autowired 184 @Autowired
184 private FlowVersionService flowVersionService; 185 private FlowVersionService flowVersionService;
  186 +
  187 + @Autowired
  188 + private ReportVersionService reportVersionService;
185 189
186 @Autowired 190 @Autowired
187 private PackService packService; 191 private PackService packService;
@@ -225,6 +229,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen @@ -225,6 +229,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen
225 fileVersionService.uploadAll(); 229 fileVersionService.uploadAll();
226 pageVersionService.uploadAll(); 230 pageVersionService.uploadAll();
227 formVersionService.uploadAll(); 231 formVersionService.uploadAll();
  232 + reportVersionService.uploadAll();
228 233
229 gerarInternacionalizacao(); 234 gerarInternacionalizacao();
230 } 235 }
@@ -2170,6 +2175,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen @@ -2170,6 +2175,7 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen
2170 internacionalizacaoList.add(new Internacionalizacao("ESI.DATAOBJECT", "Objeto de dados", dominio, modulo)); 2175 internacionalizacaoList.add(new Internacionalizacao("ESI.DATAOBJECT", "Objeto de dados", dominio, modulo));
2171 internacionalizacaoList.add(new Internacionalizacao("ESI.RESTORE_MANY_TO_ONE", "Recupera relacionamentos muitos para um", dominio, modulo)); 2176 internacionalizacaoList.add(new Internacionalizacao("ESI.RESTORE_MANY_TO_ONE", "Recupera relacionamentos muitos para um", dominio, modulo));
2172 internacionalizacaoList.add(new Internacionalizacao("ESI.RESTORE_ONE_TO_MANY", "Recupera relacionamentos um para muitos", dominio, modulo)); 2177 internacionalizacaoList.add(new Internacionalizacao("ESI.RESTORE_ONE_TO_MANY", "Recupera relacionamentos um para muitos", dominio, modulo));
  2178 + internacionalizacaoList.add(new Internacionalizacao("ESI.ATRIBUTO", "Atributo", dominio, modulo));
2173 2179
2174 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_NENHUM", "Nenhum", dominio, modulo)); 2180 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_NENHUM", "Nenhum", dominio, modulo));
2175 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_CONEXAO", "Conexão de dados", dominio, modulo)); 2181 internacionalizacaoList.add(new Internacionalizacao("ESI.ENUMERADO.DATASOURCE_CONEXAO", "Conexão de dados", dominio, modulo));
cit-esi-web/src/main/resources/reports/empregado.jrxml
@@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
6 <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> 6 <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
7 <defaultValueExpression><![CDATA[]]></defaultValueExpression> 7 <defaultValueExpression><![CDATA[]]></defaultValueExpression>
8 </parameter> 8 </parameter>
  9 + <parameter name="logo" class="java.lang.String"/>
  10 + <parameter name="titulo" class="java.lang.String"/>
9 <queryString> 11 <queryString>
10 <![CDATA[select id, nome, matricula from rh_empregado]]> 12 <![CDATA[select id, nome, matricula from rh_empregado]]>
11 </queryString> 13 </queryString>
@@ -17,7 +19,19 @@ @@ -17,7 +19,19 @@
17 <band splitType="Stretch"/> 19 <band splitType="Stretch"/>
18 </background> 20 </background>
19 <title> 21 <title>
20 - <band height="79" splitType="Stretch"/> 22 + <band height="79" splitType="Stretch">
  23 + <image>
  24 + <reportElement x="7" y="6" width="229" height="53" uuid="31a8d692-cfa6-4a78-923f-79ab2b2097ad"/>
  25 + <imageExpression><![CDATA[$P{logo}]]></imageExpression>
  26 + </image>
  27 + <textField>
  28 + <reportElement x="258" y="14" width="286" height="20" uuid="b557e877-9ab5-4810-9959-a72a5ab19c71"/>
  29 + <textElement>
  30 + <font size="14" isBold="true"/>
  31 + </textElement>
  32 + <textFieldExpression><![CDATA[$P{titulo}]]></textFieldExpression>
  33 + </textField>
  34 + </band>
21 </title> 35 </title>
22 <columnHeader> 36 <columnHeader>
23 <band height="27" splitType="Stretch"> 37 <band height="27" splitType="Stretch">
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js
@@ -172,7 +172,6 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository @@ -172,7 +172,6 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
172 172
173 $rootScope.formVersion = $scope.report.formVersion; 173 $rootScope.formVersion = $scope.report.formVersion;
174 $rootScope.widgets = $scope.widgets; 174 $rootScope.widgets = $scope.widgets;
175 - $rootScope.formBuilderControllerScope = $scope;  
176 $scope.appController.addNewWorkspace($translate.instant("ESI.DESENHO_TELA"), componentsPage, true, 'mod-red-dark', $scope.report.formVersion); 175 $scope.appController.addNewWorkspace($translate.instant("ESI.DESENHO_TELA"), componentsPage, true, 'mod-red-dark', $scope.report.formVersion);
177 }; 176 };
178 177
@@ -230,8 +229,6 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository @@ -230,8 +229,6 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
230 $timeout(function(){ 229 $timeout(function(){
231 $scope.reportForm.$submitted = false; 230 $scope.reportForm.$submitted = false;
232 $scope.reportForm.$setPristine(); 231 $scope.reportForm.$setPristine();
233 - $scope.showComponents();  
234 - $scope.appController.activeWorkspace($scope.workspace);  
235 }); 232 });
236 }; 233 };
237 234
@@ -351,6 +348,10 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository @@ -351,6 +348,10 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
351 } 348 }
352 }; 349 };
353 350
  351 + $scope.closeModal = function() {
  352 + $scope.$modalInstance.close();
  353 + };
  354 +
354 $scope.afterSave = function() { 355 $scope.afterSave = function() {
355 $scope.setLoading(false); 356 $scope.setLoading(false);
356 357
@@ -398,8 +399,6 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository @@ -398,8 +399,6 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
398 $scope.getReport = function(report, edit){ 399 $scope.getReport = function(report, edit){
399 $scope.setLoadingGet(true); 400 $scope.setLoadingGet(true);
400 401
401 - $scope.resetForm();  
402 -  
403 ReportRepository.get(report.id).then(function(result) { 402 ReportRepository.get(report.id).then(function(result) {
404 $scope.report = result.originalElement; 403 $scope.report = result.originalElement;
405 404
@@ -424,9 +423,13 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository @@ -424,9 +423,13 @@ citApp.controller(&#39;ReportController&#39;, [&quot;$scope&quot;, &quot;appService&quot;, &quot;ReportRepository
424 ,controllerCode : $scope.RESOURCE_REPORT_CONTROLLER 423 ,controllerCode : $scope.RESOURCE_REPORT_CONTROLLER
425 ,dependencies: $scope.RESOURCE_REPORT_DEPENDENCIES ? $scope.RESOURCE_REPORT_DEPENDENCIES.split(',') : [] }; 424 ,dependencies: $scope.RESOURCE_REPORT_DEPENDENCIES ? $scope.RESOURCE_REPORT_DEPENDENCIES.split(',') : [] };
426 } 425 }
427 - 426 + $scope.showComponents();
  427 + $scope.appController.activeWorkspace($scope.workspace);
428 } 428 }
429 }); 429 });
  430 + }else{
  431 + $scope.showComponents();
  432 + $scope.appController.activeWorkspace($scope.workspace);
430 } 433 }
431 434
432 $scope.edit = edit; 435 $scope.edit = edit;
cit-esi-web/src/main/webapp/assets/js/angular/custom/directive/FormBuilderDirective.js
@@ -13,6 +13,7 @@ citApp.directive(&quot;formBuilder&quot;, [&#39;ImageRepository&#39;, &#39;$translate&#39;, &#39;$filter&#39;, &#39;$t @@ -13,6 +13,7 @@ citApp.directive(&quot;formBuilder&quot;, [&#39;ImageRepository&#39;, &#39;$translate&#39;, &#39;$filter&#39;, &#39;$t
13 templateUrl : '/cit-esi-web/assets/js/angular/custom/directive/html/formBuilder.html', 13 templateUrl : '/cit-esi-web/assets/js/angular/custom/directive/html/formBuilder.html',
14 14
15 link : function($scope, $element, attributes) { 15 link : function($scope, $element, attributes) {
  16 + $scope.showSaveButton = $rootScope.formBuilderControllerScope != undefined;
16 $scope.appController = angular.element("#citapp-controller").scope(); 17 $scope.appController = angular.element("#citapp-controller").scope();
17 18
18 $scope.msg = []; 19 $scope.msg = [];
cit-esi-web/src/main/webapp/assets/js/angular/custom/directive/html/formBuilder.html
@@ -2,11 +2,11 @@ @@ -2,11 +2,11 @@
2 <div class="bar-buttons-action fixed"> 2 <div class="bar-buttons-action fixed">
3 <div class="row" ng-drop="true" ng-drop-success="onDropAction($data,$event)"> 3 <div class="row" ng-drop="true" ng-drop-success="onDropAction($data,$event)">
4 <div class="col-sm-12 text-left"> 4 <div class="col-sm-12 text-left">
5 - <button title="{{$translate.instant('LABEL.SALVAR')}}" alt="{{$translate.instant('LABEL.SALVAR')}}" class="btn btn-clear" ng-click="saveOrUpdate(false)" ng-show="!formContainer.id"> 5 + <button title="{{$translate.instant('LABEL.SALVAR')}}" alt="{{$translate.instant('LABEL.SALVAR')}}" class="btn btn-clear" ng-click="saveOrUpdate(false)" ng-show="showSaveButton && !formContainer.id">
6 <i class="fa fa-save green"></i> <translate>LABEL.SALVAR</translate> 6 <i class="fa fa-save green"></i> <translate>LABEL.SALVAR</translate>
7 </button> 7 </button>
8 8
9 - <div ng-show="formContainer.id" class="btn-group dropdown" role="group" dropdown> 9 + <div ng-show="showSaveButton && formContainer.id" class="btn-group dropdown" role="group" dropdown>
10 <button title="{{$translate.instant('LABEL.SALVAR')}}" alt="{{$translate.instant('LABEL.SALVAR')}}" type="button" class="btn btn-clear" dropdown-toggle> 10 <button title="{{$translate.instant('LABEL.SALVAR')}}" alt="{{$translate.instant('LABEL.SALVAR')}}" type="button" class="btn btn-clear" dropdown-toggle>
11 <i class="fa fa-save green"></i> <translate>LABEL.SALVAR</translate><span class="fa fa-caret-down icon-on-right"></span> 11 <i class="fa fa-save green"></i> <translate>LABEL.SALVAR</translate><span class="fa fa-caret-down icon-on-right"></span>
12 </button> 12 </button>
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 <translate>ESI.INTERFACE_USUARIO.PREVIA</translate> 25 <translate>ESI.INTERFACE_USUARIO.PREVIA</translate>
26 </button> 26 </button>
27 27
28 - <button class="btn btn-clear" ng-click="showSarchPage();"> 28 + <button class="btn btn-clear" ng-click="showSarchPage();" ng-show="showSaveButton">
29 <i class="fa fa-search"></i> <translate>LABEL.PESQUISAR</translate> 29 <i class="fa fa-search"></i> <translate>LABEL.PESQUISAR</translate>
30 </button> 30 </button>
31 31
cit-esi-web/src/main/webapp/assets/js/angular/custom/repository/ReportRepository.js
@@ -9,7 +9,8 @@ citApp.factory(&#39;ReportRepository&#39;, [&#39;RestangularEsi&#39;, &#39;AbstractRepository&#39;, &#39;$tr @@ -9,7 +9,8 @@ citApp.factory(&#39;ReportRepository&#39;, [&#39;RestangularEsi&#39;, &#39;AbstractRepository&#39;, &#39;$tr
9 this.getAllVersions = function (params) { 9 this.getAllVersions = function (params) {
10 return this.restangular.all(this.route + '/getAllVersions').post(params); 10 return this.restangular.all(this.route + '/getAllVersions').post(params);
11 }, 11 },
12 - this.execute = function (report) { 12 + this.execute = function (report, params) {
  13 + report.inputMap = params;
13 return this.restangular.all(this.route + '/execute').post(report); 14 return this.restangular.all(this.route + '/execute').post(report);
14 }, 15 },
15 this.replace = function (resource) { 16 this.replace = function (resource) {
cit-esi-web/src/main/webapp/html/report/dialogReportParameter.html
@@ -22,12 +22,12 @@ @@ -22,12 +22,12 @@
22 <legend><translate>ESI.PARAMETRO</translate></legend> 22 <legend><translate>ESI.PARAMETRO</translate></legend>
23 23
24 <div class='row'> 24 <div class='row'>
25 - <div class="col-sm-7"> 25 + <div class="col-sm-6">
26 <label-input-identifier ng-label="LABEL.NOME" ng-type="text" ng-id="parameter.name" ng-obrigatorio="true" 26 <label-input-identifier ng-label="LABEL.NOME" ng-type="text" ng-id="parameter.name" ng-obrigatorio="true"
27 ng-disabled="!edit" ng-model="parameter.name" ng-custom-maxlength="100" form="formReportParameter"/> 27 ng-disabled="!edit" ng-model="parameter.name" ng-custom-maxlength="100" form="formReportParameter"/>
28 </div> 28 </div>
29 29
30 - <div class="col-sm-5"> 30 + <div class="col-sm-6">
31 <label-select ng-id="parameter.type" ng-label="LABEL.TIPO" ng-model="parameter.type" ng-obrigatorio='true' form="formReportParameter" 31 <label-select ng-id="parameter.type" ng-label="LABEL.TIPO" ng-model="parameter.type" ng-obrigatorio='true' form="formReportParameter"
32 ng-list="parameterTypeList | domainFilter" ng-custom-options="item.originalElement.chave as item.descricao for item"> 32 ng-list="parameterTypeList | domainFilter" ng-custom-options="item.originalElement.chave as item.descricao for item">
33 </label-select> 33 </label-select>
@@ -63,18 +63,23 @@ @@ -63,18 +63,23 @@
63 </auto-complete> 63 </auto-complete>
64 </div> 64 </div>
65 65
66 - </div>  
67 -  
68 - <div class="row"> 66 + <div class="col-md-6" ng-if="parameter.type == 'FLOW' && parameter.flow">
  67 + <label-input-identifier ng-id="parameter.outputAttributeName" ng-label="ESI.VARIAVEL_SAIDA_FLUXO" ng-model="parameter.outputAttributeName"
  68 + form="reportForm" ng-obrigatorio="true" ng-disabled="!edit" ng-obrigatorio="true" />
  69 + </div><!-- .col -->
  70 +
69 <div class="col-md-6" ng-if="parameter.type == 'DATAOBJECT' && parameter.dataObject"> 71 <div class="col-md-6" ng-if="parameter.type == 'DATAOBJECT' && parameter.dataObject">
70 - <label-select ng-id="parameter.customSQL" ng-label="ESI.SQL" ng-model="parameter.customSQL" ng-obrigatorio='false' form="reportForm" 72 + <label-select ng-id="parameter.customSQL" ng-label="ESI.SQL" ng-model="parameter.customSQL.id" ng-obrigatorio='false' form="reportForm"
71 ng-list="parameter.dataObject.sqls" ng-custom-options="sql.id as sql.description for sql" > 73 ng-list="parameter.dataObject.sqls" ng-custom-options="sql.id as sql.description for sql" >
72 </label-select> 74 </label-select>
73 </div> 75 </div>
74 - <div class="col-md-6" ng-if="parameter.type == 'FLOW' && parameter.flow">  
75 - <label-input-identifier ng-id="parameter.outputAttributeName" ng-label="ESI.VARIAVEL_SAIDA_FLUXO" ng-model="parameter.outputAttributeName" 76 + </div>
  77 +
  78 + <div class="row" ng-if="parameter.type == 'DATAOBJECT' && parameter.dataObject">
  79 + <div class="col-md-6" >
  80 + <label-input-identifier ng-id="parameter.outputAttributeName" ng-label="ESI.ATRIBUTO" ng-model="parameter.outputAttributeName"
76 form="reportForm" ng-obrigatorio="true" ng-disabled="!edit" ng-obrigatorio="true" /> 81 form="reportForm" ng-obrigatorio="true" ng-disabled="!edit" ng-obrigatorio="true" />
77 - </div><!-- .col --> 82 + </div>
78 </div> 83 </div>
79 84
80 <div class='row' ng-if="parameter.type == 'SCRIPT'"> 85 <div class='row' ng-if="parameter.type == 'SCRIPT'">
@@ -83,7 +88,7 @@ @@ -83,7 +88,7 @@
83 </div> 88 </div>
84 </div> 89 </div>
85 90
86 - <div class="row"> 91 + <div class="row" ng-if="parameter.type == 'IMAGE'">
87 <div class="col-md-6"> 92 <div class="col-md-6">
88 <auto-complete ng-find="findImage(value)" 93 <auto-complete ng-find="findImage(value)"
89 ng-acao-borracha="clearAutoCompleteImage()" 94 ng-acao-borracha="clearAutoCompleteImage()"
cit-esi-web/src/main/webapp/html/report/reportEdit.html
@@ -150,7 +150,7 @@ @@ -150,7 +150,7 @@
150 150
151 <div class="row"> 151 <div class="row">
152 <div class="col-md-6" ng-if="report.dataSource.type == 'DATAOBJECT' && report.dataSource.dataObject"> 152 <div class="col-md-6" ng-if="report.dataSource.type == 'DATAOBJECT' && report.dataSource.dataObject">
153 - <label-select ng-id="report.dataSource.customSQL" ng-label="ESI.SQL" ng-model="report.dataSource.customSQL" ng-obrigatorio='false' form="reportForm" 153 + <label-select ng-id="report.dataSource.customSQL" ng-label="ESI.SQL" ng-model="report.dataSource.customSQL.id" ng-obrigatorio='false' form="reportForm"
154 ng-list="report.dataSource.dataObject.sqls" ng-custom-options="sql.id as sql.description for sql" > 154 ng-list="report.dataSource.dataObject.sqls" ng-custom-options="sql.id as sql.description for sql" >
155 </label-select> 155 </label-select>
156 </div> 156 </div>