All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gorm.tools.validation.ValidationCode.groovy Maven / Gradle / Ivy

There is a newer version: 7.3.74
Show newest version
/*
* Copyright 2021 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package gorm.tools.validation

import groovy.transform.CompileStatic

import yakworks.commons.lang.EnumUtils

/**
 * Adapts the Gorm error codes to jakarta validation codes
 */
@CompileStatic
enum ValidationCode {

    CreditCardNumber,
    Email,
    NotBlank,
    Range,
    InList,
    URL,
    Pattern,
    Size,
    Min,
    Max,
    MaxLength,
    MinLength,
    Scale,
    NotEqual,
    NotNull

    //case insensitive find
    static ValidationCode get(Object key){
        if(!key) return null
        return EnumUtils.getEnum(ValidationCode, key.toString().toLowerCase())
    }

    String getJakartaCode(){
        Map messagesMap = JakartaValidationCodeAdaptor.messagesMap
        return messagesMap[this] ? messagesMap[this]['code'] : null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy