comparison 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
comparison
equal deleted inserted replaced
8987:5ff8ce9a2e06 8988:ae76f618d990
24 import org.dive4elements.river.importer.ImportRiver; 24 import org.dive4elements.river.importer.ImportRiver;
25 import org.dive4elements.river.importer.common.AbstractParser; 25 import org.dive4elements.river.importer.common.AbstractParser;
26 import org.dive4elements.river.importer.common.ParsingState; 26 import org.dive4elements.river.importer.common.ParsingState;
27 import org.dive4elements.river.importer.sinfo.importitem.InfrastructureKmLineImport; 27 import org.dive4elements.river.importer.sinfo.importitem.InfrastructureKmLineImport;
28 import org.dive4elements.river.importer.sinfo.importitem.InfrastructureSeriesImport; 28 import org.dive4elements.river.importer.sinfo.importitem.InfrastructureSeriesImport;
29 import org.dive4elements.river.model.AnnotationType;
30 import org.dive4elements.river.model.sinfo.Infrastructure; 29 import org.dive4elements.river.model.sinfo.Infrastructure;
31 import org.dive4elements.river.model.sinfo.InfrastructureValue; 30 import org.dive4elements.river.model.sinfo.InfrastructureValue;
32 31
33 /** 32 /**
34 * Reads and parses an infrastructure file 33 * Reads and parses an infrastructure file
63 private int heightColIndex; 62 private int heightColIndex;
64 63
65 private int bankColIndex; 64 private int bankColIndex;
66 65
67 private final HashMap<String, ImportAttribute> bankAttributes; 66 private final HashMap<String, ImportAttribute> bankAttributes;
68
69 private final HashMap<String, ImportAnnotationType> types;
70 67
71 68
72 /***** CONSTRUCTORS *****/ 69 /***** CONSTRUCTORS *****/
73 70
74 public InfrastructureParser(final File importPath, final File rootRelativePath, final ImportRiver river) { 71 public InfrastructureParser(final File importPath, final File rootRelativePath, final ImportRiver river) {
77 this.bankColIndex = -1; 74 this.bankColIndex = -1;
78 this.bankAttributes = new HashMap<>(); 75 this.bankAttributes = new HashMap<>();
79 this.bankAttributes.put("links", new ImportAttribute(DB_BANK_LEFT)); 76 this.bankAttributes.put("links", new ImportAttribute(DB_BANK_LEFT));
80 this.bankAttributes.put("rechts", new ImportAttribute(DB_BANK_RIGHT)); 77 this.bankAttributes.put("rechts", new ImportAttribute(DB_BANK_RIGHT));
81 this.bankAttributes.put("", new ImportAttribute(DB_BANK_NULL)); 78 this.bankAttributes.put("", new ImportAttribute(DB_BANK_NULL));
82 this.types = new HashMap<>();
83 for (final AnnotationType type : AnnotationType.getTypes())
84 this.types.put(type.getName().trim().toLowerCase(), new ImportAnnotationType(type.getName()));
85 } 79 }
86 80
87 81
88 /***** METHODS *****/ 82 /***** METHODS *****/
89 83
102 /** 96 /**
103 * Creates a list of parsers for all infrastructure import files in a directory 97 * Creates a list of parsers for all infrastructure import files in a directory
104 */ 98 */
105 public static List<InfrastructureParser> createParsers(final File importDir, final File relativeDir, final ImportRiver river) { 99 public static List<InfrastructureParser> createParsers(final File importDir, final File relativeDir, final ImportRiver river) {
106 final List<InfrastructureParser> parsers = new ArrayList<>(); 100 final List<InfrastructureParser> parsers = new ArrayList<>();
107 for (final File file : listFiles(importDir, ".csv")) 101 if (importDir.exists())
108 parsers.add(new InfrastructureParser(file, new File(relativeDir, file.getName()), river)); 102 for (final File file : listFiles(importDir, ".csv"))
103 parsers.add(new InfrastructureParser(file, new File(relativeDir, file.getName()), river));
109 return parsers; 104 return parsers;
110 } 105 }
111 106
112 @Override 107 @Override
113 protected InfrastructureSeriesImport createSeriesImport(final String filename) { 108 protected InfrastructureSeriesImport createSeriesImport(final String filename) {
135 130
136 private boolean handleMetaType() { 131 private boolean handleMetaType() {
137 final Matcher m = META_TYPE.matcher(this.currentLine); 132 final Matcher m = META_TYPE.matcher(this.currentLine);
138 if (m.matches()) { 133 if (m.matches()) {
139 this.metaPatternsMatched.add(META_TYPE); 134 this.metaPatternsMatched.add(META_TYPE);
140 if (this.types.containsKey(m.group(1).trim().toLowerCase())) 135 if (this.river.getAnnotationClassifier() != null) {
141 this.seriesHeader.setType(this.types.get(m.group(1).trim().toLowerCase())); 136 final ImportAnnotationType type = this.river.getAnnotationClassifier().classifyDescription(m.group(1).trim(),
137 this.river.getAnnotationClassifier().getDefaultType());
138 this.seriesHeader.setType(type);
139 log.info(String.format("Type name in file: '%s', will be assigned to database name '%s'", m.group(1).trim(), type.getName()));
140 }
142 else { 141 else {
143 final ImportAnnotationType type = new ImportAnnotationType(m.group(1).trim()); 142 log.error("No annotation types file configured, cannot process type '" + m.group(1).trim() + "'");
144 this.types.put(m.group(1).trim().toLowerCase(), type); 143 this.headerParsingState = ParsingState.STOP;
145 this.seriesHeader.setType(type);
146 } 144 }
147 return true; 145 return true;
148 } 146 }
149 return false; 147 return false;
150 } 148 }

http://dive4elements.wald.intevation.org