if (props != null) {
Map<String, ToscaProperty> properties = new HashMap<>();
// take only the properties of this resource
- props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property -> {
- properties.put(property.getName(), convertProperty(dataTypes, property, PropertyType.PROPERTY));
- });
+ props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property ->
+ properties.put(property.getName(), convertProperty(dataTypes, property, PropertyType.PROPERTY))
+ );
if (!properties.isEmpty()) {
toscaNodeType.setProperties(properties);
}
prop.setStatus(property.getStatus());
}
prop.setMetadata(property.getMetadata());
-
- List<ToscaPropertyConstraint> constraints = new ArrayList<>();
+
if (CollectionUtils.isNotEmpty(property.getConstraints())) {
- constraints = convertConstraints(property.getConstraints());
- prop.setConstraints(constraints);
+ prop.setConstraints(convertConstraints(property.getConstraints()));
}
return prop;
}
-
+
private List<ToscaPropertyConstraint> convertConstraints(List<PropertyConstraint> constraints) {
List<ToscaPropertyConstraint> convertedConstraints = new ArrayList<>();
- for (PropertyConstraint constraint: constraints){
+ for (PropertyConstraint constraint : constraints) {
if (constraint instanceof EqualConstraint) {
convertedConstraints.add(new ToscaPropertyConstraintEqual(((EqualConstraint) constraint).getEqual()));
}
}
if (constraint instanceof InRangeConstraint) {
InRangeConstraint inRangeConstraint = (InRangeConstraint) constraint;
- List<String> range = new ArrayList<>();
+ List<Object> range = new ArrayList<>();
range.add(inRangeConstraint.getRangeMinValue());
range.add(inRangeConstraint.getRangeMaxValue());
convertedConstraints.add(new ToscaPropertyConstraintInRange(range));
}
if (constraint instanceof ValidValuesConstraint) {
- convertedConstraints.add(new ToscaPropertyConstraintValidValues(((ValidValuesConstraint) constraint).getValidValues()));
+ List validValues = ((ValidValuesConstraint) constraint).getValidValues();
+ convertedConstraints.add(new ToscaPropertyConstraintValidValues(validValues));
}
if (constraint instanceof LengthConstraint) {
- convertedConstraints.add(new ToscaPropertyConstraintLength(((LengthConstraint) constraint).getLength().toString()));
+ convertedConstraints.add(new ToscaPropertyConstraintLength(((LengthConstraint) constraint).getLength()));
}
if (constraint instanceof MinLengthConstraint) {
convertedConstraints.add(new ToscaPropertyConstraintMinLength(((MinLengthConstraint) constraint).getMinLength()));
.convertDataTypeToToscaObject(innerType, dataTypes, innerConverter, isScalar, jsonElement, preserveEmptyValue);
}
return convertedValue;
-
+
} catch (JsonParseException e) {
log.trace("{} not parsable as JSON. Convert as YAML instead", value);
- return new Yaml().load(value);
+ return new Yaml().load(value);
} catch (Exception e) {
log.debug("convertToToscaValue failed to parse json value :", e);
return null;