summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main
diff options
context:
space:
mode:
authorDavid Brilla <david.brilla@tieto.com>2020-02-12 11:00:39 +0100
committerJames Forsyth <jf2512@att.com>2020-02-21 19:55:35 +0000
commite654645a50a0d028d8e67ea997f84efe8d28a6a0 (patch)
treece460c6da06fc6e33a204b8a68e1bcd471c956df /aai-core/src/main
parent4f436e1378f7ee4533701f5b1766fe04d123cd1c (diff)
AAI-common sonar fixes
Fixing bugs, code smells of aai-common repo found on sonar. Issue-ID: AAI-2786 Change-Id: I421f8b46f385c7334b0f3cd80c07cb2f833f127f Signed-off-by: David Brilla <david.brilla@tieto.com>
Diffstat (limited to 'aai-core/src/main')
-rw-r--r--aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java10
-rw-r--r--aai-core/src/main/java/org/onap/aai/logging/EcompResponseDescription.java13
-rw-r--r--aai-core/src/main/java/org/onap/aai/logging/LoggingContext.java15
-rw-r--r--aai-core/src/main/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertex.java4
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java2
5 files changed, 21 insertions, 23 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java b/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java
index bca4b48c..320d5630 100644
--- a/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java
+++ b/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java
@@ -48,7 +48,7 @@ public class AAIException extends Exception {
public AAIException() {
super();
this.code = DEFAULT_EXCEPTION_CODE;
- this.templateVars = new LinkedList<String>();
+ this.templateVars = new LinkedList<>();
try {
this.errorObject = ErrorLogHelper.getErrorObject(getCode());
@@ -67,7 +67,7 @@ public class AAIException extends Exception {
super();
this.code = code;
- this.templateVars = new LinkedList<String>();
+ this.templateVars = new LinkedList<>();
try {
this.errorObject = ErrorLogHelper.getErrorObject(getCode());
@@ -87,7 +87,7 @@ public class AAIException extends Exception {
super(details);
this.code = code;
- this.templateVars = new LinkedList<String>();
+ this.templateVars = new LinkedList<>();
try {
this.errorObject = ErrorLogHelper.getErrorObject(getCode());
@@ -108,7 +108,7 @@ public class AAIException extends Exception {
super(cause);
this.code = code;
- this.templateVars = new LinkedList<String>();
+ this.templateVars = new LinkedList<>();
try {
this.errorObject = ErrorLogHelper.getErrorObject(getCode());
@@ -129,7 +129,7 @@ public class AAIException extends Exception {
super(details, cause);
this.code = code;
- this.templateVars = new LinkedList<String>();
+ this.templateVars = new LinkedList<>();
try {
this.errorObject = ErrorLogHelper.getErrorObject(getCode());
diff --git a/aai-core/src/main/java/org/onap/aai/logging/EcompResponseDescription.java b/aai-core/src/main/java/org/onap/aai/logging/EcompResponseDescription.java
index 4b2b3b46..b72cc100 100644
--- a/aai-core/src/main/java/org/onap/aai/logging/EcompResponseDescription.java
+++ b/aai-core/src/main/java/org/onap/aai/logging/EcompResponseDescription.java
@@ -22,25 +22,26 @@ package org.onap.aai.logging;
import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
-
import org.onap.aai.logging.LoggingContext.LoggingField;
public class EcompResponseDescription extends ClassicConverter {
- public final static String DefaultDescription = "Unknown response/error description";
+ public static final String DEFAULT_DESCRIPTION = "Unknown response/error description";
@Override
public String convert(ILoggingEvent event) {
if (!event.getMDCPropertyMap().containsKey(LoggingField.RESPONSE_DESCRIPTION.toString())) {
- return (DefaultDescription);
+ return (DEFAULT_DESCRIPTION);
}
// Replace pipes and new lines
String currentDesc = event.getMDCPropertyMap().get(LoggingField.RESPONSE_DESCRIPTION.toString());
if ((currentDesc == null) || (currentDesc.length() == 0)) {
- return (DefaultDescription);
+ return (DEFAULT_DESCRIPTION);
}
- currentDesc = currentDesc.replaceAll("|", "!");
+ currentDesc = currentDesc.replaceAll("\\|", "!");
currentDesc = currentDesc.replaceAll("[\\r\\n]+", "^");
- return event.getMDCPropertyMap().get(LoggingField.RESPONSE_DESCRIPTION.toString());
+ return event.getMDCPropertyMap().get(currentDesc);
}
}
+
+
diff --git a/aai-core/src/main/java/org/onap/aai/logging/LoggingContext.java b/aai-core/src/main/java/org/onap/aai/logging/LoggingContext.java
index f79025a2..5630fd10 100644
--- a/aai-core/src/main/java/org/onap/aai/logging/LoggingContext.java
+++ b/aai-core/src/main/java/org/onap/aai/logging/LoggingContext.java
@@ -34,7 +34,6 @@ import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import org.onap.aai.exceptions.AAIException;
import org.slf4j.MDC;
public class LoggingContext {
@@ -56,7 +55,7 @@ public class LoggingContext {
public static final String BUSINESS_PROCESS_ERROR = "500";
public static final String UNKNOWN_ERROR = "900";
- public static final Map<String, String> responseMap = new HashMap();
+ protected static final Map<String, String> responseMap = new HashMap();
static {
responseMap.put(SUCCESS, "Success");
@@ -64,7 +63,7 @@ public class LoggingContext {
}
// Specific Log Event Fields
- public static enum LoggingField {
+ public enum LoggingField {
START_TIME("startTime"), REQUEST_ID("requestId"), SERVICE_INSTANCE_ID("serviceInstanceId"), SERVER_NAME(
"serverName"), SERVICE_NAME("serviceName"), PARTNER_NAME("partnerName"), STATUS_CODE(
"statusCode"), RESPONSE_CODE("responseCode"), RESPONSE_DESCRIPTION(
@@ -89,6 +88,7 @@ public class LoggingContext {
this.text = text;
}
+ @Override
public String toString() {
return text;
}
@@ -162,7 +162,7 @@ public class LoggingContext {
}
public static String responseCode() {
- return (String) MDC.get(LoggingField.RESPONSE_CODE.toString());
+ return MDC.get(LoggingField.RESPONSE_CODE.toString());
}
public static void responseCode(String responseCode) {
@@ -268,10 +268,7 @@ public class LoggingContext {
public static boolean isStopWatchStarted() {
final String rawStopWatchStart = MDC.get(LoggingField.STOP_WATCH_START.toString());
- if (rawStopWatchStart == null) {
- return false;
- }
- return true;
+ return rawStopWatchStart != null;
}
public static void stopWatchStart() {
@@ -406,7 +403,7 @@ public class LoggingContext {
}
public static Map<String, String> getCopy() {
- final Map<String, String> copy = new HashMap<String, String>();
+ final Map<String, String> copy = new HashMap<>();
for (LoggingField field : LoggingField.values()) {
final String value = MDC.get(field.toString());
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertex.java b/aai-core/src/main/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertex.java
index c2856a77..700005ac 100644
--- a/aai-core/src/main/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertex.java
+++ b/aai-core/src/main/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertex.java
@@ -39,8 +39,8 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
public class TreeBackedVertex extends DetachedVertex implements Vertex {
private static final long serialVersionUID = -976854460992756953L;
- private final Tree<Element> tree;
- private final Vertex self;
+ private final transient Tree<Element> tree;
+ private final transient Vertex self;
public TreeBackedVertex(Vertex v, Tree<Element> tree) {
super(v, true);
diff --git a/aai-core/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java b/aai-core/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java
index fef10a77..a41ad27b 100644
--- a/aai-core/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java
+++ b/aai-core/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java
@@ -55,7 +55,7 @@ public class HbaseSaltPrefixer {
* @return the string
*/
public String prependSalt(String key) {
- int salt = Math.abs(key.hashCode()) % NUM_REGION_BUCKETS;
+ int salt = key.hashCode() % NUM_REGION_BUCKETS;
return salt + "-" + key;
}
}