From a05cc62b6426d31c23f60dbe4a6f367331431ea4 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 27 Apr 2021 15:08:59 -0400 Subject: Remove GroupValidationResult Removed GroupValidationResult, replacing it with BeanValidationResult. Modified the ParameterGroup subclasses to use BeanValidator, adding annotations where needed to trigger the validations that had been automatically performed by GroupValidationResult. Issue-ID: POLICY-2059 Change-Id: Ib5c0dc0ac3762e68307e63f5ce29efb49208e55d Signed-off-by: Jim Hahn --- .../parameters/PolicyForwarderParameters.java | 70 ++++------------------ 1 file changed, 13 insertions(+), 57 deletions(-) (limited to 'forwarding') 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 index e5c757b1..bc8041a4 100644 --- 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -21,23 +22,25 @@ package org.onap.policy.distribution.forwarding.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Getter; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; /** * Class to hold all the policy forwarder parameters. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@Getter +@NotBlank public class PolicyForwarderParameters implements ParameterGroup { - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyForwarderParameters.class); - - private String forwarderType; - private String forwarderClassName; + private @NotNull String forwarderType; + private @NotNull @ClassName String forwarderClassName; private String forwarderConfigurationName; /** @@ -54,33 +57,6 @@ public class PolicyForwarderParameters implements ParameterGroup { this.forwarderConfigurationName = forwarderConfigurationName; } - /** - * 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; - } - - /** - * Return the name of the forwarder configuration of this PolicyForwarderParameters instance. - * - * @return the the name of the forwarder configuration - */ - public String getForwarderConfigurationName() { - return forwarderConfigurationName; - } - /** * {@inheritDoc}. */ @@ -101,27 +77,7 @@ public class PolicyForwarderParameters implements ParameterGroup { * {@inheritDoc}. */ @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 exp) { - LOGGER.trace("policy forwarder class not found in classpath", exp); - validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, - "policy forwarder class not found in classpath"); - } + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } -- cgit 1.2.3-korg