Fixes two problems in the update of VFC map or list properties. One was
related to a schema validation in the backend.
The other is related to setting the property value when the default
value was being edited.
Change-Id: Icd85346144c8763ced1b8fbcd750c9baf783f6a6
Issue-ID: SDC-4050
Signed-off-by: andre.schmid <andre.schmid@est.tech>
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
private void evaluateListType(PropertyDefinition propertyDefinition) {
try {
private void evaluateListType(PropertyDefinition propertyDefinition) {
try {
- String schemaType = propertyDefinition.getSchemaType();
+ if (propertyDefinition.getSchemaType() == null) {
+ propertyDefinition.setSchema(createStringSchema());
+ }
List<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
List<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
- evaluateCollectionType(propertyDefinition, list, schemaType);
+ evaluateCollectionType(propertyDefinition, list);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
}
}
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
}
}
- private void evaluateMapType(PropertyDefinition propertyDefinition) {
+ private SchemaDefinition createStringSchema() {
+ final SchemaDefinition schemaDefinition = new SchemaDefinition();
+ final PropertyDefinition schemaStringProperty = new PropertyDefinition();
+ schemaStringProperty.setType(ToscaType.STRING.getType());
+ schemaDefinition.setProperty(schemaStringProperty);
+ return schemaDefinition;
+ }
+
+ private void evaluateMapType(final PropertyDefinition propertyDefinition) {
- String schemaType = propertyDefinition.getSchemaType();
- Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
- evaluateCollectionType(propertyDefinition, map.values(), schemaType);
+ if (propertyDefinition.getSchemaType() == null) {
+ propertyDefinition.setSchema(createStringSchema());
+ }
+ final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
+ evaluateCollectionType(propertyDefinition, map.values());
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
- private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Collection<Object> valueList, final String schemaType) {
+ private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Collection<Object> valueList) {
+ final String schemaType = propertyDefinition.getSchemaType();
for (final Object value : valueList) {
try {
for (final Object value : valueList) {
try {
- final PropertyDefinition propertyDefinition1 = copyPropertyWithNewValue(propertyDefinition, objectMapper.writeValueAsString(value));
+ final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition, objectMapper.writeValueAsString(value));
if (ToscaType.isPrimitiveType(schemaType)) {
if (ToscaType.isPrimitiveType(schemaType)) {
- evaluateCollectionPrimitiveSchemaType(propertyDefinition1, schemaType);
+ evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
} else if (ToscaType.isCollectionType(schemaType)) {
} else if (ToscaType.isCollectionType(schemaType)) {
- propertyDefinition1.setType(schemaType);
- propertyDefinition1.setSchemaType(propertyDefinition.getSchemaProperty().getSchemaType());
- evaluateCollectionTypeProperties(propertyDefinition1);
+ propertyCopyWithNewValue.setType(schemaType);
+ propertyCopyWithNewValue.setSchemaType(propertyDefinition.getSchemaProperty().getSchemaType());
+ evaluateCollectionTypeProperties(propertyCopyWithNewValue);
- propertyDefinition1.setType(schemaType);
+ propertyCopyWithNewValue.setType(schemaType);
completePropertyName.append(UNDERSCORE);
completePropertyName.append(UNDERSCORE);
- completePropertyName.append(propertyDefinition1.getName());
- evaluateComplexTypeProperties(propertyDefinition1);
+ completePropertyName.append(propertyCopyWithNewValue.getName());
+ evaluateComplexTypeProperties(propertyCopyWithNewValue);
}
} catch (final Exception e) {
logger.debug(e.getMessage(), e);
}
} catch (final Exception e) {
logger.debug(e.getMessage(), e);
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.exception.ResponseFormat;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.exception.ResponseFormat;
@Mock
ApplicationDataTypeCache applicationDataTypeCache;
@Mock
ApplicationDataTypeCache applicationDataTypeCache;
- @Mock
- ToscaOperationFacade toscaOperationFacade;
-
@Spy
@InjectMocks
PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil;
@Spy
@InjectMocks
PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
public enum ToscaType {
// @formatter:off
STRING("string"),
public enum ToscaType {
// @formatter:off
STRING("string"),
SCALAR_UNIT_FREQUENCY("scalar-unit.frequency");
// @formatter:on
SCALAR_UNIT_FREQUENCY("scalar-unit.frequency");
// @formatter:on
- private String type;
-
- ToscaType(String type) {
- this.type = type;
- }
+ @Getter
+ private final String type;
public static ToscaType getToscaType(String typeName) {
if (typeName == null) {
public static ToscaType getToscaType(String typeName) {
if (typeName == null) {
return ToscaPropertyType.MAP.getType().equals(type) || ToscaPropertyType.LIST.getType().equals(type);
}
return ToscaPropertyType.MAP.getType().equals(type) || ToscaPropertyType.LIST.getType().equals(type);
}
- public String getType() {
- return type;
- }
-
public boolean isValidValue(String value) {
switch (this) {
case BOOLEAN:
public boolean isValidValue(String value) {
switch (this) {
case BOOLEAN:
private initResource = ():void => {
this.$scope.editPropertyModel.property = new PropertyModel(this.property);
this.$scope.editPropertyModel.property.type = this.property.type ? this.property.type : null;
private initResource = ():void => {
this.$scope.editPropertyModel.property = new PropertyModel(this.property);
this.$scope.editPropertyModel.property.type = this.property.type ? this.property.type : null;
- this.$scope.editPropertyModel.property.value = this.$scope.editPropertyModel.property.value || this.$scope.editPropertyModel.property.defaultValue;
- this.$scope.constraints = this.property.constraints && this.property.constraints[0] ? this.property.constraints[0]["validValues"] : null;
+ this.$scope.constraints = this.property.constraints && this.property.constraints[0] ? this.property.constraints[0]["validValues"] : null;
this.initToscaGetFunction();
this.setMaxLength();
};
this.initToscaGetFunction();
this.setMaxLength();
};
}
private openEditPropertyModal = (property:PropertyModel):void => {
}
private openEditPropertyModal = (property:PropertyModel):void => {
- this.ModalsHandler.openEditPropertyModal(property, this.$scope.component, this.$scope.filteredProperties, false, 'component', this.$scope.component.uniqueId).then((updatedProperty:PropertyModel) => {
- //property = updatedProperty;
- });
+ this.ModalsHandler.openEditPropertyModal(property, this.$scope.component, this.$scope.filteredProperties, false, 'component', this.$scope.component.uniqueId);
};
private initScope = ():void => {
};
private initScope = ():void => {
this.$scope.filteredProperties = this.$scope.component.properties;
this.$scope.sortBy = 'name';
this.$scope.reverse = false;
this.$scope.filteredProperties = this.$scope.component.properties;
this.$scope.sortBy = 'name';
this.$scope.reverse = false;