Support get_input for complex data types 25/125025/5
authoraribeiro <anderson.ribeiro@est.tech>
Fri, 15 Oct 2021 12:41:39 +0000 (13:41 +0100)
committerMichael Morris <michael.morris@est.tech>
Tue, 19 Oct 2021 13:53:09 +0000 (13:53 +0000)
Issue-ID: SDC-3760
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Change-Id: I68ceaa47012186533a90f06c2688454f5dde799b

catalog-ui/src/app/ng2/pages/properties-assignment/input-list/input-list.component.html
catalog-ui/src/app/ng2/pages/properties-assignment/input-list/input-list.component.ts
catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
catalog-ui/src/app/ng2/services/data-type.service.ts

index e080463..b61d25c 100644 (file)
   <form class="w-sdc-form">
     <div class="i-sdc-form-item">
       <label class="i-sdc-form-label required">Input Value</label>
-      <select [(ngModel)]="selectInputValue" name="selectInputValue">
-        <option *ngFor="let index of inputModel"
-                [ngValue]="index">{{index.name}}</option>
-      </select>
+        <select [(ngModel)]="selectInputValue" name="selectInputValue">
+          <option *ngFor="let input of inputs"
+                  [ngValue]="input">{{input.name}}</option>
+        </select>
     </div>
   </form>
 </div>
index 64ebcaa..0bdd028 100644 (file)
  */
 
 import {Component} from '@angular/core';
-import {InputBEModel, ComponentMetadata} from 'app/models';
+import {
+    ComponentMetadata, DataTypeModel, PropertyBEModel
+} from 'app/models';
 import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
 import {WorkspaceService} from "../../workspace/workspace.service";
 import {PropertiesService} from "../../../services/properties.service";
+import {PROPERTY_DATA} from "../../../../utils/constants";
+import {DataTypeService} from "../../../services/data-type.service";
 
 @Component({
     selector: 'input-list',
@@ -32,16 +36,18 @@ import {PropertiesService} from "../../../services/properties.service";
 export class InputListComponent {
 
     selectInputValue;
-    inputModel: Array<InputBEModel> = [];
     isLoading: boolean;
     propertyType: string;
+    inputs: Array<PropertyBEModel> = [];
 
+    private dataTypeProperties: Array<PropertyBEModel> = [];
     private componentMetadata: ComponentMetadata;
 
     constructor(private topologyTemplateService: TopologyTemplateService,
                 private workspaceService: WorkspaceService,
-                private propertiesService: PropertiesService
-    ) {}
+                private propertiesService: PropertiesService,
+                private dataTypeService: DataTypeService) {
+    }
 
     ngOnInit() {
         this.componentMetadata = this.workspaceService.metadata;
@@ -53,9 +59,11 @@ export class InputListComponent {
         this.isLoading = true;
         this.topologyTemplateService.getComponentInputsValues(this.componentMetadata.componentType, this.componentMetadata.uniqueId)
         .subscribe((response) => {
-            response.inputs.forEach((input: any) => {
-                if (input.type === propertyType) {
-                    this.inputModel.push(input);
+            response.inputs.forEach((inputProperty: any) => {
+                if (propertyType === inputProperty.type) {
+                    this.inputs.push(inputProperty);
+                } else if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(inputProperty.type) === -1 && inputProperty.type !== propertyType) {
+                    this.buildInputDataForComplexType(inputProperty, propertyType);
                 }
             });
         }, () => {
@@ -64,4 +72,17 @@ export class InputListComponent {
             this.isLoading = false;
         });
     }
+
+    private buildInputDataForComplexType(inputProperty: PropertyBEModel, propertyType: string) {
+        let dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
+        if (dataTypeFound && dataTypeFound.properties) {
+            dataTypeFound.properties.forEach(dataTypeProperty => {
+                let inputData = inputProperty.name + "->" + dataTypeProperty.name;
+                dataTypeProperty.name = inputData;
+                if (this.dataTypeProperties.indexOf(dataTypeProperty) === -1 && dataTypeProperty.type === propertyType) {
+                    this.inputs.push(dataTypeProperty);
+                }
+            });
+        }
+    }
 }
index 8e483ea..09fd888 100644 (file)
@@ -527,7 +527,9 @@ export class PropertiesAssignmentComponent {
                                         propertyInputDetail.inputName = selectInputValue.name;
                                         propertyInputDetail.inputType = selectInputValue.type;
                                         property.getInputValues.push(propertyInputDetail);
-                                        property.value = '{"get_input":"' + selectInputValue.name + '"}';
+                                        property.value = selectInputValue.name.indexOf("->") !== -1
+                                            ? '{"get_input":[' + selectInputValue.name.replace("->", ", ") + ']}'
+                                            : '{"get_input":"' + selectInputValue.name+ '"}' ;
                                         property.toscaGetFunctionType = ToscaGetFunctionType.GET_INPUT;
                                         this.updateInstancePropertiesWithInput(checkedProperties, selectedInstanceData);
                                         modal.instance.close();
index 85c8b89..5b08e93 100644 (file)
@@ -39,6 +39,15 @@ export class DataTypeService {
         this.dataTypes = dataTypeService.getAllDataTypes(); //This should eventually be replaced by an NG2 call to the backend instead of utilizing Angular1 downgraded component.
     }
 
+    public getDataTypeByModelAndTypeName(modelName: string, typeName: string): DataTypeModel {
+        this.dataTypes = this.dataTypeService.getAllDataTypesFromModel(modelName);
+        let dataTypeFound = this.dataTypes[typeName];
+        if (!dataTypeFound) {
+            console.log("MISSING Datatype for model " + modelName + " and type: " + typeName);
+        }
+        return dataTypeFound;
+    }
+
     public getDataTypeByTypeName(typeName: string): DataTypeModel {
         if(!this.dataTypes){
             this.dataTypes = this.dataTypeService.getAllDataTypes();