From c6cb16f234b8ae9de4aede3ca09a57e6ca177abe Mon Sep 17 00:00:00 2001 From: franciscovila Date: Tue, 31 Jan 2023 14:24:02 +0000 Subject: Constraints in data type view Develop all necessary changes in the UI to allow managing data type constraints Issue-ID: SDC-4331 Signed-off-by: franciscovila Change-Id: I337438ba088e4f2f4978a1aff2408eda8157b892 --- .../src/app/utils/service-data-type-reader.ts | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'catalog-ui/src/app/utils') diff --git a/catalog-ui/src/app/utils/service-data-type-reader.ts b/catalog-ui/src/app/utils/service-data-type-reader.ts index 99b3d3ae63..9686f3d40e 100644 --- a/catalog-ui/src/app/utils/service-data-type-reader.ts +++ b/catalog-ui/src/app/utils/service-data-type-reader.ts @@ -19,6 +19,7 @@ */ import {DataTypeModel, PropertyBEModel} from "../models"; +import {Constraint, ConstraintTypes} from "../ng2/pages/properties-assignment/constraints/constraints.component"; import {load} from 'js-yaml'; export class ServiceDataTypeReader { @@ -81,8 +82,123 @@ export class ServiceDataTypeReader { property.type = properties[key]["type"]; property.schemaType = properties[key]["schema"]; property.required = properties[key]["required"]; + const constraints = properties[key]["constraints"]; + + if (constraints) { + property.constraints = new Array(); + let constraintArray = new Array(); + Object.keys(constraints).forEach((constrainKey) => { + Object.keys(constraints[constrainKey]).forEach((kc) => { + let newConstraint = this.mapValuesToConstraint(kc, constraints[constrainKey][kc]); + let jsonObject = this.getConstraintFormat(newConstraint); + constraintArray.push(jsonObject); + + }); + }); + property.constraints.push(constraintArray); + } this.serviceDataType.properties.push(property); } ); } + + private getConstraintFormat(constraint: Constraint): any { + switch (constraint.type) { + case ConstraintTypes.equal: + return { + [ConstraintTypes.equal]: constraint.value + } + case ConstraintTypes.less_or_equal: + return { + [ConstraintTypes.less_or_equal]: constraint.value + } + case ConstraintTypes.less_than: + return { + [ConstraintTypes.less_than]: constraint.value + } + case ConstraintTypes.greater_or_equal: + return { + [ConstraintTypes.greater_or_equal]: constraint.value + } + case ConstraintTypes.greater_than: + return { + [ConstraintTypes.greater_than]: constraint.value + } + case ConstraintTypes.in_range: + return { + [ConstraintTypes.in_range]: constraint.value + } + case ConstraintTypes.length: + return { + [ConstraintTypes.length]: constraint.value + } + case ConstraintTypes.max_length: + return { + [ConstraintTypes.max_length]: constraint.value + } + case ConstraintTypes.min_length: + return { + [ConstraintTypes.min_length]: constraint.value + } + case ConstraintTypes.pattern: + return { + [ConstraintTypes.pattern]: constraint.value + } + case ConstraintTypes.valid_values: + return { + [ConstraintTypes.valid_values]: constraint.value + } + default: + return; + } + } + + private mapValuesToConstraint(type: string, value: any):Constraint { + let constraintType: ConstraintTypes; + let constraintValue: any; + if (!type) { + constraintType = ConstraintTypes.null; + constraintValue = ""; + } else if(type === "valid_values"){ + constraintType = ConstraintTypes.valid_values; + constraintValue = value; + } else if(type === "equal") { + constraintType = ConstraintTypes.equal; + constraintValue = value; + } else if(type === "greater_than") { + constraintType = ConstraintTypes.greater_than; + constraintValue = value; + } else if(type === "greater_or_equal") { + constraintType = ConstraintTypes.greater_or_equal; + constraintValue = value; + } else if(type === "less_than") { + constraintType = ConstraintTypes.less_than; + constraintValue = value; + } else if(type === "less_or_equal") { + constraintType = ConstraintTypes.less_or_equal; + constraintValue = value; + } else if(type === "in_range") { + constraintType = ConstraintTypes.in_range; + constraintValue = value; + } else if(type === "range_max_value" || type === "range_min_value") { + constraintType = ConstraintTypes.in_range; + constraintValue = value; + } else if(type === "length") { + constraintType = ConstraintTypes.length; + constraintValue = value; + } else if(type === "min_length") { + constraintType = ConstraintTypes.min_length; + constraintValue = value; + } else if(type === "max_length") { + constraintType = ConstraintTypes.max_length; + constraintValue = value; + } else if(type === "pattern") { + constraintType = ConstraintTypes.pattern; + constraintValue = value; + } + return { + type:constraintType, + value:constraintValue + } + } } \ No newline at end of file -- cgit 1.2.3-korg