aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-08-26 16:22:12 -0400
committerRam Krishna Verma <ram_krishna.verma@bell.ca>2021-08-26 16:22:19 -0400
commita90a763fa3c9260c3a5e08440ec99e4438852e77 (patch)
treecfc6a1fc63005c81da72c4823948914084e8b6cc
parent83d39d27d8b549f551d45221f764eac90c69cc2c (diff)
Fix sonar issues
Issue-ID: POLICY-3077 Change-Id: I480b97984754ec4b69c6cde6481510fbbf62252e Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java10
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java18
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java6
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java2
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java8
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java8
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java12
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java22
8 files changed, 43 insertions, 43 deletions
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
index c3789b5e3..7c3e4cb01 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
@@ -98,22 +98,22 @@ public class CommandLineCommandTest {
assertEquals(0, commandLineCommand.compareTo(commandLineCommand));
CommandLineCommand otherCommand = new CommandLineCommand();
otherCommand.setSystemCommand(true);
- assertThat(commandLineCommand.compareTo(otherCommand)).isNotZero();
+ assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
otherCommand.getArgumentList().add(new CommandLineArgument("testArgument"));
- assertThat(commandLineCommand.compareTo(otherCommand)).isNotZero();
+ assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
}
@Test
public void testCompareKeywordList() {
CommandLineCommand otherCommand = new CommandLineCommand();
otherCommand.getKeywordlist().add("test");
- assertThat(commandLineCommand.compareTo(otherCommand)).isNotZero();
+ assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
commandLineCommand.getKeywordlist().add("test");
assertEquals(0, commandLineCommand.compareTo(otherCommand));
commandLineCommand.getKeywordlist().add("test2");
- assertThat(commandLineCommand.compareTo(otherCommand)).isNotZero();
+ assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
otherCommand.getKeywordlist().add("test3");
- assertThat(commandLineCommand.compareTo(otherCommand)).isNotZero();
+ assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
}
@Test
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
index 65a253f87..e45c47952 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java
@@ -111,7 +111,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
schemaHelper = new SchemaHelperFactory().createSchemaHelper(albumDefinition.getKey(),
albumDefinition.getItemSchema());
} catch (final ContextRuntimeException e) {
- final String resultString = "could not initiate schema management for context album " + albumDefinition;
+ final var resultString = "could not initiate schema management for context album " + albumDefinition;
LOGGER.warn(resultString, e);
throw new ContextException(resultString, e);
}
@@ -237,7 +237,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
@Override
public Object get(final Object key) {
if (key == null) {
- final String returnString =
+ final var returnString =
ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for get()";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -304,21 +304,21 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
@Override
public Object put(final String key, final Object incomingValue) {
if (key == null) {
- final String returnString =
+ final var returnString =
ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for put()";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
if (incomingValue == null) {
- final String returnString = ALBUM + albumDefinition.getId() + "\" null values are illegal on key \""
+ final var returnString = ALBUM + albumDefinition.getId() + "\" null values are illegal on key \""
+ key + "\" for put()";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
if (!albumDefinition.isWritable()) {
- final String returnString = ALBUM + albumDefinition.getId()
+ final var returnString = ALBUM + albumDefinition.getId()
+ "\" put() not allowed on read only albums for key=\"" + key + "\", value=\"" + incomingValue;
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -342,7 +342,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
// Put the translated value on the map and return the old map value
return albumMap.put(key, valueToPut);
} catch (final ContextRuntimeException e) {
- final String returnString = "Failed to set context value for key \"" + key + "\" in album \""
+ final var returnString = "Failed to set context value for key \"" + key + "\" in album \""
+ albumDefinition.getId() + "\": " + e.getMessage();
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString, e);
@@ -355,7 +355,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
@Override
public void putAll(final Map<? extends String, ? extends Object> incomingContextAlbum) {
if (!albumDefinition.isWritable()) {
- final String returnString =
+ final var returnString =
ALBUM + albumDefinition.getId() + "\" putAll() not allowed on read only albums";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -390,7 +390,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
@Override
public Object remove(final Object key) {
if (!albumDefinition.isWritable()) {
- final String returnString = ALBUM + albumDefinition.getId()
+ final var returnString = ALBUM + albumDefinition.getId()
+ "\" remove() not allowed on read only albums for key=\"" + key + "\"";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -416,7 +416,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA
@Override
public void clear() {
if (!albumDefinition.isWritable()) {
- final String returnString =
+ final var returnString =
ALBUM + albumDefinition.getId() + "\" clear() not allowed on read only albums";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java
index 4d5d01c86..d47ac9ef2 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/AbstractDistributor.java
@@ -143,7 +143,7 @@ public abstract class AbstractDistributor implements Distributor {
// Get the context album definition
final AxContextAlbum album = ModelService.getModel(AxContextAlbums.class).get(axContextAlbumKey);
if (album == null) {
- final String resultString = "context album " + axContextAlbumKey.getId() + " does not exist";
+ final var resultString = "context album " + axContextAlbumKey.getId() + " does not exist";
LOGGER.warn(resultString);
throw new ContextException(resultString);
}
@@ -151,7 +151,7 @@ public abstract class AbstractDistributor implements Distributor {
// Check if the context album is valid
final AxValidationResult result = album.validate(new AxValidationResult());
if (!result.isValid()) {
- final String resultString = "context album definition for " + album.getKey().getId() + " is invalid"
+ final var resultString = "context album definition for " + album.getKey().getId() + " is invalid"
+ result;
LOGGER.warn(resultString);
throw new ContextException(resultString);
@@ -160,7 +160,7 @@ public abstract class AbstractDistributor implements Distributor {
// Get the schema of the context album
final AxContextSchema schema = ModelService.getModel(AxContextSchemas.class).get(album.getItemSchema());
if (schema == null) {
- final String resultString = "schema \"" + album.getItemSchema().getId() + "\" for context album "
+ final var resultString = "schema \"" + album.getItemSchema().getId() + "\" for context album "
+ album.getKey().getId() + " does not exist";
LOGGER.warn(resultString);
throw new ContextException(resultString);
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java
index 3e7e0e8cb..431c38789 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java
@@ -67,7 +67,7 @@ public class DistributorFactory {
// Check the class is a distributor
if (!(contextDistributorObject instanceof Distributor)) {
- final String returnString = "Specified Apex context distributor plugin class \"" + pluginClass
+ final var returnString = "Specified Apex context distributor plugin class \"" + pluginClass
+ "\" does not implement the ContextDistributor interface";
throw new ContextException(returnString);
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
index 2c2388953..97261adde 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java
@@ -85,7 +85,7 @@ public abstract class AbstractSchemaHelper implements SchemaHelper {
@Override
public Object createNewInstance() {
if (schemaClass == null) {
- final String returnString =
+ final var returnString =
userKey.getId() + ": could not create an instance, schema class for the schema is null";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -94,7 +94,7 @@ public abstract class AbstractSchemaHelper implements SchemaHelper {
try {
return schemaClass.getDeclaredConstructor().newInstance();
} catch (final Exception e) {
- final String returnString =
+ final var returnString =
userKey.getId() + ": could not create an instance of class \"" + schemaClass.getName()
+ "\" using the default constructor \"" + schemaClass.getSimpleName() + "()\"";
LOGGER.warn(returnString, e);
@@ -108,7 +108,7 @@ public abstract class AbstractSchemaHelper implements SchemaHelper {
@Override
public Object createNewInstance(final String stringValue) {
if (schemaClass == null) {
- final String returnString =
+ final var returnString =
userKey.getId() + ": could not create an instance, schema class for the schema is null";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
@@ -121,7 +121,7 @@ public abstract class AbstractSchemaHelper implements SchemaHelper {
// Invoke the constructor
return stringConstructor.newInstance(stringValue);
} catch (final Exception e) {
- final String returnString =
+ final var returnString =
userKey.getId() + ": could not create an instance of class \"" + schemaClass.getName()
+ "\" using the string constructor \"" + schemaClass.getSimpleName() + "(String)\"";
LOGGER.warn(returnString, e);
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java
index d1cd3b11b..a5fa26870 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java
@@ -63,7 +63,7 @@ public class SchemaHelperFactory {
// Get the schema for items in the album
final AxContextSchema schema = ModelService.getModel(AxContextSchemas.class).get(schemaKey);
if (schema == null) {
- final String resultString =
+ final var resultString =
"schema \"" + schemaKey.getId() + "\" for entity " + owningEntityKey.getId() + " does not exist";
LOGGER.warn(resultString);
throw new ContextRuntimeException(resultString);
@@ -76,7 +76,7 @@ public class SchemaHelperFactory {
final SchemaHelperParameters schemaHelperParameters =
schemaParameters.getSchemaHelperParameters(schema.getSchemaFlavour());
if (schemaHelperParameters == null) {
- final String resultString = "context schema helper parameters not found for context schema \""
+ final var resultString = "context schema helper parameters not found for context schema \""
+ schema.getSchemaFlavour() + "\"";
LOGGER.warn(resultString);
throw new ContextRuntimeException(resultString);
@@ -88,7 +88,7 @@ public class SchemaHelperFactory {
try {
schemaHelperObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance();
} catch (final Exception e) {
- final String resultString = "Apex context schema helper class not found for context schema helper plugin \""
+ final var resultString = "Apex context schema helper class not found for context schema helper plugin \""
+ pluginClass + "\"";
LOGGER.warn(resultString, e);
throw new ContextRuntimeException(resultString, e);
@@ -96,7 +96,7 @@ public class SchemaHelperFactory {
// Check the class is a schema helper
if (!(schemaHelperObject instanceof SchemaHelper)) {
- final String resultString = "Specified Apex context schema helper plugin class \"" + pluginClass
+ final var resultString = "Specified Apex context schema helper plugin class \"" + pluginClass
+ "\" does not implement the SchemaHelper interface";
LOGGER.warn(resultString);
throw new ContextRuntimeException(resultString);
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
index 43288f40b..7d67788b6 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
@@ -101,14 +101,14 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
}
if (getSchemaClass() == null) {
- final String returnString =
+ final var returnString =
getUserKey().getId() + ": could not create an instance, schema class for the schema is null";
LOGGER.warn(returnString);
throw new ContextRuntimeException(returnString);
}
if (incomingObject instanceof JsonElement) {
- final String elementJsonString = getGson().toJson((JsonElement) incomingObject);
+ final var elementJsonString = getGson().toJson((JsonElement) incomingObject);
return getGson().fromJson(elementJsonString, this.getSchemaClass());
}
@@ -116,7 +116,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
return incomingObject;
}
- final String returnString = getUserKey().getId() + ": the object \"" + incomingObject + "\" of type \""
+ final var returnString = getUserKey().getId() + ": the object \"" + incomingObject + "\" of type \""
+ incomingObject.getClass().getName()
+ "\" is not an instance of JsonObject and is not assignable to \"" + getSchemaClass().getName() + "\"";
LOGGER.warn(returnString);
@@ -163,7 +163,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
// Use Gson to translate the object
return getGson().toJson(schemaObject);
} else {
- final String returnString = getUserKey().getId() + ": object \"" + schemaObject.toString()
+ final var returnString = getUserKey().getId() + ": object \"" + schemaObject.toString()
+ "\" of class \"" + schemaObject.getClass().getName() + "\" not compatible with class \""
+ getSchemaClass().getName() + "\"";
LOGGER.warn(returnString);
@@ -220,7 +220,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
final Constructor<?> stringConstructor = getSchemaClass().getConstructor(String.class);
return stringConstructor.newInstance(object.toString());
} catch (final Exception e) {
- final String returnString = getUserKey().getId() + ": object \"" + object.toString() + "\" of class \""
+ final var returnString = getUserKey().getId() + ": object \"" + object.toString() + "\" of class \""
+ object.getClass().getName() + "\" not compatible with class \"" + getSchemaClass().getName()
+ "\"";
LOGGER.warn(returnString, e);
@@ -253,7 +253,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
try {
adapterObject = jsonAdapterEntry.getAdaptorClazz().getDeclaredConstructor().newInstance();
} catch (Exception e) {
- final String returnString = getUserKey().getId() + ": instantiation of adapter class \""
+ final var returnString = getUserKey().getId() + ": instantiation of adapter class \""
+ jsonAdapterEntry.getAdaptorClass() + "\" to decode and encode class \""
+ jsonAdapterEntry.getAdaptedClass() + "\" failed: " + e.getMessage();
LOGGER.warn(returnString, e);
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java b/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java
index c37323759..9a668e9e0 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/monitoring/ContextMonitor.java
@@ -46,7 +46,7 @@ public class ContextMonitor {
*/
public void monitorInit(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value) {
- String monitorInitString = monitor("INIT", null, albumKey, schemaKey, name, value);
+ var monitorInitString = monitor("INIT", null, albumKey, schemaKey, name, value);
LOGGER.trace(monitorInitString);
}
@@ -61,7 +61,7 @@ public class ContextMonitor {
*/
public void monitorInit(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- String monitorInitString = monitor("INIT", userArtifactStack, albumKey, schemaKey, name, value);
+ var monitorInitString = monitor("INIT", userArtifactStack, albumKey, schemaKey, name, value);
LOGGER.trace(monitorInitString);
}
@@ -76,7 +76,7 @@ public class ContextMonitor {
*/
public void monitorDelete(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- String monitorDeleteString = monitor("DEL", userArtifactStack, albumKey, schemaKey, name, value);
+ var monitorDeleteString = monitor("DEL", userArtifactStack, albumKey, schemaKey, name, value);
LOGGER.trace(monitorDeleteString);
}
@@ -91,7 +91,7 @@ public class ContextMonitor {
*/
public void monitorGet(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- String monitorGetString = monitor("GET", userArtifactStack, albumKey, schemaKey, name, value);
+ var monitorGetString = monitor("GET", userArtifactStack, albumKey, schemaKey, name, value);
LOGGER.trace(monitorGetString);
}
@@ -106,7 +106,7 @@ public class ContextMonitor {
*/
public void monitorSet(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final Object value, final AxConcept[] userArtifactStack) {
- String monitorSetString = monitor("SET", userArtifactStack, albumKey, schemaKey, name, value);
+ var monitorSetString = monitor("SET", userArtifactStack, albumKey, schemaKey, name, value);
LOGGER.trace(monitorSetString);
}
@@ -120,7 +120,7 @@ public class ContextMonitor {
*/
public void monitorReadLock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- String monitorReadLockString = monitor("READLOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ var monitorReadLockString = monitor("READLOCK", userArtifactStack, albumKey, schemaKey, name, null);
LOGGER.trace(monitorReadLockString);
}
@@ -134,7 +134,7 @@ public class ContextMonitor {
*/
public void monitorWriteLock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- String writeLockMonitorString = monitor("WRITELOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ var writeLockMonitorString = monitor("WRITELOCK", userArtifactStack, albumKey, schemaKey, name, null);
LOGGER.trace(writeLockMonitorString);
}
@@ -148,7 +148,7 @@ public class ContextMonitor {
*/
public void monitorReadUnlock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- String monitorReadUnlockString = monitor("READUNLOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ var monitorReadUnlockString = monitor("READUNLOCK", userArtifactStack, albumKey, schemaKey, name, null);
LOGGER.trace(monitorReadUnlockString);
}
@@ -162,7 +162,7 @@ public class ContextMonitor {
*/
public void monitorWriteUnlock(final AxArtifactKey albumKey, final AxArtifactKey schemaKey, final String name,
final AxConcept[] userArtifactStack) {
- String monitorWriteUnlockString = monitor("WRITEUNLOCK", userArtifactStack, albumKey, schemaKey, name, null);
+ var monitorWriteUnlockString = monitor("WRITEUNLOCK", userArtifactStack, albumKey, schemaKey, name, null);
LOGGER.trace(monitorWriteUnlockString);
}
@@ -179,13 +179,13 @@ public class ContextMonitor {
*/
private String monitor(final String preamble, final AxConcept[] userArtifactStack, final AxArtifactKey albumKey,
final AxArtifactKey schemaKey, final String name, final Object value) {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(preamble);
builder.append(",[");
if (userArtifactStack != null) {
- boolean first = true;
+ var first = true;
for (final AxConcept stackKey : userArtifactStack) {
if (first) {
first = false;