Search in sources :

Example 1 with MongoEnumValue

use of core.framework.mongo.MongoEnumValue in project core-ng-project by neowu.

the class MongoClassValidator method validateEnumClass.

private void validateEnumClass(Class<?> enumClass, Field field) {
    Enum<?>[] constants = (Enum<?>[]) enumClass.getEnumConstants();
    Set<String> enumValues = Sets.newHashSet();
    for (Enum<?> constant : constants) {
        MongoEnumValue enumValue = Enums.constantAnnotation(constant, MongoEnumValue.class);
        if (enumValue == null) {
            throw Exceptions.error("mongo enum must have @MongoEnumValue, field={}, enum={}", Fields.path(field), Enums.path(constant));
        }
        boolean added = enumValues.add(enumValue.value());
        if (!added) {
            throw Exceptions.error("mongo enum value must be unique, enum={}, value={}", Enums.path(constant), enumValue.value());
        }
        Property property = Enums.constantAnnotation(constant, Property.class);
        if (property != null) {
            throw Exceptions.error("mongo enum must not have json annotation, please separate view and entity, field={}, enum={}", Fields.path(field), Enums.path(constant));
        }
    }
}
Also used : MongoEnumValue(core.framework.mongo.MongoEnumValue) Property(core.framework.api.json.Property)

Aggregations

Property (core.framework.api.json.Property)1 MongoEnumValue (core.framework.mongo.MongoEnumValue)1