aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org/onap/policy/drools/protocol
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-07 09:18:12 -0400
committerJim Hahn <jrh3@att.com>2020-04-07 11:59:10 -0400
commit19663843f4fc612f73df8ba970800f2f1a5166a2 (patch)
tree47176d60279a21cd975831b433227917d43de39b /policy-management/src/main/java/org/onap/policy/drools/protocol
parentece155048af47ea83ff898c999aa5137dc99a988 (diff)
Address sonar issues in policy-management
Addressed the following sonar issues: - modified code to specify the correct class name in the getLogger() call - use equals() instead of "==" for string comparison - remove deprecated code - use ',' instead of "," in indexOf - remove code that is commented out; typically bogus, so the comment was adjusted to satisfy sonar - missing assert in junits - use "{}" instead of concatenation when using logger - either log or rethrow - put arguments for assertEquals() in the correct order - remove "return" statements from the end of void methods - don't always return the same value; just disabled sonar as refactoring would have obfuscated the code - cognitive complexity; used eclipse auto-refactoring to extract out chunks of code into separate methods - don't pass array of classes to class.getDeclaredMethod(); use ellided arguments instead - fix argument count in logger calls - remove unnecessary casts - don't use "volatile" - make methods "synchronized" to match parent class definitions Issue-ID: POLICY-2305 Change-Id: Ie96418f696da4ae6c2ca8d4a914371469e695419 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/protocol')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java22
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java11
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java82
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java6
5 files changed, 58 insertions, 69 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java
index cb4ce07e..b16186d6 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GenericEventProtocolCoder.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -150,9 +150,7 @@ abstract class GenericEventProtocolCoder {
}
}
- if (present) {
- return;
- } else {
+ if (!present) {
logger.info("{}: adding coder set for {}: {} ", this, reverseKey, coderTools);
toolsets.add(coderTools);
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java
index ff154fb5..51b28d66 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/GsonProtocolCoderToolset.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory;
* Tools used for encoding/decoding using GSON.
*/
class GsonProtocolCoderToolset extends ProtocolCoderToolset {
+ private static final String CANNOT_FETCH_CLASS = "{}: cannot fetch application class {}";
private static final String FETCH_CLASS_EX_MSG = "cannot fetch application class ";
/**
@@ -174,13 +175,12 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
try {
decoderClass = droolsController.fetchModelClass(decoderFilter.getCodedClass());
if (decoderClass == null) {
- logger.warn("{}: cannot fetch application class {}", this, decoderFilter.getCodedClass());
+ logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getCodedClass());
throw new IllegalStateException(
FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass());
}
} catch (final Exception e) {
- logger.warn("{}: cannot fetch application class {} because of {}", this,
- decoderFilter.getCodedClass(), e.getMessage());
+ logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getCodedClass());
throw new UnsupportedOperationException(
FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass(), e);
}
@@ -192,11 +192,10 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
final Object gsonObject = gsonField.get(null);
final Method fromJsonMethod = gsonObject.getClass().getDeclaredMethod("fromJson",
- new Class[] {String.class, Class.class});
+ String.class, Class.class);
return fromJsonMethod.invoke(gsonObject, json, decoderClass);
} catch (final Exception e) {
- logger.warn("{}: cannot fetch application class {} because of {}", this,
- decoderFilter.getCodedClass(), e.getMessage());
+ logger.warn(CANNOT_FETCH_CLASS, this, decoderFilter.getCodedClass());
throw new UnsupportedOperationException(
FETCH_CLASS_EX_MSG + decoderFilter.getCodedClass(), e);
}
@@ -204,8 +203,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
try {
return this.decoder.fromJson(json, decoderClass);
} catch (final Exception e) {
- logger.warn("{} cannot decode {} into {} because of {}", this, json, decoderClass.getName(),
- e.getMessage(), e);
+ logger.warn("{} cannot decode {} into {}", this, json, decoderClass.getName());
throw new UnsupportedOperationException(
"cannont decode into " + decoderFilter.getCodedClass(), e);
}
@@ -227,17 +225,17 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
final Field gsonField = gsonClassContainer.getField(this.customCoder.staticCoderField);
final Object gsonObject = gsonField.get(null);
final Method toJsonMethod =
- gsonObject.getClass().getDeclaredMethod("toJson", new Class[] {Object.class});
+ gsonObject.getClass().getDeclaredMethod("toJson", Object.class);
return (String) toJsonMethod.invoke(gsonObject, event);
} catch (final Exception e) {
- logger.warn("{} cannot custom-encode {} because of {}", this, event, e.getMessage(), e);
+ logger.warn("{} cannot custom-encode {}", this, event);
throw new UnsupportedOperationException("event cannot be encoded", e);
}
} else {
try {
return this.encoder.toJson(event);
} catch (final Exception e) {
- logger.warn("{} cannot encode {} because of {}", this, event, e.getMessage(), e);
+ logger.warn("{} cannot encode {}", this, event);
throw new UnsupportedOperationException("event cannot be encoded", e);
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
index a4add9ce..8f99f0dd 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,6 @@
package org.onap.policy.drools.protocol.coders;
-import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -66,11 +65,6 @@ public abstract class ProtocolCoderToolset {
protected final List<CoderFilters> coders = new CopyOnWriteArrayList<>();
/**
- * Tree model (instead of class model) generic parsing to be able to inspect elements.
- */
- protected JsonParser filteringParser = new JsonParser();
-
- /**
* custom coder.
*/
protected CustomCoder customCoder;
@@ -287,8 +281,7 @@ public abstract class ProtocolCoderToolset {
builder.append("ProtocolCoderToolset [topic=").append(this.topic).append(", controllerId=")
.append(this.controllerId).append(", groupId=").append(this.groupId).append(", artifactId=")
.append(this.artifactId).append(", coders=").append(this.coders)
- .append(", filteringParser=").append(this.filteringParser).append(", customCoder=")
- .append(this.customCoder).append("]");
+ .append(", customCoder=").append(this.customCoder).append("]");
return builder.toString();
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
index 35a49a1d..2d694530 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/TopicCoderFilterConfiguration.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
* 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.
@@ -44,23 +44,23 @@ public class TopicCoderFilterConfiguration {
public CustomCoder(String rawCustomCoder) {
if (rawCustomCoder != null && !rawCustomCoder.isEmpty()) {
- this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(","));
+ this.className = rawCustomCoder.substring(0, rawCustomCoder.indexOf(','));
if (this.className == null || this.className.isEmpty()) {
throw new IllegalArgumentException(
"No classname to create CustomCoder cannot be created");
}
- this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(",") + 1);
+ this.staticCoderField = rawCustomCoder.substring(rawCustomCoder.indexOf(',') + 1);
if (this.staticCoderField == null || this.staticCoderField.isEmpty()) {
throw new IllegalArgumentException(
"No staticCoderField to create CustomCoder cannot be created for class " + className);
}
}
}
-
+
/**
* Constructor.
- *
+ *
* @param className class name
* @param staticCoderField static coder field
*/
@@ -78,37 +78,37 @@ public class TopicCoderFilterConfiguration {
this.staticCoderField = staticCoderField;
}
- /**
+ /**
* Get class container.
- *
- * @return the className
+ *
+ * @return the className
**/
public String getClassContainer() {
return className;
}
- /**
+ /**
* Set class container.
- *
- * @param className the className to set
+ *
+ * @param className the className to set
**/
public void setClassContainer(String className) {
this.className = className;
}
- /**
+ /**
* Get static coder field.
- *
- * @return the staticCoderField
+ *
+ * @return the staticCoderField
**/
public String getStaticCoderField() {
return staticCoderField;
}
- /**
+ /**
* Set static coder field.
- *
- * @param staticCoderField the staticGson to set
+ *
+ * @param staticCoderField the staticGson to set
**/
public void setStaticCoderField(String staticCoderField) {
this.staticCoderField = staticCoderField;
@@ -154,7 +154,7 @@ public class TopicCoderFilterConfiguration {
/* decoder class (pending from being able to be fetched and found in some class loader) */
protected String codedClass;
- /* filters to apply to the selection of the decodedClass; */
+ /* filters to apply to the selection of the decodedClass */
protected JsonProtocolFilter filter;
/**
@@ -168,36 +168,36 @@ public class TopicCoderFilterConfiguration {
this.filter = filter;
}
- /**
+ /**
* Get coded class.
- *
- * @return the decodedClass
+ *
+ * @return the decodedClass
**/
public String getCodedClass() {
return codedClass;
}
/** Set coded class.
- *
- * @param decodedClass the decodedClass to set
+ *
+ * @param decodedClass the decodedClass to set
**/
public void setCodedClass(String decodedClass) {
this.codedClass = decodedClass;
}
- /**
+ /**
* Get filter.
- *
- * @return the filter
+ *
+ * @return the filter
**/
public JsonProtocolFilter getFilter() {
return filter;
}
- /**
+ /**
* Set filter.
- *
- * @param filter the filter to set
+ *
+ * @param filter the filter to set
**/
public void setFilter(JsonProtocolFilter filter) {
this.filter = filter;
@@ -241,35 +241,35 @@ public class TopicCoderFilterConfiguration {
this.customGsonCoder = customGsonCoder;
}
- /**
+ /**
* Get topic.
- * @return the topic
+ * @return the topic
**/
public String getTopic() {
return topic;
}
/** Get coder filters.
- *
- * @return the decoderFilters
+ *
+ * @return the decoderFilters
**/
public List<PotentialCoderFilter> getCoderFilters() {
return coderFilters;
}
- /**
+ /**
* Get custom gson coder.
- *
- * @return the customGsonCoder
+ *
+ * @return the customGsonCoder
**/
public CustomGsonCoder getCustomGsonCoder() {
return customGsonCoder;
}
- /**
+ /**
* Set custom gson coder.
- *
- * @param customGsonCoder the customGsonCoder to set
+ *
+ * @param customGsonCoder the customGsonCoder to set
**/
public void setCustomGsonCoder(CustomGsonCoder customGsonCoder) {
this.customGsonCoder = customGsonCoder;
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
index d6df0e42..d6504c38 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.
@@ -260,7 +260,7 @@ public class ControllerConfiguration {
*/
public void set(String name, Object value) {
if (!declaredProperty(name, value)) {
- getAdditionalProperties().put(name, (Object) value);
+ getAdditionalProperties().put(name, value);
}
}
@@ -273,7 +273,7 @@ public class ControllerConfiguration {
*/
public ControllerConfiguration with(String name, Object value) {
if (!declaredProperty(name, value)) {
- getAdditionalProperties().put(name, (Object) value);
+ getAdditionalProperties().put(name, value);
}
return this;
}