Search in sources :

Example 16 with ConstraintValueDoNotMatchPropertyTypeException

use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.

the class ConstraintPropertyService method checkListPropertyConstraint.

private static void checkListPropertyConstraint(String propertyName, List<Object> listPropertyValue, PropertyDefinition propertyDefinition, Consumer<String> missingPropertyConsumer) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    if (!ToscaTypes.LIST.equals(propertyDefinition.getType())) {
        throwConstraintValueDoNotMatchPropertyTypeException("The property definition should be a list but we found " + propertyDefinition.getType(), propertyName, ToscaTypes.LIST, null);
    }
    PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
    if (entrySchema == null) {
        throw new ConstraintValueDoNotMatchPropertyTypeException("value is a list but type actually is <" + propertyDefinition.getType() + ">");
    }
    checkLengthConstraints(propertyDefinition.getConstraints(), listPropertyValue);
    for (int i = 0; i < listPropertyValue.size(); i++) {
        checkPropertyConstraint(propertyName + "[" + String.valueOf(i) + "]", listPropertyValue.get(i), entrySchema, missingPropertyConsumer);
    }
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)

Example 17 with ConstraintValueDoNotMatchPropertyTypeException

use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.

the class ConstraintPropertyService method rangeTypeError.

private static void rangeTypeError(final String propertyName, final List<Object> rangeValue) throws ConstraintValueDoNotMatchPropertyTypeException {
    log.debug("The property value for property {} is not of type {}: {}", propertyName, ToscaTypes.RANGE, rangeValue);
    ConstraintInformation consInformation = new ConstraintInformation(propertyName, null, rangeValue.toString(), ToscaTypes.RANGE);
    throw new ConstraintValueDoNotMatchPropertyTypeException("Range type must define numeric min and max values of the range.", null, consInformation);
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) ConstraintInformation(alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation)

Aggregations

ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)17 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)11 Map (java.util.Map)7 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)4 Audit (alien4cloud.audit.annotation.Audit)3 NotFoundException (alien4cloud.exception.NotFoundException)3 Application (alien4cloud.model.application.Application)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 Location (alien4cloud.model.orchestrators.locations.Location)3 ConstraintInformation (alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation)3 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)3 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)3 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 ConstraintUtil (alien4cloud.tosca.properties.constraints.ConstraintUtil)2 DeploymentInputs (org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs)2 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)2 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)2 Topology (org.alien4cloud.tosca.model.templates.Topology)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2