diff options
Diffstat (limited to 'catalog-ui/src/app/utils')
-rw-r--r-- | catalog-ui/src/app/utils/service-data-type-reader.ts | 116 |
1 files changed, 116 insertions, 0 deletions
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(<ConstraintTypes>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 |