Changeset 5201


Ignore:
Timestamp:
Dec 16, 2009, 10:33:25 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1447: Annotation importer should have "crop" option for the "Too many values" error handling option

Location:
branches/2.14-stable/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.14-stable/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java

    r4835 r5201  
    312312    "If no value is specified the default error handling is used.\n\n"+
    313313    "skip = Skip the current annotation and continue\n"+
     314    "crop = Use as many values as the annotation type allows and discard the rest\n" +
    314315    "fail = Stop with an error message",
    315     new StringParameterType(255, null, false, 1, 0, 0,
    316         Arrays.asList( new String[] { "skip", "fail"} ))
     316    new StringParameterType(255, "crop", false, 1, 0, 0,
     317        Arrays.asList( new String[] { "skip", "crop", "fail"} ))
    317318    ); 
    318319
     
    617618  private boolean failIfMultipleFoundItems;
    618619  private boolean failIfTooManyValues;
     620  private boolean cropTooManyValues;
    619621 
    620622  // Messaging
     
    680682    this.cropStrings = "crop".equals(job.getValue("stringTooLongError"));
    681683    this.failIfTooManyValues = "fail".equals(getErrorOption("tooManyValuesError"));
     684    this.cropTooManyValues = "crop".equals(job.getValue("tooManyValuesError"));
    682685   
    683686    ErrorHandler defaultErrorHandler = new SimpleErrorHandler("skip".equals(job.getValue("defaultError")));
     
    855858          {
    856859            // Add annotation value to the cache
    857             item.addValue(at, annotationValue, unit);
     860            item.addValue(at, annotationValue, unit, cropTooManyValues);
    858861          }
    859862        }
     
    12701273      error before calling this method.
    12711274    */
    1272     void addValue(AnnotationType at, Object value, Unit unit)
     1275    void addValue(AnnotationType at, Object value, Unit unit, boolean limitToMultiplicty)
    12731276    {
    12741277      List<AnnotationValue> listOfValues = values.get(at);
     
    12771280        listOfValues = new LinkedList<AnnotationValue>();
    12781281        values.put(at, listOfValues);
     1282      }
     1283      // If "Too many values"=crop we check how many is allowed by the annotation type
     1284      // and don't allow the list to grow larger
     1285      if (limitToMultiplicty)
     1286      {
     1287        int multiplicity = at.getMultiplicity();
     1288        if (multiplicity > 0 && listOfValues.size() >= multiplicity) value = null;
    12791289      }
    12801290      if (value != null)
  • branches/2.14-stable/src/test/TestAnnotationFlatFileImporter.java

    r4822 r5201  
    8989    // Test: list the result
    9090    TestAnnotation.test_list_annotations(Item.SAMPLE, sample1, 4);
    91     TestAnnotation.test_list_annotations(Item.SAMPLE, sample2, 2);
     91    TestAnnotation.test_list_annotations(Item.SAMPLE, sample2, 3);
    9292    TestAnnotation.test_list_annotations(Item.SAMPLE, sample3, 2);
    9393    TestAnnotation.test_list_annotations(Item.SAMPLE, sample4, 2);
    9494    TestAnnotation.test_list_annotations(Item.SAMPLE, sampleDup1, 4);
    9595    TestAnnotation.test_list_annotations(Item.SAMPLE, sampleDup2, 4);
     96    ok &= TestAnnotation.ok;
    9697   
    9798    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
     
    168169      request.setParameterValue("numberOutOfRangeError", "skip");
    169170      request.setParameterValue("invalidEnumError", "skip");
    170       request.setParameterValue("tooManyValuesError", "skip");
     171      request.setParameterValue("tooManyValuesError", "crop");
    171172      request.setParameterValue("multipleItemsFoundError", "all");
    172173      response = request.invoke();
  • branches/2.14-stable/src/test/data/test.annotation.import.txt

    r4822 r5201  
    55Sample #2 24  xx  BETA  Bad Not so bad
    66# Test: multiple annotations on separate lines; long string that should be cropped
     7#       'Too many values = crop' option should keep the 24 from previous line
    78Sample #2 18      Yet another comment And one more which is too long and will be cropped
    89# Test: number out of range: -12; float conversion to int; invalid enum: Gamm
Note: See TracChangeset for help on using the changeset viewer.