Commit 4d5320286c5851842ab7808e24795e74d6871ebb
1 parent
fbb5fa54
Exists in
master
Implementação dos recursos de relatório
Showing
10 changed files
with
152 additions
and
51 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/data/service/impl/DataManager.java
... | ... | @@ -55,8 +55,13 @@ public class DataManager { |
55 | 55 | } |
56 | 56 | } |
57 | 57 | } |
58 | + | |
59 | + public void findAllRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
60 | + this.findManyToOneRelationships(dataObject, lines); | |
61 | + this.findOneToManyRelationships(dataObject, lines); | |
62 | + } | |
58 | 63 | |
59 | - private void findRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
64 | + public void findManyToOneRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
60 | 65 | if (dataObject.getRelationships() != null) { |
61 | 66 | for (HashMap<String, Object> line : lines) { |
62 | 67 | for (Relationship relationship : dataObject.getRelationships()) { |
... | ... | @@ -72,6 +77,50 @@ public class DataManager { |
72 | 77 | } |
73 | 78 | } |
74 | 79 | } |
80 | + | |
81 | + /*DataObjectRepository.get(relationship.referencedObject.id).then(function(dataObject) { | |
82 | + relationship.referencedObject = dataObject.originalElement; | |
83 | + var filterCriteria = { | |
84 | + start : 1, | |
85 | + dir : 'asc', | |
86 | + sort : relationship.searchObject.keys[0].referencedColumn, | |
87 | + limit : 99999, | |
88 | + fields: self.buildColumnsArray(relationship.referencedObject), | |
89 | + filters : [], | |
90 | + findRelationships : true | |
91 | + }; | |
92 | + angular.forEach(relationship.searchObject.keys, function(key){ | |
93 | + filterCriteria.filters.push({type: key.type, field: key.referencedColumn, value: object[key.objectColumn]}); | |
94 | + }); | |
95 | + DataRepository.listPaged(relationship.referencedObject, filterCriteria).then(function(result) { | |
96 | + var array = []; | |
97 | + angular.forEach(result.originalElement.objects, function(object){ | |
98 | + object.originalElement = angular.copy(object); | |
99 | + array.push(object); | |
100 | + }); | |
101 | + $timeout(function(){ | |
102 | + object[relationship.name] = array; | |
103 | + }); | |
104 | + }); | |
105 | + | |
106 | + });*/ | |
107 | + | |
108 | + public void findOneToManyRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
109 | + if (dataObject.getRelationships() != null) { | |
110 | + for (HashMap<String, Object> line : lines) { | |
111 | + for (Relationship relationship : dataObject.getRelationships()) { | |
112 | + if (relationship.getType().equals(RelationshipTypeEnum.ONE_TO_MANY)) { | |
113 | + HashMap<String, Object> searchObject = new HashMap<String, Object>(); | |
114 | + for (RelationshipColumn relationshipColumn : relationship.getColumns()) { | |
115 | + searchObject.put(relationshipColumn.getReferencedColumn().getName(), line.get(relationshipColumn.getObjectColumn().getName())); | |
116 | + } | |
117 | + relationship.setSearchObject(searchObject); | |
118 | + restoreRelationship(relationship, line); | |
119 | + } | |
120 | + } | |
121 | + } | |
122 | + } | |
123 | + } | |
75 | 124 | |
76 | 125 | private void validateData(DataObject dataObject, HashMap<String, Object> data) { |
77 | 126 | String errors = ""; |
... | ... | @@ -193,7 +242,7 @@ public class DataManager { |
193 | 242 | } |
194 | 243 | |
195 | 244 | if (searchParams.isFindRelationships()) { |
196 | - this.findRelationships(dataObject, result); | |
245 | + this.findManyToOneRelationships(dataObject, result); | |
197 | 246 | } |
198 | 247 | return new PageImpl<HashMap<String, Object>>(result, pageable, totalElements); |
199 | 248 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/JasperReportManagerImpl.java
... | ... | @@ -13,8 +13,8 @@ import net.sf.jasperreports.engine.JasperExportManager; |
13 | 13 | import net.sf.jasperreports.engine.JasperFillManager; |
14 | 14 | import net.sf.jasperreports.engine.JasperPrint; |
15 | 15 | import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; |
16 | -import net.sf.json.JSONArray; | |
17 | 16 | |
17 | +import org.json.JSONArray; | |
18 | 18 | import org.springframework.stereotype.Component; |
19 | 19 | |
20 | 20 | import br.com.centralit.esi.api.execution.component.ExecuteScript; |
... | ... | @@ -108,16 +108,16 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper |
108 | 108 | case DATAOBJECT: |
109 | 109 | String SQLName = reportDataSource.getCustomSQL() != null ? reportDataSource.getCustomSQL().getName() : null; |
110 | 110 | List<HashMap<String, Object>> resultSet = dataManager.executeQuery(reportDataSource.getDataObject(), SQLName, inputMap); |
111 | - dataSource = new JRBeanCollectionDataSource(resultSet); | |
111 | + //dataManager.findManyToOneRelationships(reportDataSource.getDataObject(), resultSet); | |
112 | + dataSource = new JRBeanCollectionDataSource(net.sf.json.JSONArray.fromObject(resultSet)); | |
112 | 113 | break; |
113 | 114 | |
114 | 115 | case FLOW: |
115 | 116 | RuntimeEnvironmentOutput output = runtimeManager.execute(reportDataSource.getFlow().getName(), inputMap); |
116 | 117 | if (output.getOutputVariables() != null) { |
117 | 118 | Object value = output.getValue(reportDataSource.getOutputAttributeName()); |
118 | - if (value != null) { | |
119 | - JSONArray array = JSONArray.fromObject(value); | |
120 | - dataSource = new JRBeanCollectionDataSource(array); | |
119 | + if (value != null && value instanceof JSONArray) { | |
120 | + dataSource = new JRBeanCollectionDataSource(net.sf.json.JSONArray.fromObject(value.toString())); | |
121 | 121 | } |
122 | 122 | } |
123 | 123 | break; |
... | ... | @@ -125,9 +125,8 @@ public class JasperReportManagerImpl extends ReportManagerImpl implements Jasper |
125 | 125 | case SCRIPT: |
126 | 126 | RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironmentImpl(null, inputMap); |
127 | 127 | Object value = ExecuteScript.execute(runtimeEnvironment, report.getResource().getName(), reportDataSource.getScriptCode()); |
128 | - if (value != null) { | |
129 | - JSONArray array = JSONArray.fromObject(value); | |
130 | - dataSource = new JRBeanCollectionDataSource(array); | |
128 | + if (value != null && value instanceof JSONArray) { | |
129 | + dataSource = new JRBeanCollectionDataSource(net.sf.json.JSONArray.fromObject(value.toString())); | |
131 | 130 | } |
132 | 131 | break; |
133 | 132 | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/ReportVersionServiceImpl.java
... | ... | @@ -142,8 +142,12 @@ public class ReportVersionServiceImpl extends ResourceVersionServiceImpl impleme |
142 | 142 | |
143 | 143 | FormVersion formVersion = reportVersion.getFormVersion(); |
144 | 144 | formVersion.setPath(reportVersion.getPath()); |
145 | - formVersion = (FormVersion) formVersionService.save(reportVersion.getFormVersion()); | |
146 | - | |
145 | + formVersion.setGenerateDefaultPage(true); | |
146 | + if (formVersion.isNew()) { | |
147 | + formVersion = (FormVersion) formVersionService.save(reportVersion.getFormVersion()); | |
148 | + }else{ | |
149 | + formVersion = (FormVersion) formVersionService.merge(reportVersion.getFormVersion()); | |
150 | + } | |
147 | 151 | reportVersion.setForm(formVersion.getResource()); |
148 | 152 | } |
149 | 153 | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentImpl.java
... | ... | @@ -304,7 +304,7 @@ public class RuntimeEnvironmentImpl implements RuntimeEnvironment { |
304 | 304 | |
305 | 305 | public RuntimeEnvironmentImpl(FlowVersion flowVersion, HashMap<String, Object> inputMap) { |
306 | 306 | RuntimeEnvironmentInput input = new RuntimeEnvironmentInput( |
307 | - flowVersion.getFlow().getName() | |
307 | + flowVersion != null ? flowVersion.getFlow().getName() : null | |
308 | 308 | ,false |
309 | 309 | ,false) |
310 | 310 | .setInputMap(inputMap); | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/runtime/RuntimeEnvironmentOutput.java
... | ... | @@ -11,6 +11,7 @@ import br.com.centralit.esi.api.design.model.FlowVersion; |
11 | 11 | import br.com.centralit.esi.api.execution.model.ProcessInstance; |
12 | 12 | import br.com.centralit.esi.api.execution.model.WorkItem; |
13 | 13 | import br.com.centralit.esi.api.resource.model.Resource; |
14 | +import br.com.centralit.esi.api.util.ConvertUtilsESI; | |
14 | 15 | import br.com.centralit.framework.esi.enumerated.VariableTypeEnum; |
15 | 16 | import br.com.centralit.framework.esi.environment.EnvironmentOutput; |
16 | 17 | import br.com.centralit.framework.esi.environment.EnvironmentVariable; |
... | ... | @@ -168,7 +169,11 @@ public class RuntimeEnvironmentOutput extends EnvironmentOutput { |
168 | 169 | public Object getValue(String name) { |
169 | 170 | EnvironmentVariable var = this.getRuntimeVariable(name); |
170 | 171 | if (var != null) { |
171 | - return var.getValue(); | |
172 | + Object result = var.getValue(); | |
173 | + if (var.getVariableType().equals(VariableTypeEnum.JSON) && result instanceof String) { | |
174 | + result = ConvertUtilsESI.convertJson(result); | |
175 | + } | |
176 | + return result; | |
172 | 177 | }else{ |
173 | 178 | return null; |
174 | 179 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ConvertUtilsESI.java
... | ... | @@ -10,10 +10,12 @@ import java.text.ParseException; |
10 | 10 | import java.text.SimpleDateFormat; |
11 | 11 | import java.util.ArrayList; |
12 | 12 | import java.util.Calendar; |
13 | +import java.util.Collection; | |
13 | 14 | import java.util.Date; |
14 | 15 | import java.util.HashMap; |
15 | 16 | import java.util.Iterator; |
16 | 17 | import java.util.List; |
18 | +import java.util.Map; | |
17 | 19 | |
18 | 20 | import org.apache.commons.lang.math.NumberUtils; |
19 | 21 | import org.apache.commons.lang3.time.DateUtils; |
... | ... | @@ -597,4 +599,17 @@ public class ConvertUtilsESI { |
597 | 599 | |
598 | 600 | return result; |
599 | 601 | } |
602 | + | |
603 | + public static Collection<Map<String, ?>> convertMapListToMapCollection(List<HashMap<String, Object>> input) { | |
604 | + Collection<Map<String, ?>> result = new ArrayList<Map<String, ?>>(); | |
605 | + | |
606 | + if (input != null) { | |
607 | + for (HashMap<String, Object> map : input) { | |
608 | + result.add(map); | |
609 | + } | |
610 | + } | |
611 | + | |
612 | + return result; | |
613 | + } | |
614 | + | |
600 | 615 | } | ... | ... |
cit-esi-web/src/main/resources/reports/empregado.jrxml
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | -<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="empregado" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6525ccf4-d2ac-4fad-a579-12cb4c715330"> | |
2 | +<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="empregado" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6525ccf4-d2ac-4fad-a579-12cb4c715330"> | |
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 | - <field name="id" class="java.lang.Long"/> | |
6 | + <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> | |
7 | + <defaultValueExpression><![CDATA["D:\\cit\\cit-grp-esi\\cit-esi-web\\src\\main\\resources\\reports\\"]]></defaultValueExpression> | |
8 | + </parameter> | |
9 | + <parameter name="telefones" class="java.util.Collection"/> | |
10 | + <field name="id" class="java.lang.Integer"> | |
11 | + <fieldDescription><![CDATA[id]]></fieldDescription> | |
12 | + </field> | |
7 | 13 | <field name="nome" class="java.lang.String"/> |
8 | 14 | <field name="matricula" class="java.lang.String"/> |
15 | + <field name="telefones" class="java.util.Collection"> | |
16 | + <property name="numero" value=""/> | |
17 | + </field> | |
9 | 18 | <background> |
10 | 19 | <band splitType="Stretch"/> |
11 | 20 | </background> |
12 | 21 | <title> |
13 | 22 | <band height="79" splitType="Stretch"/> |
14 | 23 | </title> |
15 | - <pageHeader> | |
16 | - <band height="35" splitType="Stretch"/> | |
17 | - </pageHeader> | |
18 | 24 | <columnHeader> |
19 | 25 | <band height="27" splitType="Stretch"> |
20 | 26 | <staticText> |
21 | - <reportElement x="0" y="0" width="185" height="20" uuid="c48d969b-0389-4d09-9200-06c4170b9f8e"/> | |
22 | - <text><![CDATA[id]]></text> | |
27 | + <reportElement x="78" y="0" width="238" height="20" uuid="ebd455e7-e461-480c-8112-23333ac99413"/> | |
28 | + <text><![CDATA[Nome]]></text> | |
23 | 29 | </staticText> |
24 | 30 | <staticText> |
25 | - <reportElement x="185" y="0" width="185" height="20" uuid="ebd455e7-e461-480c-8112-23333ac99413"/> | |
26 | - <text><![CDATA[nome]]></text> | |
31 | + <reportElement x="331" y="0" width="90" height="20" uuid="75d8796f-1a6b-4509-a0f2-68d0478928ad"/> | |
32 | + <text><![CDATA[Matrícula]]></text> | |
27 | 33 | </staticText> |
28 | 34 | <staticText> |
29 | - <reportElement x="370" y="0" width="185" height="20" uuid="75d8796f-1a6b-4509-a0f2-68d0478928ad"/> | |
30 | - <text><![CDATA[matricula]]></text> | |
35 | + <reportElement x="434" y="0" width="110" height="20" uuid="6cbee36c-4ba1-49f2-b67b-0b83f8fd30c2"/> | |
36 | + <text><![CDATA[Telefones]]></text> | |
37 | + </staticText> | |
38 | + <staticText> | |
39 | + <reportElement x="4" y="2" width="63" height="20" uuid="24e25739-a9aa-49cf-8b2e-7e98d0da13ca"/> | |
40 | + <text><![CDATA[Id]]></text> | |
31 | 41 | </staticText> |
32 | 42 | </band> |
33 | 43 | </columnHeader> |
34 | 44 | <detail> |
35 | - <band height="31" splitType="Stretch"> | |
36 | - <textField> | |
37 | - <reportElement x="0" y="0" width="185" height="20" uuid="10b5dbca-ff9b-4f10-bb95-45709fe220eb"/> | |
38 | - <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> | |
39 | - </textField> | |
45 | + <band height="32" splitType="Stretch"> | |
40 | 46 | <textField> |
41 | - <reportElement x="185" y="0" width="185" height="20" uuid="45f3d992-9c27-4064-8ac6-91db2d938ca0"/> | |
47 | + <reportElement x="78" y="0" width="238" height="20" uuid="45f3d992-9c27-4064-8ac6-91db2d938ca0"/> | |
42 | 48 | <textFieldExpression><![CDATA[$F{nome}]]></textFieldExpression> |
43 | 49 | </textField> |
44 | 50 | <textField> |
45 | - <reportElement x="370" y="0" width="185" height="20" uuid="7fbb5eb2-bf1f-4d4d-81c2-f9b33278064a"/> | |
51 | + <reportElement x="331" y="0" width="90" height="20" uuid="7fbb5eb2-bf1f-4d4d-81c2-f9b33278064a"/> | |
46 | 52 | <textFieldExpression><![CDATA[$F{matricula}]]></textFieldExpression> |
47 | 53 | </textField> |
54 | + <subreport> | |
55 | + <reportElement x="434" y="0" width="110" height="20" uuid="067824da-77b3-453a-a169-721c2a99fd6c"/> | |
56 | + <dataSourceExpression><![CDATA[$F{telefones}]]></dataSourceExpression> | |
57 | + <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "empregado_telefone.jasper"]]></subreportExpression> | |
58 | + </subreport> | |
59 | + <textField> | |
60 | + <reportElement x="4" y="2" width="63" height="20" uuid="d28bb265-561b-4cb9-b95b-5d3f5a7c7496"/> | |
61 | + <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> | |
62 | + </textField> | |
48 | 63 | </band> |
49 | 64 | </detail> |
50 | 65 | <columnFooter> |
51 | - <band height="45" splitType="Stretch"/> | |
66 | + <band splitType="Stretch"/> | |
52 | 67 | </columnFooter> |
53 | - <pageFooter> | |
54 | - <band height="54" splitType="Stretch"/> | |
55 | - </pageFooter> | |
56 | - <summary> | |
57 | - <band height="42" splitType="Stretch"/> | |
58 | - </summary> | |
59 | 68 | </jasperReport> | ... | ... |
cit-esi-web/src/main/resources/reports/empregado_telefone.jrxml
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="empregado_telefone" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="78583037-6cbe-45ff-9619-61ad66d5c8de"> | |
3 | + <property name="ireport.zoom" value="1.0"/> | |
4 | + <property name="ireport.x" value="0"/> | |
5 | + <property name="ireport.y" value="0"/> | |
6 | + <field name="numero" class="java.lang.String"> | |
7 | + <fieldDescription><![CDATA[Número]]></fieldDescription> | |
8 | + </field> | |
9 | + <background> | |
10 | + <band splitType="Stretch"/> | |
11 | + </background> | |
12 | + <detail> | |
13 | + <band height="42" splitType="Stretch"> | |
14 | + <textField> | |
15 | + <reportElement x="11" y="12" width="100" height="20" uuid="42865c6c-27a5-48de-9549-8c87e20aa594"/> | |
16 | + <textFieldExpression><![CDATA[$F{numero}]]></textFieldExpression> | |
17 | + </textField> | |
18 | + </band> | |
19 | + </detail> | |
20 | +</jasperReport> | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/ReportController.js
... | ... | @@ -69,7 +69,7 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
69 | 69 | return formVersion; |
70 | 70 | }; |
71 | 71 | |
72 | - $scope.findDataSource = function(value) { | |
72 | + $scope.findConnection = function(value) { | |
73 | 73 | var dataSourceVH = { |
74 | 74 | nome : value |
75 | 75 | }; |
... | ... | @@ -78,21 +78,21 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
78 | 78 | }); |
79 | 79 | }; |
80 | 80 | |
81 | - $scope.clearDataSourceAutoComplete = function() { | |
81 | + $scope.clearConnectionAutoComplete = function() { | |
82 | 82 | $scope.report.dataSource.connection = null; |
83 | 83 | }; |
84 | 84 | |
85 | - $scope.setDataSource = function (item) { | |
85 | + $scope.setConnection = function (item) { | |
86 | 86 | if(item && item.id) { |
87 | 87 | $scope.report.dataSource.connection = item; |
88 | 88 | } |
89 | 89 | }; |
90 | 90 | |
91 | - $scope.clearParameterDataSource = function() { | |
91 | + $scope.clearParameterConnection = function() { | |
92 | 92 | $scope.parameter.connection = null; |
93 | 93 | }; |
94 | 94 | |
95 | - $scope.setParameterDataSource = function (item) { | |
95 | + $scope.setParameterConnection = function (item) { | |
96 | 96 | if(item && item.id) { |
97 | 97 | $scope.parameter.connection = item; |
98 | 98 | } |
... | ... | @@ -118,12 +118,12 @@ citApp.controller('ReportController', ["$scope", "appService", "ReportRepository |
118 | 118 | }; |
119 | 119 | |
120 | 120 | $scope.clearParameterDataObject = function() { |
121 | - $scope.parameter.report = null; | |
121 | + $scope.parameter.dataObject = null; | |
122 | 122 | }; |
123 | 123 | |
124 | 124 | $scope.setParameterDataObject = function (item) { |
125 | 125 | if(item && item.id) { |
126 | - $scope.parameter.report = item; | |
126 | + $scope.parameter.dataObject = item; | |
127 | 127 | } |
128 | 128 | }; |
129 | 129 | ... | ... |
cit-esi-web/src/main/webapp/html/report/reportEdit.html
... | ... | @@ -132,12 +132,12 @@ |
132 | 132 | <div class='col-sm-6' ng-if="report.dataSource.type == 'CONNECTION'"> |
133 | 133 | <auto-complete |
134 | 134 | ng-label="ESI.CONEXAO_BANCO" |
135 | - ng-find="findDataSource(value)" | |
136 | - ng-acao-borracha="clearParameterDataSource()" | |
135 | + ng-find="findConnection(value)" | |
136 | + ng-acao-borracha="clearConnection()" | |
137 | 137 | ng-item="item.description" |
138 | - ng-id="parameter.connection" | |
139 | - ng-model="parameter.connection" | |
140 | - ng-set-result="setParameterDataSource(item)" | |
138 | + ng-id="report.dataSource.connection" | |
139 | + ng-model="report.dataSource.connection" | |
140 | + ng-set-result="setConnection(item)" | |
141 | 141 | form="reportForm" |
142 | 142 | ng-obrigatorio="true"> |
143 | 143 | </auto-complete> | ... | ... |