Changeset 4614


Ignore:
Timestamp:
Oct 29, 2008, 9:58:38 AM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1159: Annotation importer should detect non-existing column mappings

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  
    11711171    throws InvalidDataException
    11721172  {
     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   
    11731196    if (mapExpression == null || mapExpression.length() == 0)
    11741197    {
     
    11971220      }
    11981221    }
    1199     else
    1200     {
    1201       if (isJep)
     1222   
     1223    if (ffp != null)
     1224    {
     1225      try
    12021226      {
    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() + ")");
    12121246      }
    12131247    }
  • trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java

    r4605 r4614  
    425425
    426426        ParameterValues wrapper = new ParameterValuesWrapper(request, job, configuration, forJob);
     427        FlatFileParser parser = null;
    427428        if (forJob)
    428429        {
    429430          // Check that file can be parsed with given regular expressions
    430           FlatFileParser ffp = getInitializedFlatFileParser(wrapper);
     431          parser = getInitializedFlatFileParser(wrapper);
    431432          File f = (File)request.getParameterValue("file");
    432433          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();
    436437          in.close();
    437438          if (result == FlatFileParser.LineType.UNKNOWN)
    438439          {
    439440            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);
    441442            return;
    442443          }
    443444          // Store column headers for use in the next configuration step
    444           columnHeaders = ffp.getColumnHeaders();
     445          columnHeaders = parser.getColumnHeaders();
    445446        }
    446447
     
    487488        // Check the mapping expressions
    488489        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());
    492493
    493494        // Everything is ok, save values
Note: See TracChangeset for help on using the changeset viewer.