Support TOSCA functions in Node Filters
[sdc.git] / catalog-ui / src / app / models / capability-filter-constraint.ts
1 /*
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 *  Copyright (C) 2020 Nordix Foundation. All rights reserved.
6 *  ================================================================================
7 *  Licensed under the Apache License, Version 2.0 (the "License");
8 *  you may not use this file except in compliance with the License.
9 *  You may obtain a copy of the License at
10 *
11 *        http://www.apache.org/licenses/LICENSE-2.0
12 *  Unless required by applicable law or agreed to in writing, software
13 *  distributed under the License is distributed on an "AS IS" BASIS,
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
17 *
18 *  SPDX-License-Identifier: Apache-2.0
19 *  ============LICENSE_END=========================================================
20 */
21
22 export class CapabilityFilterConstraint {
23     capabilityName: string;
24     servicePropertyName: string;
25     constraintOperator: string;
26     sourceType: string;
27     sourceName: string;
28     value: string;
29
30     constructor(input?: any) {
31         if (input) {
32             this.capabilityName = input.capabilityName;
33             this.servicePropertyName = input.servicePropertyName;
34             this.constraintOperator = input.constraintOperator;
35             this.sourceType = input.sourceType;
36             this.sourceName = input.sourceName;
37             this.value = input.value;
38         }
39     }
40 }
41
42 export class CapabilityFilterConstraintUI extends CapabilityFilterConstraint {
43     isValidValue: boolean;
44
45     constructor(input?: any) {
46         super(input);
47         if (input) {
48             this.isValidValue = input.isValidValue ? input.isValidValue : input.value !== '';
49         }
50     }
51
52     public updateValidity(isValidValue: boolean) {
53         this.isValidValue = isValidValue;
54     }
55
56     public isValidRule(isStatic) {
57         const isValidValue = isStatic ? this.isValidValue : true;
58         return this.servicePropertyName != null && this.servicePropertyName !== ''
59             && this.value != null && this.value !== '' && isValidValue;
60     }
61 }