summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/models')
-rw-r--r--catalog-ui/src/app/models/capability-filter-constraint.ts61
-rw-r--r--catalog-ui/src/app/models/filter-constraint.ts17
-rw-r--r--catalog-ui/src/app/models/properties-inputs/property-fe-model.ts5
-rw-r--r--catalog-ui/src/app/models/tosca-concat-function.ts36
-rw-r--r--catalog-ui/src/app/models/tosca-function-parameter.ts1
-rw-r--r--catalog-ui/src/app/models/tosca-function.ts2
-rw-r--r--catalog-ui/src/app/models/tosca-get-function.ts39
-rw-r--r--catalog-ui/src/app/models/tosca-string-parameter.ts11
-rw-r--r--catalog-ui/src/app/models/ui-models/constraint-object-ui.ts26
-rw-r--r--catalog-ui/src/app/models/yaml-function.ts9
10 files changed, 205 insertions, 2 deletions
diff --git a/catalog-ui/src/app/models/capability-filter-constraint.ts b/catalog-ui/src/app/models/capability-filter-constraint.ts
new file mode 100644
index 0000000000..64d9913a54
--- /dev/null
+++ b/catalog-ui/src/app/models/capability-filter-constraint.ts
@@ -0,0 +1,61 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+* ================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+export class CapabilityFilterConstraint {
+ capabilityName: string;
+ servicePropertyName: string;
+ constraintOperator: string;
+ sourceType: string;
+ sourceName: string;
+ value: string;
+
+ constructor(input?: any) {
+ if (input) {
+ this.capabilityName = input.capabilityName;
+ this.servicePropertyName = input.servicePropertyName;
+ this.constraintOperator = input.constraintOperator;
+ this.sourceType = input.sourceType;
+ this.sourceName = input.sourceName;
+ this.value = input.value;
+ }
+ }
+}
+
+export class CapabilityFilterConstraintUI extends CapabilityFilterConstraint {
+ isValidValue: boolean;
+
+ constructor(input?: any) {
+ super(input);
+ if (input) {
+ this.isValidValue = input.isValidValue ? input.isValidValue : input.value !== '';
+ }
+ }
+
+ public updateValidity(isValidValue: boolean) {
+ this.isValidValue = isValidValue;
+ }
+
+ public isValidRule(isStatic) {
+ const isValidValue = isStatic ? this.isValidValue : true;
+ return this.servicePropertyName != null && this.servicePropertyName !== ''
+ && this.value != null && this.value !== '' && isValidValue;
+ }
+}
diff --git a/catalog-ui/src/app/models/filter-constraint.ts b/catalog-ui/src/app/models/filter-constraint.ts
new file mode 100644
index 0000000000..a118c97d7b
--- /dev/null
+++ b/catalog-ui/src/app/models/filter-constraint.ts
@@ -0,0 +1,17 @@
+export class FilterConstraint {
+ servicePropertyName: string;
+ constraintOperator: string;
+ sourceType: string;
+ sourceName: string;
+ value: any;
+
+ constructor(input?: any) {
+ if (input) {
+ this.servicePropertyName = input.servicePropertyName;
+ this.constraintOperator = input.constraintOperator;
+ this.sourceType = input.sourceType;
+ this.sourceName = input.sourceName;
+ this.value = input.value;
+ }
+ }
+}
diff --git a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
index eb18c4e4f9..49baefd4e0 100644
--- a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
+++ b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts
@@ -46,6 +46,9 @@ export class PropertyFEModel extends PropertyBEModel {
constructor(property: PropertyBEModel){
super(property);
+ if (!property) {
+ return;
+ }
this.value = property.value ? property.value : property.defaultValue;//In FE if a property doesn't have value - display the default value
this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
this.setNonDeclared();
@@ -290,7 +293,7 @@ export class PropertyFEModel extends PropertyBEModel {
propertyType !== PROPERTY_TYPES.TIMESTAMP &&
propertyType !== PROPERTY_TYPES.JSON &&
PROPERTY_DATA.SCALAR_TYPES.indexOf(<string>propertyType) == -1) {
- return JSON.parse(value); // the value object contains the real value ans not the value as string
+ return JSON.parse(valueObj); // the value object contains the real value ans not the value as string
}
return valueObj;
}
diff --git a/catalog-ui/src/app/models/tosca-concat-function.ts b/catalog-ui/src/app/models/tosca-concat-function.ts
index 9656d8ddb9..74fe7f6793 100644
--- a/catalog-ui/src/app/models/tosca-concat-function.ts
+++ b/catalog-ui/src/app/models/tosca-concat-function.ts
@@ -22,6 +22,9 @@
import {ToscaFunction} from "./tosca-function";
import {ToscaFunctionType} from "./tosca-function-type.enum";
import {ToscaFunctionParameter} from "./tosca-function-parameter";
+import {ToscaGetFunction} from "./tosca-get-function";
+import {YamlFunction} from "./yaml-function";
+import {ToscaStringParameter} from "./tosca-string-parameter";
export class ToscaConcatFunction implements ToscaFunction, ToscaFunctionParameter {
type = ToscaFunctionType.CONCAT;
@@ -33,6 +36,39 @@ export class ToscaConcatFunction implements ToscaFunction, ToscaFunctionParamete
return;
}
this.value = toscaConcatFunction.value;
+ if (toscaConcatFunction.parameters) {
+ toscaConcatFunction.parameters.forEach(parameter => {
+ switch (parameter.type) {
+ case ToscaFunctionType.GET_INPUT:
+ case ToscaFunctionType.GET_ATTRIBUTE:
+ case ToscaFunctionType.GET_PROPERTY:
+ this.parameters.push(new ToscaGetFunction(<ToscaGetFunction>parameter));
+ break;
+ case ToscaFunctionType.CONCAT:
+ this.parameters.push(new ToscaConcatFunction(<ToscaConcatFunction>parameter));
+ break;
+ case ToscaFunctionType.YAML:
+ this.parameters.push(new YamlFunction(<YamlFunction>parameter));
+ break;
+ case ToscaFunctionType.STRING:
+ this.parameters.push(new ToscaStringParameter(<ToscaStringParameter>parameter));
+ break;
+ default:
+ console.error(`Unsupported parameter type "${parameter.type}"`);
+ this.parameters.push(parameter);
+ }
+ });
+ }
+ }
+
+ public buildValueString(): string {
+ return JSON.stringify(this.buildValueObject());
+ }
+
+ public buildValueObject(): Object {
+ return {
+ [this.type.toLowerCase()]: this.parameters.map(parameter => parameter.buildValueObject())
+ }
}
} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/tosca-function-parameter.ts b/catalog-ui/src/app/models/tosca-function-parameter.ts
index 84c4f0b014..a667543f74 100644
--- a/catalog-ui/src/app/models/tosca-function-parameter.ts
+++ b/catalog-ui/src/app/models/tosca-function-parameter.ts
@@ -24,4 +24,5 @@ import {ToscaFunctionType} from "./tosca-function-type.enum";
export interface ToscaFunctionParameter {
type: ToscaFunctionType;
value: any;
+ buildValueObject(): Object;
} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/tosca-function.ts b/catalog-ui/src/app/models/tosca-function.ts
index ebb024ee7c..8ea2a829a8 100644
--- a/catalog-ui/src/app/models/tosca-function.ts
+++ b/catalog-ui/src/app/models/tosca-function.ts
@@ -24,4 +24,6 @@ import {ToscaFunctionType} from "./tosca-function-type.enum";
export interface ToscaFunction {
type: ToscaFunctionType;
value: any;
+ buildValueString(): string
+ buildValueObject(): Object
} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/tosca-get-function.ts b/catalog-ui/src/app/models/tosca-get-function.ts
index 2386338c98..7e6c5ad739 100644
--- a/catalog-ui/src/app/models/tosca-get-function.ts
+++ b/catalog-ui/src/app/models/tosca-get-function.ts
@@ -23,8 +23,9 @@ import {PropertySource} from "./property-source";
import {ToscaGetFunctionType} from "./tosca-get-function-type";
import {ToscaFunction} from "./tosca-function";
import {ToscaFunctionType} from "./tosca-function-type.enum";
+import {ToscaFunctionParameter} from "./tosca-function-parameter";
-export class ToscaGetFunction implements ToscaFunction {
+export class ToscaGetFunction implements ToscaFunction, ToscaFunctionParameter {
type: ToscaFunctionType;
propertyUniqueId: string;
propertyName: string;
@@ -39,6 +40,8 @@ export class ToscaGetFunction implements ToscaFunction {
if (!toscaGetFunction) {
return;
}
+ this.type = toscaGetFunction.type;
+ this.value = toscaGetFunction.value;
this.propertyUniqueId = toscaGetFunction.propertyUniqueId;
this.propertyName = toscaGetFunction.propertyName;
this.propertySource = toscaGetFunction.propertySource;
@@ -50,4 +53,38 @@ export class ToscaGetFunction implements ToscaFunction {
}
}
+ public buildValueString(): string {
+ return JSON.stringify(this.buildValueObject());
+ }
+
+ public buildValueObject(): Object {
+ if (this.functionType == ToscaGetFunctionType.GET_PROPERTY || this.functionType == ToscaGetFunctionType.GET_ATTRIBUTE) {
+ return this.buildFunctionValueWithPropertySource();
+ }
+ if (this.functionType == ToscaGetFunctionType.GET_INPUT) {
+ return this.buildGetInputFunctionValue();
+ }
+ return undefined;
+ }
+
+ private buildGetInputFunctionValue(): Object {
+ if (this.propertyPathFromSource.length === 1) {
+ return {[this.functionType.toLowerCase()]: this.propertyPathFromSource[0]};
+ }
+ return {[this.functionType.toLowerCase()]: this.propertyPathFromSource};
+ }
+
+ private buildFunctionValueWithPropertySource(): Object {
+ if (this.propertySource == PropertySource.SELF) {
+ return {
+ [this.functionType.toLowerCase()]: [PropertySource.SELF, ...this.propertyPathFromSource]
+ };
+ }
+ if (this.propertySource == PropertySource.INSTANCE) {
+ return {
+ [this.functionType.toLowerCase()]: [this.sourceName, ...this.propertyPathFromSource]
+ };
+ }
+ }
+
} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/tosca-string-parameter.ts b/catalog-ui/src/app/models/tosca-string-parameter.ts
index 0f7423582c..64f6676624 100644
--- a/catalog-ui/src/app/models/tosca-string-parameter.ts
+++ b/catalog-ui/src/app/models/tosca-string-parameter.ts
@@ -25,4 +25,15 @@ import {ToscaFunctionType} from "./tosca-function-type.enum";
export class ToscaStringParameter implements ToscaFunctionParameter {
type: ToscaFunctionType = ToscaFunctionType.STRING;
value: string;
+
+
+ constructor(toscaStringParameter?: ToscaStringParameter) {
+ if (toscaStringParameter) {
+ this.value = toscaStringParameter.value;
+ }
+ }
+
+ buildValueObject(): Object {
+ return this.value;
+ }
} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/ui-models/constraint-object-ui.ts b/catalog-ui/src/app/models/ui-models/constraint-object-ui.ts
new file mode 100644
index 0000000000..48cf2abdc6
--- /dev/null
+++ b/catalog-ui/src/app/models/ui-models/constraint-object-ui.ts
@@ -0,0 +1,26 @@
+import {FilterConstraint} from "../filter-constraint";
+
+export class ConstraintObjectUI extends FilterConstraint {
+ isValidValue: boolean;
+
+ constructor(input?: any) {
+ super(input);
+ if (input) {
+ this.isValidValue = input.isValidValue ? input.isValidValue : input.value !== '';
+ }
+ }
+
+ public updateValidity(isValidValue: boolean) {
+ this.isValidValue = isValidValue;
+ }
+
+ public isValidRule() {
+ const isValidValue = this.isStatic() ? this.isValidValue : true;
+ return this.servicePropertyName != null && this.servicePropertyName !== ''
+ && this.value != null && this.value !== '' && isValidValue;
+ }
+
+ private isStatic() {
+ return this.sourceName === 'static';
+ }
+} \ No newline at end of file
diff --git a/catalog-ui/src/app/models/yaml-function.ts b/catalog-ui/src/app/models/yaml-function.ts
index e80d783424..e992d6bf47 100644
--- a/catalog-ui/src/app/models/yaml-function.ts
+++ b/catalog-ui/src/app/models/yaml-function.ts
@@ -22,6 +22,7 @@
import {ToscaFunction} from "./tosca-function";
import {ToscaFunctionType} from "./tosca-function-type.enum";
import {ToscaFunctionParameter} from "./tosca-function-parameter";
+import * as jsYaml from 'js-yaml';
export class YamlFunction implements ToscaFunction, ToscaFunctionParameter {
type = ToscaFunctionType.YAML;
@@ -34,4 +35,12 @@ export class YamlFunction implements ToscaFunction, ToscaFunctionParameter {
this.value = yamlFunction.value;
}
+ public buildValueObject(): Object {
+ return jsYaml.load(this.value);
+ }
+
+ public buildValueString(): string {
+ return this.value;
+ }
+
} \ No newline at end of file