use of org.alien4cloud.tosca.normative.types.ScalarType in project alien4cloud by alien4cloud.
the class PropertyValueService method getValueInUnit.
public static String getValueInUnit(String propertyValue, String unit, boolean ceil, String toscaType) {
IPropertyType type = ToscaTypes.fromYamlTypeName(toscaType);
if (type instanceof ScalarType) {
try {
ScalarUnit scalarUnit = ((ScalarType) type).parse(propertyValue);
double convertedValue = scalarUnit.convert(unit);
if (ceil) {
convertedValue = Math.ceil(convertedValue);
}
return format(convertedValue);
} catch (InvalidPropertyValueException e) {
log.error("e");
throw new InvalidArgumentException(e.getMessage());
}
}
throw new InvalidArgumentException("Type is not a scalar type");
}
Aggregations