diff options
author | 2021-05-04 11:56:38 +0000 | |
---|---|---|
committer | 2021-05-04 11:56:38 +0000 | |
commit | e57a113a469c36f5ca483fe3a8f35bb5fd657691 (patch) | |
tree | b4e9f6e77318e7f8d0ce391e7a5c52f987b31016 /context/context-management | |
parent | e0b224292938634c10aecd17b641a0888065a8b1 (diff) | |
parent | e168ce2fad71650ad730519c772a9b093c0a8f43 (diff) |
Merge "Remove GroupValidationResult"
Diffstat (limited to 'context/context-management')
8 files changed, 74 insertions, 194 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java index 0c68c42a1..75099f6ad 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java @@ -24,7 +24,9 @@ package org.onap.policy.apex.context.impl.schema.java; import com.google.gson.JsonDeserializer; import com.google.gson.JsonSerializer; import com.google.gson.TypeAdapter; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.apache.commons.lang3.StringUtils; +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.ext.XLogger; @@ -145,8 +147,8 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup { * {@inheritDoc}. */ @Override - public GroupValidationResult validate() { - final GroupValidationResult result = new GroupValidationResult(this); + public BeanValidationResult validate() { + final BeanValidationResult result = new BeanValidator().validateTop(getClass().getSimpleName(), this); getClass(ADAPTED_CLASS, adaptedClass, result); @@ -172,7 +174,7 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup { } if (errorMessage != null) { - result.setResult(ADAPTOR_CLASS, ValidationStatus.INVALID, errorMessage); + result.addResult(ADAPTOR_CLASS, adaptorClazz, ValidationStatus.INVALID, errorMessage); } } @@ -186,9 +188,9 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup { * @param classToCheck the class to check for existence * @param result the result of the check */ - private Class<?> getClass(String parameterName, String classToCheck, final GroupValidationResult result) { - if (classToCheck == null || classToCheck.trim().length() == 0) { - result.setResult(parameterName, ValidationStatus.INVALID, "parameter is null or blank"); + private Class<?> getClass(String parameterName, String classToCheck, final BeanValidationResult result) { + if (StringUtils.isBlank(classToCheck)) { + result.addResult(parameterName, classToCheck, ValidationStatus.INVALID, "parameter is null or blank"); return null; } @@ -196,7 +198,8 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup { try { return Class.forName(classToCheck); } catch (final ClassNotFoundException e) { - result.setResult(parameterName, ValidationStatus.INVALID, "class not found: " + e.getMessage()); + result.addResult(parameterName, classToCheck, ValidationStatus.INVALID, + "class not found: " + e.getMessage()); LOGGER.warn("class not found: ", e); return null; } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java index 2c57d4ea9..417a2e8ce 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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. @@ -22,9 +23,9 @@ package org.onap.policy.apex.context.impl.schema.java; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; import org.onap.policy.apex.context.parameters.SchemaHelperParameters; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; /** * The Schema helper parameter class for the Java schema helper is an empty parameter class that acts as a placeholder. @@ -33,7 +34,7 @@ import org.onap.policy.common.parameters.GroupValidationResult; */ public class JavaSchemaHelperParameters extends SchemaHelperParameters { // Map of specific type adapters for this event - private Map<String, JavaSchemaHelperJsonAdapterParameters> jsonAdapters = new LinkedHashMap<>(); + private Map<String, @NotNull @Valid JavaSchemaHelperJsonAdapterParameters> jsonAdapters = new LinkedHashMap<>(); /** * Constructor for Java schema helper parameters. @@ -61,17 +62,4 @@ public class JavaSchemaHelperParameters extends SchemaHelperParameters { this.jsonAdapters = jsonAdapters; } - /** - * {@inheritDoc}. - */ - @Override - public GroupValidationResult validate() { - final GroupValidationResult result = new GroupValidationResult(this); - - for (Entry<String, JavaSchemaHelperJsonAdapterParameters> typeAdapterEntry : jsonAdapters.entrySet()) { - result.setResult("jsonAdapters", typeAdapterEntry.getKey(), typeAdapterEntry.getValue().validate()); - } - return result; - } - } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java index 21b3a5eaf..56b6c8ec4 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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. @@ -20,8 +21,9 @@ package org.onap.policy.apex.context.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; // @formatter:off /** @@ -42,25 +44,19 @@ import org.onap.policy.common.parameters.ParameterGroup; * being used for context album persistence * </ol> */ -// @formatter:on -public class ContextParameters implements ParameterGroup { - // @formatter:off - // Plugin Parameters - private String name; - private DistributorParameters distributorParameters = new DistributorParameters(); - private SchemaParameters schemaParameters = new SchemaParameters(); - private LockManagerParameters lockManagerParameters = new LockManagerParameters(); - private PersistorParameters persistorParameters = new PersistorParameters(); +@NotNull +public class ContextParameters extends ParameterGroupImpl { + private @Valid DistributorParameters distributorParameters = new DistributorParameters(); + private @Valid SchemaParameters schemaParameters = new SchemaParameters(); + private @Valid LockManagerParameters lockManagerParameters = new LockManagerParameters(); + private @Valid PersistorParameters persistorParameters = new PersistorParameters(); // @formatter:on /** * Constructor to create a context parameters instance and register the instance with the parameter service. */ public ContextParameters() { - super(); - - // Set the name for the parameters - this.name = ContextParameterConstants.MAIN_GROUP_NAME; + super(ContextParameterConstants.MAIN_GROUP_NAME); } /** @@ -137,32 +133,8 @@ public class ContextParameters implements ParameterGroup { @Override public String toString() { - return "ContextParameters [name=" + name + ", distributorParameters=" + distributorParameters + return "ContextParameters [name=" + getName() + ", distributorParameters=" + distributorParameters + ", schemaParameters=" + schemaParameters + ", lockManagerParameters=" + lockManagerParameters + ", persistorParameters=" + persistorParameters + "]"; } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(final String name) { - this.name = name; - } - - @Override - public GroupValidationResult validate() { - GroupValidationResult result = new GroupValidationResult(this); - - // @formatter:off - result.setResult("distributorParameters", distributorParameters.validate()); - result.setResult("schemaParameters", schemaParameters.validate()); - result.setResult("lockManagerParameters", lockManagerParameters.validate()); - result.setResult("persistorParameters", persistorParameters.validate()); - // @formatter:on - - return result; - } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java index 8cb6c5916..e1432e6c5 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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,8 +22,9 @@ package org.onap.policy.apex.context.parameters; import org.onap.policy.apex.context.impl.distribution.jvmlocal.JvmLocalDistributor; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotNull; /** * An empty distributor parameter class that may be specialized by context distributor plugins that @@ -31,22 +33,19 @@ import org.onap.policy.common.parameters.ParameterGroup; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class DistributorParameters implements ParameterGroup { +@NotNull +public class DistributorParameters extends ParameterGroupImpl { /** The default distributor makes context albums available to all threads in a single JVM. */ public static final String DEFAULT_DISTRIBUTOR_PLUGIN_CLASS = JvmLocalDistributor.class.getName(); - private String name; - private String pluginClass = DEFAULT_DISTRIBUTOR_PLUGIN_CLASS; + private @ClassName String pluginClass = DEFAULT_DISTRIBUTOR_PLUGIN_CLASS; /** * Constructor to create a distributor parameters instance and register the instance with the * parameter service. */ public DistributorParameters() { - super(); - - // Set the name for the parameters - this.name = ContextParameterConstants.DISTRIBUTOR_GROUP_NAME; + super(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); } /** @@ -69,21 +68,6 @@ public class DistributorParameters implements ParameterGroup { @Override public String toString() { - return "DistributorParameters [name=" + name + ", pluginClass=" + pluginClass + "]"; - } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(final String name) { - this.name = name; - } - - @Override - public GroupValidationResult validate() { - return new GroupValidationResult(this); + return "DistributorParameters [name=" + getName() + ", pluginClass=" + pluginClass + "]"; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java index 2f8aa0d2a..d49adf464 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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,8 +22,9 @@ package org.onap.policy.apex.context.parameters; import org.onap.policy.apex.context.impl.locking.jvmlocal.JvmLocalLockManager; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotNull; /** * An empty lock manager parameter class that may be specialized by context lock manager plugins @@ -31,24 +33,21 @@ import org.onap.policy.common.parameters.ParameterGroup; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class LockManagerParameters implements ParameterGroup { +@NotNull +public class LockManagerParameters extends ParameterGroupImpl { /** * The default lock manager can lock context album instance across all threads in a single JVM. */ public static final String DEFAULT_LOCK_MANAGER_PLUGIN_CLASS = JvmLocalLockManager.class.getName(); - private String name; - private String pluginClass = DEFAULT_LOCK_MANAGER_PLUGIN_CLASS; + private @ClassName String pluginClass = DEFAULT_LOCK_MANAGER_PLUGIN_CLASS; /** * Constructor to create a lock manager parameters instance and register the instance with the * parameter service. */ public LockManagerParameters() { - super(); - - // Set the name for the parameters - this.name = ContextParameterConstants.LOCKING_GROUP_NAME; + super(ContextParameterConstants.LOCKING_GROUP_NAME); } /** @@ -68,24 +67,9 @@ public class LockManagerParameters implements ParameterGroup { public void setPluginClass(final String pluginClass) { this.pluginClass = pluginClass; } - - @Override - public String toString() { - return "LockManagerParameters [name=" + name + ", pluginClass=" + pluginClass + "]"; - } @Override - public String getName() { - return name; - } - - @Override - public void setName(final String name) { - this.name = name; - } - - @Override - public GroupValidationResult validate() { - return new GroupValidationResult(this); + public String toString() { + return "LockManagerParameters [name=" + getName() + ", pluginClass=" + pluginClass + "]"; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java index 3616b526e..98865cd88 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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. @@ -20,8 +21,9 @@ package org.onap.policy.apex.context.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotNull; /** * A persistor parameter class that may be specialized by context persistor plugins that require @@ -36,7 +38,8 @@ import org.onap.policy.common.parameters.ParameterGroup; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class PersistorParameters implements ParameterGroup { +@NotNull +public class PersistorParameters extends ParameterGroupImpl { /** The default persistor is a dummy persistor that stubs the Persistor interface. */ public static final String DEFAULT_PERSISTOR_PLUGIN_CLASS = "org.onap.policy.apex.context.impl.persistence.ephemeral.EphemeralPersistor"; @@ -44,8 +47,7 @@ public class PersistorParameters implements ParameterGroup { /** Default periodic flushing interval, 5 minutes in milliseconds. */ public static final long DEFAULT_FLUSH_PERIOD = 300000; - private String name; - private String pluginClass = DEFAULT_PERSISTOR_PLUGIN_CLASS; + private @ClassName String pluginClass = DEFAULT_PERSISTOR_PLUGIN_CLASS; // Parameters for flushing private long flushPeriod = DEFAULT_FLUSH_PERIOD; @@ -55,10 +57,7 @@ public class PersistorParameters implements ParameterGroup { * parameter service. */ public PersistorParameters() { - super(); - - // Set the name for the parameters - this.name = ContextParameterConstants.PERSISTENCE_GROUP_NAME; + super(ContextParameterConstants.PERSISTENCE_GROUP_NAME); } /** @@ -103,22 +102,7 @@ public class PersistorParameters implements ParameterGroup { @Override public String toString() { - return "PersistorParameters [name=" + name + ", pluginClass=" + pluginClass + ", flushPeriod=" + flushPeriod - + "]"; - } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(final String name) { - this.name = name; - } - - @Override - public GroupValidationResult validate() { - return new GroupValidationResult(this); + return "PersistorParameters [name=" + getName() + ", pluginClass=" + pluginClass + ", flushPeriod=" + + flushPeriod + "]"; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java index e2bb4d6b9..0c6d3592b 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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. @@ -20,8 +21,9 @@ package org.onap.policy.apex.context.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotNull; /** * An empty schema helper parameter class that may be specialized by context schema helper plugins that require plugin @@ -29,9 +31,9 @@ import org.onap.policy.common.parameters.ParameterGroup; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class SchemaHelperParameters implements ParameterGroup { - private String name; - private String schemaHelperPluginClass; +@NotNull +public class SchemaHelperParameters extends ParameterGroupImpl { + private @ClassName String schemaHelperPluginClass; /** * Constructor to create a schema helper parameters instance and register the instance with the parameter service. @@ -57,24 +59,10 @@ public class SchemaHelperParameters implements ParameterGroup { public void setSchemaHelperPluginClass(final String pluginClass) { schemaHelperPluginClass = pluginClass; } - - @Override - public String toString() { - return "SchemaHelperParameters [name=" + name + ", schemaHelperPluginClass=" + schemaHelperPluginClass + "]"; - } - - @Override - public String getName() { - return name; - } @Override - public void setName(final String name) { - this.name = name; - } - - @Override - public GroupValidationResult validate() { - return new GroupValidationResult(this); + public String toString() { + return "SchemaHelperParameters [name=" + getName() + ", schemaHelperPluginClass=" + schemaHelperPluginClass + + "]"; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java index 3f5c26e34..a1dedc5c0 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-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,11 +22,11 @@ package org.onap.policy.apex.context.parameters; import java.util.Map; -import java.util.Map.Entry; import java.util.TreeMap; import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; /** * Bean class holding schema parameters for schemas and their helpers. As more than one schema can be used in Apex @@ -37,23 +38,20 @@ import org.onap.policy.common.parameters.ParameterGroup; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class SchemaParameters implements ParameterGroup { +@NotNull +public class SchemaParameters extends ParameterGroupImpl { /** The Java schema flavour is always available for use. */ public static final String DEFAULT_SCHEMA_FLAVOUR = "Java"; - private String name; // A map of parameters for executors of various logic types - private Map<String, SchemaHelperParameters> schemaHelperParameterMap; + private Map<String, @NotNull @Valid SchemaHelperParameters> schemaHelperParameterMap; /** * Constructor to create a distributor parameters instance and register the instance with the parameter service. */ public SchemaParameters() { - super(); - - // Set the name for the parameters - this.name = ContextParameterConstants.SCHEMA_GROUP_NAME; + super(ContextParameterConstants.SCHEMA_GROUP_NAME); schemaHelperParameterMap = new TreeMap<>(); @@ -88,25 +86,4 @@ public class SchemaParameters implements ParameterGroup { public SchemaHelperParameters getSchemaHelperParameters(final String schemaFlavour) { return schemaHelperParameterMap.get(schemaFlavour); } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(final String name) { - this.name = name; - } - - @Override - public GroupValidationResult validate() { - final GroupValidationResult result = new GroupValidationResult(this); - - for (Entry<String, SchemaHelperParameters> schemaHelperEntry : schemaHelperParameterMap.entrySet()) { - result.setResult("schemaHelperParameterMap", schemaHelperEntry.getKey(), - schemaHelperEntry.getValue().validate()); - } - return result; - } } |