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()));
}
.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;
}
private Object getJsonPrimitive(JsonPrimitive je) {
- if (je.isBoolean())
+ if (je.isBoolean()) {
return je.getAsBoolean();
- if (je.isString())
+ }
+ if (je.isString()) {
return je.getAsString();
- if (je.isNumber()){
+ }
+ if (je.isNumber()) {
double number = je.getAsNumber().floatValue();
if ((number % 1) == 0) {
return je.getAsNumber().intValue();
propertyConstraint = deserializeConstraintWithIntegerOperand(value, MaxLengthConstraint.class);
break;
case PATTERN:
- propertyConstraint = deserializeConstraintWithStringOperand(value, PatternConstraint.class);
+ propertyConstraint = deserializeConstraintWithStringPatternOperand(value, PatternConstraint.class);
break;
default:
log.warn("Key {} is not supported. Ignored.", field.getKey());
}
}
+ private PropertyConstraint deserializeConstraintWithStringPatternOperand(JsonNode value,
+ Class<? extends PropertyConstraint> constraintClass) {
+ String asString = value.asText();
+ log.debug("Before adding value to {} object. value = {}", constraintClass, asString);
+ try {
+ return constraintClass.getConstructor(String.class).newInstance(asString);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+ | SecurityException exception) {
+ log.error("Error deserializing constraint", exception);
+ return null;
+ }
+ }
+
private PropertyConstraint deserializeConstraintWithIntegerOperand(JsonNode value, Class<? extends PropertyConstraint> constraintClass) {
Integer asInt = value.asInt();
log.debug("Before adding value to {} object. value = {}", constraintClass, asInt);
@Override
public ConstraintType getConstraintType() {
- return null;
+ return ConstraintType.EQUAL;
}
@Override
@Override
public ConstraintType getConstraintType() {
- return null;
+ return ConstraintType.LENGTH;
}
@Override
@Override
public ConstraintType getConstraintType() {
- return null;
+ return ConstraintType.MAX_LENGTH;
}
@Override
import java.util.regex.Pattern;
import javax.validation.constraints.NotNull;
+import lombok.Getter;
import lombok.NoArgsConstructor;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
-import lombok.Getter;
@NoArgsConstructor
public class PatternConstraint extends AbstractStringPropertyConstraint {
@Override
public ConstraintType getConstraintType() {
- return null;
+ return ConstraintType.PATTERN;
}
@Override
public void validateValueOnUpdate(PropertyConstraint newConstraint) throws PropertyConstraintException {
+ // no need for implementation
}
@Override