diff options
Diffstat (limited to 'forwarding')
-rw-r--r-- | forwarding/pom.xml | 7 | ||||
-rw-r--r-- | forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java | 97 |
2 files changed, 103 insertions, 1 deletions
diff --git a/forwarding/pom.xml b/forwarding/pom.xml index d2bcc29e..6a7b123a 100644 --- a/forwarding/pom.xml +++ b/forwarding/pom.xml @@ -30,12 +30,17 @@ <name>${project.artifactId}</name> <description>The module of Policy Distribution that forwards policies to other components.</description> - + <dependencies> <dependency> <groupId>org.onap.policy.distribution</groupId> <artifactId>distribution-model</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.onap.policy.common</groupId> + <artifactId>common-parameters</artifactId> + <version>1.3.0-SNAPSHOT</version> + </dependency> </dependencies> </project> diff --git a/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java b/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java new file mode 100644 index 00000000..3bde5009 --- /dev/null +++ b/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.forwarding.parameters; + +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ValidationStatus; + +/** + * Class to hold all the policy forwarder parameters. + * + * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) + */ +public class PolicyForwarderParameters implements ParameterGroup { + private String forwarderType; + private String forwarderClassName; + + /** + * Constructor for instantiating PolicyForwarderParameters. + * + * @param forwarderType the policy forwarder type + * @param forwarderClassName the policy forwarder class name + */ + public PolicyForwarderParameters(final String forwarderType, final String forwarderClassName) { + this.forwarderType = forwarderType; + this.forwarderClassName = forwarderClassName; + } + + /** + * Return the forwarderType of this PolicyForwarderParameters instance. + * + * @return the forwarderType + */ + public String getForwarderType() { + return forwarderType; + } + + /** + * Return the forwarderClassName of this PolicyForwarderParameters instance. + * + * @return the forwarderClassName + */ + public String getForwarderClassName() { + return forwarderClassName; + } + + @Override + public String getName() { + return null; + } + + /** + * Validate the policy forwarder parameters. + * + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult validationResult = new GroupValidationResult(this); + if (forwarderType == null || forwarderType.trim().length() == 0) { + validationResult.setResult("forwarderType", ValidationStatus.INVALID, "must be a non-blank string"); + } + if (forwarderClassName == null || forwarderClassName.trim().length() == 0) { + validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, + "must be a non-blank string containing full class name of the forwarder"); + } else { + validatePolicyForwarderClass(validationResult); + } + return validationResult; + } + + private void validatePolicyForwarderClass(final GroupValidationResult validationResult) { + try { + Class.forName(forwarderClassName); + } catch (final ClassNotFoundException e) { + validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, + "policy forwarder class not found in classpath"); + } + } +} |