Changeset 4632


Ignore:
Timestamp:
Nov 7, 2008, 2:46:52 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #792: Add support for units to annotation values

Fixes a permission problem with annotation flat file importer that doesn't try to use units, but still receieved a PermissionDeniedException?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Annotation.java

    r4548 r4632  
    403403    checkPermission(Permission.WRITE);
    404404    AnnotationType annotationType = getAnnotationType();
    405     if (unit == null) unit = annotationType.getDefaultUnit();
    406     UnitConverter converter = getUnitConverter(unit);
    407     if (converter != null && value instanceof Number)
    408     {
    409       value = converter.convertToReferenceUnit(((Number)value).doubleValue());
     405    UnitConverter converter = null;
     406    if (annotationType.supportUnits() && unit != null)
     407    {
     408      converter = getUnitConverter(unit);
     409      if (converter != null && value instanceof Number)
     410      {
     411        value = converter.convertToReferenceUnit(((Number)value).doubleValue());
     412      }
    410413    }
    411414    annotationType.validateAnnotationValue(value);
    412     if (unit != null) getData().setUnit(unit.getData());
     415    if (annotationType.supportUnits())
     416    {
     417      getData().setUnit(unit == null ? annotationType.getData().getDefaultUnit() : unit.getData());
     418    }
    413419    getData().getValues().setSingleValue(Values.getDataValue(value));
    414420  }
     
    439445    checkPermission(Permission.WRITE);
    440446    AnnotationType annotationType = getAnnotationType();
    441     if (unit == null) unit = annotationType.getDefaultUnit();
    442447    int multiplicity = annotationType.getMultiplicity();
    443448    if (multiplicity > 0 && values.size() > multiplicity)
     
    445450      throw new InvalidDataException("Too many values. Max "+multiplicity+" value(s) are allowed for this annotation type");
    446451    }
    447     UnitConverter converter = getUnitConverter(unit);
     452    UnitConverter converter = null;
     453    if (annotationType.supportUnits() && unit != null)
     454    {
     455      converter = getUnitConverter(unit);
     456    }
    448457    List<Object> convertedValues = new ArrayList<Object>(values.size());
    449458    Type valueType = getValueType();
     
    457466      convertedValues.add(value);
    458467    }
    459     if (unit != null) getData().setUnit(unit.getData());
     468    if (annotationType.supportUnits())
     469    {
     470      getData().setUnit(unit == null ? annotationType.getData().getDefaultUnit() : unit.getData());
     471    }
    460472    getData().getValues().replaceValues(Values.getDataValues(convertedValues));
    461473  }
Note: See TracChangeset for help on using the changeset viewer.