use of alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation 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);
}
use of alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation in project alien4cloud by alien4cloud.
the class ConstraintPropertyService method checkComplexPropertyDerivedFromPrimitiveTypeConstraints.
/**
* Check constraints defined on a property which has a type derived from a primitive.
*/
private static void checkComplexPropertyDerivedFromPrimitiveTypeConstraints(final String propertyName, final String stringValue, final PropertyDefinition propertyDefinition, final DataType dataType) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
ConstraintInformation consInformation = null;
boolean hasDefinitionConstraints = propertyDefinition.getConstraints() != null && !propertyDefinition.getConstraints().isEmpty();
boolean hasTypeConstraints = false;
if (dataType instanceof PrimitiveDataType && ((PrimitiveDataType) dataType).getConstraints() != null && !((PrimitiveDataType) dataType).getConstraints().isEmpty()) {
hasTypeConstraints = true;
}
String derivedFromPrimitiveType = dataType.getDerivedFrom().get(0);
// Check the type of the property even if there is no constraints.
checkBasicType(propertyName, derivedFromPrimitiveType, stringValue);
if (hasDefinitionConstraints || hasTypeConstraints) {
// check the constraints if there is any defined
if (hasDefinitionConstraints) {
checkConstraints(propertyName, stringValue, derivedFromPrimitiveType, propertyDefinition.getConstraints());
}
if (hasTypeConstraints) {
checkConstraints(propertyName, stringValue, derivedFromPrimitiveType, ((PrimitiveDataType) dataType).getConstraints());
}
}
}
use of alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation in project alien4cloud by alien4cloud.
the class RuntimeController method validateParameters.
private void validateParameters(Interface interfass, OperationExecRequest operationRequest, Set<CSARDependency> dependencies) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException, ConstraintRequiredParameterException {
try {
if (dependencies != null) {
ToscaContext.init(dependencies);
}
ArrayList<String> missingParams = Lists.newArrayList();
Operation operation = interfass.getOperations().get(operationRequest.getOperationName());
if (operation.getInputParameters() != null) {
for (Entry<String, IValue> inputParameter : operation.getInputParameters().entrySet()) {
if (inputParameter.getValue().isDefinition()) {
Object requestInputParameter = operationRequest.getParameters() == null ? null : operationRequest.getParameters().get(inputParameter.getKey());
PropertyDefinition currentOperationParameter = (PropertyDefinition) inputParameter.getValue();
if (requestInputParameter != null) {
if (!(requestInputParameter instanceof Map) || !FunctionEvaluator.containGetSecretFunction(PropertyService.asFunctionPropertyValue(requestInputParameter))) {
// recover the good property definition for the current parameter
ConstraintPropertyService.checkPropertyConstraint(inputParameter.getKey(), requestInputParameter, currentOperationParameter);
}
} else if (currentOperationParameter.isRequired()) {
// input param not in the request, id required this is a missing parameter...
missingParams.add(inputParameter.getKey());
} else {
// set the value to null
operation.getInputParameters().put(inputParameter.getKey(), null);
}
}
}
}
// check required input issue
if (!missingParams.isEmpty()) {
log.error("Missing required parameter", missingParams);
ConstraintInformation constraintInformation = new ConstraintInformation(null, null, missingParams.toString(), "required");
throw new ConstraintRequiredParameterException("Missing required parameters", null, constraintInformation);
}
} finally {
if (ToscaContext.get() != null) {
ToscaContext.destroy();
}
}
}
Aggregations