Issue 10702

Use IntepretedEnum for applicable fields

10702
Reporter: kbraak
Assignee: fmendez
Type: Improvement
Summary: Use IntepretedEnum for applicable fields
Priority: Minor
Resolution: Fixed
Status: Closed
Created: 2012-01-27 11:36:00.289
Updated: 2013-12-09 13:41:00.023
Resolved: 2012-07-13 17:08:03.803
        
Description: The InterpretedEnum preserves the verbatim and the interpreted values, where the interpreted value is an enum.
Changes need refactoring of the model class, the persistence mappers.

Please create a sub task for each field to be converted to use it. ]]>
    


Author: mdoering@gbif.org
Created: 2012-01-27 11:43:01.036
Updated: 2012-01-27 11:43:01.036
        
When replacing existing enums in the data model with InterpretedEnum it might be worth considering keeping the existing
getters and delegate them to the interpretedEnum one.

There are many (untyped) usages of those getters in the free marker templates in the portal app already that would need to be updated otherwise.
    


Author: mdoering@gbif.org
Created: 2012-07-11 17:24:17.402
Updated: 2012-07-11 17:24:17.402
        
http://dev.gbif.org/wiki/display/POR/Range+of+values+to+be+used+by+the+enum+types


    


Author: fmendez@gbif.org
Created: 2012-07-12 10:03:30.523
Updated: 2012-07-12 10:03:30.523
        
There's an issue with refacto Language and Country into interpreted enums. The implementation requires a MyBatis TypeHandler for both, there's 1 specific method that can carry inconsistencies:
  @Override
  public void setParameter(PreparedStatement ps, int i, Country parameter, JdbcType jdbcType) throws SQLException {
    ps.setObject(i, parameter.getIso2LetterCode());
  }
If in a database we have the country code stored as Iso3LetterCode, the typehandler will set a wrong value for the parameter; the only way of setting this parameyer correctly is knowing if the the stored value is Iso2 or Iso3, which is not possible to determine from the type handler.
    


Author: mdoering@gbif.org
Created: 2012-07-12 10:27:36.986
Updated: 2012-07-12 10:27:36.986
        
the type handler should accept both 2 and 3 letter case insensitive iso codes when converting into the enum. As far as I can see exactly this is implemented by Country.fromIsoCode(String).

The other way around is not that important as we don't offer any write service yet.
Still I would convert the enums into 2 letter codes, both for Country and Language, by calling the respective getIso2LetterCode() method on the enum.