Fix datatype in model not found 35/133035/2
authorMichaelMorris <michael.morris@est.tech>
Wed, 25 Jan 2023 16:29:38 +0000 (16:29 +0000)
committerMichael Morris <michael.morris@est.tech>
Thu, 26 Jan 2023 18:36:57 +0000 (18:36 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-4348
Change-Id: I648ffd91d719982e55d5ddc786a471f641ece088

catalog-ui/src/app/directives/property-types/data-type-fields-structure/data-type-fields-structure.ts
catalog-ui/src/app/directives/property-types/type-list/type-list-directive.html
catalog-ui/src/app/directives/property-types/type-list/type-list-directive.ts
catalog-ui/src/app/directives/property-types/type-map/type-map-directive.html
catalog-ui/src/app/directives/property-types/type-map/type-map-directive.ts
catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/add-property/add-property.component.ts
catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts
catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html

index ff23445..cb16ffa 100644 (file)
@@ -70,9 +70,8 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
         fieldsPrefixName: '=',
         readOnly: '=',
         defaultValue: '@',
-        //     types: '=',
-        expandByDefault: '='
-        
+        types: '=',
+        expandByDefault: '='        
     };
 
     restrict = 'E';
@@ -102,7 +101,7 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
 
     private initDataOnScope = (scope:any, $attr:any):void => {
         scope.dataTypesService = this.DataTypesService;
-        scope.dataTypeProperties = this.DataTypesService.getFirsLevelOfDataTypeProperties(scope.typeName);
+        scope.dataTypeProperties = this.getDataTypeProperties(scope.typeName, scope.types);
         if ($attr.defaultValue) {
             scope.currentTypeDefaultValue = JSON.parse($attr.defaultValue);
         } else {
@@ -123,6 +122,14 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
             }
         });
     };
+    
+    private getDataTypeProperties = (dataTypeName:string, typesInModel:DataTypesMap):Array<DataTypePropertyModel> => {
+        let properties = typesInModel[dataTypeName].properties || [];
+        if (typesInModel[dataTypeName].derivedFromName != "tosca.datatypes.Root") {
+            properties = this.getDataTypeProperties(typesInModel[dataTypeName].derivedFromName, typesInModel).concat(properties);
+        }
+        return properties;
+    };
 
     private rerender = (scope:any):void => {
         scope.expanded = false;
index 842b890..e92e8b1 100644 (file)
@@ -22,6 +22,7 @@
                             type-name="schemaProperty.type"
                             parent-form-obj="parentFormObj"
                             fields-prefix-name="fieldsPrefixName+''+$index"
+                            types="types"
                             read-only="readOnly"></fields-structure>
         </div>
         <div data-ng-if="!isSchemaTypeDataType">
index fe50941..23add53 100644 (file)
@@ -22,8 +22,8 @@
  * Created by rcohen on 9/15/2016.
  */
 'use strict';
-import {SchemaProperty, PropertyModel} from "app/models";
-import {ValidationUtils, PROPERTY_TYPES} from "app/utils";
+import {SchemaProperty, PropertyModel, DataTypesMap} from "app/models";
+import {ValidationUtils, PROPERTY_TYPES, PROPERTY_DATA} from "app/utils";
 import {DataTypesService} from "app/services";
 import {InstanceFeDetails} from "app/models/instance-fe-details";
 import {ToscaGetFunction} from "app/models/tosca-get-function";
@@ -45,6 +45,7 @@ export interface ITypeListScope extends ng.IScope {
     stringSchema: SchemaProperty;
     showToscaFunction: Array<boolean>;
     constraints:string[];
+    types:DataTypesMap;
 
     getValidationPattern(type:string):RegExp;
     validateIntRange(value:string):boolean;
@@ -81,7 +82,8 @@ export class TypeListDirective implements ng.IDirective {
         readOnly: '=',//is form read only
         defaultValue: '@',//this list default value
         maxLength: '=',
-        constraints: '='
+        constraints: '=',
+        types: '='
     };
 
     restrict = 'E';
@@ -89,6 +91,32 @@ export class TypeListDirective implements ng.IDirective {
     template = ():string => {
         return require('./type-list-directive.html');
     };
+    
+    private isDataTypeForSchemaType = (property:SchemaProperty, types:DataTypesMap):boolean=> {
+        property.simpleType = "";
+        if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
+            return false;
+        }
+        let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type, types);
+        if (simpleType) {
+            property.simpleType = simpleType;
+            return false;
+        }
+        return true;
+    };
+    
+    private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string, types:DataTypesMap):string => {
+        if (!types[dataTypeName]) {
+            return 'string';
+        }
+        if (types[dataTypeName].derivedFromName == "tosca.datatypes.Root" || types[dataTypeName].properties) {
+            return null;
+        }
+        if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(types[dataTypeName].derivedFromName) > -1) {
+            return types[dataTypeName].derivedFromName
+        }
+        return this.getTypeForDataTypeDerivedFromSimple(types[dataTypeName].derivedFromName, types);
+    };
 
     link = (scope:ITypeListScope, element:any, $attr:any) => {
         scope.propertyNameValidationPattern = this.PropertyNameValidationPattern;
@@ -110,7 +138,7 @@ export class TypeListDirective implements ng.IDirective {
         });
         //reset valueObjRef when schema type is changed
         scope.$watchCollection('schemaProperty.type', (newData:any):void => {
-            scope.isSchemaTypeDataType = this.DataTypesService.isDataTypeForSchemaType(scope.schemaProperty);
+            scope.isSchemaTypeDataType = this.isDataTypeForSchemaType(scope.schemaProperty, scope.types);
         });
 
         //when user brows between properties in "edit property form"
index 5c89511..b4ac6aa 100644 (file)
                               type-name="schemaProperty.type"
                               parent-form-obj="parentFormObj"
                               fields-prefix-name="'mapValue'+fieldsPrefixName+''+$index"
+                              types="types"
                               read-only="readOnly"
             ></fields-structure>
         </div>
index ce8b997..20470be 100644 (file)
@@ -22,9 +22,9 @@
  * Created by rcohen on 9/15/2016.
  */
 'use strict';
-import {ValidationUtils, PROPERTY_TYPES} from "app/utils";
+import {ValidationUtils, PROPERTY_TYPES, PROPERTY_DATA} from "app/utils";
 import {DataTypesService} from "app/services";
-import {SchemaProperty, PropertyModel} from "app/models";
+import {SchemaProperty, PropertyModel, DataTypesMap} from "app/models";
 import {InstanceFeDetails} from "app/models/instance-fe-details";
 import {ToscaGetFunction} from "app/models/tosca-get-function";
 import {SubPropertyToscaFunction} from "app/models/sub-property-tosca-function";
@@ -47,6 +47,7 @@ export interface ITypeMapScope extends ng.IScope {
     constraints:string[];
     showAddBtn: boolean;
     showToscaFunction: Array<boolean>;
+    types:DataTypesMap;
 
     getValidationPattern(type:string):RegExp;
     validateIntRange(value:string):boolean;
@@ -80,7 +81,8 @@ export class TypeMapDirective implements ng.IDirective {
         maxLength: '=',
         constraints: '=',
         showAddBtn: '=?',
-        parentProperty: '='
+        parentProperty: '=',
+        types: '='
     };
 
     restrict = 'E';
@@ -88,6 +90,32 @@ export class TypeMapDirective implements ng.IDirective {
     template = (): string => {
         return require('./type-map-directive.html');
     };
+    
+    private isDataTypeForSchemaType = (property:SchemaProperty, types:DataTypesMap):boolean=> {
+        property.simpleType = "";
+        if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
+            return false;
+        }
+        let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type, types);
+        if (simpleType) {
+            property.simpleType = simpleType;
+            return false;
+        }
+        return true;
+    };
+    
+    private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string, types:DataTypesMap):string => {
+        if (!types[dataTypeName]) {
+            return 'string';
+        }
+        if (types[dataTypeName].derivedFromName == "tosca.datatypes.Root" || types[dataTypeName].properties) {
+            return null;
+        }
+        if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(types[dataTypeName].derivedFromName) > -1) {
+            return types[dataTypeName].derivedFromName
+        }
+        return this.getTypeForDataTypeDerivedFromSimple(types[dataTypeName].derivedFromName, types);
+    };
 
     link = (scope:ITypeMapScope, element:any, $attr:any) => {
         scope.showAddBtn = angular.isDefined(scope.showAddBtn) ? scope.showAddBtn : true;
@@ -110,7 +138,7 @@ export class TypeMapDirective implements ng.IDirective {
 
         //reset valueObjRef and mapKeys when schema type is changed
         scope.$watchCollection('schemaProperty.type', (newData:any):void => {
-            scope.isSchemaTypeDataType = this.DataTypesService.isDataTypeForSchemaType(scope.schemaProperty);
+            scope.isSchemaTypeDataType = this.isDataTypeForSchemaType(scope.schemaProperty, scope.types);
             if (scope.valueObjRef) {
                 scope.mapKeys = Object.keys(scope.valueObjRef);
                 //keeping another copy of the keys, as the mapKeys gets overridden sometimes
index eda5efc..151c34f 100644 (file)
@@ -154,10 +154,36 @@ export class PropertyFormViewModel {
         this.$scope.editPropertyModel.hasGetFunctionValue = this.$scope.editPropertyModel.property.isToscaFunction();
         this.$scope.editPropertyModel.isGetFunctionValid = true;
     }
+    
+    private isDataTypeForPropertyType = (property:PropertyModel):boolean=> {
+        property.simpleType = "";
+        if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
+            return false;
+        }
+        let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
+        if (simpleType) {
+            property.simpleType = simpleType;
+            return false;
+        }
+        return true;
+    };
+    
+    private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string):string => {
+        if (!this.$scope.dataTypes[dataTypeName]) {
+            return 'string';
+        }
+        if (this.$scope.dataTypes[dataTypeName].derivedFromName == "tosca.datatypes.Root" || this.$scope.dataTypes[dataTypeName].properties) {
+            return null;
+        }
+        if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.$scope.dataTypes[dataTypeName].derivedFromName) > -1) {
+            return this.$scope.dataTypes[dataTypeName].derivedFromName
+        }
+        return this.getTypeForDataTypeDerivedFromSimple(this.$scope.dataTypes[dataTypeName].derivedFromName);
+    };
 
     private initForNotSimpleType = ():void => {
         const property = this.$scope.editPropertyModel.property;
-        this.$scope.isTypeDataType = this.DataTypesService.isDataTypeForPropertyType(this.$scope.editPropertyModel.property);
+        this.$scope.isTypeDataType = this.isDataTypeForPropertyType(this.$scope.editPropertyModel.property);
         if (property.isToscaFunction()) {
             this.initValueForGetFunction();
             return;
@@ -274,7 +300,6 @@ export class PropertyFormViewModel {
             }
         }
         this.initResource();
-        this.initForNotSimpleType();
         this.initComponentInstanceMap();
 
         this.$scope.validateJson = (json:string):boolean => {
@@ -286,10 +311,11 @@ export class PropertyFormViewModel {
 
         this.DataTypesService.fetchDataTypesByModel(this.workspaceService.metadata.model).then(response => {
             this.$scope.dataTypes = response.data as DataTypesMap;
+
             this.$scope.nonPrimitiveTypes = _.filter(Object.keys(this.$scope.dataTypes), (type:string)=> {
                 return this.$scope.editPropertyModel.types.indexOf(type) == -1;
             });
-
+            this.initForNotSimpleType();
             this.$scope.isLoading = false;
         });
 
@@ -565,4 +591,4 @@ export class PropertyFormViewModel {
         return this.topologyTemplateService.deleteProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, propertyId).map(onSuccess, onFailed);
     };
 
-}
\ No newline at end of file
+}
index 6a9013c..dc26d1f 100644 (file)
                                               fields-prefix-name="currentPropertyIndex"
                                               read-only="editPropertyModel.property.readonly && !isPropertyValueOwner"
                                               default-value="{{getDefaultValue()}}"
+                                              types="dataTypes"
                                               expand-by-default="true"></fields-structure>
 
                         </div>
                                           read-only="(editPropertyModel.property.readonly && !isPropertyValueOwner) || isVnfConfiguration"
                                           default-value="{{getDefaultValue()}}"
                                           max-length="maxLength"
+                                          types="dataTypes"
                                           constraints="editPropertyModel.property.constraints && editPropertyModel.property.constraints[0].validValues">
                                 </type-map>
                             </div>
                                            read-only="editPropertyModel.property.readonly && !isPropertyValueOwner"
                                            default-value="{{getDefaultValue()}}"
                                            max-length="maxLength"
+                                           types="dataTypes"
                                            constraints="editPropertyModel.property.constraints && editPropertyModel.property.constraints[0].validValues"></type-list>
                             </div>