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;
78 private int pipeTypeIndex = -1;
79 private int pipeCodeIndex = -1;
80 private int installationYearIndex = -1;
81 private int wallThicknessIndex = -1;
82 private int insulationConductivityIndex = -1;
83 private int pipeSizeDNIndex = -1;
84 private int roughnessIndex = -1;
85 private int structureIndex = -1;
89 public CSVImportModel() {
90 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
93 public void setSource(Path source) {
97 public void setDelimiter(char delimiter) {
98 this.delimiter = delimiter;
101 public void setReadFirstAsHeader(boolean read) {
102 this.readFirstAsHeader = read;
105 public Path getSource() {
109 public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
111 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
113 return Collections.emptyList();
116 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
118 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
120 return Collections.emptyMap();
123 public Map<String, Integer> getHeader() throws IOException {
124 Map<String, Integer> header = null;
126 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
128 header = Collections.emptyMap();
132 public boolean getReadFirstAsHeader() {
133 return readFirstAsHeader;
136 public String[] getDelimiterFormats() {
137 return delimiters.keySet().toArray(new String[delimiters.size()]);
140 public void setDelimiterByLabel(String item) {
141 setDelimiter(delimiters.get(item));
144 public List<Map<String, String>> readRows(int amount) throws IOException {
146 return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
148 return Collections.emptyList();
151 public char getDelimiter() {
155 // public Path getWKTFile() {
159 public int getXCoordIndex() {
163 public void setXCoordIndex(int xCoordIndex) {
164 this.xCoordIndex = xCoordIndex;
167 public int getYCoordIndex() {
171 public void setYCoordIndex(int yCoordIndex) {
172 this.yCoordIndex = yCoordIndex;
175 public int getZCoordIndex() {
179 public void setZCoordIndex(int zCoordIndex) {
180 this.zCoordIndex = zCoordIndex;
183 public int getComponentMappingIndex() {
184 return componentMappingIndex;
187 public void setComponentMappingIndex(int componentMappingIndex) {
188 this.componentMappingIndex = componentMappingIndex;
191 public void setParentDiagram(Resource diagram) {
192 this.targetDiagram = diagram;
195 public Resource getParentDiagram() {
196 return targetDiagram;
199 // public void setWKTFile(Path wktFile) {
200 // this.wktFile = wktFile;
203 public void setComponentMappings(String value, Resource resource) {
204 componentMappings.put(value, resource);
207 public Map<String, Resource> getComponentMappings() {
208 return componentMappings;
211 public boolean isVertexImport() {
212 return isVertexImport;
215 public void setVertexImport(boolean isVertexImport) {
216 this.isVertexImport = isVertexImport;
219 public void setStartXCoordIndex(int parseInt) {
220 this.startXCoordIndex = parseInt;
223 public int getStartXCoordIndex() {
224 return startXCoordIndex;
227 public void setStartYCoordIndex(int parseInt) {
228 this.startYCoordIndex = parseInt;
231 public int getStartYCoordIndex() {
232 return startYCoordIndex;
235 public void setStartZCoordIndex(int parseInt) {
236 this.startZCoordIndex = parseInt;
239 public int getStartZCoordIndex() {
240 return startZCoordIndex;
243 public void setEndXCoordIndex(int parseInt) {
244 this.endXCoordIndex = parseInt;
247 public int getEndXCoordIndex() {
248 return endXCoordIndex;
251 public void setEndYCoordIndex(int parseInt) {
252 this.endYCoordIndex = parseInt;
255 public int getEndYCoordIndex() {
256 return endYCoordIndex;
259 public void setEndZCoordIndex(int parseInt) {
260 this.endZCoordIndex = parseInt;
263 public int getEndZCoordIndex() {
264 return endZCoordIndex;
267 public void setSourceCRS(String crs) {
268 this.sourceCRS = crs;
271 public String getSourceCRS() {
275 public void setSupplyTempIndex(int supplyTempIndex) {
276 this.supplytempIndex = supplyTempIndex;
279 public int getSupplyTempIndex() {
280 return supplytempIndex;
283 public void setSupplyPressureIndex(int supplyPressureIndex) {
284 this.supplypressureIndex = supplyPressureIndex;
287 public int getSupplyPressureIndex() {
288 return supplypressureIndex;
291 public void setReturnTempIndex(int returnTempIndex) {
292 this.returnTempIndex = returnTempIndex;
295 public int getReturnTempIndex() {
296 return returnTempIndex;
299 public void setReturnPressureIndex(int returnPressureIndex) {
300 this.returnPressureIndex = returnPressureIndex;
303 public int getReturnPressureIndex() {
304 return returnPressureIndex;
307 public void setDiameterIndex(int parseInt) {
308 this.diameterIndex = parseInt;
311 public int getDiameterIndex() {
312 return diameterIndex;
315 public void setOuterDiameterIndex(int parseInt) {
316 this.outerDiamterIndex = parseInt;
319 public int getOuterDiamterIndex() {
320 return outerDiamterIndex;
323 public void setNominalMassFlowIndex(int parseInt) {
324 this.nominalMassFlowIndex = parseInt;
327 public int getNominalMassFlowIndex() {
328 return nominalMassFlowIndex;
331 public void setDeltaPressureIndex(int parseInt) {
332 this.deltaPressureIndex = parseInt;
335 public int getDeltaPressureIndex() {
336 return deltaPressureIndex;
339 public void setDeltaTemperatureIndex(int parseInt) {
340 this.deltaTemperatureIndex = parseInt;
343 public int getDeltaTemperatureIndex() {
344 return deltaTemperatureIndex;
347 public void setHeatPowerIndex(int parseInt) {
348 this.heatPowerIndex = parseInt;
351 public int getHeatPowerIndex() {
352 return heatPowerIndex;
355 public void setNominalHeadMIndex(int parseInt) {
356 this.nominalHeadMIndex = parseInt;
359 public int getNominalHeadMIndex() {
360 return nominalHeadMIndex;
363 public void setNominalHeadBIndex(int parseInt) {
364 this.nominalHeadBIndex = parseInt;
367 public int getNominalHeadBIndex() {
368 return nominalHeadBIndex;
371 public void setNominalFlowIndex(int parseInt) {
372 this.nominalFlowIndex = parseInt;
375 public int getNominalFlowIndex() {
376 return nominalFlowIndex;
379 public void setMaximumHeadMIndex(int parseInt) {
380 this.maximumHeadMIndex = parseInt;
383 public int getMaximumHeadMIndex() {
384 return maximumHeadMIndex;
387 public void setHeatLoadDsIndex(int parseInt) {
388 this.heatLoadDsIndex = parseInt;
391 public int getHeatLoadDsIndex() {
392 return heatLoadDsIndex;
395 public void setMassFlowIndex(int parseInt) {
396 this.massFlowIndex = parseInt;
399 public int getMassFlowIndex() {
400 return massFlowIndex;
403 public void setVolFlowIndex(int parseInt) {
404 this.volFlowIndex = parseInt;
407 public int getVolFlowIndex() {
411 public void setVelocityIndex(int parseInt) {
412 this.velocityIndex = parseInt;
415 public int getVelocityIndex() {
416 return velocityIndex;
419 public void setFlowAreaIndex(int parseInt) {
420 this.flowAreaIndex = parseInt;
423 public int getFlowAreaIndex() {
424 return flowAreaIndex;
427 public void setNominalPressureLossIndex(int parseInt) {
428 this.nominalPressureLossIndex = parseInt;
431 public int getNominalPressureLossIndex() {
432 return nominalPressureLossIndex;
435 public void setEdgeFlowAreaIndex(int parseInt) {
436 this.edgeFlowAreaIndex = parseInt;
439 public int getEdgeFlowAreaIndex() {
440 return edgeFlowAreaIndex;
443 public void setKReturnIndex(int parseInt) {
444 this.kReturnIndex = parseInt;
447 public int getkReturnIndex() {
451 public void setKSupplyIndex(int parseInt) {
452 this.kSupplyIndex = parseInt;
455 public int getkSupplyIndex() {
459 public void setTGroundIndex(int parseInt) {
460 this.tGroundIndex = parseInt;
463 public int gettGroundIndex() {
467 public int getIdIndex() {
471 public void setIdIndex(int idIndex) {
472 this.idIndex = idIndex;
475 public void setEdgePadding(double edgePadding) {
476 this.edgePadding = edgePadding;
479 public double getEdgePadding() {
483 public void setValvePositionIndex(int valvePositionIndx) {
484 this.valvePositionIndx = valvePositionIndx;
487 public int getValvePositionIndx() {
488 return valvePositionIndx;
491 public void setAddressIndex(int parseInt) {
492 this.addressIndex = parseInt;
495 public int getAddressIndex() {
499 public int getLengthIndex() {
503 public void setLengthIndex(int lengthIndex) {
504 this.lengthIndex = lengthIndex;
507 public void detailedGeometryIndex(int detailedGeometryIndex) {
508 this.detailedGeometryIndex = detailedGeometryIndex;
511 public int getDetailedGeometryIndex() {
512 return detailedGeometryIndex;
515 public int getAlternativeElevationIndex() {
516 return altElevationIndex;
519 public void setAltElevationIndex(int parseInt) {
520 this.altElevationIndex = parseInt;
523 public void setPeakPowerIndex(int parseInt) {
524 this.peakPowerIndex = parseInt;
527 public int getPeakPowerIndex() {
528 return peakPowerIndex;
531 public int getRegionIndex() {
535 public void setRegionIndex(int regionIndex) {
536 this.regionIndex = regionIndex;
539 public int getPipeTypeIndex() {
540 return pipeTypeIndex;
543 public void setPipeTypeIndex(int pipeTypeIndex) {
544 this.pipeTypeIndex = pipeTypeIndex;
547 public int getPipeCodeIndex() {
548 return pipeCodeIndex;
551 public void setPipeCodeIndex(int pipeCodeIndex) {
552 this.pipeCodeIndex = pipeCodeIndex;
555 public int getInstallationYearIndex() {
556 return installationYearIndex;
559 public void setInstallationYearIndex(int installationYearIndex) {
560 this.installationYearIndex = installationYearIndex;
563 public int getWallThicknessIndex() {
564 return wallThicknessIndex;
567 public void setWallThicknessIndex(int wallThicknessIndex) {
568 this.wallThicknessIndex = wallThicknessIndex;
571 public int getInsulationConductivityIndex() {
572 return insulationConductivityIndex;
575 public void setInsulationConductivityIndex(int insulationConductivityIndex) {
576 this.insulationConductivityIndex = insulationConductivityIndex;
579 public int getPipeSizeDNIndex() {
580 return pipeSizeDNIndex;
583 public void setPipeSizeDNIndex(int pipeSizeDNIndex) {
584 this.pipeSizeDNIndex = pipeSizeDNIndex;
587 public int getRoughnessIndex() {
588 return roughnessIndex;
591 public void setRoughnessIndex(int roughnessIndex) {
592 this.roughnessIndex = roughnessIndex;
595 public int getStructureIndex() {
596 return structureIndex;
599 public void setStructureIndex(int structureIndex) {
600 this.structureIndex = structureIndex;