Commit 3cd770af4d565c9a58de2895676cfd981f36f63e
1 parent
4d532028
Exists in
master
Implementação dos recursos de relatório
Showing
5 changed files
with
42 additions
and
69 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/data/core/DataObjectUtil.java
... | ... | @@ -510,7 +510,7 @@ public final class DataObjectUtil { |
510 | 510 | |
511 | 511 | public static StringBuilder selectQueryPiece(DataObject dataObject, DataObjectParams searchParams) { |
512 | 512 | StringBuilder sql = new StringBuilder(); |
513 | - if (UtilString.isNullOrEmpty(searchParams.getSQLName())) { | |
513 | + if (searchParams != null && UtilString.isNullOrEmpty(searchParams.getSQLName())) { | |
514 | 514 | int i = 0; |
515 | 515 | |
516 | 516 | sql.append("SELECT "); |
... | ... | @@ -534,7 +534,7 @@ public final class DataObjectUtil { |
534 | 534 | public static StringBuilder fromWhereQueryPiece(DataObject dataObject, DataObjectParams searchParams) { |
535 | 535 | StringBuilder sql = new StringBuilder(); |
536 | 536 | |
537 | - if (UtilString.isNullOrEmpty(searchParams.getSQLName())) { | |
537 | + if (searchParams == null || UtilString.isNullOrEmpty(searchParams.getSQLName())) { | |
538 | 538 | sql.append(" FROM "+dataObject.getFullName()); |
539 | 539 | if (searchParams != null && !UtilString.isNullOrEmpty(searchParams.getWhereCustomize())) { |
540 | 540 | sql.append(" WHERE "+searchParams.getWhereCustomize()); |
... | ... | @@ -586,7 +586,7 @@ public final class DataObjectUtil { |
586 | 586 | public static StringBuilder buildFilters(DataObject dataObject, DataObjectParams searchParams) { |
587 | 587 | StringBuilder sql = new StringBuilder(); |
588 | 588 | |
589 | - if (searchParams.getFilters() != null) { | |
589 | + if (searchParams != null && searchParams.getFilters() != null) { | |
590 | 590 | int i = 0; |
591 | 591 | SearchSeven search = new SearchSeven(searchParams); |
592 | 592 | if (UtilString.isNullOrEmpty(searchParams.getKeywordValue())) { | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/data/service/impl/DataManager.java
... | ... | @@ -34,6 +34,8 @@ import br.com.centralit.esi.exception.EsiControlledException; |
34 | 34 | import br.com.centralit.esi.exception.EsiExecutionException; |
35 | 35 | import br.com.centralit.framework.esi.enumerated.VariableTypeEnum; |
36 | 36 | import br.com.centralit.framework.esi.environment.EnvironmentVariable; |
37 | +import br.com.centralit.framework.model.Filter; | |
38 | +import br.com.centralit.framework.util.ConstantsQuery; | |
37 | 39 | import br.com.centralit.framework.util.UtilString; |
38 | 40 | |
39 | 41 | @Component("dataManager") |
... | ... | @@ -45,77 +47,49 @@ public class DataManager { |
45 | 47 | @Autowired |
46 | 48 | private BusinessRuleManager businessRuleManager; |
47 | 49 | |
48 | - private void restoreRelationship(Relationship relationship, HashMap<String, Object> line) { | |
49 | - if (relationship.getSearchObject() != null) { | |
50 | - HashMap<String, Object> object = this.executeDefaultRestore(relationship.getReferencedObject(), relationship.getSearchObject()); | |
51 | - if (object != null) { | |
52 | - for (String key : object.keySet()) { | |
53 | - line.put(relationship.getReferencedObject().getName()+"."+key, object.get(key)); | |
50 | + private void restoreRelationship(Relationship relationship, HashMap<String, Object> searchObject, HashMap<String, Object> line) { | |
51 | + if (searchObject != null) { | |
52 | + if (relationship.getType().equals(RelationshipTypeEnum.MANY_TO_ONE)) { | |
53 | + HashMap<String, Object> object = this.executeDefaultRestore(relationship.getReferencedObject(), searchObject); | |
54 | + if (object != null) { | |
55 | + for (String key : object.keySet()) { | |
56 | + line.put(relationship.getReferencedObject().getName()+"."+key, object.get(key)); | |
57 | + } | |
54 | 58 | } |
55 | - } | |
56 | - } | |
57 | - } | |
58 | - | |
59 | - public void findAllRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
60 | - this.findManyToOneRelationships(dataObject, lines); | |
61 | - this.findOneToManyRelationships(dataObject, lines); | |
62 | - } | |
63 | - | |
64 | - public void findManyToOneRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
65 | - if (dataObject.getRelationships() != null) { | |
66 | - for (HashMap<String, Object> line : lines) { | |
67 | - for (Relationship relationship : dataObject.getRelationships()) { | |
68 | - if (relationship.getType().equals(RelationshipTypeEnum.MANY_TO_ONE)) { | |
69 | - HashMap<String, Object> searchObject = new HashMap<String, Object>(); | |
70 | - for (RelationshipColumn relationshipColumn : relationship.getColumns()) { | |
71 | - searchObject.put(relationshipColumn.getReferencedColumn().getName(), line.get(relationshipColumn.getObjectColumn().getName())); | |
72 | - } | |
73 | - relationship.setSearchObject(searchObject); | |
74 | - restoreRelationship(relationship, line); | |
59 | + }else if (relationship.getType().equals(RelationshipTypeEnum.ONE_TO_MANY)) { | |
60 | + DataObjectParams searchParams = new DataObjectParams(); | |
61 | + searchParams.setStart(1); | |
62 | + searchParams.setLimit(99999); | |
63 | + List<Filter> filters = new ArrayList<Filter>(); | |
64 | + | |
65 | + for (String key : searchObject.keySet()) { | |
66 | + DataColumn dataColumn = relationship.getReferencedObject().getColumn(key); | |
67 | + if (dataColumn != null) { | |
68 | + filters.add(new Filter(key, dataColumn.getSearchType(), searchObject.get(key).toString(), ConstantsQuery.COMPARE_EQUALS)); | |
75 | 69 | } |
76 | 70 | } |
71 | + searchParams.setFilters(filters); | |
72 | + Page<HashMap<String, Object>> page = this.executePagedQuery(relationship.getReferencedObject(), searchObject, searchParams); | |
73 | + line.put(relationship.getAttributeName(), page.getContent()); | |
77 | 74 | } |
78 | 75 | } |
79 | 76 | } |
80 | 77 | |
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) { | |
78 | + public void restoreAllRelationships(DataObject dataObject, List<HashMap<String, Object>> lines) { | |
79 | + this.restoreRelationships(dataObject, RelationshipTypeEnum.MANY_TO_ONE, lines); | |
80 | + this.restoreRelationships(dataObject, RelationshipTypeEnum.ONE_TO_MANY, lines); | |
81 | + } | |
82 | + | |
83 | + public void restoreRelationships(DataObject dataObject, RelationshipTypeEnum relationshipType, List<HashMap<String, Object>> lines) { | |
109 | 84 | if (dataObject.getRelationships() != null) { |
110 | 85 | for (HashMap<String, Object> line : lines) { |
111 | 86 | for (Relationship relationship : dataObject.getRelationships()) { |
112 | - if (relationship.getType().equals(RelationshipTypeEnum.ONE_TO_MANY)) { | |
87 | + if (relationship.getType().equals(relationshipType)) { | |
113 | 88 | HashMap<String, Object> searchObject = new HashMap<String, Object>(); |
114 | 89 | for (RelationshipColumn relationshipColumn : relationship.getColumns()) { |
115 | 90 | searchObject.put(relationshipColumn.getReferencedColumn().getName(), line.get(relationshipColumn.getObjectColumn().getName())); |
116 | 91 | } |
117 | - relationship.setSearchObject(searchObject); | |
118 | - restoreRelationship(relationship, line); | |
92 | + this.restoreRelationship(relationship, searchObject, line); | |
119 | 93 | } |
120 | 94 | } |
121 | 95 | } |
... | ... | @@ -242,7 +216,7 @@ public class DataManager { |
242 | 216 | } |
243 | 217 | |
244 | 218 | if (searchParams.isFindRelationships()) { |
245 | - this.findManyToOneRelationships(dataObject, result); | |
219 | + this.restoreRelationships(dataObject, RelationshipTypeEnum.MANY_TO_ONE, result); | |
246 | 220 | } |
247 | 221 | return new PageImpl<HashMap<String, Object>>(result, pageable, totalElements); |
248 | 222 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/resource/service/impl/JasperReportManagerImpl.java
... | ... | @@ -108,7 +108,7 @@ 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 | - //dataManager.findManyToOneRelationships(reportDataSource.getDataObject(), resultSet); | |
111 | + dataManager.restoreAllRelationships(reportDataSource.getDataObject(), resultSet); | |
112 | 112 | dataSource = new JRBeanCollectionDataSource(net.sf.json.JSONArray.fromObject(resultSet)); |
113 | 113 | break; |
114 | 114 | ... | ... |
cit-esi-web/src/main/resources/reports/empregado.jrxml
... | ... | @@ -6,7 +6,6 @@ |
6 | 6 | <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> |
7 | 7 | <defaultValueExpression><![CDATA["D:\\cit\\cit-grp-esi\\cit-esi-web\\src\\main\\resources\\reports\\"]]></defaultValueExpression> |
8 | 8 | </parameter> |
9 | - <parameter name="telefones" class="java.util.Collection"/> | |
10 | 9 | <field name="id" class="java.lang.Integer"> |
11 | 10 | <fieldDescription><![CDATA[id]]></fieldDescription> |
12 | 11 | </field> |
... | ... | @@ -51,15 +50,15 @@ |
51 | 50 | <reportElement x="331" y="0" width="90" height="20" uuid="7fbb5eb2-bf1f-4d4d-81c2-f9b33278064a"/> |
52 | 51 | <textFieldExpression><![CDATA[$F{matricula}]]></textFieldExpression> |
53 | 52 | </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 | 53 | <textField> |
60 | 54 | <reportElement x="4" y="2" width="63" height="20" uuid="d28bb265-561b-4cb9-b95b-5d3f5a7c7496"/> |
61 | 55 | <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> |
62 | 56 | </textField> |
57 | + <subreport> | |
58 | + <reportElement x="438" y="0" width="106" height="20" uuid="904cdc0b-98c8-40ac-af91-baaed29629f0"/> | |
59 | + <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> | |
60 | + <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "empregado_telefone.jasper"]]></subreportExpression> | |
61 | + </subreport> | |
63 | 62 | </band> |
64 | 63 | </detail> |
65 | 64 | <columnFooter> | ... | ... |
cit-esi-web/src/main/resources/reports/empregado_telefone.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_telefone" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="78583037-6cbe-45ff-9619-61ad66d5c8de"> | |
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" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="78583037-6cbe-45ff-9619-61ad66d5c8de"> | |
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"/> | ... | ... |