OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 140 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 140 Rev 181
Line 17... Line 17...
17
import org.openconcerto.openoffice.ODPackage;
17
import org.openconcerto.openoffice.ODPackage;
18
import org.openconcerto.openoffice.spreadsheet.Cell;
18
import org.openconcerto.openoffice.spreadsheet.Cell;
19
import org.openconcerto.openoffice.spreadsheet.Sheet;
19
import org.openconcerto.openoffice.spreadsheet.Sheet;
20
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
20
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
21
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.model.DBRoot;
-
 
22
import org.openconcerto.sql.model.SQLRow;
-
 
23
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
24
import org.openconcerto.sql.model.SQLRowListRSH;
22
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLRowValuesCluster;
26
import org.openconcerto.sql.model.SQLRowValuesCluster;
24
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
-
 
25
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
27
import org.openconcerto.sql.model.SQLRowValuesCluster.StoreMode;
-
 
28
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
-
 
29
import org.openconcerto.sql.model.SQLSelect;
-
 
30
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.utils.cc.IdentityHashSet;
31
import org.openconcerto.utils.cc.IdentityHashSet;
27
import org.openconcerto.utils.text.CSVReader;
32
import org.openconcerto.utils.text.CSVReader;
28
import org.openconcerto.utils.text.CharsetHelper;
33
import org.openconcerto.utils.text.CharsetHelper;
29
 
34
 
30
public class LeadImporter {
35
public class LeadImporter {
Line 74... Line 79...
74
        }
79
        }
75
 
80
 
76
        public abstract T convert(String[] line);
81
        public abstract T convert(String[] line);
77
    }
82
    }
78
 
83
 
-
 
84
    public Map<Object, LeadCSV> exportLeads(SQLTable tableLead, File dir2save, File sheetFile) throws Exception {
-
 
85
        List<String[]> adresse = new ArrayList<String[]>();
-
 
86
        List<String[]> leadList = new ArrayList<String[]>();
-
 
87
 
-
 
88
        Map<Object, LeadCSV> leadMap = new HashMap<Object, LeadCSV>();
-
 
89
 
-
 
90
        SQLSelect sel = new SQLSelect();
-
 
91
        sel.addSelectStar(tableLead);
-
 
92
        List<SQLRow> leads = SQLRowListRSH.execute(sel);
-
 
93
        int i = 1;
-
 
94
        for (SQLRow lead : leads) {
-
 
95
 
-
 
96
            int idAdr = adresse.size();
-
 
97
            AdresseCSV adr = createAdresse(i, lead.getForeign("ID_ADRESSE"));
-
 
98
            adresse.add(adr.toCSVLine());
-
 
99
            LeadCSV leadCsv = createLeadFromRow(i, lead, Integer.valueOf(adr.getId().toString()));
-
 
100
            leadList.add(leadCsv.toCSVLine());
-
 
101
            leadMap.put(leadCsv.getId(), leadCsv);
-
 
102
            i++;
-
 
103
        }
-
 
104
 
-
 
105
        DataImporter importer = new DataImporter(tableLead);
-
 
106
        final File csvFile = new File(dir2save, "Lead.csv");
-
 
107
        csvFile.createNewFile();
-
 
108
        importer.exportModelToCSV(csvFile, leadList);
-
 
109
        DataImporter importerAdr = new DataImporter(tableLead.getForeignTable("ID_ADRESSE"));
-
 
110
        final File csvFile2 = new File(dir2save, "Address.csv");
-
 
111
        csvFile2.createNewFile();
-
 
112
        importerAdr.exportModelToCSV(csvFile2, adresse);
-
 
113
 
-
 
114
        return leadMap;
-
 
115
    }
-
 
116
 
-
 
117
    public AdresseCSV createAdresse(int i, SQLRow rowAdr) {
-
 
118
 
-
 
119
        String street = rowAdr.getString("RUE");
-
 
120
        final String ville = rowAdr.getString("VILLE");
-
 
121
        final String cp = rowAdr.getString("CODE_POSTAL");
-
 
122
 
-
 
123
        AdresseCSV adrLine = new AdresseCSV(i, street, ville, cp);
-
 
124
 
-
 
125
        return adrLine;
-
 
126
    }
-
 
127
 
-
 
128
    public LeadCSV createLeadFromRow(int i, SQLRowAccessor row, int idAdr) {
-
 
129
 
-
 
130
        LeadCSV leadLine = new LeadCSV(i, row.getString("COMPANY"), "");
-
 
131
 
-
 
132
        leadLine.setIdAdr(idAdr);
-
 
133
 
-
 
134
        leadLine.setPhone(row.getString("PHONE"));
-
 
135
        leadLine.setMail(row.getString("EMAIL"));
-
 
136
        leadLine.setCell(row.getString("MOBILE"));
-
 
137
        leadLine.setFax(row.getString("FAX"));
-
 
138
        leadLine.setContact(row.getString("NAME"));
-
 
139
        leadLine.setLocalisation(row.getString("LOCALISATION"));
-
 
140
        leadLine.setSecteur(row.getString("INDUSTRY"));
-
 
141
        leadLine.setEffectif(String.valueOf(row.getInt("EMPLOYEES")));
-
 
142
        leadLine.setOrigine(row.getString("SOURCE"));
-
 
143
 
-
 
144
        leadLine.setSiret(row.getString("SIRET"));
-
 
145
        leadLine.setApe(row.getString("APE"));
-
 
146
 
-
 
147
        leadLine.setNom(row.getString("NAME"));
-
 
148
        leadLine.setPrenom(row.getString("FIRSTNAME"));
-
 
149
        leadLine.setDesc(row.getString("INFORMATION"));
-
 
150
        // rowVals.put("REVENUE", (getBudget().trim().length()==0?0:Integer);
-
 
151
        leadLine.setDispo(row.getString("DISPO"));
-
 
152
        leadLine.setTypeT(row.getString("INDUSTRY"));
-
 
153
        leadLine.setStatut(row.getString("STATUS"));
-
 
154
        leadLine.setInfos(row.getString("INFOS"));
-
 
155
 
-
 
156
        return leadLine;
-
 
157
 
-
 
158
    }
-
 
159
 
79
    public LeadCSV createLead(int i, Sheet sheet, int idAdr, int id) {
160
    public LeadCSV createLead(int i, Sheet sheet, int idAdr, int id) {
80
        final Cell<SpreadSheet> cell0 = sheet.getImmutableCellAt(0, i);
161
        final Cell<SpreadSheet> cell0 = sheet.getImmutableCellAt(0, i);
81
        final String societeName = cell0.getValue().toString().trim();
162
        final String societeName = cell0.getValue().toString().trim();
82
        final Cell<SpreadSheet> cell1 = sheet.getImmutableCellAt(1, i);
163
        final Cell<SpreadSheet> cell1 = sheet.getImmutableCellAt(1, i);
83
        final String loc = cell1.getValue().toString().trim();
164
        final String loc = cell1.getValue().toString().trim();