aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/utils
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2023-01-31 14:24:02 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-02-08 22:19:53 +0000
commitc6cb16f234b8ae9de4aede3ca09a57e6ca177abe (patch)
treef14c9a73bb1f78a928b6a9d6ffe9cee289be947e /catalog-ui/src/app/utils
parent442784e34ef8cae76cca559a600f360dfdeee97e (diff)
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 <javier.paradela.vila@est.tech> Change-Id: I337438ba088e4f2f4978a1aff2408eda8157b892
Diffstat (limited to 'catalog-ui/src/app/utils')
-rw-r--r--catalog-ui/src/app/utils/service-data-type-reader.ts116
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