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

templates.Validator.xpt Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
?IMPORT dom?
?IMPORT core?
?IMPORT guidesign?
?IMPORT flex?
?EXTENSION extensions::EntityExtension?
?EXTENSION extensions::Names?
?EXTENSION extensions::JavaUtil?
?EXTENSION extensions::File?
?EXTENSION extensions::SimpleTypeExtension?
?EXTENSION extensions::Validation?
?EXTENSION org::openxma::dsl::common::extensions::LogUtil?

?DEFINE main FOR Model?
    ?EXPAND genValidatorClass FOREACH eAllContents.typeSelect(Entity)?
    ?EXPAND manValidatorClass FOREACH eAllContents.typeSelect(Entity)?
?ENDDEFINE?

?DEFINE genValidatorClass FOR Entity?
?info("Write "+getGenValidatorClassFileName())?
?FILE getGenValidatorClassFileName()-?
package ?getValidatorPackageName()?;

import org.springframework.validation.Errors;
?addImports()-?

@SuppressWarnings("boxing")
public abstract class ?getGenValidatorClassName()? extends ?IF superType!=null??registerImport(superType.getValidatorPackageName() + "." + superType.getValidatorClassName())??ELSE??registerImport("org.openxma.dsl.platform.validation.Validators")??ENDIF? {
    ?LET getRequiredApplicationContext() AS applicationContext-?
    ?IF applicationContext!=null-?
    private ?applicationContext.getQualifiedInterfaceName()? context;
    
    public ?applicationContext.getQualifiedInterfaceName()? getContext() {
        return context;
    }
    
    public void setContext(?applicationContext.getQualifiedInterfaceName()? context) {
        this.context = context;
    }
    ?ENDIF-?
    ?ENDLET-?
    ?EXPAND function(this) FOREACH eAllContents.typeSelect(ReferenceableByXmadslVariable).sortBy(e|e.metaType.getProperty("name").get(e))-?
    ?FOREACH attributes.select(e|!e.attributProperties.typeSelect(RequiredFlag).isEmpty) AS attribute?
    public boolean is?attribute.name.toFirstUpper()?Required(?name? ?name.toVariableName()?) {
        return ?EXPAND Expression::expression FOR attribute.attributProperties.typeSelect(RequiredFlag).first().expression?;
    }
    ?ENDFOREACH-?
    ?FOREACH attributes.select(e|!e.attributProperties.typeSelect(AttributeValidationProperty).constraints.isEmpty) AS attribute?
    ?FOREACH attribute.attributProperties.typeSelect(AttributeValidationProperty).constraints AS constraint ITERATOR iter-?
    public boolean is?attribute.name.toFirstUpper()?Constraint?iter.counter1?Enabled(?name? ?name.toVariableName()?) {
        return ?IF constraint.condition!=null??EXPAND Expression::expression FOR constraint.condition??ELSE?Boolean.TRUE?ENDIF?;
    }
    ?ENDFOREACH-?
    ?ENDFOREACH-?
        
    @SuppressWarnings("unchecked")
    public boolean supports(Class clazz) {
        return ?registerImport(getQualifiedInterfaceName())?.class.isAssignableFrom(clazz);
    }
    
    public Errors validate(?name? ?name.toVariableName()?) {
        Errors errors = createErrors(?name.toVariableName()?);      
        ?IF superType!=null-?
        super.validate(?name.toVariableName()?,errors);
        ?ENDIF-?
        validate(?name.toVariableName()?,errors);
        return errors;
    }

    public void validate(Object object, Errors errors) {
        ?name? ?name.toVariableName()? = (?name?) object;
        ?FOREACH attributes.select(e|!e.attributProperties.typeSelect(RequiredFlag).isEmpty) AS attribute-?
        if (is?attribute.name.toFirstUpper()?Required(?name.toVariableName()?)) {
            ?registerImport("org.springframework.validation.ValidationUtils")?.rejectIfEmpty?IF attribute.type.hasStringValidator()?OrWhitespace?ENDIF?(errors, "?attribute.name.toFirstLower()?", "field.required");
        }
        ?ENDFOREACH-?
        ?FOREACH attributes AS attribute-?
        ?IF attribute.type.hasStringValidator()-?
        ?LET ((StringValidator)attribute.type.getValidatorReferenceDefinition().createXMAValidator(attribute.type.getDefinitionStack())) AS validator-?
        ?IF validator.cntMinLength!=null-?
        rejectIfMinLength(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntMinLength?);
        ?ENDIF-?
        ?IF validator.cntMaxLength!=null-?
        rejectIfMaxLength(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntMaxLength?);
        ?ENDIF-?
        ?ENDLET-?
        ?ELSEIF attribute.type.hasNumberValidator()-?
        ?LET ((BcdValidator)attribute.type.getValidatorReferenceDefinition().createXMAValidator(attribute.type.getDefinitionStack())) AS validator-?
        ?IF validator.cntBeforeComma!=null && (attribute.type.getTypeForName("Integer")==null || validator.cntBeforeComma.asInteger()!=10) && (attribute.type.getTypeForName("Long")==null || validator.cntBeforeComma.asInteger()!=19)-?
        rejectIfMaxIntegerDigits(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntBeforeComma?);
        ?ENDIF-?
        ?IF validator.cntAfterComma!=null && attribute.type.getTypeForName("Integer")==null && attribute.type.getTypeForName("Long")==null-?
        rejectIfMaxFractionDigits(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntAfterComma?);
        ?ENDIF-?
        ?ENDLET-?
        ?ENDIF-?
        ?ENDFOREACH-?
        ?FOREACH attributes.select(e|!e.attributProperties.typeSelect(AttributeValidationProperty).constraints.isEmpty) AS attribute-?
        ?FOREACH attribute.attributProperties.typeSelect(AttributeValidationProperty).constraints AS constraint ITERATOR iter-?
        ?IF constraint.validatorReference.isStringValidator()-?
        ?LET ((StringValidator)constraint.validatorReference.createXMAValidator()) AS validator-?
        if (is?attribute.name.toFirstUpper()?Constraint?iter.counter1?Enabled(?name.toVariableName()?)) {
            ?IF validator.cntMinLength!=null-?
            rejectIfMinLength(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntMinLength?);
            ?ENDIF-?
            ?IF validator.cntMaxLength!=null-?
            rejectIfMaxLength(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntMaxLength?);
            ?ENDIF-?
            ?IF validator.txtFormatrange!=null-?
            rejectIfInvalidFormat(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),"?validator.txtFormatrange?");
            ?ENDIF-?
        }
        ?ENDLET-?
        ?ELSEIF constraint.validatorReference.isNumberValidator()-?
        ?LET ((BcdValidator)constraint.validatorReference.createXMAValidator()) AS validator-?
        if (is?attribute.name.toFirstUpper()?Constraint?iter.counter1?Enabled(?name.toVariableName()?)) {
            ?IF validator.qntMinVal!=null-?
            rejectIfMinValue(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.qntMinVal?);
            ?ENDIF-?
            ?IF validator.qntMaxVal!=null-?
            rejectIfMaxValue(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.qntMaxVal?);
            ?ENDIF-?
            ?IF validator.cntBeforeComma!=null && (attribute.type.getTypeForName("Integer")==null || validator.cntBeforeComma.asInteger()!=10) && (attribute.type.getTypeForName("Long")==null || validator.cntBeforeComma.asInteger()!=19)-?
            rejectIfMaxIntegerDigits(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntBeforeComma?);
            ?ENDIF-?
            ?IF validator.cntAfterComma!=null && attribute.type.getTypeForName("Integer")==null && attribute.type.getTypeForName("Long")==null-?
            rejectIfMaxFractionDigits(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),?validator.cntAfterComma?);
            ?ENDIF-?
        }
        ?ENDLET-?
        ?ELSEIF constraint.validatorReference.isCustomValidator()-?
        ?LET ((CustomValidator)constraint.validatorReference.createXMAValidator()) AS validator-?
        if (is?attribute.name.toFirstUpper()?Constraint?iter.counter1?Enabled(?name.toVariableName()?)) {
            ?IF validator.txtFormatingString!=null-?
            rejectIfInvalidFormat(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),"?validator.txtFormatingString?");
            ?ENDIF-?
        }
        ?ENDLET-?
        ?ELSEIF constraint.validatorReference.isUserDefinedValidator()-?
        ?LET ((UserDefinedValidator)constraint.validatorReference.createXMAValidator()) AS validator-?
        if (is?attribute.name.toFirstUpper()?Constraint?iter.counter1?Enabled(?name.toVariableName()?)) {
            ?IF validator.namClass!=null-?
            rejectIfInvalidFormat(errors,"?attribute.name?",?name.toVariableName()?.?attribute.getAccessorMethodName()?(),new ?validator.namClass.replaceAll("\\^", "")?("?validator.txtParameterString?"));
            ?ENDIF-?
        }
        ?ENDLET-?
        ?ENDIF-?
        ?ENDFOREACH-?
        ?ENDFOREACH-? 
    }
    
}
?ENDFILE?
?ENDDEFINE?

?DEFINE manValidatorClass FOR Entity?
?info("Write "+getValidatorClassFileName())?
?FILE getValidatorClassFileName() OUTLET_JAVA-?
package ?getValidatorPackageName()?;

import org.springframework.validation.Errors;

public class ?getValidatorClassName()? extends ?getGenValidatorClassName()? {
    @Override
    public void validate(Object object, Errors errors) {
        super.validate(object, errors);
        // validate additional constraints
    }
}
?ENDFILE?
?ENDDEFINE?

?DEFINE function(Entity entity) FOR ReferenceableByXmadslVariable??ENDDEFINE?
?DEFINE function(Entity entity) FOR StatusFlag?
    public boolean ?name.toFirstUpper()?(?entity.getFullyQualifiedName(false)? ?entity.name.toVariableName()?) {
        return ?EXPAND Expression::expression FOR expression?;
    }
?ENDDEFINE?
?DEFINE function(Entity entity) FOR Property?
    public boolean ?name.toFirstUpper()?(?entity.getFullyQualifiedName(false)? ?entity.name.toVariableName()?) {
        return false;
    }
?ENDDEFINE?




© 2015 - 2024 Weber Informatics LLC | Privacy Policy