aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZlatko Murgoski <zlatko.murgoski@nokia.com>2019-01-14 11:24:22 +0100
committerZlatko Murgoski <zlatko.murgoski@nokia.com>2019-01-29 09:50:05 +0100
commit038e80074e8ad5f466690aef436034fcda0eeab3 (patch)
treea58263115206f927c31c91b29d8a069c4e7880eb
parent7ab93201e557976ed8b383cb5652fa129d7b36f7 (diff)
Fix sonar violation
Fix sonar violation Issue-ID: DCAEGEN2-1016 Signed-off-by: Zlatko Murgoski <zlatko.murgoski@nokia.com> Change-Id: I0db722972aeeb57ebb4b61b11f1e302f613890d5
-rw-r--r--src/main/java/org/onap/dcae/ApplicationException.java40
-rw-r--r--src/main/java/org/onap/dcae/ApplicationSettings.java27
-rw-r--r--src/main/java/org/onap/dcae/VesApplication.java2
-rw-r--r--src/main/java/org/onap/dcae/common/AnyNode.java2
-rw-r--r--src/main/java/org/onap/dcae/common/publishing/DMaaPEventPublisher.java4
-rw-r--r--src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java2
-rw-r--r--src/main/java/org/onap/dcae/controller/ConfigLoader.java2
-rw-r--r--src/main/java/org/onap/dcae/controller/ConfigSource.java9
-rw-r--r--src/main/java/org/onap/dcae/restapi/ServletConfig.java3
-rw-r--r--src/main/java/org/onap/dcae/restapi/VesRestController.java3
10 files changed, 67 insertions, 27 deletions
diff --git a/src/main/java/org/onap/dcae/ApplicationException.java b/src/main/java/org/onap/dcae/ApplicationException.java
new file mode 100644
index 00000000..2079d867
--- /dev/null
+++ b/src/main/java/org/onap/dcae/ApplicationException.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PROJECT
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 Nokia. All rights reserved.s
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcae;
+
+import java.io.IOException;
+import org.apache.commons.configuration.ConfigurationException;
+
+public class ApplicationException extends RuntimeException {
+
+ public ApplicationException(ConfigurationException ex) {
+ super(ex);
+ }
+
+ public ApplicationException(String message, Exception ex) {
+ super(message,ex);
+ }
+
+ public ApplicationException(IOException ex) {
+ super(ex);
+ }
+}
diff --git a/src/main/java/org/onap/dcae/ApplicationSettings.java b/src/main/java/org/onap/dcae/ApplicationSettings.java
index f140def2..7d52c5e8 100644
--- a/src/main/java/org/onap/dcae/ApplicationSettings.java
+++ b/src/main/java/org/onap/dcae/ApplicationSettings.java
@@ -21,6 +21,10 @@
package org.onap.dcae;
+import static io.vavr.API.Tuple;
+import static java.lang.String.format;
+import static java.nio.file.Files.readAllBytes;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
@@ -32,23 +36,16 @@ import io.vavr.Tuple2;
import io.vavr.collection.HashMap;
import io.vavr.collection.List;
import io.vavr.collection.Map;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import javax.annotation.Nullable;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nullable;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Base64;
-
-import static io.vavr.API.Tuple;
-import static java.lang.String.format;
-import static java.nio.file.Files.readAllBytes;
-import static java.util.Arrays.stream;
-
/**
* Abstraction over application configuration.
* Its job is to provide easily discoverable (by method names lookup) and type safe access to configuration properties.
@@ -72,7 +69,7 @@ public class ApplicationSettings {
Map<String, String> parsedArgs = argsParser.apply(args);
configurationFileLocation = findOutConfigurationFileLocation(parsedArgs);
loadPropertiesFromFile();
- parsedArgs.filterKeys(k -> !k.equals("c")).forEach(this::updateProperty);
+ parsedArgs.filterKeys(k -> !"c".equals(k)).forEach(this::updateProperty);
loadedJsonSchemas = loadJsonSchemas();
}
@@ -81,7 +78,7 @@ public class ApplicationSettings {
properties.load(configurationFileLocation);
} catch (ConfigurationException ex) {
log.error("Cannot load properties cause:", ex);
- throw new RuntimeException(ex);
+ throw new ApplicationException(ex);
}
}
@@ -124,7 +121,7 @@ public class ApplicationSettings {
private Map<String, JsonSchema> loadJsonSchemas() {
return jsonSchema().toMap().entrySet().stream()
- .map(versionToFilePath -> readSchemaForVersion(versionToFilePath))
+ .map(this::readSchemaForVersion)
.collect(HashMap.collector());
}
@@ -136,7 +133,7 @@ public class ApplicationSettings {
JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(schemaNode);
return Tuple(versionToFilePath.getKey(), schema);
} catch (IOException | ProcessingException e) {
- throw new RuntimeException("Could not read schema from path: " + versionToFilePath.getValue(), e);
+ throw new ApplicationException("Could not read schema from path: " + versionToFilePath.getValue(), e);
}
}
diff --git a/src/main/java/org/onap/dcae/VesApplication.java b/src/main/java/org/onap/dcae/VesApplication.java
index 48ac6b88..2dcd8fa8 100644
--- a/src/main/java/org/onap/dcae/VesApplication.java
+++ b/src/main/java/org/onap/dcae/VesApplication.java
@@ -86,7 +86,7 @@ public class VesApplication {
Paths.get(properties.dMaaPConfigurationFileLocation()),
properties.configurationFileLocation());
scheduledThreadPoolExecutor
- .scheduleAtFixedRate(() -> configLoader.updateConfig(),
+ .scheduleAtFixedRate(configLoader::updateConfig,
properties.configurationUpdateFrequency(),
properties.configurationUpdateFrequency(),
TimeUnit.MINUTES);
diff --git a/src/main/java/org/onap/dcae/common/AnyNode.java b/src/main/java/org/onap/dcae/common/AnyNode.java
index a68e6299..d55cb1ea 100644
--- a/src/main/java/org/onap/dcae/common/AnyNode.java
+++ b/src/main/java/org/onap/dcae/common/AnyNode.java
@@ -82,7 +82,7 @@ public class AnyNode {
public Option<AnyNode> getAsOption(String key) {
try {
AnyNode value = get(key);
- if (value.toString().equals("null")) {
+ if ("null".equals(value.toString())) {
return Option.none();
}
return Option.some(value);
diff --git a/src/main/java/org/onap/dcae/common/publishing/DMaaPEventPublisher.java b/src/main/java/org/onap/dcae/common/publishing/DMaaPEventPublisher.java
index aa3dc7a3..b00b2744 100644
--- a/src/main/java/org/onap/dcae/common/publishing/DMaaPEventPublisher.java
+++ b/src/main/java/org/onap/dcae/common/publishing/DMaaPEventPublisher.java
@@ -46,9 +46,9 @@ class DMaaPEventPublisher implements EventPublisher {
private final DMaaPPublishersCache publishersCache;
private final Logger outputLogger;
- DMaaPEventPublisher(DMaaPPublishersCache DMaaPPublishersCache,
+ DMaaPEventPublisher(DMaaPPublishersCache publishersCache,
Logger outputLogger) {
- this.publishersCache = DMaaPPublishersCache;
+ this.publishersCache = publishersCache;
this.outputLogger = outputLogger;
}
diff --git a/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java b/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java
index c83db2df..0b2c197d 100644
--- a/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java
+++ b/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java
@@ -53,7 +53,7 @@ class ConfigFilesFacade {
Try<Map<String, String>> readCollectorProperties() {
log.info(f("Reading collector properties from path: '%s'", propertiesPath));
- return Try(() -> readProperties())
+ return Try(this::readProperties)
.map(prop -> toList(prop.getKeys()).toMap(k -> k, k -> (String) prop.getProperty(k)))
.mapFailure(enhanceError("Unable to read properties configuration from path '%s'", propertiesPath))
.onFailure(logError(log))
diff --git a/src/main/java/org/onap/dcae/controller/ConfigLoader.java b/src/main/java/org/onap/dcae/controller/ConfigLoader.java
index c1ac65d2..e11c2b8a 100644
--- a/src/main/java/org/onap/dcae/controller/ConfigLoader.java
+++ b/src/main/java/org/onap/dcae/controller/ConfigLoader.java
@@ -68,7 +68,7 @@ public class ConfigLoader {
log.info("Trying to dynamically update config from Config Binding Service");
readEnvProps(envVariablesSupplier.get())
.onEmpty(() -> log.warn(SKIP_MSG))
- .forEach(props -> updateConfig(props));
+ .forEach(this::updateConfig);
}
private void updateConfig(EnvProps props) {
diff --git a/src/main/java/org/onap/dcae/controller/ConfigSource.java b/src/main/java/org/onap/dcae/controller/ConfigSource.java
index 68dc2501..a9e439e4 100644
--- a/src/main/java/org/onap/dcae/controller/ConfigSource.java
+++ b/src/main/java/org/onap/dcae/controller/ConfigSource.java
@@ -26,6 +26,7 @@ import static org.onap.dcae.common.publishing.VavrUtils.f;
import static org.onap.dcae.controller.Conversions.toJson;
import static org.onap.dcae.controller.Conversions.toJsonArray;
+import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.vavr.control.Try;
import org.json.JSONArray;
@@ -41,11 +42,11 @@ final class ConfigSource {
log.info("Fetching app configuration from CBS");
return callConsulForCBSConfiguration(envProps)
.peek(strBody -> log.info(f("Received following CBS configuration from Consul '%s'", strBody)))
- .flatMap(strBody -> toJsonArray(strBody))
- .flatMap(json -> withdrawCatalog(json))
+ .flatMap(Conversions::toJsonArray)
+ .flatMap(ConfigSource::withdrawCatalog)
.flatMap(json -> constructFullCBSUrl(envProps, json))
.flatMap(cbsUrl -> callCBSForAppConfig(envProps, cbsUrl))
- .flatMap(strBody -> toJson(strBody))
+ .flatMap(Conversions::toJson)
.peek(jsonNode -> log.info(f("Received app configuration: '%s'", jsonNode)))
.onFailure(exc -> log.error("Could not fetch application config", exc));
}
@@ -83,7 +84,7 @@ final class ConfigSource {
res -> res.getStatus() == 200,
res -> new RuntimeException(f("HTTP call (GET '%s') failed with status %s and body '%s'",
url, res.getStatus(), res.getBody())))
- .map(res -> res.getBody())
+ .map(HttpResponse::getBody)
.peek(body -> log.info(f("HTTP GET on '%s' returned body '%s'", url, body)));
}
diff --git a/src/main/java/org/onap/dcae/restapi/ServletConfig.java b/src/main/java/org/onap/dcae/restapi/ServletConfig.java
index 2ba8a28e..35616ac1 100644
--- a/src/main/java/org/onap/dcae/restapi/ServletConfig.java
+++ b/src/main/java/org/onap/dcae/restapi/ServletConfig.java
@@ -21,6 +21,7 @@
package org.onap.dcae.restapi;
+import org.onap.dcae.ApplicationException;
import org.onap.dcae.ApplicationSettings;
import org.onap.dcae.common.SSLContextCreator;
import org.slf4j.Logger;
@@ -100,7 +101,7 @@ public class ServletConfig implements WebServerFactoryCustomizer<ConfigurableSer
return new String(readAllBytes(location));
} catch (IOException e) {
log.error("Could not read keystore password from: '" + location + "'.", e);
- throw new RuntimeException(e);
+ throw new ApplicationException(e);
}
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/dcae/restapi/VesRestController.java b/src/main/java/org/onap/dcae/restapi/VesRestController.java
index 68aecce5..510031df 100644
--- a/src/main/java/org/onap/dcae/restapi/VesRestController.java
+++ b/src/main/java/org/onap/dcae/restapi/VesRestController.java
@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
import org.json.JSONArray;
import org.json.JSONObject;
+import org.onap.dcae.ApplicationException;
import org.onap.dcae.ApplicationSettings;
import org.onap.dcae.common.VESLogger;
import org.slf4j.Logger;
@@ -165,7 +166,7 @@ public class VesRestController {
}
return report.isSuccess();
} catch (Exception e) {
- throw new RuntimeException("Unable to validate against schema", e);
+ throw new ApplicationException("Unable to validate against schema", e);
}
}