55 lines
1.6 KiB
Java
55 lines
1.6 KiB
Java
|
package eu.eudat.migration.utils;
|
||
|
|
||
|
import eu.eudat.migration.entities.Organization;
|
||
|
|
||
|
import javax.persistence.AttributeConverter;
|
||
|
import javax.persistence.Converter;
|
||
|
|
||
|
@Converter
|
||
|
public class OrganizationTypeConverter implements AttributeConverter<Organization.Type, Integer> {
|
||
|
|
||
|
@Override
|
||
|
public Integer convertToDatabaseColumn(Organization.Type type) {
|
||
|
if (type == null)
|
||
|
return null;
|
||
|
switch (type) {
|
||
|
case INSTITUTION:
|
||
|
return 1;
|
||
|
case FUNDER:
|
||
|
return 2;
|
||
|
case ORGANIZATION:
|
||
|
return 3;
|
||
|
case RESEARCH_INSTITUTE:
|
||
|
return 4;
|
||
|
case PROJECT:
|
||
|
return 5;
|
||
|
case SCHOOL:
|
||
|
return 6;
|
||
|
default:
|
||
|
throw new IllegalArgumentException(type + " not supported.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Organization.Type convertToEntityAttribute(Integer type) {
|
||
|
if (type == null)
|
||
|
return null;
|
||
|
switch (type) {
|
||
|
case 1:
|
||
|
return Organization.Type.INSTITUTION;
|
||
|
case 2:
|
||
|
return Organization.Type.FUNDER;
|
||
|
case 3:
|
||
|
return Organization.Type.ORGANIZATION;
|
||
|
case 4:
|
||
|
return Organization.Type.RESEARCH_INSTITUTE;
|
||
|
case 5:
|
||
|
return Organization.Type.PROJECT;
|
||
|
case 6:
|
||
|
return Organization.Type.SCHOOL;
|
||
|
default:
|
||
|
throw new IllegalArgumentException(type + " not supported.");
|
||
|
}
|
||
|
}
|
||
|
}
|