Support property of type List<Map<String,String>> 15/127515/3
authorMichaelMorris <michael.morris@est.tech>
Mon, 7 Mar 2022 12:44:23 +0000 (12:44 +0000)
committerAndr� Schmid <andre.schmid@est.tech>
Tue, 8 Mar 2022 10:35:28 +0000 (10:35 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3898
Change-Id: Ifc9ea422e0eafcf84b5b7e47a9108f62925e2ea0

catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/validators/ListValidator.java
catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts
catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html
catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts

index a069e25..20d927f 100644 (file)
@@ -69,6 +69,9 @@ public class ListValidator implements PropertyTypeValidator {
                 case JSON:
                     innerValidator = ToscaPropertyType.JSON.getValidator();
                     break;
+                case MAP:
+                       innerValidator = ToscaPropertyType.MAP.getValidator();
+                       break;
                 default:
                     log.debug("inner Tosca Type is unknown. {}", innerToscaType);
                     return false;
@@ -88,7 +91,7 @@ public class ListValidator implements PropertyTypeValidator {
             for (int i = 0; i < size; i++) {
                 JsonElement currentValue = jo.get(i);
                 String element = JsonUtils.toString(currentValue);
-                if (!innerValidator.isValid(element, null, allDataTypes)) {
+                if (!innerValidator.isValid(element, innerToscaType.equals(ToscaPropertyType.MAP)? ToscaPropertyType.STRING.getType(): null, allDataTypes)) {
                     log.debug("validation of element : {} failed", element);
                     return false;
                 }
index ac05f19..2d406e2 100644 (file)
@@ -41,6 +41,7 @@ export class DerivedFEProperty extends PropertyBEModel {
     canBeDeclared: boolean;
     mapKey: string;
     mapKeyError: string;
+    mapInlist: boolean
 
     constructor(property: PropertyBEModel, parentName?: string, createChildOfListOrMap?: boolean, key?:string, value?:any) {
         if (!createChildOfListOrMap) { //creating a standard derived prop
@@ -60,6 +61,11 @@ export class DerivedFEProperty extends PropertyBEModel {
                 this.mapKey = property.schema.property.type.split('.').pop();
                 this.mapKeyError = null;
                 this.type = property.schema.property.type;
+                if (this.type == PROPERTY_TYPES.MAP){
+                    this.mapInlist = true;
+                }
+
+                this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
             } else { //map
                 if (key) {
                     this.mapKey = key;
@@ -69,9 +75,19 @@ export class DerivedFEProperty extends PropertyBEModel {
                     this.mapKeyError = 'Key cannot be empty.';
                 }
                 this.type = property.type;
+                if (property.schema.property.type == PROPERTY_TYPES.MAP){
+                    const schProp = new SchemaProperty();
+                    schProp.isSimpleType = true;
+                    schProp.isDataType = false;
+                    schProp.simpleType = PROPERTY_TYPES.STRING;
+                    this.schema = new SchemaPropertyGroupModel(schProp);
+                    this.schemaType = PROPERTY_TYPES.STRING;
+                } else {
+                    this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
+                }
+       
             }
             this.valueObj = (this.type == PROPERTY_TYPES.JSON && typeof value == 'object') ? JSON.stringify(value) : value;
-            this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
             this.updateValueObjOrig();
         }
         // this.constraints = property ? property.constraints : null;
@@ -97,6 +113,7 @@ export class DerivedFEProperty extends PropertyBEModel {
     public hasValueObjChanged() {
         return !_.isEqual(this.valueObj, this.valueObjOrig);
     }
+
 }
 export class DerivedFEPropertyMap {
     [parentPath: string]: Array<DerivedFEProperty>;
index 3b8c2d1..d4b4540 100644 (file)
@@ -157,7 +157,7 @@ export class PropertyFEModel extends PropertyBEModel {
                     _.set(this.valueObj, childPropName, null);
                 }
             } else {
-                _.set(this.valueObj, childPropName, childProp.valueObj);
+                _.set(this.valueObj, childPropName, childProp.valueObj);        
             }
             if (childProp.valueObjIsChanged) {
                 _.set(this.valueObjValidation, childPropName, childProp.valueObjIsValid);
@@ -175,7 +175,6 @@ export class PropertyFEModel extends PropertyBEModel {
         if (!childProp.isChildOfListOrMap || childProp.derivedDataType !== DerivedPropertyType.MAP) {
             return;
         }
-
         const childParentNames = this.getParentNamesArray(childProp.parentName);
         const oldActualMapKey = childProp.getActualMapKey();
 
@@ -240,7 +239,7 @@ export class PropertyFEModel extends PropertyBEModel {
         let nameToInsert: string = parentProp.name;
 
         if (parentProp.isChildOfListOrMap) {
-            if (!noHashKeys && parentProp.derivedDataType == DerivedPropertyType.MAP) {
+            if (!noHashKeys && parentProp.derivedDataType == DerivedPropertyType.MAP && !parentProp.mapInlist) {
                 nameToInsert = parentProp.getActualMapKey();
             } else { //LIST
                 let siblingProps = this.flattenedChildren.filter(prop => prop.parentName == parentProp.parentName).map(prop => prop.propertiesName);
index 78c3030..81f0d53 100644 (file)
@@ -27,7 +27,7 @@
         <div class="table-cell" *ngIf="!canBeDeclared && !property.isChildOfListOrMap">
             <div class="inner-cell-div" tooltip="{{property.name}}"><span>{{property.name}}</span></div>
         </div> <!-- simple children of complex type within map or list -->
-        <div class="table-cell map-entry" *ngIf="property.isChildOfListOrMap && propType == derivedPropertyTypes.MAP"><!-- map left cell -->
+        <div class="table-cell map-entry" *ngIf="property.isChildOfListOrMap && propType == derivedPropertyTypes.MAP && !property.mapInlist"><!-- map left cell -->
             <dynamic-element #mapKeyInput
                 class="value-input"
                 pattern="validationUtils.getValidationPattern(string)"
@@ -66,7 +66,8 @@
     </ng-container>
     <!-- ICONS: add, delete, and expand -->
     <ng-container *ngIf="!property.isDeclared && !property.isToscaGetFunction()">
-            <a *ngIf="(propType == derivedPropertyTypes.LIST || propType == derivedPropertyTypes.MAP) && !property.isChildOfListOrMap" class="property-icon add-item" (click)="createNewChildProperty();" [ngClass]="{'disabled':readonly || preventInsertItem(property)}" [attr.data-tests-id]="'add-to-list-' + propertyTestsId">Add value to list</a>
+            <a *ngIf="(propType == derivedPropertyTypes.LIST) && (!property.isChildOfListOrMap || property.mapInlist)" class="property-icon add-item" (click)="createNewChildProperty();" [ngClass]="{'disabled':readonly || preventInsertItem(property)}" [attr.data-tests-id]="'add-to-list-' + propertyTestsId">Add value to list</a>
+            <a *ngIf="(propType == derivedPropertyTypes.MAP) && (!property.isChildOfListOrMap || property.mapInlist)" class="property-icon add-item" (click)="createNewChildProperty();" [ngClass]="{'disabled':readonly || preventInsertItem(property)}" [attr.data-tests-id]="'add-to-list-' + propertyTestsId">Add value to map</a>
             <span *ngIf="property.isChildOfListOrMap" (click)="deleteItem.emit(property);" class="property-icon sprite-new delete-item-icon" [ngClass]="{'disabled':readonly}" [attr.data-tests-id]="'delete-from-list-' + propertyTestsId"></span>
             <span *ngIf="!isPropertyFEModel && (propType == derivedPropertyTypes.COMPLEX || ((propType == derivedPropertyTypes.LIST || propType == derivedPropertyTypes.MAP) && hasChildren))" (click)="expandChildById(propPath)" class="property-icon sprite-new round-expand-icon" [class.open]="expandedChildId.indexOf(propPath) == 0" [attr.data-tests-id]="'expand-' + propertyTestsId" ></span>
     </ng-container>
index 34d2a53..02dbf91 100644 (file)
@@ -129,7 +129,14 @@ export class PropertiesUtils {
             if (property.derivedDataType == DerivedPropertyType.LIST || property.derivedDataType == DerivedPropertyType.MAP) {
                 property.flattenedChildren = [];
                 Object.keys(property.valueObj).forEach((key) => {
-                    property.flattenedChildren.push(...this.createListOrMapChildren(property, key, property.valueObj[key]))
+                    property.flattenedChildren.push(...this.createListOrMapChildren(property, key, property.valueObj[key]));
+                    const lastCreatedChild = property.flattenedChildren.slice(-1)[0];
+                    if (property.schemaType == PROPERTY_TYPES.MAP && property.valueObj[key]){
+                        const nestedValue:object = property.valueObj[key];
+                        Object.keys(nestedValue).forEach((keyNested) => {
+                            property.flattenedChildren.push(...this.createListOrMapChildren(lastCreatedChild, keyNested, nestedValue[keyNested]));
+                        });
+                    };
                 });
             } else if (property.derivedDataType === DerivedPropertyType.COMPLEX) {
                 property.flattenedChildren = this.createFlattenedChildren(property.type, property.name);