2023-06-14 11:17:38 +02:00
|
|
|
package eu.dnetlib.openaire.community.db.enums;
|
2023-06-14 11:14:24 +02:00
|
|
|
|
|
|
|
import javax.persistence.AttributeConverter;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
public class CommunityMembershipTypeConverter implements AttributeConverter<CommunityMembershipType, String> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String convertToDatabaseColumn(final CommunityMembershipType attribute) {
|
|
|
|
if (attribute == null) {
|
|
|
|
return null;
|
|
|
|
} else if (attribute == CommunityMembershipType.byInvitation) {
|
|
|
|
return "by-invitation";
|
|
|
|
} else {
|
|
|
|
return attribute.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CommunityMembershipType convertToEntityAttribute(final String dbData) {
|
|
|
|
if (StringUtils.isBlank(dbData)) {
|
|
|
|
return null;
|
|
|
|
} else if (dbData.equalsIgnoreCase("by-invitation")) {
|
|
|
|
return CommunityMembershipType.byInvitation;
|
|
|
|
} else {
|
|
|
|
return CommunityMembershipType.valueOf(dbData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|