36 lines
997 B
Java
36 lines
997 B
Java
|
package eu.dnetlib.openaire.community.db;
|
||
|
|
||
|
import javax.persistence.AttributeConverter;
|
||
|
|
||
|
import org.apache.commons.lang3.StringUtils;
|
||
|
|
||
|
public class CommunityClaimTypeConverter implements AttributeConverter<CommunityClaimType, String> {
|
||
|
|
||
|
@Override
|
||
|
public String convertToDatabaseColumn(final CommunityClaimType attribute) {
|
||
|
if (attribute == null) {
|
||
|
return null;
|
||
|
} else if (attribute == CommunityClaimType.managersOnly) {
|
||
|
return "managers-only";
|
||
|
} else if (attribute == CommunityClaimType.membersOnly) {
|
||
|
return "members-only";
|
||
|
} else {
|
||
|
return attribute.toString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public CommunityClaimType convertToEntityAttribute(final String dbData) {
|
||
|
if (StringUtils.isBlank(dbData)) {
|
||
|
return null;
|
||
|
} else if (dbData.equalsIgnoreCase("managers-only")) {
|
||
|
return CommunityClaimType.managersOnly;
|
||
|
} else if (dbData.equalsIgnoreCase("members-only")) {
|
||
|
return CommunityClaimType.membersOnly;
|
||
|
} else {
|
||
|
return CommunityClaimType.valueOf(dbData);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|