}
private initSelectedSourceType(): void {
- if (!this.currentRule.sourceType || this.currentRule.sourceType === SourceType.STATIC) {
+ if (!this.currentRule.sourceType || this.currentRule.sourceType === SourceType.STATIC
+ || (this.currentRule.sourceType === SourceType.SEVERAL && !ToscaFunctionHelper.convertObjectToToscaFunction(this.currentRule.value[0]))) {
this.selectedSourceType = SourceType.STATIC;
} else {
if (!this.isValidValuesOperator() && !this.isRangeType() && !this.isInRangeOperator()) {
} else if (ToscaFunctionHelper.isValueToscaFunction(this.currentRule.value)) {
newProperty.toscaFunction = ToscaFunctionHelper.convertObjectToToscaFunction(this.currentRule.value);
newProperty.value = newProperty.toscaFunction.buildValueString();
- } else if (Array.isArray(this.currentRule.value) &&
- typeof this.currentRule.value[0] === "object") {
- this.validValuesToscaFunctionList = this.currentRule.value;
- this.rangeToscaFunctionList = this.currentRule.value;
- newProperty.toscaFunction = this.currentRule.value;
+ } else if (Array.isArray(this.currentRule.value)) {
+ if (typeof this.currentRule.value[0] === 'object') {
+ this.rangeToscaFunctionList = [];
+ this.validValuesToscaFunctionList = [];
+ this.currentRule.value.forEach(val => {
+ this.rangeToscaFunctionList.push(ToscaFunctionHelper.convertObjectToToscaFunction(val));
+ this.validValuesToscaFunctionList.push(ToscaFunctionHelper.convertObjectToToscaFunction(val));
+ });
+ newProperty.toscaFunction = this.currentRule.value;
+ newProperty.value = this.currentRule.value;
+ }
+ else {
+ this.validValuesToscaFunctionList = this.currentRule.value;
+ this.rangeToscaFunctionList = this.currentRule.value;
+ newProperty.toscaFunction = this.currentRule.value;
+ }
} else {
newProperty.value = JSON.stringify(this.currentRule.value);
this.propertiesUtils.initValueObjectRef(newProperty);
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.Nullable;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction;
final Object valueYaml = operatorYaml.get(operator);
final Optional<ToscaFunction> toscaFunction = createToscaFunctionFromLegacyConstraintValue(valueYaml);
if (toscaFunction.isPresent()) {
- propertyFilterConstraint.setValue(toscaFunction.get());
- propertyFilterConstraint.setValueType(detectValueType(valueYaml));
- }
- else {
- propertyFilterConstraint.setValue(valueYaml);
if (valueYaml instanceof List) {
List<ToscaFunction> listToscaFunction = new ArrayList<>();
((List<?>) valueYaml).stream().forEach(val -> {
propertyFilterConstraint.setValueType(FilterValueType.SEVERAL);
}
else {
+ propertyFilterConstraint.setValue(toscaFunction.get());
propertyFilterConstraint.setValueType(detectValueType(valueYaml));
}
}
+ else {
+ propertyFilterConstraint.setValue(valueYaml);
+ propertyFilterConstraint.setValueType(detectValueType(valueYaml));
+ }
propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
return propertyFilterConstraint;
}
public static Optional<ToscaFunction> createToscaFunctionFromLegacyConstraintValue(final Object filterValue) {
- if (!(filterValue instanceof Map)) {
+ if (!(filterValue instanceof Map) && !(filterValue instanceof List)) {
return Optional.empty();
}
+ if (filterValue instanceof List) {
+ final Map<String, Object>[] filterValueAsMap = new Map[] {new HashMap<>()};
+ final String[] toscaFunctionType = new String[1];
+ try {
+ ((List<?>) filterValue).stream().forEach(filterArrayValue -> {
+
+ filterValueAsMap[0] = (Map<String, Object>) filterArrayValue;
+ final Set<?> keys = filterValueAsMap[0].keySet();
+ toscaFunctionType[0] = (String) keys.iterator().next();
+
+ });
+ }
+ catch (Exception ex) {
+ return Optional.empty();
+ }
+ return buildToscaFunctionBasedOnPropertyValue(filterValueAsMap[0]);
+ }
final Map<?, ?> filterValueAsMap = (Map<?, ?>) filterValue;
final Set<?> keys = filterValueAsMap.keySet();
if (keys.size() != 1) {
private static FilterValueType detectValueType(final Object value) {
if (value instanceof Map) {
final Map<?, ?> valueAsMap = (Map<?, ?>) value;
- if (valueAsMap.containsKey(ToscaFunctionType.CONCAT.getName())) {
- return FilterValueType.CONCAT;
- }
- if (valueAsMap.containsKey(ToscaFunctionType.GET_ATTRIBUTE.getName())) {
- return FilterValueType.GET_ATTRIBUTE;
- }
- if (valueAsMap.containsKey(ToscaFunctionType.GET_PROPERTY.getName())) {
- return FilterValueType.GET_PROPERTY;
- }
- if (valueAsMap.containsKey(ToscaFunctionType.GET_INPUT.getName())) {
- return FilterValueType.GET_INPUT;
- }
- if (valueAsMap.containsKey("$get_input_ext") ||
- valueAsMap.containsKey("$juel") ||
- valueAsMap.containsKey("$other")) {
- return FilterValueType.CUSTOM;
+ FilterValueType filterValueType = getFilterValueType(valueAsMap);
+ if (filterValueType != null) {
+ return filterValueType;
}
}
else if (value instanceof List) {
- final Map<?, ?> valueAsMap = (Map<?, ?>) ((List<?>) value).get(0);
- if (valueAsMap.containsKey(ToscaFunctionType.CONCAT.getName())) {
- return FilterValueType.CONCAT;
- }
- if (valueAsMap.containsKey(ToscaFunctionType.GET_ATTRIBUTE.getName())) {
- return FilterValueType.GET_ATTRIBUTE;
- }
- if (valueAsMap.containsKey(ToscaFunctionType.GET_PROPERTY.getName())) {
- return FilterValueType.GET_PROPERTY;
- }
- if (valueAsMap.containsKey(ToscaFunctionType.GET_INPUT.getName())) {
- return FilterValueType.GET_INPUT;
- }
- if (valueAsMap.containsKey("$get_input_ext") ||
- valueAsMap.containsKey("$juel") ||
- valueAsMap.containsKey("$other")) {
- return FilterValueType.CUSTOM;
+ try {
+ final Map<?, ?> valueAsMap = (Map<?, ?>) ((List<?>) value).get(0);
+ FilterValueType filterValueType = getFilterValueType(valueAsMap);
+ if (filterValueType != null) {
+ return filterValueType;
+ }
+ } catch (ClassCastException ex) {
+ return FilterValueType.SEVERAL;
}
}
return FilterValueType.STATIC;
}
+ @Nullable
+ private static FilterValueType getFilterValueType(Map<?, ?> valueAsMap) {
+ if (valueAsMap.containsKey(ToscaFunctionType.CONCAT.getName())) {
+ return FilterValueType.CONCAT;
+ }
+ if (valueAsMap.containsKey(ToscaFunctionType.GET_ATTRIBUTE.getName())) {
+ return FilterValueType.GET_ATTRIBUTE;
+ }
+ if (valueAsMap.containsKey(ToscaFunctionType.GET_PROPERTY.getName())) {
+ return FilterValueType.GET_PROPERTY;
+ }
+ if (valueAsMap.containsKey(ToscaFunctionType.GET_INPUT.getName())) {
+ return FilterValueType.GET_INPUT;
+ }
+ if (valueAsMap.containsKey("$get_input_ext") ||
+ valueAsMap.containsKey("$juel") ||
+ valueAsMap.containsKey("$other")) {
+ return FilterValueType.CUSTOM;
+ }
+ return null;
+ }
}