From db3e2ef238fa29e06cec3cb3f5b11fb407b161ce Mon Sep 17 00:00:00 2001 From: imamSidero Date: Wed, 21 Dec 2022 17:51:43 +0000 Subject: Provide tosca function to custom datatypes of list and map Providing the capability to add tosca function as the custom datatypes of list and map Issue-ID: SDC-4311 Signed-off-by: Imam hussain Change-Id: I7ec8943d8008440b091fc4eaa2aba49cdadcda8d --- .../dynamic-property.component.html | 11 ++--- .../dynamic-property/dynamic-property.component.ts | 23 +++++++++- .../properties-assignment.page.component.ts | 52 +++++++++++++++------- .../services/properties.utils.ts | 23 ++++++++-- .../tosca-function/tosca-function.component.ts | 12 +++-- .../tosca-get-function.component.ts | 18 ++++++-- 6 files changed, 107 insertions(+), 32 deletions(-) (limited to 'catalog-ui') diff --git a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html index d79c6dbb08..a5c2b60ee3 100644 --- a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html +++ b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html @@ -25,6 +25,7 @@
{{property.name}}
+
{{property.name}}
@@ -41,7 +42,7 @@
- +
- +
{{property.type | contentAfterLastDot }}
{{property.schema.property.type | contentAfterLastDot }}
- +
- + Add value to list Add value to map @@ -75,7 +76,7 @@ -
+
{ - - let newProps: Array = this.propertiesUtils.createListOrMapChildren(this.property, "", null); + + let mapKeyValue = this.property instanceof DerivedFEProperty ? this.property.mapKey : ""; + if (this.property.type == PROPERTY_TYPES.LIST && mapKeyValue === "") { + if(this.property.value != null) { + const valueJson = JSON.parse(this.property.value); + if(this.property instanceof PropertyFEModel && this.property.expandedChildPropertyId != null){ + let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1; + mapKeyValue = indexNumber.toString(); + }else{ + mapKeyValue = Object.keys(valueJson).sort().reverse()[0]; + } + }else { + mapKeyValue = "0"; + } + } + let newProps: Array = this.propertiesUtils.createListOrMapChildren(this.property, mapKeyValue, null); this.propertiesUtils.assignFlattenedChildrenValues(this.property.valueObj, [newProps[0]], this.property.propertiesName); if (this.property instanceof PropertyFEModel) { @@ -255,6 +269,11 @@ export class DynamicPropertyComponent { if (this.property instanceof PropertyFEModel) { let oldKey = childProp.getActualMapKey(); this.property.childPropMapKeyUpdated(childProp, newMapKey); + this.property.flattenedChildren.forEach(tempDervObj => { + if (childProp.propertiesName === tempDervObj.parentName) { + tempDervObj.mapKey = newMapKey; + } + }); if (this.property.subPropertyToscaFunctions != null) { this.property.subPropertyToscaFunctions.forEach((item : SubPropertyToscaFunction) => { if(item.subPropertyPath[0] === oldKey){ diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts index 2bf1b1076b..a3477792cf 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts @@ -46,7 +46,7 @@ import {ComponentServiceNg2} from "../../services/component-services/component.s import {TopologyTemplateService} from "../../services/component-services/topology-template.service"; import {ComponentInstanceServiceNg2} from "../../services/component-instance-services/component-instance.service" import {KeysPipe} from 'app/ng2/pipes/keys.pipe'; -import {EVENTS, PROPERTY_TYPES, WorkspaceMode} from "../../../utils/constants"; +import {EVENTS, PROPERTY_TYPES, WorkspaceMode, PROPERTY_DATA} from "../../../utils/constants"; import {EventListenerService} from "app/services/event-listener-service" import {HierarchyDisplayOptions} from "../../components/logic/hierarchy-navigtion/hierarchy-display-options"; import {FilterPropertiesAssignmentComponent} from "../../components/logic/filter-properties-assignment/filter-properties-assignment.component"; @@ -587,21 +587,29 @@ export class PropertiesAssignmentComponent { if (checkedInstanceProperty instanceof PropertyDeclareAPIModel && (checkedInstanceProperty).propertiesName){ const propertiesNameArray = (checkedInstanceProperty).propertiesName; const parts = propertiesNameArray.split("#"); - const currentKey = (checkedInstanceProperty.type == PROPERTY_TYPES.MAP || checkedInstanceProperty.type == PROPERTY_TYPES.LIST) ? (checkedInstanceProperty.input).mapKey : null; + let currentKey = []; + if (this.isListOrMap(checkedInstanceProperty.type)) { + currentKey.push((checkedInstanceProperty.input).mapKey); + if (this.isComplexSchemaType(checkedInstanceProperty.schemaType)) { + currentKey.push(parts.reverse()[0]); + } + } if (propertiesNameArray.length > 1){ - const index = checkedInstanceProperty.subPropertyToscaFunctions.findIndex(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey != null ? [currentKey] : parts.slice(1))); + const index = checkedInstanceProperty.subPropertyToscaFunctions.findIndex(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey.length > 0 ? currentKey : parts.slice(1))); checkedInstanceProperty.subPropertyToscaFunctions.splice(index, 1); } - if(currentValue !== null && currentKey !== null){ + if(currentValue !== null && currentKey.length > 0){ let valueJson = JSON.parse(currentValue); - let tempValue = valueJson[currentKey]; - delete valueJson[currentKey]; - if (checkedInstanceProperty.type == PROPERTY_TYPES.LIST) { - let listValue = []; - valueJson.forEach(item => { - if (item != null && item != '' && item != tempValue) { - listValue.push(item); - } + if(currentKey.length >1){ + let innerObj = valueJson[currentKey[0]]; + delete innerObj[currentKey[1]]; + valueJson[currentKey[0]] = innerObj; + }else{ + delete valueJson[currentKey[0]]; + } + if (checkedInstanceProperty.type == PROPERTY_TYPES.LIST && currentKey.length == 1) { + let listValue = valueJson.filter(function (item) { + return item != null && item != ''; }); checkedInstanceProperty.value = JSON.stringify(listValue); } else { @@ -623,17 +631,23 @@ export class PropertiesAssignmentComponent { if (checkedProperty instanceof PropertyDeclareAPIModel && (checkedProperty).propertiesName){ const propertiesName = (checkedProperty).propertiesName; const parts = propertiesName.split("#"); - const currentKey = (checkedProperty.type == PROPERTY_TYPES.MAP || checkedProperty.type == PROPERTY_TYPES.LIST) ? (checkedProperty.input).mapKey : null; + let currentKey = []; + if (this.isListOrMap(checkedProperty.type)) { + currentKey.push((checkedProperty.input).mapKey); + if (this.isComplexSchemaType(checkedProperty.schemaType)) { + currentKey.push(parts.reverse()[0]); + } + } if (checkedProperty.subPropertyToscaFunctions == null){ checkedProperty.subPropertyToscaFunctions = []; } - let subPropertyToscaFunction = checkedProperty.subPropertyToscaFunctions.find(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey != null ? [currentKey] : parts.slice(1))); + let subPropertyToscaFunction = checkedProperty.subPropertyToscaFunctions.find(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey.length > 0 ? currentKey : parts.slice(1))); if (!subPropertyToscaFunction){ subPropertyToscaFunction = new SubPropertyToscaFunction(); checkedProperty.subPropertyToscaFunctions.push(subPropertyToscaFunction); } subPropertyToscaFunction.toscaFunction = toscaFunction; - subPropertyToscaFunction.subPropertyPath = currentKey != null ? [currentKey] : parts.slice(1); + subPropertyToscaFunction.subPropertyPath = currentKey.length > 0 ? currentKey : parts.slice(1); } else { checkedProperty.subPropertyToscaFunctions = null; @@ -648,6 +662,14 @@ export class PropertiesAssignmentComponent { } } + private isComplexSchemaType(propertyType: string): boolean { + return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1; + } + + private isListOrMap(propertyType: string): boolean { + return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType; + } + private areEqual(array1: string[], array2: string[]): boolean { return array1.length === array2.length && array1.every(function(value, index) { return value === array2[index]}) } diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts index 876fc8e5fa..0b984ac2a4 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts @@ -108,9 +108,21 @@ export class PropertiesUtils { newProps.push(parentProp); if (!property.schema.property.isSimpleType) { - let additionalChildren:Array = this.createFlattenedChildren(property.schema.property.type, parentProp.propertiesName); + let additionalChildren:Array = this.createFlattenedChildren(property.schema.property.type, parentProp.propertiesName, key); this.assignFlattenedChildrenValues(parentProp.valueObj, additionalChildren, parentProp.propertiesName); - additionalChildren.forEach(prop => prop.canBeDeclared = false); + additionalChildren.forEach(prop => { + prop.canBeDeclared = false; + if (property.subPropertyToscaFunctions != null) { + const subToscaFunctArray : SubPropertyToscaFunction[] = property.subPropertyToscaFunctions; + subToscaFunctArray.forEach(subToscaFunct => { + const keyArray : string[] = subToscaFunct.subPropertyPath; + if (keyArray.length > 1 && prop.mapKey == keyArray[0] && prop.name == keyArray[1]) { + prop.toscaFunction = subToscaFunct.toscaFunction; + } + }); + + } + }); newProps.push(...additionalChildren); } return newProps; @@ -119,10 +131,13 @@ export class PropertiesUtils { /** * Creates derivedFEProperties of a specified type and returns them. */ - private createFlattenedChildren = (type: string, parentName: string):Array => { + private createFlattenedChildren = (type: string, parentName: string, key: string):Array => { let tempProps: Array = []; let dataTypeObj: DataTypeModel = this.dataTypeService.getDataTypeByTypeName(type); this.dataTypeService.getDerivedDataTypeProperties(dataTypeObj, tempProps, parentName); + tempProps.forEach(tempDervObj => { + tempDervObj.mapKey = key; + }); return _.sortBy(tempProps, ['propertiesName']); } @@ -151,7 +166,7 @@ export class PropertiesUtils { } }); } else if (property.derivedDataType === DerivedPropertyType.COMPLEX) { - property.flattenedChildren = this.createFlattenedChildren(property.type, property.name); + property.flattenedChildren = this.createFlattenedChildren(property.type, property.name, ""); this.assignFlattenedChildrenValues(property.valueObj, property.flattenedChildren, property.name); this.setFlattenedChildernToscaFunction(property.subPropertyToscaFunctions, property.flattenedChildren, property.name); property.flattenedChildren.forEach((childProp) => { diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts index 0198dfd760..6b43cb014d 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts @@ -29,7 +29,7 @@ import {ToscaFunctionType} from "../../../../models/tosca-function-type.enum"; import {ToscaGetFunctionValidationEvent} from "./tosca-get-function/tosca-get-function.component"; import {ToscaFunction} from "../../../../models/tosca-function"; import {ToscaConcatFunctionValidationEvent} from "./tosca-concat-function/tosca-concat-function.component"; -import {PROPERTY_TYPES} from "../../../../utils/constants"; +import {PROPERTY_TYPES, PROPERTY_DATA} from "../../../../utils/constants"; import {YamlFunctionValidationEvent} from "./yaml-function/yaml-function.component"; import {ToscaConcatFunction} from "../../../../models/tosca-concat-function"; import {YamlFunction} from "../../../../models/yaml-function"; @@ -101,8 +101,14 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { if (this.property instanceof PropertyDeclareAPIModel && this.property.subPropertyToscaFunctions && ( this.property).propertiesName){ let propertiesPath = ( this.property).propertiesName.split("#"); if (propertiesPath.length > 1){ - let keyToFind = (this.property.type == PROPERTY_TYPES.MAP || this.property.type == PROPERTY_TYPES.LIST) ? [(this.property.input).mapKey] : propertiesPath.slice(1); - let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind !== null ? keyToFind : propertiesPath.slice(1))); + let keyToFind = []; + if (this.property.type == PROPERTY_TYPES.MAP || this.property.type == PROPERTY_TYPES.LIST) { + keyToFind.push((this.property.input).mapKey); + if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.property.schemaType) === -1) { + keyToFind.push(propertiesPath.reverse()[0]); + } + } + let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind.length > 0 ? keyToFind : propertiesPath.slice(1))); if (subPropertyToscaFunction){ this.toscaFunction = subPropertyToscaFunction.toscaFunction; diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts index 46541cf355..84018fd546 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts @@ -261,7 +261,15 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { } private propertyTypeToString() { - if (this.isSubProperty() && this.property.type != PROPERTY_TYPES.MAP && this.property.type != PROPERTY_TYPES.LIST){ + if (this.isSubProperty()){ + if (this.typeHasSchema(this.property.type) && this.property instanceof PropertyDeclareAPIModel && + ( this.property).input instanceof DerivedFEProperty) { + if(this.isComplexType(this.property.schemaType)){ + return this.property.input.type; + }else{ + return this.property.schema.property.type; + } + } return this.getType((this.property).propertiesName.split("#").slice(1), this.property.type); } if (this.property.schemaType) { @@ -367,8 +375,12 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { private hasSameType(property: PropertyBEModel | AttributeBEModel): boolean { if (this.typeHasSchema(this.property.type)) { - if ((this.property.type === PROPERTY_TYPES.MAP || this.property.type === PROPERTY_TYPES.LIST) && this.property instanceof PropertyDeclareAPIModel && ( this.property).input instanceof DerivedFEProperty) { - return property.type === this.property.schema.property.type; + if (this.property instanceof PropertyDeclareAPIModel && ( this.property).input instanceof DerivedFEProperty) { + if(this.isComplexType(this.property.schemaType)){ + return property.type === this.property.input.type; + }else{ + return property.type === this.property.schema.property.type; + } } if (!property.schema || !property.schema.property) { return false; -- cgit 1.2.3-korg