comparison backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents 0c4bdf00f94f
children 50416a0df385 0a5239a1e46e
comparison
equal deleted inserted replaced
8855:d7c005e12af0 8856:5e38e2924c07
96 96
97 public static final String SEDIMENT_DENSITY_DIR = "Sedimentdichte"; 97 public static final String SEDIMENT_DENSITY_DIR = "Sedimentdichte";
98 98
99 public static final String POROSITY_DIR = "Porositaet"; 99 public static final String POROSITY_DIR = "Porositaet";
100 100
101 public static final String MORPHOLOGICAL_WIDTH_DIR = "morphologische_Breite"; 101 public static final String MORPHOLOGICAL_WIDTH_DIR =
102 102 "morphologische_Breite";
103 public static final String FLOW_VELOCITY_DIR = "Geschwindigkeit_Schubspannung"; 103
104 public static final String FLOW_VELOCITY_DIR =
105 "Geschwindigkeit_Schubspannung";
104 106
105 public static final String FLOW_VELOCITY_MODEL = "Modellrechnungen"; 107 public static final String FLOW_VELOCITY_MODEL = "Modellrechnungen";
106 108
107 public static final String FLOW_VELOCITY_MEASUREMENTS = "v-Messungen"; 109 public static final String FLOW_VELOCITY_MEASUREMENTS = "v-Messungen";
108 110
114 116
115 public static final String SEDIMENT_LOAD_SINGLE_DIR = "Einzeljahre"; 117 public static final String SEDIMENT_LOAD_SINGLE_DIR = "Einzeljahre";
116 118
117 public static final String SEDIMENT_LOAD_EPOCH_DIR = "Epochen"; 119 public static final String SEDIMENT_LOAD_EPOCH_DIR = "Epochen";
118 120
119 public static final String SEDIMENT_LOAD_OFF_EPOCH_DIR = "amtliche Epochen"; 121 public static final String SEDIMENT_LOAD_OFF_EPOCH_DIR =
122 "amtliche Epochen";
120 123
121 public static final String MINFO_FIXATIONS_DIR = "Fixierungsanalyse"; 124 public static final String MINFO_FIXATIONS_DIR = "Fixierungsanalyse";
122 125
123 public static final String MINFO_WATERLEVELS_DIR = "Wasserspiegellagen"; 126 public static final String MINFO_WATERLEVELS_DIR = "Wasserspiegellagen";
124 127
125 public static final String MINFO_WATERLEVEL_DIFF_DIR = "Wasserspiegeldifferenzen"; 128 public static final String MINFO_WATERLEVEL_DIFF_DIR =
129 "Wasserspiegeldifferenzen";
126 130
127 public static final String MINFO_BASE_DIR = "Basisdaten"; 131 public static final String MINFO_BASE_DIR = "Basisdaten";
128 132
129 public static final String MINFO_CORE_DATA_FILE = "Stammdaten_Messstellen.csv"; 133 public static final String MINFO_CORE_DATA_FILE =
130 134 "Stammdaten_Messstellen.csv";
131 public static final String MINFO_SQ_DIR = "Feststofftransport-Abfluss-Beziehung"; 135
136 public static final String MINFO_SQ_DIR =
137 "Feststofftransport-Abfluss-Beziehung";
132 138
133 protected String name; 139 protected String name;
134 140
135 protected String modelUuid; 141 protected String modelUuid;
136 142
214 @Override 220 @Override
215 public boolean accept(File file) { 221 public boolean accept(File file) {
216 HashedFile hf = new HashedFile(file); 222 HashedFile hf = new HashedFile(file);
217 boolean success = files.add(hf); 223 boolean success = files.add(hf);
218 if (!success) { 224 if (!success) {
219 log.warn(type + " file '" + file + "' seems to be a duplicate."); 225 log.warn(type + " file '" + file
226 + "' seems to be a duplicate.");
220 } 227 }
221 return success; 228 return success;
222 } 229 }
223 230
224 231
247 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) { 254 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) {
248 Double km = entry.getKey(); 255 Double km = entry.getKey();
249 List<XY> points = entry.getValue(); 256 List<XY> points = entry.getValue();
250 numReadPoints += points.size(); 257 numReadPoints += points.size();
251 if (simplificationEpsilon != null) { 258 if (simplificationEpsilon != null) {
252 points = DouglasPeuker.simplify(points, simplificationEpsilon); 259 points = DouglasPeuker.simplify(
260 points, simplificationEpsilon);
253 } 261 }
254 numRemainingPoints += points.size(); 262 numRemainingPoints += points.size();
255 lines.add(new ImportCrossSectionLine(km, points)); 263 lines.add(new ImportCrossSectionLine(km, points));
256 } 264 }
257 265
273 private void addCrossSections( 281 private void addCrossSections(
274 String description, 282 String description,
275 ImportTimeInterval ti, 283 ImportTimeInterval ti,
276 List<ImportCrossSectionLine> lines 284 List<ImportCrossSectionLine> lines
277 ) { 285 ) {
278 crossSections.add(new ImportCrossSection(this, description, ti, lines)); 286 crossSections.add(
287 new ImportCrossSection(this, description, ti, lines));
279 } 288 }
280 289
281 290
282 public ImportRiver() { 291 public ImportRiver() {
283 hyks = new ArrayList<ImportHYK>(); 292 hyks = new ArrayList<ImportHYK>();
284 crossSections = new ArrayList<ImportCrossSection>(); 293 crossSections = new ArrayList<ImportCrossSection>();
285 extraWsts = new ArrayList<ImportWst>(); 294 extraWsts = new ArrayList<ImportWst>();
286 fixations = new ArrayList<ImportWst>(); 295 fixations = new ArrayList<ImportWst>();
287 officialLines = new ArrayList<ImportWst>(); 296 officialLines = new ArrayList<ImportWst>();
288 floodWater = new ArrayList<ImportWst>(); 297 floodWater = new ArrayList<ImportWst>();
289 waterlevels = new ArrayList<ImportWst>(); 298 waterlevels = new ArrayList<ImportWst>();
290 waterlevelDifferences = new ArrayList<ImportWst>(); 299 waterlevelDifferences = new ArrayList<ImportWst>();
291 floodProtection = new ArrayList<ImportWst>(); 300 floodProtection = new ArrayList<ImportWst>();
292 sedimentDensities = new ArrayList<ImportSedimentDensity>(); 301 sedimentDensities = new ArrayList<ImportSedimentDensity>();
293 porosities = new ArrayList<ImportPorosity>(); 302 porosities = new ArrayList<ImportPorosity>();
294 morphologicalWidths = new ArrayList<ImportMorphWidth>(); 303 morphologicalWidths = new ArrayList<ImportMorphWidth>();
295 flowVelocityModels = new ArrayList<ImportFlowVelocityModel>(); 304 flowVelocityModels = new ArrayList<ImportFlowVelocityModel>();
296 flowVelocityMeasurements = new ArrayList<ImportFlowVelocityMeasurement>(); 305 flowVelocityMeasurements =
297 sedimentLoadLSs = new ArrayList<ImportSedimentLoadLS>(); 306 new ArrayList<ImportFlowVelocityMeasurement>();
298 sedimentLoads = new ArrayList<ImportSedimentLoad>(); 307 sedimentLoadLSs = new ArrayList<ImportSedimentLoadLS>();
299 measurementStations = new ArrayList<ImportMeasurementStation>(); 308 sedimentLoads = new ArrayList<ImportSedimentLoad>();
300 sqRelations = new ArrayList<ImportSQRelation>(); 309 measurementStations = new ArrayList<ImportMeasurementStation>();
310 sqRelations = new ArrayList<ImportSQRelation>();
301 } 311 }
302 312
303 public ImportRiver( 313 public ImportRiver(
304 String name, 314 String name,
305 String modelUuid, 315 String modelUuid,
362 public void setWst(ImportWst wst) { 372 public void setWst(ImportWst wst) {
363 this.wst = wst; 373 this.wst = wst;
364 } 374 }
365 375
366 public File getMinfoDir() { 376 public File getMinfoDir() {
367 File riverDir = wstFile.getParentFile().getParentFile().getParentFile(); 377 File riverDir = wstFile
378 .getParentFile().getParentFile().getParentFile();
368 return new File(riverDir, MINFO_DIR); 379 return new File(riverDir, MINFO_DIR);
369 } 380 }
370 381
371 public void parseDependencies() throws IOException { 382 public void parseDependencies() throws IOException {
372 parseGauges(); 383 parseGauges();
432 try { 443 try {
433 WstParser wstParser = new WstParser(); 444 WstParser wstParser = new WstParser();
434 wstParser.parse(file); 445 wstParser.parse(file);
435 ImportWst iw = wstParser.getWst(); 446 ImportWst iw = wstParser.getWst();
436 iw.setKind(5); 447 iw.setKind(5);
437 iw.setDescription(FLOOD_PROTECTION + "/" + iw.getDescription()); 448 iw.setDescription(
449 FLOOD_PROTECTION + "/" + iw.getDescription());
438 floodProtection.add(iw); 450 floodProtection.add(iw);
439 } 451 }
440 catch (WstParser.ParseException e) { 452 catch (WstParser.ParseException e) {
441 log.error(e.getMessage()); 453 log.error(e.getMessage());
442 } 454 }
490 parser.parse(file); 502 parser.parse(file);
491 } 503 }
492 504
493 sedimentDensities = parser.getSedimentDensities(); 505 sedimentDensities = parser.getSedimentDensities();
494 506
495 log.info("Parsed " + sedimentDensities.size() + " sediment densities."); 507 log.info("Parsed " + sedimentDensities.size()
508 + " sediment densities.");
496 } 509 }
497 510
498 protected void parsePorosity() throws IOException { 511 protected void parsePorosity() throws IOException {
499 if (Config.INSTANCE.skipPorosity()) { 512 if (Config.INSTANCE.skipPorosity()) {
500 log.info("skip parsing porosity."); 513 log.info("skip parsing porosity.");
548 parser.parse(file); 561 parser.parse(file);
549 } 562 }
550 563
551 morphologicalWidths = parser.getMorphologicalWidths(); 564 morphologicalWidths = parser.getMorphologicalWidths();
552 565
553 log.info("Parsed " + morphologicalWidths.size() + " morph. widths files."); 566 log.info("Parsed " + morphologicalWidths.size()
567 + " morph. widths files.");
554 } 568 }
555 569
556 570
557 protected void parseFlowVelocity() throws IOException { 571 protected void parseFlowVelocity() throws IOException {
558 if (Config.INSTANCE.skipFlowVelocity()) { 572 if (Config.INSTANCE.skipFlowVelocity()) {
666 } 680 }
667 681
668 682
669 protected void parseSedimentLoad() throws IOException { 683 protected void parseSedimentLoad() throws IOException {
670 if (Config.INSTANCE.skipSedimentLoad()) { 684 if (Config.INSTANCE.skipSedimentLoad()) {
671 log.info("skip parsing sediment load data at measurement stations"); 685 log.info(
686 "skip parsing sediment load data at measurement stations");
672 return; 687 return;
673 } 688 }
674 689
675 log.debug("Parse sediment load data at measurement stations"); 690 log.debug("Parse sediment load data at measurement stations");
676 691
732 File minfo = getMinfoDir(); 747 File minfo = getMinfoDir();
733 File minfoBaseDir = new File(minfo, MINFO_BASE_DIR); 748 File minfoBaseDir = new File(minfo, MINFO_BASE_DIR);
734 File coredataFile = new File(minfoBaseDir, MINFO_CORE_DATA_FILE); 749 File coredataFile = new File(minfoBaseDir, MINFO_CORE_DATA_FILE);
735 750
736 if (coredataFile == null || !coredataFile.exists()) { 751 if (coredataFile == null || !coredataFile.exists()) {
737 log.warn("No core data file '" + coredataFile.getAbsolutePath() + "' found"); 752 log.warn("No core data file '"
753 + coredataFile.getAbsolutePath() + "' found");
738 return; 754 return;
739 } 755 }
740 756
741 MeasurementStationsParser parser = new MeasurementStationsParser(); 757 MeasurementStationsParser parser = new MeasurementStationsParser();
742 try { 758 try {
743 parser.parse(coredataFile); 759 parser.parse(coredataFile);
744 measurementStations = parser.getMeasurementStations(); 760 measurementStations = parser.getMeasurementStations();
745 761
746 log.info("Successfully parsed " + measurementStations.size() + " measurement stations."); 762 log.info("Successfully parsed " + measurementStations.size()
763 + " measurement stations.");
747 } 764 }
748 catch (IOException ioe) { 765 catch (IOException ioe) {
749 log.error("unable to parse file '" + coredataFile.getName() + 766 log.error("unable to parse file '" + coredataFile.getName() +
750 ": " + ioe.getMessage()); 767 ": " + ioe.getMessage());
751 } 768 }
905 log.warn("no official lines wst file found"); 922 log.warn("no official lines wst file found");
906 continue; 923 continue;
907 } 924 }
908 log.debug("Found WST file: " + file); 925 log.debug("Found WST file: " + file);
909 926
910 ImportWst iw = new ImportWst(ImportOfficialWstColumn.COLUMN_FACTORY); 927 ImportWst iw = new ImportWst(
928 ImportOfficialWstColumn.COLUMN_FACTORY);
911 929
912 WstParser wstParser = new WstParser(iw); 930 WstParser wstParser = new WstParser(iw);
913 try { 931 try {
914 wstParser.parse(file); 932 wstParser.parse(file);
915 } 933 }
919 } 937 }
920 938
921 iw.setKind(3); 939 iw.setKind(3);
922 iw.setDescription(folder + "/" + iw.getDescription()); 940 iw.setDescription(folder + "/" + iw.getDescription());
923 941
924 File configFile = FileTools.repair(new File(dir, OFFICIAL_LINES_CONFIG)); 942 File configFile = FileTools.repair(
943 new File(dir, OFFICIAL_LINES_CONFIG));
925 if (!configFile.isFile() || !configFile.canRead()) { 944 if (!configFile.isFile() || !configFile.canRead()) {
926 log.warn("no config file for official lines found"); 945 log.warn("no config file for official lines found");
927 } 946 }
928 else { 947 else {
929 OfficialLinesConfigParser olcp = new OfficialLinesConfigParser(); 948 OfficialLinesConfigParser olcp =
949 new OfficialLinesConfigParser();
930 try { 950 try {
931 olcp.parse(configFile); 951 olcp.parse(configFile);
932 } 952 }
933 catch (IOException ioe) { 953 catch (IOException ioe) {
934 log.warn("Error reading offical lines config", ioe); 954 log.warn("Error reading offical lines config", ioe);
935 } 955 }
936 List<String> mainValueNames = olcp.getMainValueNames(); 956 List<String> mainValueNames = olcp.getMainValueNames();
937 if (mainValueNames.isEmpty()) { 957 if (mainValueNames.isEmpty()) {
938 log.warn("config file for offical lines contains no entries"); 958 log.warn(
959 "config file for offical lines contains no entries");
939 } 960 }
940 else { 961 else {
941 // Join as much as possible. 962 // Join as much as possible.
942 Iterator<ImportWstColumn> wi = iw.getColumns().iterator(); 963 Iterator<ImportWstColumn> wi = iw.getColumns().iterator();
943 Iterator<String> si = olcp.getMainValueNames().iterator(); 964 Iterator<String> si = olcp.getMainValueNames().iterator();
944 while (wi.hasNext() && si.hasNext()) { 965 while (wi.hasNext() && si.hasNext()) {
945 ImportOfficialWstColumn wc = (ImportOfficialWstColumn)wi.next(); 966 ImportOfficialWstColumn wc =
967 (ImportOfficialWstColumn)wi.next();
946 String name = si.next(); 968 String name = si.next();
947 ImportOfficialLine iol = new ImportOfficialLine(name, wc); 969 ImportOfficialLine iol =
970 new ImportOfficialLine(name, wc);
948 wc.setOfficialLine(iol); 971 wc.setOfficialLine(iol);
949 } 972 }
950 } 973 }
951 } 974 }
952 975
1042 try { 1065 try {
1043 WstParser wstParser = new WstParser(); 1066 WstParser wstParser = new WstParser();
1044 wstParser.parse(file); 1067 wstParser.parse(file);
1045 ImportWst iw = wstParser.getWst(); 1068 ImportWst iw = wstParser.getWst();
1046 iw.setKind(1); 1069 iw.setKind(1);
1047 iw.setDescription(EXTRA_LONGITUDINALS + "/" + iw.getDescription()); 1070 iw.setDescription(
1071 EXTRA_LONGITUDINALS + "/" + iw.getDescription());
1048 extraWsts.add(iw); 1072 extraWsts.add(iw);
1049 } 1073 }
1050 catch (WstParser.ParseException e) { 1074 catch (WstParser.ParseException e) {
1051 log.error(e.getMessage()); 1075 log.error(e.getMessage());
1052 } 1076 }
1129 @Override 1153 @Override
1130 public boolean hykAccept(File file) { 1154 public boolean hykAccept(File file) {
1131 HashedFile hf = new HashedFile(file); 1155 HashedFile hf = new HashedFile(file);
1132 boolean success = hfs.add(hf); 1156 boolean success = hfs.add(hf);
1133 if (!success) { 1157 if (!success) {
1134 log.warn("HYK file '" + file + "' seems to be a duplicate."); 1158 log.warn("HYK file '" + file
1159 + "' seems to be a duplicate.");
1135 } 1160 }
1136 return success; 1161 return success;
1137 } 1162 }
1138 1163
1139 @Override 1164 @Override
1209 parser.parseDA50s(riverDir, da50Callback); 1234 parser.parseDA50s(riverDir, da50Callback);
1210 } 1235 }
1211 1236
1212 1237
1213 /** Create a DA66 Parser and parse the da66 files found. */ 1238 /** Create a DA66 Parser and parse the da66 files found. */
1214 // TODO this is a copy of parsePRFs, extract interfaces (e.g. CrossSectionParser). 1239 // TODO this is a copy of parsePRFs, extract interfaces
1240 //(e.g. CrossSectionParser).
1215 public void parseDA66s() { 1241 public void parseDA66s() {
1216 if (Config.INSTANCE.skipDA66s()) { 1242 if (Config.INSTANCE.skipDA66s()) {
1217 log.info("skip parsing DA66s"); 1243 log.info("skip parsing DA66s");
1218 return; 1244 return;
1219 } 1245 }
1265 Session session = ImporterSession.getInstance().getDatabaseSession(); 1291 Session session = ImporterSession.getInstance().getDatabaseSession();
1266 Query query = session.createQuery("from River where name=:name"); 1292 Query query = session.createQuery("from River where name=:name");
1267 query.setString("name", name); 1293 query.setString("name", name);
1268 List<River> rivers = query.list(); 1294 List<River> rivers = query.list();
1269 if (rivers.isEmpty() && Config.INSTANCE.skipWst()){ 1295 if (rivers.isEmpty() && Config.INSTANCE.skipWst()){
1270 log.error("River not yet in database. You cannot skip importing waterlevel model."); 1296 log.error("River not yet in database. "
1297 + "You cannot skip importing waterlevel model.");
1271 return; 1298 return;
1272 } 1299 }
1273 1300
1274 storeWstUnit(); 1301 storeWstUnit();
1275 storeAnnotations(); 1302 storeAnnotations();
1296 storeOfficialNumber(); 1323 storeOfficialNumber();
1297 } 1324 }
1298 1325
1299 public void storeWstUnit() { 1326 public void storeWstUnit() {
1300 if (wst == null) { 1327 if (wst == null) {
1301 log.warn("No unit given. Waterlevel-model WST-file has to be imported already."); 1328 log.warn("No unit given. "
1329 + "Waterlevel-model WST-file has to be imported already.");
1302 } 1330 }
1303 else { 1331 else {
1304 wstUnit = wst.getUnit(); 1332 wstUnit = wst.getUnit();
1305 } 1333 }
1306 } 1334 }
1334 River river = getPeer(); 1362 River river = getPeer();
1335 wst.storeDependencies(river); 1363 wst.storeDependencies(river);
1336 1364
1337 // The flow direction of the main wst and the corresponding 1365 // The flow direction of the main wst and the corresponding
1338 // waterlevels determine if the river is 'km_up'. 1366 // waterlevels determine if the river is 'km_up'.
1339 Session session = ImporterSession.getInstance().getDatabaseSession(); 1367 Session session = ImporterSession.getInstance()
1368 .getDatabaseSession();
1340 river.setKmUp(wst.getKmUp()); 1369 river.setKmUp(wst.getKmUp());
1341 session.save(river); 1370 session.save(river);
1342 } 1371 }
1343 } 1372 }
1344 1373
1406 for (ImportWstColumn wc: wst.getColumns()) { 1435 for (ImportWstColumn wc: wst.getColumns()) {
1407 ImportOfficialWstColumn owc = (ImportOfficialWstColumn)wc; 1436 ImportOfficialWstColumn owc = (ImportOfficialWstColumn)wc;
1408 ImportOfficialLine ioc = owc.getOfficialLine(); 1437 ImportOfficialLine ioc = owc.getOfficialLine();
1409 if (ioc != null) { 1438 if (ioc != null) {
1410 if (ioc.getPeer(river) == null) { 1439 if (ioc.getPeer(river) == null) {
1411 log.warn("Cannot store official line: " + ioc.getName()); 1440 log.warn("Cannot store official line: "
1441 + ioc.getName());
1412 } 1442 }
1413 } 1443 }
1414 } 1444 }
1415 } 1445 }
1416 } 1446 }
1510 if (!Config.INSTANCE.skipFlowVelocity()) { 1540 if (!Config.INSTANCE.skipFlowVelocity()) {
1511 log.info("store flow velocity"); 1541 log.info("store flow velocity");
1512 1542
1513 River river = getPeer(); 1543 River river = getPeer();
1514 1544
1515 for (ImportFlowVelocityModel flowVelocityModel: flowVelocityModels){ 1545 for (ImportFlowVelocityModel flowVelocityModel: flowVelocityModels
1546 ) {
1516 flowVelocityModel.storeDependencies(river); 1547 flowVelocityModel.storeDependencies(river);
1517 } 1548 }
1518 1549
1519 for (ImportFlowVelocityMeasurement m: flowVelocityMeasurements) { 1550 for (ImportFlowVelocityMeasurement m: flowVelocityMeasurements) {
1520 m.storeDependencies(river); 1551 m.storeDependencies(river);
1607 } 1638 }
1608 } 1639 }
1609 1640
1610 public River getPeer() { 1641 public River getPeer() {
1611 if (peer == null) { 1642 if (peer == null) {
1612 Session session = ImporterSession.getInstance().getDatabaseSession(); 1643 Session session = ImporterSession.getInstance()
1644 .getDatabaseSession();
1613 Query query = session.createQuery("from River where name=:name"); 1645 Query query = session.createQuery("from River where name=:name");
1614 1646
1615 Unit u = null; 1647 Unit u = null;
1616 if (wstUnit != null) { 1648 if (wstUnit != null) {
1617 u = wstUnit.getPeer(); 1649 u = wstUnit.getPeer();

http://dive4elements.wald.intevation.org