diff options
author | Jim Hahn <jrh3@att.com> | 2021-04-27 15:08:59 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-04-29 14:49:33 -0400 |
commit | a05cc62b6426d31c23f60dbe4a6f367331431ea4 (patch) | |
tree | bb38e4b81c133004ab9541c15db030750957f5f3 /reception/src/main/java/org/onap | |
parent | adfc3ee02f3194a143bcea430e5e3aeb99a23206 (diff) |
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 <jrh3@att.com>
Diffstat (limited to 'reception/src/main/java/org/onap')
3 files changed, 47 insertions, 178 deletions
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java index bd0ad900..c3e44274 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * 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,10 +22,13 @@ package org.onap.policy.distribution.reception.parameters; import java.util.Map; -import java.util.Map.Entry; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Setter; +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.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Size; +import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; /** @@ -32,13 +36,19 @@ import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParamet * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@NotNull public class PluginHandlerParameters implements ParameterGroup { private static final String PLUGIN_HANDLER = "_PluginHandler"; + @Setter private String name; - private Map<String, PolicyDecoderParameters> policyDecoders; - private Map<String, PolicyForwarderParameters> policyForwarders; + + @Size(min = 1) + private Map<String, @NotNull @Valid PolicyDecoderParameters> policyDecoders; + + @Size(min = 1) + private Map<String, @NotNull @Valid PolicyForwarderParameters> policyForwarders; /** * Constructor for instantiating PluginHandlerParameters. @@ -80,36 +90,7 @@ public class PluginHandlerParameters implements ParameterGroup { * */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (policyDecoders == null || policyDecoders.size() == 0) { - validationResult.setResult("policyDecoders", ValidationStatus.INVALID, - "must have at least one policy decoder"); - } else { - for (final Entry<String, PolicyDecoderParameters> nestedGroupEntry : policyDecoders.entrySet()) { - validationResult.setResult("policyDecoders", nestedGroupEntry.getKey(), - nestedGroupEntry.getValue().validate()); - } - } - if (policyForwarders == null || policyForwarders.size() == 0) { - validationResult.setResult("policyForwarders", ValidationStatus.INVALID, - "must have at least one policy forwarder"); - } else { - for (final Entry<String, PolicyForwarderParameters> nestedGroupEntry : policyForwarders.entrySet()) { - validationResult.setResult("policyForwarders", nestedGroupEntry.getKey(), - nestedGroupEntry.getValue().validate()); - } - } - return validationResult; - } - - /** - * Set the name of this group. - * - * @param name the name to set. - */ - @Override - public void setName(final String name) { - this.name = name; + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java index f8ede1a9..492e2e05 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.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,24 @@ package org.onap.policy.distribution.reception.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 decoder parameters. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@Getter +@NotBlank public class PolicyDecoderParameters implements ParameterGroup { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderParameters.class); - - private String decoderType; - private String decoderClassName; + private @NotNull String decoderType; + private @NotNull @ClassName String decoderClassName; private String decoderConfigurationName; /** @@ -55,33 +57,6 @@ public class PolicyDecoderParameters implements ParameterGroup { } /** - * Return the decoderType of this PolicyDecoderParameters instance. - * - * @return the decoderType - */ - public String getDecoderType() { - return decoderType; - } - - /** - * Return the decoderClassName of this PolicyDecoderParameters instance. - * - * @return the decoderClassName - */ - public String getDecoderClassName() { - return decoderClassName; - } - - /** - * Return the name of the decoder configuration of this {@link PolicyDecoderParameters} instance. - * - * @return the the name of the decoder configuration - */ - public String getDecoderConfigurationName() { - return decoderConfigurationName; - } - - /** * {@inheritDoc}. */ @Override @@ -101,27 +76,7 @@ public class PolicyDecoderParameters implements ParameterGroup { * {@inheritDoc}. */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (decoderType == null || decoderType.trim().length() == 0) { - validationResult.setResult("decoderType", ValidationStatus.INVALID, "must be a non-blank string"); - } - if (decoderClassName == null || decoderClassName.trim().length() == 0) { - validationResult.setResult("decoderClassName", ValidationStatus.INVALID, - "must be a non-blank string containing full class name of the decoder"); - } else { - validatePolicyDecoderClass(validationResult); - } - return validationResult; - } - - private void validatePolicyDecoderClass(final GroupValidationResult validationResult) { - try { - Class.forName(decoderClassName); - } catch (final ClassNotFoundException exp) { - LOGGER.trace("policy decoder class not found in classpath", exp); - validationResult.setResult("decoderClassName", ValidationStatus.INVALID, - "policy decoder class not found in classpath"); - } + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java index ea6d8d86..901c4968 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.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,26 +22,30 @@ package org.onap.policy.distribution.reception.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Getter; +import lombok.Setter; +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; +import org.onap.policy.common.parameters.annotations.Valid; /** * Class to hold all the reception handler parameters. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@NotNull +@NotBlank +@Getter public class ReceptionHandlerParameters implements ParameterGroup { - - private static final Logger LOGGER = LoggerFactory.getLogger(ReceptionHandlerParameters.class); - - private String name; + private @Setter String name; private String receptionHandlerType; - private String receptionHandlerClassName; + private @ClassName String receptionHandlerClassName; private String receptionHandlerConfigurationName; - private PluginHandlerParameters pluginHandlerParameters; + private @Valid PluginHandlerParameters pluginHandlerParameters; /** * Constructor for instantiating ReceptionHandlerParameters. @@ -58,42 +63,6 @@ public class ReceptionHandlerParameters implements ParameterGroup { this.pluginHandlerParameters = pluginHandlerParameters; } - /** - * Return the receptionHandlerType of this ReceptionHandlerParameters instance. - * - * @return the receptionHandlerType - */ - public String getReceptionHandlerType() { - return receptionHandlerType; - } - - /** - * Return the receptionHandlerClassName of this ReceptionHandlerParameters instance. - * - * @return the receptionHandlerClassName - */ - public String getReceptionHandlerClassName() { - return receptionHandlerClassName; - } - - /** - * Return the name of the reception handler configuration for this ReceptionHandlerParameters instance. - * - * @return the PssdConfigurationParametersGroup - */ - public String getReceptionHandlerConfigurationName() { - return receptionHandlerConfigurationName; - } - - /** - * Return the pluginHandlerParameters of this ReceptionHandlerParameters instance. - * - * @return the pluginHandlerParameters - */ - public PluginHandlerParameters getPluginHandlerParameters() { - return pluginHandlerParameters; - } - @Override public String getName() { return name + "_" + receptionHandlerType; @@ -104,43 +73,7 @@ public class ReceptionHandlerParameters implements ParameterGroup { * */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (receptionHandlerType == null || receptionHandlerType.trim().length() == 0) { - validationResult.setResult("receptionHandlerType", ValidationStatus.INVALID, "must be a non-blank string"); - } - if (receptionHandlerClassName == null || receptionHandlerClassName.trim().length() == 0) { - validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID, - "must be a non-blank string containing full class name of the reception handler"); - } else { - validateReceptionHandlerClass(validationResult); - } - if (pluginHandlerParameters == null) { - validationResult.setResult("pluginHandlerParameters", ValidationStatus.INVALID, - "must have a plugin handler"); - } else { - validationResult.setResult("pluginHandlerParameters", pluginHandlerParameters.validate()); - } - return validationResult; - } - - private void validateReceptionHandlerClass(final GroupValidationResult validationResult) { - try { - Class.forName(receptionHandlerClassName); - } catch (final ClassNotFoundException exp) { - LOGGER.error("reception handler class not found in classpath", exp); - validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID, - "reception handler class not found in classpath"); - } - } - - /** - * Set the name of this group. - * - * @param name the name to set - */ - @Override - public void setName(final String name) { - this.name = name; + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } |