aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/main
diff options
context:
space:
mode:
authorOren Kleks <orenkle@amdocs.com>2018-10-02 07:40:13 +0000
committerGerrit Code Review <gerrit@onap.org>2018-10-02 07:40:13 +0000
commit1c758acea9ce43fee28b0f8dcffa1234358b42c8 (patch)
tree00aa6918e397c508d717484a05639b246211d3a1 /workflow-designer-be/src/main
parentced52387d2d333d860dbee2fa1ee0a7a0108a960 (diff)
parent73e9794f9996a5f633c7d8597d3bde659b687ed4 (diff)
Merge "Configurable name validation"
Diffstat (limited to 'workflow-designer-be/src/main')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java3
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java65
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java38
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java2
4 files changed, 108 insertions, 0 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java
index fd29fdf3..972e99cc 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java
@@ -18,6 +18,7 @@ package org.onap.sdc.workflow.api.types.activityspec;
import io.swagger.annotations.ApiModel;
import java.util.List;
+import javax.validation.Valid;
import lombok.EqualsAndHashCode;
import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter;
@@ -27,7 +28,9 @@ import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter;
public class ActivitySpecRequest extends ActivitySpecBase {
private String description;
+ @Valid
private List<ActivitySpecParameter> inputs;
+ @Valid
private List<ActivitySpecParameter> outputs;
private String type;
private String content;
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java
new file mode 100644
index 00000000..06818c9d
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.sdc.workflow.api.validation;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component("ActivitySpecParameterNameValidator")
+public class ActivitySpecParameterNameValidator implements ConstraintValidator<ValidName, ActivitySpecParameter> {
+
+ private String validationRegex;
+ private static final String defaultValidationRegex = "^\\S*$";
+ private String validationMessage;
+ private static final String defaultValidationMessage = "Input and Output names must not contain any spaces";
+
+ @Override
+ public boolean isValid(ActivitySpecParameter parameter, ConstraintValidatorContext context) {
+ Pattern pattern = Pattern.compile(validationRegex);
+ Matcher matcher = pattern.matcher(parameter.getName());
+ boolean isValid = matcher.find();
+ if (!isValid) {
+ context.disableDefaultConstraintViolation();
+ context.buildConstraintViolationWithTemplate(validationMessage).addConstraintViolation();
+ }
+ return isValid;
+ }
+
+ @Value("${activitySpec.parameterName.validation:" + defaultValidationRegex + "}")
+ void setValidationRegex(String regex) {
+ if (Objects.isNull(regex) || regex.equals("")) {
+ Objects.requireNonNull(regex);
+ } else {
+ validationRegex = regex;
+ }
+ }
+
+ @Value("${activitySpec.parameterName.validationMessage:" + defaultValidationMessage + "}")
+ void setValidationMessage(String message) {
+ if (Objects.isNull(message) || message.equals("")) {
+ Objects.requireNonNull(message);
+ } else {
+ validationMessage = message;
+ }
+ }
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java
new file mode 100644
index 00000000..2d90aeba
--- /dev/null
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.onap.sdc.workflow.api.validation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+@Target({ElementType.TYPE, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Constraint(validatedBy = {ActivitySpecParameterNameValidator.class})
+public @interface ValidName {
+
+ String message() default "";
+
+ Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
+}
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java
index 3f2562e3..ec1c2681 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java
@@ -19,10 +19,12 @@ package org.onap.sdc.workflow.persistence.types;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
+import org.onap.sdc.workflow.api.validation.ValidName;
@Data
@NoArgsConstructor
@AllArgsConstructor
+@ValidName
public class ActivitySpecParameter {
private String name;