2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
21 import {AttributeBEModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel, PropertyDeclareAPIModel, DerivedFEProperty} from 'app/models';
22 import {TopologyTemplateService} from "../../../../services/component-services/topology-template.service";
23 import {WorkspaceService} from "../../../workspace/workspace.service";
24 import {PropertiesService} from "../../../../services/properties.service";
25 import {PROPERTY_DATA, PROPERTY_TYPES} from "../../../../../utils/constants";
26 import {DataTypeService} from "../../../../services/data-type.service";
27 import {ToscaGetFunctionType} from "../../../../../models/tosca-get-function-type";
28 import {TranslateService} from "../../../../shared/translator/translate.service";
29 import {ComponentGenericResponse} from '../../../../services/responses/component-generic-response';
30 import {Observable} from 'rxjs/Observable';
31 import {PropertySource} from "../../../../../models/property-source";
32 import {InstanceFeDetails} from "../../../../../models/instance-fe-details";
33 import {ToscaGetFunction} from "../../../../../models/tosca-get-function";
34 import {FormControl, FormGroup, Validators} from "@angular/forms";
35 import {ToscaGetFunctionTypeConverter} from "../../../../../models/tosca-get-function-type-converter";
38 selector: 'app-tosca-get-function',
39 templateUrl: './tosca-get-function.component.html',
40 styleUrls: ['./tosca-get-function.component.less']
42 export class ToscaGetFunctionComponent implements OnInit, OnChanges {
44 @Input() property: PropertyBEModel;
45 @Input() overridingType: PROPERTY_TYPES;
46 @Input() toscaGetFunction: ToscaGetFunction;
47 @Input() componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
48 @Input() functionType: ToscaGetFunctionType;
49 @Input() compositionMap: boolean;
50 @Input() compositionMapKey: string;
51 @Output() onValidFunction: EventEmitter<ToscaGetFunction> = new EventEmitter<ToscaGetFunction>();
52 @Output() onValidityChange: EventEmitter<ToscaGetFunctionValidationEvent> = new EventEmitter<ToscaGetFunctionValidationEvent>();
54 formGroup: FormGroup = new FormGroup({
55 'selectedProperty': new FormControl(undefined, Validators.required),
56 'propertySource': new FormControl(undefined, Validators.required)
59 isLoading: boolean = false;
60 propertyDropdownList: Array<PropertyDropdownValue> = [];
61 propertySourceList: Array<string> = [];
62 instanceNameAndIdMap: Map<string, string> = new Map<string, string>();
63 dropdownValuesLabel: string;
64 dropDownErrorMsg: string;
65 indexListValues:Array<ToscaIndexObject>;
66 parentListTypeFlag : boolean;
68 private isInitialized: boolean = false;
69 private componentMetadata: ComponentMetadata;
71 constructor(private topologyTemplateService: TopologyTemplateService,
72 private workspaceService: WorkspaceService,
73 private propertiesService: PropertiesService,
74 private dataTypeService: DataTypeService,
75 private translateService: TranslateService) {
79 this.componentMetadata = this.workspaceService.metadata;
80 this.indexListValues = [];
81 if (this.property != null) {
82 this.parentListTypeFlag = (this.property.type != PROPERTY_TYPES.LIST && (!this.isComplexType(this.property.type) || (this.isComplexType(this.property.type)
83 && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty && this.property.input.type != PROPERTY_TYPES.LIST)));
85 this.formGroup.valueChanges.subscribe(() => {
86 this.formValidation();
88 this.loadPropertySourceDropdown();
89 this.loadPropertyDropdownLabel();
90 this.initToscaGetFunction().subscribe(() => {
91 this.isInitialized = true;
95 ngOnChanges(_changes: SimpleChanges): void {
96 if (!this.isInitialized) {
99 this.isInitialized = false;
101 this.loadPropertySourceDropdown();
102 this.loadPropertyDropdownLabel();
103 this.initToscaGetFunction().subscribe(() => {
104 this.isInitialized = true;
108 private initToscaGetFunction(): Observable<void> {
109 return new Observable(subscriber => {
110 if (!this.toscaGetFunction) {
111 if (this.isGetInput()) {
112 this.setSelfPropertySource();
113 this.loadPropertyDropdown();
118 if (this.toscaGetFunction.propertySource == PropertySource.SELF) {
119 this.propertySource.setValue(PropertySource.SELF);
120 } else if (this.toscaGetFunction.propertySource == PropertySource.INSTANCE) {
122 .setValue(this.propertySourceList.find(source => this.toscaGetFunction.sourceName === source));
124 if (this.propertySource.valid) {
125 this.loadPropertyDropdown(() => {
126 this.selectedProperty
127 .setValue(this.propertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.propertyName));
128 if (this.toscaGetFunction.toscaIndexList.length > 0) {
129 let tempSelectedProperty : PropertyDropdownValue = this.selectedProperty.value;
130 this.toscaGetFunction.toscaIndexList.forEach((indexValue: string, index) => {
131 let tempIndexFlag = false;
132 let tempNestedFlag = false;
133 let tempIndexValue = "0";
134 let tempIndexProperty = tempSelectedProperty;
135 let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
137 tempIndexFlag = true;
138 tempIndexValue = indexValue;
139 tempSelectedProperty = null;
140 if (this.toscaGetFunction.toscaIndexList[index+1]) {
141 tempNestedFlag = true;
142 if (tempIndexProperty.schemaType != null) {
143 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, tempIndexProperty.schemaType);
144 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
145 tempSelectedProperty = subPropertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.toscaIndexList[index+1])
148 let tempIndexValueMap : ToscaIndexObject = {indexFlag : tempIndexFlag, nestedFlag : tempNestedFlag, indexValue: tempIndexValue, indexProperty: tempSelectedProperty, subPropertyArray: subPropertyDropdownList};
149 this.indexListValues.push(tempIndexValueMap);
161 private buildGetFunctionFromForm() {
162 const toscaGetFunction = new ToscaGetFunction();
163 toscaGetFunction.type = ToscaGetFunctionTypeConverter.convertToToscaFunctionType(this.functionType);
164 toscaGetFunction.functionType = this.functionType;
165 const propertySource = this.propertySource.value;
166 if (this.isPropertySourceSelf()) {
167 toscaGetFunction.propertySource = propertySource
168 toscaGetFunction.sourceName = this.componentMetadata.name;
169 toscaGetFunction.sourceUniqueId = this.componentMetadata.uniqueId;
171 toscaGetFunction.propertySource = PropertySource.INSTANCE;
172 toscaGetFunction.sourceName = propertySource;
173 toscaGetFunction.sourceUniqueId = this.instanceNameAndIdMap.get(propertySource);
176 const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
177 toscaGetFunction.propertyUniqueId = selectedProperty.propertyId;
178 toscaGetFunction.propertyName = selectedProperty.propertyName;
179 toscaGetFunction.propertyPathFromSource = selectedProperty.propertyPath;
180 if (this.indexListValues.length > 0) {
181 let indexAndProperty : Array<string> = [];
182 this.indexListValues.forEach((indexObject : ToscaIndexObject) => {
183 indexAndProperty.push(indexObject.indexValue);
184 if(indexObject.nestedFlag && indexObject.indexProperty != null) {
185 indexAndProperty.push(indexObject.indexProperty.propertyName);
188 toscaGetFunction.toscaIndexList = indexAndProperty;
190 return toscaGetFunction;
193 private loadPropertySourceDropdown(): void {
194 if (this.isGetInput()) {
197 this.propertySourceList = [];
198 this.propertySourceList.push(PropertySource.SELF);
199 this.componentInstanceMap.forEach((value, key) => {
200 const instanceName = value.name;
201 this.instanceNameAndIdMap.set(instanceName, key);
202 if (instanceName !== PropertySource.SELF) {
203 this.addToPropertySource(instanceName);
208 private addToPropertySource(source: string): void {
209 this.propertySourceList.push(source);
210 this.propertySourceList.sort((a, b) => {
211 if (a === PropertySource.SELF) {
213 } else if (b === PropertySource.SELF) {
217 return a.localeCompare(b);
221 private formValidation(): void {
222 if (!this.isInitialized) {
225 let formGroupStatus : boolean = this.formGroup.valid;
226 const selectedProperty: PropertyDropdownValue = this.formGroup.value.selectedProperty;
227 if (selectedProperty != null && selectedProperty.isList && formGroupStatus && this.indexListValues.length > 0) {
228 this.indexListValues.forEach((indexObject : ToscaIndexObject, index) => {
229 if (indexObject.indexValue == null) {
230 formGroupStatus = false;
233 if (indexObject.nestedFlag && indexObject.indexProperty == null) {
234 formGroupStatus = false;
239 this.onValidityChange.emit({
240 isValid: formGroupStatus,
241 toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
243 if (this.formGroup.valid) {
244 this.onValidFunction.emit(this.buildGetFunctionFromForm());
248 private loadPropertyDropdown(onComplete?: () => any): void {
249 this.loadPropertyDropdownLabel();
250 this.loadPropertyDropdownValues(onComplete);
253 private resetForm(): void {
254 this.formGroup.reset();
257 private loadPropertyDropdownLabel(): void {
258 if (!this.functionType) {
261 if (this.isGetInput()) {
262 this.dropdownValuesLabel = this.translateService.translate('INPUT_DROPDOWN_LABEL');
263 } else if (this.isGetProperty()) {
264 this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_PROPERTY_DROPDOWN_LABEL');
265 } else if (this.isGetAttribute()) {
266 this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_ATTRIBUTE_DROPDOWN_LABEL');
270 private loadPropertyDropdownValues(onComplete?: () => any): void {
271 if (!this.functionType) {
274 this.resetPropertyDropdown();
275 this.fillPropertyDropdownValues(onComplete);
278 private resetPropertyDropdown(): void {
279 this.dropDownErrorMsg = undefined;
280 this.selectedProperty.reset();
281 this.indexListValues = [];
282 this.propertyDropdownList = [];
285 private fillPropertyDropdownValues(onComplete?: () => any): void {
287 const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable();
288 propertiesObservable.subscribe( (response: ComponentGenericResponse) => {
289 const properties: Array<PropertyBEModel | AttributeBEModel> = this.extractProperties(response);
290 if (!properties || properties.length === 0) {
291 const msgCode = this.getNotFoundMsgCode();
292 this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.overridingType != undefined ? this.overridingType : this.propertyTypeToString()});
295 this.addPropertiesToDropdown(properties, this.propertyDropdownList);
296 if (this.propertyDropdownList.length == 0) {
297 const msgCode = this.getNotFoundMsgCode();
298 this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.overridingType != undefined ? this.overridingType : this.propertyTypeToString()});
301 console.error('An error occurred while loading properties.', error);
311 private getNotFoundMsgCode(): string {
312 if (this.isGetInput()) {
313 return 'TOSCA_FUNCTION_NO_INPUT_FOUND';
315 if (this.isGetAttribute()) {
316 return 'TOSCA_FUNCTION_NO_ATTRIBUTE_FOUND';
318 if (this.isGetProperty()) {
319 return 'TOSCA_FUNCTION_NO_PROPERTY_FOUND';
325 private propertyTypeToString() {
326 if (this.isSubProperty()){
327 if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty)
328 || this.compositionMap) {
329 if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
330 let mapChildProp : DerivedFEProperty = (<DerivedFEProperty> (<PropertyDeclareAPIModel> this.property).input);
331 let propertySchemaType = mapChildProp.type;
332 if (this.property.type == PROPERTY_TYPES.MAP || propertySchemaType == PROPERTY_TYPES.MAP) {
333 if (mapChildProp.mapKey != '' && mapChildProp.mapKey != null && mapChildProp.schema.property.type != null) {
334 propertySchemaType = mapChildProp.schema.property.type;
337 if ((propertySchemaType == PROPERTY_TYPES.MAP || (propertySchemaType == PROPERTY_TYPES.LIST && mapChildProp.schema.property.type == PROPERTY_TYPES.MAP))
338 && mapChildProp.isChildOfListOrMap) {
339 propertySchemaType = PROPERTY_TYPES.STRING;
341 return propertySchemaType;
343 return this.property.schema.property.type;
346 return this.getType((<PropertyDeclareAPIModel>this.property).propertiesName.split("#").slice(1), this.property.type);
348 if (this.property.schemaType) {
349 return `${this.property.type} of ${this.property.schemaType}`;
351 return this.property.type;
354 private isSubProperty(): boolean{
355 return this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName && (<PropertyDeclareAPIModel>this.property).propertiesName.length > 1;
358 private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeBEModel> {
359 if (this.isGetInput()) {
360 return componentGenericResponse.inputs;
362 const instanceId = this.instanceNameAndIdMap.get(this.propertySource.value);
363 if (this.isGetProperty()) {
364 if (this.isPropertySourceSelf()) {
365 return componentGenericResponse.properties;
367 return this.removeSelectedProperty(componentGenericResponse.componentInstancesProperties[instanceId]);
369 if (this.isPropertySourceSelf()) {
370 return [...(componentGenericResponse.attributes || []), ...(componentGenericResponse.properties || [])];
372 return [...(componentGenericResponse.componentInstancesAttributes[instanceId] || []),
373 ...(componentGenericResponse.componentInstancesProperties[instanceId] || [])];
376 private isPropertySourceSelf() {
377 return this.propertySource.value === PropertySource.SELF;
380 private getPropertyObservable(): Observable<ComponentGenericResponse> {
381 if (this.isGetInput()) {
382 return this.topologyTemplateService.getComponentInputsValues(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
384 if (this.isGetProperty()) {
385 if (this.isPropertySourceSelf()) {
386 return this.topologyTemplateService.findAllComponentProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
388 return this.topologyTemplateService.getComponentInstanceProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
390 if (this.isGetAttribute()) {
391 if (this.isPropertySourceSelf()) {
392 return this.topologyTemplateService.findAllComponentAttributesAndProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
394 return this.topologyTemplateService.getComponentInstanceAttributesAndProperties(this.componentMetadata.uniqueId, this.componentMetadata.componentType);
398 private removeSelectedProperty(componentInstanceProperties: PropertyModel[]): PropertyModel[] {
399 if (!componentInstanceProperties) {
402 return componentInstanceProperties.filter(property =>
403 (property.uniqueId !== this.property.uniqueId) ||
404 (property.uniqueId === this.property.uniqueId && property.resourceInstanceUniqueId !== this.property.parentUniqueId)
408 private addPropertyToDropdown(propertyDropdownValue: PropertyDropdownValue, propertyList: Array<PropertyDropdownValue>): void {
409 propertyList.push(propertyDropdownValue);
410 propertyList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel));
413 private addPropertiesToDropdown(properties: Array<PropertyBEModel | AttributeBEModel>, propertyList: Array<PropertyDropdownValue>): void {
414 for (const property of properties) {
415 if (this.hasSameType(property)) {
416 this.addPropertyToDropdown({
417 propertyName: property.name,
418 propertyId: property.uniqueId,
419 propertyLabel: property.name,
420 propertyPath: [property.name],
421 isList: property.type === PROPERTY_TYPES.LIST,
422 schemaType: (property.type === PROPERTY_TYPES.LIST && this.isComplexType(property.schema.property.type)) ? property.schema.property.type : null
424 } else if (this.isComplexType(property.type)) {
425 this.fillPropertyDropdownWithMatchingChildProperties(property,propertyList);
430 private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel | AttributeBEModel, propertyList: Array<PropertyDropdownValue>,
431 parentPropertyList: Array<PropertyBEModel | AttributeBEModel> = []): void {
432 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
433 if (!dataTypeFound || !dataTypeFound.properties) {
436 parentPropertyList.push(inputProperty);
437 dataTypeFound.properties.forEach(dataTypeProperty => {
438 if (this.hasSameType(dataTypeProperty)) {
439 this.addPropertyToDropdown({
440 propertyName: dataTypeProperty.name,
441 propertyId: parentPropertyList[0].uniqueId,
442 propertyLabel: parentPropertyList.map(property => property.name).join('->') + '->' + dataTypeProperty.name,
443 propertyPath: [...parentPropertyList.map(property => property.name), dataTypeProperty.name],
444 isList : dataTypeProperty.type === PROPERTY_TYPES.LIST,
445 schemaType: (dataTypeProperty.type === PROPERTY_TYPES.LIST && this.isComplexType(dataTypeProperty.schema.property.type)) ? dataTypeProperty.schema.property.type : null
447 } else if (this.isComplexType(dataTypeProperty.type)) {
448 this.fillPropertyDropdownWithMatchingChildProperties(dataTypeProperty, propertyList, [...parentPropertyList])
453 private hasSameType(property: PropertyBEModel | AttributeBEModel): boolean {
454 if (this.overridingType != undefined) {
455 return property.type === this.overridingType;
457 if (this.property.type === PROPERTY_TYPES.ANY) {
460 let validPropertyType = (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST) ? property.schema.property.type : property.type;
461 if (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST && this.isComplexType(validPropertyType)) {
462 let returnFlag : boolean = false;
463 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, validPropertyType);
464 if (dataTypeFound && dataTypeFound.properties) {
465 dataTypeFound.properties.forEach(dataTypeProperty => {
466 if (this.hasSameType(dataTypeProperty)) {
473 if (this.typeHasSchema(this.property.type)) {
474 if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
475 let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
476 let childSchemaType = this.property.schemaType != null ? this.property.schemaType : childObject.type;
477 if(this.isComplexType(childSchemaType) && !this.compositionMap){
478 if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
479 return validPropertyType === PROPERTY_TYPES.STRING;
481 return validPropertyType === childObject.type;
483 return validPropertyType === this.property.schema.property.type;
486 if (!property.schema || !property.schema.property) {
489 return validPropertyType === this.property.type && this.property.schema.property.type === property.schema.property.type;
491 if (this.property.schema.property.isDataType && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName){
492 let typeToMatch = (<PropertyDeclareAPIModel> this.property).input.type;
493 let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
494 if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
495 typeToMatch = PROPERTY_TYPES.STRING;
497 return validPropertyType === typeToMatch;
500 return validPropertyType === this.property.type;
503 private getType(propertyPath:string[], type: string): string {
504 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, type);
505 let nestedProperty = dataTypeFound.properties.find(property => property.name === propertyPath[0]);
506 if (propertyPath.length === 1){
507 return nestedProperty.type;
509 return this.getType(propertyPath.slice(1), nestedProperty.type);
512 private isGetProperty(): boolean {
513 return this.functionType === ToscaGetFunctionType.GET_PROPERTY;
516 private isGetAttribute(): boolean {
517 return this.functionType === ToscaGetFunctionType.GET_ATTRIBUTE;
520 private isGetInput(): boolean {
521 return this.functionType === ToscaGetFunctionType.GET_INPUT;
524 private isComplexType(propertyType: string): boolean {
525 return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
528 private typeHasSchema(propertyType: string): boolean {
529 return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType;
532 private stopLoading(): void {
533 this.isLoading = false;
536 private startLoading(): void {
537 this.isLoading = true;
540 showPropertyDropdown(): boolean {
541 if (this.isGetProperty() || this.isGetAttribute()) {
542 return this.propertySource.valid && !this.isLoading && !this.dropDownErrorMsg;
545 return this.functionType && !this.isLoading && !this.dropDownErrorMsg;
548 onPropertySourceChange(): void {
549 this.selectedProperty.reset();
550 this.indexListValues = [];
551 if (!this.functionType || !this.propertySource.valid) {
554 this.loadPropertyDropdown();
557 onPropertyValueChange(): void {
558 let toscaIndexFlag = false;
559 let nestedToscaFlag = false;
560 this.indexListValues = [];
561 let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
562 const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
563 if (this.parentListTypeFlag && selectedProperty.isList) {
564 toscaIndexFlag = true;
565 if (selectedProperty.schemaType != null) {
566 nestedToscaFlag = true;
567 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, selectedProperty.schemaType);
568 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
571 if (toscaIndexFlag || nestedToscaFlag) {
572 let indexValueMap : ToscaIndexObject = {indexFlag : toscaIndexFlag, nestedFlag : nestedToscaFlag, indexValue: "0", indexProperty: null, subPropertyArray: subPropertyDropdownList};
573 this.indexListValues.push(indexValueMap);
575 this.formValidation();
578 onSubPropertyValueChange(indexObject : ToscaIndexObject, elementIndex: number): void {
579 let toscaIndexFlag = false;
580 let nestedToscaFlag = false;
581 let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
582 let selectedProperty: PropertyDropdownValue = indexObject.indexProperty;
583 if (selectedProperty.isList) {
584 toscaIndexFlag = true;
585 if (selectedProperty.schemaType != null) {
586 nestedToscaFlag = true;
587 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, selectedProperty.schemaType);
588 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
591 if (toscaIndexFlag || nestedToscaFlag) {
592 let indexValueMap : ToscaIndexObject = {indexFlag : toscaIndexFlag, nestedFlag : nestedToscaFlag, indexValue: "0", indexProperty: null, subPropertyArray: subPropertyDropdownList};
593 if(!this.indexListValues[elementIndex+1]) {
594 this.indexListValues.push(indexValueMap);
596 this.indexListValues[elementIndex+1] = indexValueMap;
599 if(this.indexListValues[elementIndex+1]) {
600 this.indexListValues.splice((elementIndex+1),1);
603 this.formValidation();
606 indexTokenChange(indexObject : ToscaIndexObject): void {
607 if ((indexObject.indexValue).toLowerCase() === 'index') {
608 this.formValidation();
611 let indexTokenValue = Number(indexObject.indexValue);
612 if (isNaN(indexTokenValue)) {
613 indexObject.indexValue = "0";
614 this.formValidation();
617 this.formValidation();
620 showPropertySourceDropdown(): boolean {
621 return this.isGetProperty() || this.isGetAttribute();
624 private setSelfPropertySource(): void {
625 this.propertySource.setValue(PropertySource.SELF);
628 private get propertySource(): FormControl {
629 return this.formGroup.get('propertySource') as FormControl;
632 private get selectedProperty(): FormControl {
633 return this.formGroup.get('selectedProperty') as FormControl;
638 export interface PropertyDropdownValue {
639 propertyName: string;
641 propertyLabel: string;
642 propertyPath: Array<string>;
647 export interface ToscaIndexObject {
651 indexProperty: PropertyDropdownValue;
652 subPropertyArray: Array<PropertyDropdownValue>;
655 export interface ToscaGetFunctionValidationEvent {
657 toscaGetFunction: ToscaGetFunction,