Mercurial > dive4elements > river
diff backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java @ 8988:ae76f618d990
Checks added for missing import directory
author | mschaefer |
---|---|
date | Sun, 08 Apr 2018 18:09:32 +0200 |
parents | 50416a0df385 |
children | a44200bf0547 |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java Sun Apr 08 18:08:35 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java Sun Apr 08 18:09:32 2018 +0200 @@ -26,7 +26,6 @@ import org.dive4elements.river.importer.common.ParsingState; import org.dive4elements.river.importer.sinfo.importitem.InfrastructureKmLineImport; import org.dive4elements.river.importer.sinfo.importitem.InfrastructureSeriesImport; -import org.dive4elements.river.model.AnnotationType; import org.dive4elements.river.model.sinfo.Infrastructure; import org.dive4elements.river.model.sinfo.InfrastructureValue; @@ -66,8 +65,6 @@ private final HashMap<String, ImportAttribute> bankAttributes; - private final HashMap<String, ImportAnnotationType> types; - /***** CONSTRUCTORS *****/ @@ -79,9 +76,6 @@ this.bankAttributes.put("links", new ImportAttribute(DB_BANK_LEFT)); this.bankAttributes.put("rechts", new ImportAttribute(DB_BANK_RIGHT)); this.bankAttributes.put("", new ImportAttribute(DB_BANK_NULL)); - this.types = new HashMap<>(); - for (final AnnotationType type : AnnotationType.getTypes()) - this.types.put(type.getName().trim().toLowerCase(), new ImportAnnotationType(type.getName())); } @@ -104,8 +98,9 @@ */ public static List<InfrastructureParser> createParsers(final File importDir, final File relativeDir, final ImportRiver river) { final List<InfrastructureParser> parsers = new ArrayList<>(); - for (final File file : listFiles(importDir, ".csv")) - parsers.add(new InfrastructureParser(file, new File(relativeDir, file.getName()), river)); + if (importDir.exists()) + for (final File file : listFiles(importDir, ".csv")) + parsers.add(new InfrastructureParser(file, new File(relativeDir, file.getName()), river)); return parsers; } @@ -137,12 +132,15 @@ final Matcher m = META_TYPE.matcher(this.currentLine); if (m.matches()) { this.metaPatternsMatched.add(META_TYPE); - if (this.types.containsKey(m.group(1).trim().toLowerCase())) - this.seriesHeader.setType(this.types.get(m.group(1).trim().toLowerCase())); + if (this.river.getAnnotationClassifier() != null) { + final ImportAnnotationType type = this.river.getAnnotationClassifier().classifyDescription(m.group(1).trim(), + this.river.getAnnotationClassifier().getDefaultType()); + this.seriesHeader.setType(type); + log.info(String.format("Type name in file: '%s', will be assigned to database name '%s'", m.group(1).trim(), type.getName())); + } else { - final ImportAnnotationType type = new ImportAnnotationType(m.group(1).trim()); - this.types.put(m.group(1).trim().toLowerCase(), type); - this.seriesHeader.setType(type); + log.error("No annotation types file configured, cannot process type '" + m.group(1).trim() + "'"); + this.headerParsingState = ParsingState.STOP; } return true; }