From fa36daa658a50d9ca2e57cae649d63c0e9e2882a Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Thu, 15 Aug 2019 21:40:16 -0400 Subject: Initial commit of validation framework to APIH Move ListenerRunner to common location Adjust request params name, update junit tests Update validations to work properly Properly escape period for the string split Issue-ID: SO-2232 Signed-off-by: Benjamin, Max (mb388a) Change-Id: Ia468cf7062cccf30e28afeb7a5cddc37ceb2e002 --- common/pom.xml | 5 ++ .../java/org/onap/so/listener/ListenerRunner.java | 56 ++++++++++++++++++++++ .../src/main/java/org/onap/so/listener/Skip.java | 29 +++++++++++ .../so/serviceinstancebeans/RequestParameters.java | 13 ++++- 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/org/onap/so/listener/ListenerRunner.java create mode 100644 common/src/main/java/org/onap/so/listener/Skip.java (limited to 'common') diff --git a/common/pom.xml b/common/pom.xml index a52897170a..2553038e6b 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -186,6 +186,11 @@ ${grpc.version} test + + org.javatuples + javatuples + 1.2 + diff --git a/common/src/main/java/org/onap/so/listener/ListenerRunner.java b/common/src/main/java/org/onap/so/listener/ListenerRunner.java new file mode 100644 index 0000000000..a489be6070 --- /dev/null +++ b/common/src/main/java/org/onap/so/listener/ListenerRunner.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.listener; + +import java.lang.annotation.Annotation; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import javax.annotation.Priority; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; + +public abstract class ListenerRunner { + + @Autowired + protected ApplicationContext context; + + public List filterListeners(List validators, Predicate predicate) { + return validators.stream().filter(item -> { + return !item.getClass().isAnnotationPresent(Skip.class) && predicate.test(item); + }).sorted(Comparator.comparing(item -> { + Priority p = Optional.ofNullable(item.getClass().getAnnotation(Priority.class)).orElse(new Priority() { + public int value() { + return 1000; + } + + @Override + public Class annotationType() { + return Priority.class; + } + }); + return p.value(); + })).collect(Collectors.toList()); + } + +} diff --git a/common/src/main/java/org/onap/so/listener/Skip.java b/common/src/main/java/org/onap/so/listener/Skip.java new file mode 100644 index 0000000000..aa3ec2a204 --- /dev/null +++ b/common/src/main/java/org/onap/so/listener/Skip.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.listener; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Skip { + +} diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java index 9fceed1641..a72229a25c 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java @@ -57,6 +57,9 @@ public class RequestParameters implements Serializable { @JsonProperty("rebuildVolumeGroups") private Boolean rebuildVolumeGroups; + @JsonProperty("enforceValidNfValues") + private Boolean enforceValidNfValues = false; + @Override public String toString() { return new ToStringBuilder(this).append("subscriptionServiceType", subscriptionServiceType) @@ -64,7 +67,15 @@ public class RequestParameters implements Serializable { .append("usePreload", usePreload).append("autoBuildVfModules", autoBuildVfModules) .append("cascadeDelete", cascadeDelete).append("testApi", testApi) .append("retainAssignments", retainAssignments).append("rebuildVolumeGroups", rebuildVolumeGroups) - .toString(); + .append("enforceValidNfValues", enforceValidNfValues).toString(); + } + + public Boolean getEnforceValidNfValues() { + return enforceValidNfValues; + } + + public void setEnforceValidNfValues(Boolean enforceValidNfValues) { + this.enforceValidNfValues = enforceValidNfValues; } public String getSubscriptionServiceType() { -- cgit 1.2.3-korg