- if (PROPERTY_DATA.SIMPLE_TYPES_COMPARABLE.indexOf(this.selectedProperty.type) === -1) {
- if (this.currentRule.constraintOperator !== ConstraintOperatorType.EQUAL) {
- this.currentRule.constraintOperator = ConstraintOperatorType.EQUAL;
- }
- this.operatorTypes = [new DropdownValue(ConstraintOperatorType.EQUAL, FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.EQUAL))];
- } else {
- const operatorList: DropdownValue[] = [];
- this.allowedOperators.forEach(constraintOperatorType =>
- operatorList.push(new DropdownValue(constraintOperatorType, FilterConstraintHelper.convertToSymbol(constraintOperatorType)))
- );
- this.operatorTypes = operatorList;
- }
- }
-
- private initSelectedSourceType(): void {
- if (!this.currentRule.sourceType || this.currentRule.sourceType === SourceType.STATIC) {
- this.selectedSourceType = SourceType.STATIC;
- } else {
- this.selectedSourceType = SourceType.TOSCA_FUNCTION;
- }
- }
-
- private initCurrentRule(): void {
- if (this.filterConstraint) {
- this.currentRule = new PropertyFilterConstraintUi(this.filterConstraint);
- } else {
- this.currentRule = new PropertyFilterConstraintUi({
- sourceName: SourceType.STATIC,
- sourceType: SourceType.STATIC,
- constraintOperator: ConstraintOperatorType.EQUAL,
- value: undefined
- });
- }
- }
-
- onCapabilityChange(): void {
- this.initPropertyDropdown();
- this.resetSelectedProperty();
- }
-
- onPropertyChange(): void {
- this.currentRule.sourceName = undefined;
- this.currentRule.value = undefined;
- this.onValueChange(false);
- this.updateSelectedProperty();
- this.initConstraintOperatorOptions();
- }
-
- syncRuleData(): void {
- if (!this.currentRule.sourceName || this.currentRule.sourceType === SourceType.STATIC) {
- this.currentRule.sourceName = SourceType.STATIC;
- this.currentRule.sourceType = SourceType.STATIC;
- }
- this.initSelectedProperty();
- this.initConstraintOperatorOptions();
- }
-
- onValueChange(isValidValue:any): void {
- this.currentRule.updateValidity(isValidValue);
- }
-
- checkFormValidForSubmit(): boolean {
- return this.currentRule.isValidRule();
- }
-
- initSelectedProperty(): void {
- if (!this.currentRule.servicePropertyName) {
- this.selectedProperty = undefined;
- return;
- }
- let newProperty;
- if (this.filterType === FilterType.CAPABILITY) {
- const currentProperty = this.capabilityNameAndPropertiesMap.get(this.currentRule.capabilityName)
- .find(property => property.name === this.currentRule.servicePropertyName);
- newProperty = new PropertyFEModel(currentProperty);
- } else {
- newProperty = new PropertyFEModel(this.selectedInstanceProperties.find(property => property.name === this.currentRule.servicePropertyName));
- }
- newProperty.value = undefined;
- newProperty.toscaFunction = undefined;
- if (typeof this.currentRule.value === 'string') {
- newProperty.value = this.currentRule.value;
- this.propertiesUtils.initValueObjectRef(newProperty);
- } else if (ToscaFunctionHelper.isValueToscaFunction(this.currentRule.value)) {
- newProperty.toscaFunction = ToscaFunctionHelper.convertObjectToToscaFunction(this.currentRule.value);
- newProperty.value = newProperty.toscaFunction.buildValueString();
- } else {
- newProperty.value = JSON.stringify(this.currentRule.value);
- this.propertiesUtils.initValueObjectRef(newProperty);
- }
-
- this.selectedProperty = newProperty;
- }
-
- updateSelectedProperty(): void {
- this.selectedProperty = undefined;
- if (!this.currentRule.servicePropertyName) {
- return;
- }
-
- let newProperty;
- if (this.filterType === FilterType.CAPABILITY) {
- const currentProperty = this.capabilityNameAndPropertiesMap.get(this.currentRule.capabilityName)
- .find(property => property.name === this.currentRule.servicePropertyName);
- newProperty = new PropertyFEModel(currentProperty);
- } else {
- newProperty = new PropertyFEModel(this.selectedInstanceProperties.find(property => property.name === this.currentRule.servicePropertyName));
- }
- newProperty.value = undefined;
- newProperty.toscaFunction = undefined;
-
- this.propertiesUtils.initValueObjectRef(newProperty);
- this.selectedProperty = newProperty;
- }
-
- isStaticSource(): boolean {
- return this.selectedSourceType === SourceType.STATIC
- }
-
- isToscaFunctionSource(): boolean {
- return this.selectedSourceType === SourceType.TOSCA_FUNCTION
- }
-
- isComplexListMapType(): boolean {
- return this.selectedProperty && this.selectedProperty.derivedDataType > 0;
- }
-
- updateComplexListMapTypeRuleValue(): void {
- this.currentRule.value = PropertyFEModel.cleanValueObj(this.selectedProperty.valueObj);
- this.onValueChange(this.selectedProperty.valueObjIsValid);
- }
-
- onToscaFunctionValidityChange(validationEvent: ToscaFunctionValidationEvent): void {
- if (validationEvent.isValid && validationEvent.toscaFunction) {
- this.currentRule.value = validationEvent.toscaFunction;
- this.currentRule.sourceType = validationEvent.toscaFunction.type
- if (validationEvent.toscaFunction instanceof ToscaGetFunction) {
- this.currentRule.sourceName = validationEvent.toscaFunction.sourceName;
- }
- } else {
- this.currentRule.updateValidity(false);
- this.currentRule.value = undefined;
- this.currentRule.sourceType = undefined;
- this.currentRule.sourceName = undefined;
+ private setOperatorDropdownValue(constraintOperatorType: ConstraintOperatorType) {
+ if (constraintOperatorType === undefined) {
+ return new DropdownValue(undefined, 'Select a Property');
+ }
+ return new DropdownValue(constraintOperatorType, FilterConstraintHelper.convertToSymbol(constraintOperatorType));
+ }
+
+ private initSelectedSourceType(): void {
+ if (!this.currentRule.sourceType || this.currentRule.sourceType === SourceType.STATIC
+ || (this.currentRule.sourceType === SourceType.SEVERAL && !ToscaFunctionHelper.convertObjectToToscaFunction(this.currentRule.value[0]))) {
+ this.selectedSourceType = SourceType.STATIC;
+ } else {
+ if (!this.isValidValuesOperator() && !this.isRangeType() && !this.isInRangeOperator()) {
+ this.selectedSourceType = SourceType.TOSCA_FUNCTION;
+ } else {
+ this.selectedSourceType = SourceType.TOSCA_FUNCTION_LIST;
+ }
+ }
+ }
+
+ private initCurrentRule(): void {
+ if (this.filterConstraint) {
+ this.currentRule = new PropertyFilterConstraintUi(this.filterConstraint);
+ } else {
+ this.currentRule = new PropertyFilterConstraintUi({
+ sourceName: SourceType.STATIC,
+ sourceType: SourceType.STATIC,
+ constraintOperator: ConstraintOperatorType.EQUAL,
+ value: undefined,
+ originalType: undefined
+ });
+ }
+ let propertyList: PropertyBEModel[] = [];
+ if (this.filterType == FilterType.CAPABILITY) {
+ if (this.currentRule.capabilityName) {
+ propertyList = this.capabilityNameAndPropertiesMap.get(this.currentRule.capabilityName);
+ }
+ } else {
+ propertyList = this.selectedInstanceProperties;
+ }
+ if (this.filterConstraint) {
+ this.filterConstraint.originalType = propertyList.find(prop => prop.name == this.filterConstraint.servicePropertyName).type;
+ }
+ }
+
+ onCapabilityChange(): void {
+ this.initPropertyDropdown();
+ this.resetSelectedProperty();
+ }
+
+ onPropertyChange(): void {
+ this.currentRule.value = undefined;
+ this.onValueChange(false);
+ this.updateSelectedProperty();
+ this.initConstraintOperatorOptions();
+ }
+
+ syncRuleData(): void {
+ if (!this.currentRule.sourceName || this.currentRule.sourceType === SourceType.STATIC) {
+ this.currentRule.sourceName = SourceType.STATIC;
+ this.currentRule.sourceType = SourceType.STATIC;
+ }
+ this.initSelectedProperty();
+ this.initConstraintOperatorOptions();
+ }
+
+ onValueChange(isValidValue: any): void {
+ this.currentRule.updateValidity(isValidValue);
+ }
+
+ checkFormValidForSubmit(): boolean {
+ return this.currentRule.isValidRule();
+ }
+
+ initSelectedProperty(): void {
+ if (!this.currentRule.servicePropertyName) {
+ this.selectedProperty = undefined;
+ return;
+ }
+ let newProperty;
+ if (this.filterType === FilterType.CAPABILITY) {
+ const currentProperty = this.capabilityNameAndPropertiesMap.get(this.currentRule.capabilityName)
+ .find(property => property.name === this.currentRule.servicePropertyName);
+ newProperty = new PropertyFEModel(currentProperty);
+ } else {
+ newProperty = new PropertyFEModel(this.selectedInstanceProperties.find(property => property.name === this.currentRule.servicePropertyName));
+ }
+ newProperty.value = undefined;
+ newProperty.toscaFunction = undefined;
+ if (typeof this.currentRule.value === 'string') {
+ newProperty.value = this.currentRule.value;
+ this.propertiesUtils.initValueObjectRef(newProperty);
+ } else if (ToscaFunctionHelper.isValueToscaFunction(this.currentRule.value)) {
+ newProperty.toscaFunction = ToscaFunctionHelper.convertObjectToToscaFunction(this.currentRule.value);
+ newProperty.value = newProperty.toscaFunction.buildValueString();
+ } else if (Array.isArray(this.currentRule.value)) {
+ if (typeof this.currentRule.value[0] === 'object') {
+ this.rangeToscaFunctionList = [];
+ this.validValuesToscaFunctionList = [];
+ this.currentRule.value.forEach(val => {
+ this.rangeToscaFunctionList.push(ToscaFunctionHelper.convertObjectToToscaFunction(val));
+ this.validValuesToscaFunctionList.push(ToscaFunctionHelper.convertObjectToToscaFunction(val));
+ });
+ newProperty.toscaFunction = this.currentRule.value;
+ newProperty.value = this.currentRule.value;
+ }
+ else {
+ this.validValuesToscaFunctionList = this.currentRule.value;
+ this.rangeToscaFunctionList = this.currentRule.value;
+ newProperty.toscaFunction = this.currentRule.value;
+ }
+ } else {
+ newProperty.value = JSON.stringify(this.currentRule.value);
+ this.propertiesUtils.initValueObjectRef(newProperty);
+ }
+
+ this.selectedProperty = newProperty;
+ this.currentRule.originalType = this.selectedProperty.type;
+ }
+
+ updateSelectedProperty(): void {
+ this.selectedProperty = undefined;
+ if (!this.currentRule.servicePropertyName) {
+ return;
+ }
+
+ let newProperty;
+ if (this.filterType === FilterType.CAPABILITY) {
+ const currentProperty = this.capabilityNameAndPropertiesMap.get(this.currentRule.capabilityName)
+ .find(property => property.name === this.currentRule.servicePropertyName);
+ newProperty = new PropertyFEModel(currentProperty);
+ } else {
+ newProperty = new PropertyFEModel(this.selectedInstanceProperties.find(property => property.name === this.currentRule.servicePropertyName));
+ }
+ newProperty.value = undefined;
+ newProperty.toscaFunction = undefined;
+
+ this.propertiesUtils.initValueObjectRef(newProperty);
+ this.selectedProperty = newProperty;
+ this.currentRule.originalType = this.selectedProperty.type;
+ }
+
+ isStaticSource(): boolean {
+ return this.selectedSourceType === SourceType.STATIC
+ }
+
+ isToscaFunctionSource(): boolean {
+ return this.selectedSourceType === SourceType.TOSCA_FUNCTION
+ }
+
+ isToscaFunctionListSource(): boolean {
+ return this.selectedSourceType === SourceType.TOSCA_FUNCTION_LIST
+ }
+
+ isComplexListMapType(): boolean {
+ return this.selectedProperty && this.selectedProperty.derivedDataType > 0;
+ }
+
+ isRangeType(): boolean {
+ return this.selectedProperty && this.selectedProperty.derivedDataType == 4;
+ }
+
+ isLengthOperator(): boolean {
+ return this.lengthArray.indexOf(this.currentRule.constraintOperator) > -1;
+ }
+
+ isInRangeOperator(): boolean {
+ return this.currentRule.constraintOperator && this.currentRule.constraintOperator === ConstraintOperatorType.IN_RANGE;
+ }
+
+ isValidValuesOperator(): boolean {
+ return this.currentRule.constraintOperator && this.currentRule.constraintOperator === ConstraintOperatorType.VALID_VALUES;
+ }
+
+ updateComplexListMapTypeRuleValue(): void {
+ this.currentRule.value = PropertyFEModel.cleanValueObj(this.selectedProperty.valueObj);
+ this.onValueChange(this.selectedProperty.valueObjIsValid);
+ }
+
+ onToscaFunctionValidityChange(validationEvent: ToscaFunctionValidationEvent): void {
+ if (validationEvent.isValid && validationEvent.toscaFunction) {
+ if (this.isValidValuesOperator()) {
+ this.currentRule.value = this.validValuesToscaFunctionList;
+ this.currentRule.sourceType = SourceType.TOSCA_FUNCTION_LIST;
+ if (validationEvent.toscaFunction instanceof ToscaGetFunction) {
+ this.currentRule.sourceName = SourceType.TOSCA_FUNCTION_LIST;
+ }
+ else if (validationEvent.toscaFunction instanceof ToscaCustomFunction) {
+ this.currentRule.sourceName = SourceType.TOSCA_FUNCTION_LIST;
+ this.currentRule.sourceType = SourceType.TOSCA_FUNCTION_LIST;
+ }
+ } else {
+ if (this.isLengthOperator()) {
+ this.overridingType = PROPERTY_TYPES.INTEGER;
+ }
+ this.currentRule.value = validationEvent.toscaFunction;
+ this.currentRule.sourceType = validationEvent.toscaFunction.type
+ if (validationEvent.toscaFunction instanceof ToscaGetFunction) {
+ this.currentRule.sourceName = validationEvent.toscaFunction.sourceName;
+ }
+ }
+ } else {
+ this.currentRule.updateValidity(false);
+ this.currentRule.value = undefined;
+ this.currentRule.sourceType = undefined;
+ this.currentRule.sourceName = undefined;
+ }