aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintPattern.java49
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java14
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java6
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/constraints/constraints.component.ts8
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java1
6 files changed, 83 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index 90a5161f7a..f1c8a17108 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -52,6 +52,7 @@ import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.PatternConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.DataTypePropertyConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter;
@@ -69,6 +70,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessOrEqual;
import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessThan;
import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMaxLength;
import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMinLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintPattern;
import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintValidValues;
import org.openecomp.sdc.be.tosca.model.ToscaSchemaDefinition;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -173,6 +175,9 @@ public class PropertyConvertor {
if (constraint instanceof MaxLengthConstraint) {
convertedConstraints.add(new ToscaPropertyConstraintMaxLength(((MaxLengthConstraint) constraint).getMaxLength()));
}
+ if (constraint instanceof PatternConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintPattern(((PatternConstraint) constraint).getPattern()));
+ }
}
return convertedConstraints;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintPattern.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintPattern.java
new file mode 100644
index 0000000000..7008d690b9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintPattern.java
@@ -0,0 +1,49 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintPattern implements ToscaPropertyConstraint {
+
+ private String pattern;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.PATTERN;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("pattern".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index b54b401eb0..dc97e25af1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -100,6 +100,7 @@ import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.PatternConstraint;
import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.be.model.validation.ToscaFunctionValidator;
@@ -2300,6 +2301,16 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
log.warn("The value of max length constraint is null");
}
break;
+ case PATTERN:
+ if (value != null) {
+ String asString = value.getAsString();
+ log.debug("Before adding value to PatternConstraint object. value = {}", asString);
+ propertyConstraint = new PatternConstraint(asString);
+ break;
+ } else {
+ log.warn("The value of pattern constraint is null");
+ }
+ break;
default:
log.warn("Key {} is not supported. Ignored.", key);
}
@@ -2360,6 +2371,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
case MAX_LENGTH:
propertyConstraint = deserializeConstraintWithIntegerOperand(value, MaxLengthConstraint.class);
break;
+ case PATTERN:
+ propertyConstraint = deserializeConstraintWithStringOperand(value, PatternConstraint.class);
+ break;
default:
log.warn("Key {} is not supported. Ignored.", field.getKey());
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java
index be4805bc87..1ee96311ec 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/PatternConstraint.java
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.model.tosca.constraints;
import java.util.regex.Pattern;
import javax.validation.constraints.NotNull;
+import lombok.NoArgsConstructor;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.tosca.ToscaType;
@@ -29,6 +30,7 @@ import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolatio
import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
import lombok.Getter;
+@NoArgsConstructor
public class PatternConstraint extends AbstractStringPropertyConstraint {
@NotNull
@@ -36,6 +38,10 @@ public class PatternConstraint extends AbstractStringPropertyConstraint {
private String pattern;
private Pattern compiledPattern;
+ public PatternConstraint(String pattern) {
+ setPattern(pattern);
+ }
+
public void setPattern(String pattern) {
this.pattern = pattern;
this.compiledPattern = Pattern.compile(this.pattern);
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/constraints/constraints.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/constraints/constraints.component.ts
index 2e56ce1580..831732dcf5 100644
--- a/catalog-ui/src/app/ng2/pages/properties-assignment/constraints/constraints.component.ts
+++ b/catalog-ui/src/app/ng2/pages/properties-assignment/constraints/constraints.component.ts
@@ -170,6 +170,14 @@ export class ConstraintsComponent implements OnInit {
if (Array.isArray(constraint.value)) {
return !(constraint.value.length == 0 || this.doesArrayContaintEmptyValues(constraint.value));
}
+ if (constraint.type == ConstraintTypes.pattern) {
+ try {
+ new RegExp(constraint.value);
+ this.valid = true;
+ } catch(e) {
+ this.valid = false;
+ }
+ }
return constraint.value && constraint.type != ConstraintTypes.null
});
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java
index cef310ea01..80672b6d73 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ConstraintType.java
@@ -39,6 +39,7 @@ public enum ConstraintType {
MAX_LENGTH("max_length", "maxLength"),
VALID_VALUES("valid_values", "validValues"),
LESS_THAN("less_than", "lessThan"),
+ PATTERN("pattern"),
SCHEMA("schema");
private static final Set<ConstraintType> comparableConstraints = Set.of(ConstraintType.GREATER_THAN, ConstraintType.LESS_THAN);