Changeset 4614
- Timestamp:
- Oct 29, 2008, 9:58:38 AM (15 years ago)
- Location:
- trunk/src/plugins/core/net/sf/basedb/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java
r4594 r4614 1171 1171 throws InvalidDataException 1172 1172 { 1173 return checkColumnMapping(null, mapExpression, allowComplex, name); 1174 } 1175 1176 /** 1177 Checks the syntax column mapping and verifies that the given file parser 1178 has found the columns that are used in the file. 1179 1180 @param ffp An optional flat file parser that should have parsed the file headers 1181 with {@link FlatFileParser#parseHeaders()} 1182 @param mapExpression The mapping expression 1183 @param allowComplex If complex column mappings should be allowed 1184 @param name The name of the column (used if an error message needs to be generated) 1185 @return The mapping string 1186 @throws InvalidDataException If the mapping isn't a valid column 1187 mapping or if the allowComplex parameter is false and the mapping is complex 1188 @since 2.9 1189 */ 1190 protected String checkColumnMapping(FlatFileParser ffp, String mapExpression, 1191 boolean allowComplex, String name) 1192 throws InvalidDataException 1193 { 1194 System.out.println("checkMapping: ffp=" + ffp + "; expr=" + mapExpression + "; name=" + name); 1195 1173 1196 if (mapExpression == null || mapExpression.length() == 0) 1174 1197 { … … 1197 1220 } 1198 1221 } 1199 else 1200 { 1201 if (isJep) 1222 1223 if (ffp != null) 1224 { 1225 try 1202 1226 { 1203 try 1204 { 1205 new JepMapper(mapExpression.substring(1), new ArrayList<String>(), null); 1206 } 1207 catch (Throwable t) 1208 { 1209 throw new InvalidDataException("Invalid expression for column '" + 1210 name + "': " + mapExpression + " (" + t.getMessage() + ")"); 1211 } 1227 Mapper m = ffp.getMapper(mapExpression); 1228 System.out.println("Mapper: " + m); 1229 } 1230 catch (Throwable t) 1231 { 1232 throw new InvalidDataException("Invalid expression for column '" + 1233 name + "': " + mapExpression + " (" + t.getMessage() + ")"); 1234 } 1235 } 1236 else if (isJep) 1237 { 1238 try 1239 { 1240 new JepMapper(mapExpression.substring(1), new ArrayList<String>(), null); 1241 } 1242 catch (Throwable t) 1243 { 1244 throw new InvalidDataException("Invalid expression for column '" + 1245 name + "': " + mapExpression + " (" + t.getMessage() + ")"); 1212 1246 } 1213 1247 } -
trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java
r4605 r4614 425 425 426 426 ParameterValues wrapper = new ParameterValuesWrapper(request, job, configuration, forJob); 427 FlatFileParser parser = null; 427 428 if (forJob) 428 429 { 429 430 // Check that file can be parsed with given regular expressions 430 FlatFileParser ffp= getInitializedFlatFileParser(wrapper);431 parser = getInitializedFlatFileParser(wrapper); 431 432 File f = (File)request.getParameterValue("file"); 432 433 InputStream in = f.getDownloadStream(0); 433 ffp.setInputStream(in, getCharset(request));434 ffp.setDefaultNumberFormat(getNumberFormat());435 FlatFileParser.LineType result = ffp.parseHeaders();434 parser.setInputStream(in, getCharset(request)); 435 parser.setDefaultNumberFormat(getNumberFormat()); 436 FlatFileParser.LineType result = parser.parseHeaders(); 436 437 in.close(); 437 438 if (result == FlatFileParser.LineType.UNKNOWN) 438 439 { 439 440 response.setError("The file could not be parsed with the given settings, " + 440 "no data found after " + ffp.getLineCount() + " lines.", null);441 "no data found after " + parser.getLineCount() + " lines.", null); 441 442 return; 442 443 } 443 444 // Store column headers for use in the next configuration step 444 columnHeaders = ffp.getColumnHeaders();445 columnHeaders = parser.getColumnHeaders(); 445 446 } 446 447 … … 487 488 // Check the mapping expressions 488 489 boolean allowComplex = "allow".equals(request.getParameterValue(complexMappings.getName())); 489 checkColumnMapping( nameMapping, allowComplex, nameColumnMapping.getLabel());490 checkColumnMapping( externalIdMapping, allowComplex, externalIdColumnMapping.getLabel());491 checkColumnMapping( internalIdMapping, allowComplex, internalIdColumnMapping.getLabel());490 checkColumnMapping(parser, nameMapping, allowComplex, nameColumnMapping.getLabel()); 491 checkColumnMapping(parser, externalIdMapping, allowComplex, externalIdColumnMapping.getLabel()); 492 checkColumnMapping(parser, internalIdMapping, allowComplex, internalIdColumnMapping.getLabel()); 492 493 493 494 // Everything is ok, save values
Note: See TracChangeset
for help on using the changeset viewer.