1 package org.simantics.district.imports;
3 import java.io.IOException;
4 import java.nio.file.Path;
5 import java.util.Collections;
6 import java.util.HashMap;
10 import org.apache.commons.csv.CSVFormat;
11 import org.apache.commons.csv.CSVRecord;
12 import org.simantics.db.Resource;
13 import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
15 public class CSVImportModel {
17 // First page fills these
18 private Resource targetDiagram;
21 // Second page fills these
22 private char delimiter;
23 private boolean readFirstAsHeader = true;
24 private Map<String, Character> delimiters;
25 // private Path wktFile;
28 private int xCoordIndex = -1;
29 private int yCoordIndex = -1;
30 private int zCoordIndex = -1;
31 private int altElevationIndex = -1;
34 private int startXCoordIndex = -1;
35 private int startYCoordIndex = -1;
36 private int startZCoordIndex = -1;
37 private int endXCoordIndex = -1;
38 private int endYCoordIndex = -1;
39 private int endZCoordIndex = -1;
42 private int componentMappingIndex = -1;
43 private Map<String, Resource> componentMappings = new HashMap<>();
44 private boolean isVertexImport;
45 private String sourceCRS;
46 private int supplytempIndex = -1;
47 private int supplypressureIndex= -1;
48 private int diameterIndex = -1;
49 private int outerDiamterIndex = -1;
50 private int nominalMassFlowIndex = -1;
51 private int returnTempIndex = -1;
52 private int returnPressureIndex = -1;
53 private int deltaPressureIndex = -1;
54 private int deltaTemperatureIndex = -1;
55 private int heatPowerIndex = -1;
56 private int nominalHeadMIndex = -1;
57 private int nominalHeadBIndex = -1;
58 private int nominalFlowIndex = -1;
59 private int maximumHeadMIndex = -1;
60 private int heatLoadDsIndex = -1;
61 private int massFlowIndex = -1;
62 private int volFlowIndex = -1;
63 private int velocityIndex = -1;
64 private int flowAreaIndex = -1;
65 private int nominalPressureLossIndex = -1;
66 private int edgeFlowAreaIndex = -1;
67 private int kReturnIndex = -1;
68 private int kSupplyIndex = -1;
69 private int tGroundIndex = -1;
70 private int idIndex = -1;
71 private double edgePadding = 0.0001; // default
72 private int valvePositionIndx = -1;
73 private int addressIndex = -1;
74 private int lengthIndex = -1;
75 private int detailedGeometryIndex = -1;
76 private int peakPowerIndex = -1;
77 private int regionIndex = -1;
81 public CSVImportModel() {
82 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
85 public void setSource(Path source) {
89 public void setDelimiter(char delimiter) {
90 this.delimiter = delimiter;
93 public void setReadFirstAsHeader(boolean read) {
94 this.readFirstAsHeader = read;
97 public Path getSource() {
101 public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
103 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
105 return Collections.emptyList();
108 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
110 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
112 return Collections.emptyMap();
115 public Map<String, Integer> getHeader() throws IOException {
116 Map<String, Integer> header = null;
118 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
120 header = Collections.emptyMap();
124 public boolean getReadFirstAsHeader() {
125 return readFirstAsHeader;
128 public String[] getDelimiterFormats() {
129 return delimiters.keySet().toArray(new String[delimiters.size()]);
132 public void setDelimiterByLabel(String item) {
133 setDelimiter(delimiters.get(item));
136 public List<Map<String, String>> readRows(int amount) throws IOException {
138 return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
140 return Collections.emptyList();
143 public char getDelimiter() {
147 // public Path getWKTFile() {
151 public int getXCoordIndex() {
155 public void setXCoordIndex(int xCoordIndex) {
156 this.xCoordIndex = xCoordIndex;
159 public int getYCoordIndex() {
163 public void setYCoordIndex(int yCoordIndex) {
164 this.yCoordIndex = yCoordIndex;
167 public int getZCoordIndex() {
171 public void setZCoordIndex(int zCoordIndex) {
172 this.zCoordIndex = zCoordIndex;
175 public int getComponentMappingIndex() {
176 return componentMappingIndex;
179 public void setComponentMappingIndex(int componentMappingIndex) {
180 this.componentMappingIndex = componentMappingIndex;
183 public void setParentDiagram(Resource diagram) {
184 this.targetDiagram = diagram;
187 public Resource getParentDiagram() {
188 return targetDiagram;
191 // public void setWKTFile(Path wktFile) {
192 // this.wktFile = wktFile;
195 public void setComponentMappings(String value, Resource resource) {
196 componentMappings.put(value, resource);
199 public Map<String, Resource> getComponentMappings() {
200 return componentMappings;
203 public boolean isVertexImport() {
204 return isVertexImport;
207 public void setVertexImport(boolean isVertexImport) {
208 this.isVertexImport = isVertexImport;
211 public void setStartXCoordIndex(int parseInt) {
212 this.startXCoordIndex = parseInt;
215 public int getStartXCoordIndex() {
216 return startXCoordIndex;
219 public void setStartYCoordIndex(int parseInt) {
220 this.startYCoordIndex = parseInt;
223 public int getStartYCoordIndex() {
224 return startYCoordIndex;
227 public void setStartZCoordIndex(int parseInt) {
228 this.startZCoordIndex = parseInt;
231 public int getStartZCoordIndex() {
232 return startZCoordIndex;
235 public void setEndXCoordIndex(int parseInt) {
236 this.endXCoordIndex = parseInt;
239 public int getEndXCoordIndex() {
240 return endXCoordIndex;
243 public void setEndYCoordIndex(int parseInt) {
244 this.endYCoordIndex = parseInt;
247 public int getEndYCoordIndex() {
248 return endYCoordIndex;
251 public void setEndZCoordIndex(int parseInt) {
252 this.endZCoordIndex = parseInt;
255 public int getEndZCoordIndex() {
256 return endZCoordIndex;
259 public void setSourceCRS(String crs) {
260 this.sourceCRS = crs;
263 public String getSourceCRS() {
267 public void setSupplyTempIndex(int supplyTempIndex) {
268 this.supplytempIndex = supplyTempIndex;
271 public int getSupplyTempIndex() {
272 return supplytempIndex;
275 public void setSupplyPressureIndex(int supplyPressureIndex) {
276 this.supplypressureIndex = supplyPressureIndex;
279 public int getSupplyPressureIndex() {
280 return supplypressureIndex;
283 public void setReturnTempIndex(int returnTempIndex) {
284 this.returnTempIndex = returnTempIndex;
287 public int getReturnTempIndex() {
288 return returnTempIndex;
291 public void setReturnPressureIndex(int returnPressureIndex) {
292 this.returnPressureIndex = returnPressureIndex;
295 public int getReturnPressureIndex() {
296 return returnPressureIndex;
299 public void setDiameterIndex(int parseInt) {
300 this.diameterIndex = parseInt;
303 public int getDiameterIndex() {
304 return diameterIndex;
307 public void setOuterDiameterIndex(int parseInt) {
308 this.outerDiamterIndex = parseInt;
311 public int getOuterDiamterIndex() {
312 return outerDiamterIndex;
315 public void setNominalMassFlowIndex(int parseInt) {
316 this.nominalMassFlowIndex = parseInt;
319 public int getNominalMassFlowIndex() {
320 return nominalMassFlowIndex;
323 public void setDeltaPressureIndex(int parseInt) {
324 this.deltaPressureIndex = parseInt;
327 public int getDeltaPressureIndex() {
328 return deltaPressureIndex;
331 public void setDeltaTemperatureIndex(int parseInt) {
332 this.deltaTemperatureIndex = parseInt;
335 public int getDeltaTemperatureIndex() {
336 return deltaTemperatureIndex;
339 public void setHeatPowerIndex(int parseInt) {
340 this.heatPowerIndex = parseInt;
343 public int getHeatPowerIndex() {
344 return heatPowerIndex;
347 public void setNominalHeadMIndex(int parseInt) {
348 this.nominalHeadMIndex = parseInt;
351 public int getNominalHeadMIndex() {
352 return nominalHeadMIndex;
355 public void setNominalHeadBIndex(int parseInt) {
356 this.nominalHeadBIndex = parseInt;
359 public int getNominalHeadBIndex() {
360 return nominalHeadBIndex;
363 public void setNominalFlowIndex(int parseInt) {
364 this.nominalFlowIndex = parseInt;
367 public int getNominalFlowIndex() {
368 return nominalFlowIndex;
371 public void setMaximumHeadMIndex(int parseInt) {
372 this.maximumHeadMIndex = parseInt;
375 public int getMaximumHeadMIndex() {
376 return maximumHeadMIndex;
379 public void setHeatLoadDsIndex(int parseInt) {
380 this.heatLoadDsIndex = parseInt;
383 public int getHeatLoadDsIndex() {
384 return heatLoadDsIndex;
387 public void setMassFlowIndex(int parseInt) {
388 this.massFlowIndex = parseInt;
391 public int getMassFlowIndex() {
392 return massFlowIndex;
395 public void setVolFlowIndex(int parseInt) {
396 this.volFlowIndex = parseInt;
399 public int getVolFlowIndex() {
403 public void setVelocityIndex(int parseInt) {
404 this.velocityIndex = parseInt;
407 public int getVelocityIndex() {
408 return velocityIndex;
411 public void setFlowAreaIndex(int parseInt) {
412 this.flowAreaIndex = parseInt;
415 public int getFlowAreaIndex() {
416 return flowAreaIndex;
419 public void setNominalPressureLossIndex(int parseInt) {
420 this.nominalPressureLossIndex = parseInt;
423 public int getNominalPressureLossIndex() {
424 return nominalPressureLossIndex;
427 public void setEdgeFlowAreaIndex(int parseInt) {
428 this.edgeFlowAreaIndex = parseInt;
431 public int getEdgeFlowAreaIndex() {
432 return edgeFlowAreaIndex;
435 public void setKReturnIndex(int parseInt) {
436 this.kReturnIndex = parseInt;
439 public int getkReturnIndex() {
443 public void setKSupplyIndex(int parseInt) {
444 this.kSupplyIndex = parseInt;
447 public int getkSupplyIndex() {
451 public void setTGroundIndex(int parseInt) {
452 this.tGroundIndex = parseInt;
455 public int gettGroundIndex() {
459 public int getIdIndex() {
463 public void setIdIndex(int idIndex) {
464 this.idIndex = idIndex;
467 public void setEdgePadding(double edgePadding) {
468 this.edgePadding = edgePadding;
471 public double getEdgePadding() {
475 public void setValvePositionIndex(int valvePositionIndx) {
476 this.valvePositionIndx = valvePositionIndx;
479 public int getValvePositionIndx() {
480 return valvePositionIndx;
483 public void setAddressIndex(int parseInt) {
484 this.addressIndex = parseInt;
487 public int getAddressIndex() {
491 public int getLengthIndex() {
495 public void setLengthIndex(int lengthIndex) {
496 this.lengthIndex = lengthIndex;
499 public void detailedGeometryIndex(int detailedGeometryIndex) {
500 this.detailedGeometryIndex = detailedGeometryIndex;
503 public int getDetailedGeometryIndex() {
504 return detailedGeometryIndex;
507 public int getAlternativeElevationIndex() {
508 return altElevationIndex;
511 public void setAltElevationIndex(int parseInt) {
512 this.altElevationIndex = parseInt;
515 public void setPeakPowerIndex(int parseInt) {
516 this.peakPowerIndex = parseInt;
519 public int getPeakPowerIndex() {
520 return peakPowerIndex;
523 public int getRegionIndex() {
527 public void setRegionIndex(int regionIndex) {
528 this.regionIndex = regionIndex;