OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.generationDoc;
15
 
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLTable;
21
 
22
import java.util.ArrayList;
41 ilm 23
import java.util.Arrays;
18 ilm 24
import java.util.List;
25
 
132 ilm 26
import org.jdom2.Element;
18 ilm 27
 
28
public class OOXMLTableElement {
29
 
41 ilm 30
    private List<SQLRow> row;
18 ilm 31
    private int firstLine, endPageLine, endLine, filterId;
32
    private List<String> listBlankLineStyle;
33
    private boolean typeStyleWhere;
34
    private SQLElement elt;
35
    private String foreignTableWhere, typeWhere, fieldWhere;
36
    private Element tableau;
63 ilm 37
    private OOXMLCache cache;
18 ilm 38
 
63 ilm 39
    public OOXMLTableElement(Element tableau, SQLRow row, OOXMLCache cache) {
18 ilm 40
 
41
        this.tableau = tableau;
63 ilm 42
        this.cache = cache;
18 ilm 43
        this.foreignTableWhere = tableau.getAttributeValue("tableForeignWhere");
44
        this.fieldWhere = tableau.getAttributeValue("fieldWhere");
21 ilm 45
 
91 ilm 46
        if (this.fieldWhere != null && row.getTable().contains(fieldWhere)) {
18 ilm 47
            this.filterId = row.getInt(this.fieldWhere);
48
        }
49
 
50
        String fieldAttribute = tableau.getAttributeValue("field");
41 ilm 51
        if (fieldAttribute != null && fieldAttribute.trim().length() > 0) {
52
            if (fieldAttribute.contains(",")) {
53
                List<String> l = SQLRow.toList(fieldAttribute);
54
                this.row = new ArrayList<SQLRow>();
55
                for (String string : l) {
56
                    this.row.add(row.getForeignRow(string));
57
                }
58
            } else {
59
                this.row = Arrays.asList(row.getForeignRow(fieldAttribute));
60
            }
61
        } else {
62
            this.row = Arrays.asList(row);
18 ilm 63
        }
64
 
65
        this.firstLine = Integer.valueOf(tableau.getAttributeValue("firstLine"));
66
 
67
        this.endPageLine = Integer.valueOf(tableau.getAttributeValue("endPageLine"));
68
        this.endLine = Integer.valueOf(tableau.getAttributeValue("endLine"));
69
 
70
        this.elt = Configuration.getInstance().getDirectory().getElement(tableau.getAttributeValue("table"));
71
 
72
        this.typeWhere = tableau.getAttributeValue("typeWhere");
73
 
74
        String blankLineBeforeStyle = tableau.getAttributeValue("blankLineBeforeStyle");
75
        this.listBlankLineStyle = new ArrayList<String>();
76
 
77
        if (blankLineBeforeStyle != null) {
78
            this.listBlankLineStyle = SQLRow.toList(blankLineBeforeStyle.trim());
79
        }
80
 
81
        this.typeStyleWhere = (this.typeWhere == null) ? false : this.typeWhere.equalsIgnoreCase("Style");
82
 
83
    }
84
 
85
    public List<? extends SQLRowAccessor> getRows() {
182 ilm 86
        String foreignTableName = this.tableau.getAttributeValue("table");
18 ilm 87
 
182 ilm 88
        SQLTable tableElt = null;
89
        if (!this.row.isEmpty()) {
90
            SQLTable tableRow = this.row.get(0).getTable();
91
            if (tableRow.getDBRoot().contains(foreignTableName)) {
92
                tableElt = tableRow.getDBRoot().getTable(foreignTableName);
93
            } else {
94
                tableElt = Configuration.getInstance().getRoot().findTable(foreignTableName);
95
            }
96
        }
97
 
18 ilm 98
        if (tableElt != null) {
19 ilm 99
 
132 ilm 100
            return cache.getReferentRows(this.row, tableElt, this.tableau.getAttributeValue("groupBy"), this.tableau.getAttributeValue("orderBy"),
101
                    Boolean.valueOf(this.tableau.getAttributeValue("expandNomenclature")), this.tableau.getAttributeValue("foreignField"),
102
                    Boolean.valueOf(this.tableau.getAttributeValue("excludeZeroQty")));
18 ilm 103
 
104
        } else {
105
            System.err.println("OOXMLTableElement.getRows() Table " + tableElt + " is null!");
106
            return new ArrayList<SQLRow>();
107
        }
108
    }
109
 
110
    public int getFirstLine() {
111
        return this.firstLine;
112
    }
113
 
114
    public int getFilterId() {
115
        return this.filterId;
116
    }
117
 
118
    public int getEndPageLine() {
119
        return this.endPageLine;
120
    }
121
 
122
    public int getEndLine() {
123
        return this.endLine;
124
    }
125
 
126
    public List<String> getListBlankLineStyle() {
127
        return this.listBlankLineStyle;
128
    }
129
 
130
    public SQLElement getSQLElement() {
131
        return this.elt;
132
    }
133
 
134
    public String getForeignTableWhere() {
135
        return this.foreignTableWhere;
136
    }
137
 
41 ilm 138
    public List<SQLRow> getRow() {
18 ilm 139
        return this.row;
140
    }
141
 
142
    public Element getTableau() {
143
        return this.tableau;
144
    }
145
 
146
    public String getTypeWhere() {
147
        return this.typeWhere;
148
    }
149
 
150
    public boolean getTypeStyleWhere() {
151
        return this.typeStyleWhere;
152
    }
153
 
154
    public String getFieldWhere() {
155
        return this.fieldWhere;
156
    }
157
}