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 && 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> = [];
136 if (!isNaN(Number(indexValue)) || indexValue.toLowerCase() === 'index') {
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])
146 if (tempSelectedProperty == null && this.toscaGetFunction.toscaIndexList[index+2]) {
147 tempSelectedProperty = subPropertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.toscaIndexList[index+2])
151 let tempIndexValueMap : ToscaIndexObject = {indexFlag : tempIndexFlag, nestedFlag : tempNestedFlag, indexValue: tempIndexValue, indexProperty: tempSelectedProperty, subPropertyArray: subPropertyDropdownList};
152 this.indexListValues.push(tempIndexValueMap);
164 private buildGetFunctionFromForm() {
165 const toscaGetFunction = new ToscaGetFunction();
166 toscaGetFunction.type = ToscaGetFunctionTypeConverter.convertToToscaFunctionType(this.functionType);
167 toscaGetFunction.functionType = this.functionType;
168 const propertySource = this.propertySource.value;
169 if (this.isPropertySourceSelf()) {
170 toscaGetFunction.propertySource = propertySource
171 toscaGetFunction.sourceName = this.componentMetadata.name;
172 toscaGetFunction.sourceUniqueId = this.componentMetadata.uniqueId;
174 toscaGetFunction.propertySource = PropertySource.INSTANCE;
175 toscaGetFunction.sourceName = propertySource;
176 toscaGetFunction.sourceUniqueId = this.instanceNameAndIdMap.get(propertySource);
179 const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
180 toscaGetFunction.propertyUniqueId = selectedProperty.propertyId;
181 toscaGetFunction.propertyName = selectedProperty.propertyName;
182 toscaGetFunction.propertyPathFromSource = selectedProperty.propertyPath;
183 if (this.indexListValues.length > 0) {
184 let indexAndProperty : Array<string> = [];
185 this.indexListValues.forEach((indexObject : ToscaIndexObject) => {
186 indexAndProperty.push(indexObject.indexValue);
187 if(indexObject.nestedFlag && indexObject.indexProperty != null) {
188 indexAndProperty.push(...indexObject.indexProperty.propertyPath);
191 toscaGetFunction.toscaIndexList = indexAndProperty;
193 return toscaGetFunction;
196 private loadPropertySourceDropdown(): void {
197 if (this.isGetInput()) {
200 this.propertySourceList = [];
201 this.propertySourceList.push(PropertySource.SELF);
202 this.componentInstanceMap.forEach((value, key) => {
203 const instanceName = value.name;
204 this.instanceNameAndIdMap.set(instanceName, key);
205 if (instanceName !== PropertySource.SELF) {
206 this.addToPropertySource(instanceName);
211 private addToPropertySource(source: string): void {
212 this.propertySourceList.push(source);
213 this.propertySourceList.sort((a, b) => {
214 if (a === PropertySource.SELF) {
216 } else if (b === PropertySource.SELF) {
220 return a.localeCompare(b);
224 private formValidation(): void {
225 if (!this.isInitialized) {
228 let formGroupStatus : boolean = this.formGroup.valid;
229 const selectedProperty: PropertyDropdownValue = this.formGroup.value.selectedProperty;
230 if (selectedProperty != null && selectedProperty.isList && formGroupStatus && this.indexListValues.length > 0) {
231 this.indexListValues.forEach((indexObject : ToscaIndexObject, index) => {
232 if (indexObject.indexValue == '') {
233 formGroupStatus = false;
236 if (indexObject.nestedFlag && indexObject.indexProperty == null) {
237 formGroupStatus = false;
242 this.onValidityChange.emit({
243 isValid: formGroupStatus,
244 toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
246 if (this.formGroup.valid) {
247 this.onValidFunction.emit(this.buildGetFunctionFromForm());
251 private loadPropertyDropdown(onComplete?: () => any): void {
252 this.loadPropertyDropdownLabel();
253 this.loadPropertyDropdownValues(onComplete);
256 private resetForm(): void {
257 this.formGroup.reset();
260 private loadPropertyDropdownLabel(): void {
261 if (!this.functionType) {
264 if (this.isGetInput()) {
265 this.dropdownValuesLabel = this.translateService.translate('INPUT_DROPDOWN_LABEL');
266 } else if (this.isGetProperty()) {
267 this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_PROPERTY_DROPDOWN_LABEL');
268 } else if (this.isGetAttribute()) {
269 this.dropdownValuesLabel = this.translateService.translate('TOSCA_FUNCTION_ATTRIBUTE_DROPDOWN_LABEL');
273 private loadPropertyDropdownValues(onComplete?: () => any): void {
274 if (!this.functionType) {
277 this.resetPropertyDropdown();
278 this.fillPropertyDropdownValues(onComplete);
281 private resetPropertyDropdown(): void {
282 this.dropDownErrorMsg = undefined;
283 this.selectedProperty.reset();
284 this.indexListValues = [];
285 this.propertyDropdownList = [];
288 private fillPropertyDropdownValues(onComplete?: () => any): void {
290 const propertiesObservable: Observable<ComponentGenericResponse> = this.getPropertyObservable();
291 propertiesObservable.subscribe( (response: ComponentGenericResponse) => {
292 const properties: Array<PropertyBEModel | AttributeBEModel> = this.extractProperties(response);
293 if (!properties || properties.length === 0) {
294 const msgCode = this.getNotFoundMsgCode();
295 this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.overridingType != undefined ? this.overridingType : this.propertyTypeToString()});
298 this.addPropertiesToDropdown(properties, this.propertyDropdownList);
299 if (this.propertyDropdownList.length == 0) {
300 const msgCode = this.getNotFoundMsgCode();
301 this.dropDownErrorMsg = this.translateService.translate(msgCode, {type: this.overridingType != undefined ? this.overridingType : this.propertyTypeToString()});
304 console.error('An error occurred while loading properties.', error);
314 private getNotFoundMsgCode(): string {
315 if (this.isGetInput()) {
316 return 'TOSCA_FUNCTION_NO_INPUT_FOUND';
318 if (this.isGetAttribute()) {
319 return 'TOSCA_FUNCTION_NO_ATTRIBUTE_FOUND';
321 if (this.isGetProperty()) {
322 return 'TOSCA_FUNCTION_NO_PROPERTY_FOUND';
328 private propertyTypeToString() {
329 if (this.isSubProperty()){
330 if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty)
331 || this.compositionMap) {
332 if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
333 let mapChildProp : DerivedFEProperty = (<DerivedFEProperty> (<PropertyDeclareAPIModel> this.property).input);
334 let propertySchemaType = mapChildProp.type;
335 if (this.property.type == PROPERTY_TYPES.MAP || propertySchemaType == PROPERTY_TYPES.MAP) {
336 if (mapChildProp.mapKey != '' && mapChildProp.mapKey != null && mapChildProp.schema.property.type != null) {
337 propertySchemaType = mapChildProp.schema.property.type;
340 if ((propertySchemaType == PROPERTY_TYPES.MAP || (propertySchemaType == PROPERTY_TYPES.LIST && mapChildProp.schema.property.type == PROPERTY_TYPES.MAP))
341 && mapChildProp.isChildOfListOrMap) {
342 propertySchemaType = PROPERTY_TYPES.STRING;
344 return propertySchemaType;
346 return this.property.schema.property.type;
349 return this.getType((<PropertyDeclareAPIModel>this.property).propertiesName.split("#").slice(1), this.property.type);
351 if (this.property.schemaType) {
352 return `${this.property.type} of ${this.property.schemaType}`;
354 return this.property.type;
357 private isSubProperty(): boolean{
358 return this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName && (<PropertyDeclareAPIModel>this.property).propertiesName.length > 1;
361 private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeBEModel> {
362 if (this.isGetInput()) {
363 return componentGenericResponse.inputs;
365 const instanceId = this.instanceNameAndIdMap.get(this.propertySource.value);
366 if (this.isGetProperty()) {
367 if (this.isPropertySourceSelf()) {
368 return componentGenericResponse.properties;
370 return this.removeSelectedProperty(componentGenericResponse.componentInstancesProperties[instanceId]);
372 if (this.isPropertySourceSelf()) {
373 return [...(componentGenericResponse.attributes || []), ...(componentGenericResponse.properties || [])];
375 return [...(componentGenericResponse.componentInstancesAttributes[instanceId] || []),
376 ...(componentGenericResponse.componentInstancesProperties[instanceId] || [])];
379 private isPropertySourceSelf() {
380 return this.propertySource.value === PropertySource.SELF;
383 private getPropertyObservable(): Observable<ComponentGenericResponse> {
384 if (this.isGetInput()) {
385 return this.topologyTemplateService.getComponentInputsValues(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
387 if (this.isGetProperty()) {
388 if (this.isPropertySourceSelf()) {
389 return this.topologyTemplateService.findAllComponentProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
391 return this.topologyTemplateService.getComponentInstanceProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
393 if (this.isGetAttribute()) {
394 if (this.isPropertySourceSelf()) {
395 return this.topologyTemplateService.findAllComponentAttributesAndProperties(this.componentMetadata.componentType, this.componentMetadata.uniqueId);
397 return this.topologyTemplateService.getComponentInstanceAttributesAndProperties(this.componentMetadata.uniqueId, this.componentMetadata.componentType);
401 private removeSelectedProperty(componentInstanceProperties: PropertyModel[]): PropertyModel[] {
402 if (!componentInstanceProperties) {
405 return componentInstanceProperties.filter(property =>
406 (property.uniqueId !== this.property.uniqueId) ||
407 (property.uniqueId === this.property.uniqueId && property.resourceInstanceUniqueId !== this.property.parentUniqueId)
411 private addPropertyToDropdown(propertyDropdownValue: PropertyDropdownValue, propertyList: Array<PropertyDropdownValue>): void {
412 propertyList.push(propertyDropdownValue);
413 propertyList.sort((a, b) => a.propertyLabel.localeCompare(b.propertyLabel));
416 private addPropertiesToDropdown(properties: Array<PropertyBEModel | AttributeBEModel>, propertyList: Array<PropertyDropdownValue>): void {
417 for (const property of properties) {
418 if (this.hasSameType(property)) {
419 this.addPropertyToDropdown({
420 propertyName: property.name,
421 propertyId: property.uniqueId,
422 propertyLabel: property.name,
423 propertyPath: [property.name],
424 isList: property.type === PROPERTY_TYPES.LIST,
425 schemaType: (property.type === PROPERTY_TYPES.LIST && this.isComplexType(property.schema.property.type)) ? property.schema.property.type : null
427 } else if (this.isComplexType(property.type)) {
428 this.fillPropertyDropdownWithMatchingChildProperties(property,propertyList);
433 private fillPropertyDropdownWithMatchingChildProperties(inputProperty: PropertyBEModel | AttributeBEModel, propertyList: Array<PropertyDropdownValue>,
434 parentPropertyList: Array<PropertyBEModel | AttributeBEModel> = []): void {
435 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, inputProperty.type);
436 if (!dataTypeFound || !dataTypeFound.properties) {
439 parentPropertyList.push(inputProperty);
440 dataTypeFound.properties.forEach(dataTypeProperty => {
441 if (this.hasSameType(dataTypeProperty)) {
442 this.addPropertyToDropdown({
443 propertyName: dataTypeProperty.name,
444 propertyId: parentPropertyList[0].uniqueId,
445 propertyLabel: parentPropertyList.map(property => property.name).join('->') + '->' + dataTypeProperty.name,
446 propertyPath: [...parentPropertyList.map(property => property.name), dataTypeProperty.name],
447 isList : dataTypeProperty.type === PROPERTY_TYPES.LIST,
448 schemaType: (dataTypeProperty.type === PROPERTY_TYPES.LIST && this.isComplexType(dataTypeProperty.schema.property.type)) ? dataTypeProperty.schema.property.type : null
450 } else if (this.isComplexType(dataTypeProperty.type)) {
451 this.fillPropertyDropdownWithMatchingChildProperties(dataTypeProperty, propertyList, [...parentPropertyList])
456 private hasSameType(property: PropertyBEModel | AttributeBEModel): boolean {
457 if (this.overridingType != undefined) {
458 return property.type === this.overridingType;
460 if (this.property.type === PROPERTY_TYPES.ANY) {
463 let validPropertyType = (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST) ? property.schema.property.type : property.type;
464 if (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST && this.isComplexType(validPropertyType)) {
465 let returnFlag : boolean = false;
466 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, validPropertyType);
467 if (dataTypeFound && dataTypeFound.properties) {
468 dataTypeFound.properties.forEach(dataTypeProperty => {
469 if (this.hasSameType(dataTypeProperty)) {
472 if (!returnFlag && this.isComplexType(dataTypeProperty.type)) {
473 const nestedDataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, dataTypeProperty.type);
474 if (nestedDataTypeFound && nestedDataTypeFound.properties) {
475 nestedDataTypeFound.properties.forEach( nestedDateTypeProperty => {
476 if (this.hasSameType(nestedDateTypeProperty)) {
486 if (this.typeHasSchema(this.property.type)) {
487 if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
488 let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
489 let childSchemaType = this.property.schemaType != null ? this.property.schemaType : childObject.type;
490 if(this.isComplexType(childSchemaType) && !this.compositionMap){
491 if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
492 return validPropertyType === PROPERTY_TYPES.STRING;
494 return validPropertyType === childObject.type;
496 return validPropertyType === this.property.schema.property.type;
499 if (!property.schema || !property.schema.property) {
502 return validPropertyType === this.property.type && this.property.schema.property.type === property.schema.property.type;
504 if (this.property.schema.property.isDataType && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName){
505 let typeToMatch = (<PropertyDeclareAPIModel> this.property).input.type;
506 let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
507 if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
508 typeToMatch = PROPERTY_TYPES.STRING;
510 return validPropertyType === typeToMatch;
513 return validPropertyType === this.property.type;
516 private getType(propertyPath:string[], type: string): string {
517 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, type);
518 let nestedProperty = dataTypeFound.properties.find(property => property.name === propertyPath[0]);
519 if (propertyPath.length === 1){
520 return nestedProperty.type;
522 return this.getType(propertyPath.slice(1), nestedProperty.type);
525 private isGetProperty(): boolean {
526 return this.functionType === ToscaGetFunctionType.GET_PROPERTY;
529 private isGetAttribute(): boolean {
530 return this.functionType === ToscaGetFunctionType.GET_ATTRIBUTE;
533 private isGetInput(): boolean {
534 return this.functionType === ToscaGetFunctionType.GET_INPUT;
537 private isComplexType(propertyType: string): boolean {
538 return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
541 private typeHasSchema(propertyType: string): boolean {
542 return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType;
545 private stopLoading(): void {
546 this.isLoading = false;
549 private startLoading(): void {
550 this.isLoading = true;
553 showPropertyDropdown(): boolean {
554 if (this.isGetProperty() || this.isGetAttribute()) {
555 return this.propertySource.valid && !this.isLoading && !this.dropDownErrorMsg;
558 return this.functionType && !this.isLoading && !this.dropDownErrorMsg;
561 onPropertySourceChange(): void {
562 this.selectedProperty.reset();
563 this.indexListValues = [];
564 if (!this.functionType || !this.propertySource.valid) {
567 this.loadPropertyDropdown();
570 onPropertyValueChange(): void {
571 let toscaIndexFlag = false;
572 let nestedToscaFlag = false;
573 this.indexListValues = [];
574 let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
575 const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
576 if (this.parentListTypeFlag && selectedProperty.isList) {
577 toscaIndexFlag = true;
578 if (selectedProperty.schemaType != null) {
579 nestedToscaFlag = true;
580 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, selectedProperty.schemaType);
581 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
584 if (toscaIndexFlag || nestedToscaFlag) {
585 let indexValueMap : ToscaIndexObject = {indexFlag : toscaIndexFlag, nestedFlag : nestedToscaFlag, indexValue: "0", indexProperty: null, subPropertyArray: subPropertyDropdownList};
586 this.indexListValues.push(indexValueMap);
588 this.formValidation();
591 onSubPropertyValueChange(indexObject : ToscaIndexObject, elementIndex: number): void {
592 let toscaIndexFlag = false;
593 let nestedToscaFlag = false;
594 let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
595 let selectedProperty: PropertyDropdownValue = indexObject.indexProperty;
596 if (selectedProperty.isList) {
597 toscaIndexFlag = true;
598 if (selectedProperty.schemaType != null) {
599 nestedToscaFlag = true;
600 const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, selectedProperty.schemaType);
601 this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
604 if (toscaIndexFlag || nestedToscaFlag) {
605 let indexValueMap : ToscaIndexObject = {indexFlag : toscaIndexFlag, nestedFlag : nestedToscaFlag, indexValue: "0", indexProperty: null, subPropertyArray: subPropertyDropdownList};
606 if(!this.indexListValues[elementIndex+1]) {
607 this.indexListValues.push(indexValueMap);
609 this.indexListValues[elementIndex+1] = indexValueMap;
612 if(this.indexListValues[elementIndex+1]) {
613 this.indexListValues.splice((elementIndex+1),1);
616 this.formValidation();
619 indexTokenChange(indexObject : ToscaIndexObject): void {
620 if ((indexObject.indexValue).toLowerCase() === 'index' ) {
621 this.formValidation();
624 const regEx = /^[0-9]*$/;
625 const error = document.getElementById('error');
627 if (!(regEx.test(indexObject.indexValue)) && (indexObject.indexValue).toLowerCase() !== 'index') {
628 error.textContent='Invalid value - must be an integer or INDEX';
629 this.onValidityChange.emit({
631 toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
634 error.textContent='';
635 this.formValidation();
639 showPropertySourceDropdown(): boolean {
640 return this.isGetProperty() || this.isGetAttribute();
643 private setSelfPropertySource(): void {
644 this.propertySource.setValue(PropertySource.SELF);
647 private get propertySource(): FormControl {
648 return this.formGroup.get('propertySource') as FormControl;
651 private get selectedProperty(): FormControl {
652 return this.formGroup.get('selectedProperty') as FormControl;
655 onChangeIndexValue(index: ToscaIndexObject, value: any) {
656 this.indexTokenChange(index);
660 export interface PropertyDropdownValue {
661 propertyName: string;
663 propertyLabel: string;
664 propertyPath: Array<string>;
669 export interface ToscaIndexObject {
673 indexProperty: PropertyDropdownValue;
674 subPropertyArray: Array<PropertyDropdownValue>;
677 export interface ToscaGetFunctionValidationEvent {
679 toscaGetFunction: ToscaGetFunction,