summaryrefslogtreecommitdiffstats
path: root/feature-state-management/src/main/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-08-26 14:36:35 -0400
committerJim Hahn <jrh3@att.com>2021-08-26 15:12:19 -0400
commitd04af420514c9c852af77780f0bd5ee23ebb401a (patch)
tree4212f3e411714770bd4bae3ecb25634190868b13 /feature-state-management/src/main/java/org/onap
parent9869e3a9665c0215dc9f9724fe3b5576c0479157 (diff)
Fix sonars in drools-pdp
Fixed sonars: - use "var" - override "equals" - unused imports Also changed some of the JPA queries to make them typed queries. Issue-ID: POLICY-3289 Change-Id: Ib3a00be322d8d00ba492673708439cacfe2c7fc4 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-state-management/src/main/java/org/onap')
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java4
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java6
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java29
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java6
4 files changed, 21 insertions, 24 deletions
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
index 0c750065..de378933 100644
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
+++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
@@ -94,7 +94,7 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase {
// create connection to DB
phase = "creating connection";
logger.debug("DbAudit: Creating connection to {}", url);
- try (Connection connection = DriverManager.getConnection(url, user, password)) {
+ try (var connection = DriverManager.getConnection(url, user, password)) {
// create audit table, if needed
if (doCreate) {
@@ -104,7 +104,7 @@ public class DbAudit extends DroolsPdpIntegrityMonitor.AuditBase {
// insert an entry into the table
phase = "insert entry";
- String key = UUID.randomUUID().toString();
+ var key = UUID.randomUUID().toString();
insertEntry(connection, key);
phase = "fetch entry";
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java
index b2878dab..8dd735e6 100644
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java
+++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-state-management
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -68,10 +68,10 @@ public class IntegrityMonitorRestManager {
// request.
synchronized (IntegrityMonitorRestManager.class) {
// will include messages associated with subsystem failures
- StringBuilder body = new StringBuilder();
+ var body = new StringBuilder();
// 200=SUCCESS, 500=failure
- int responseValue = 200;
+ var responseValue = 200;
if (im == null) {
try {
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
index 29576c4d..f5922588 100644
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
+++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
@@ -35,7 +35,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -79,14 +78,14 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
*/
private static TreeSet<Integer> countAdditionalNexusRepos() {
TreeSet<Integer> returnIndices = new TreeSet<>();
- Properties properties = StateManagementProperties.getProperties();
+ var properties = StateManagementProperties.getProperties();
Set<String> propertyNames = properties.stringPropertyNames();
for (String currName : propertyNames) {
- Matcher matcher = repoPattern.matcher(currName);
+ var matcher = repoPattern.matcher(currName);
if (matcher.matches()) {
- int currRepoNum = Integer.parseInt(matcher.group(2));
+ var currRepoNum = Integer.parseInt(matcher.group(2));
if (propertyNames.contains(matcher.group(1) + ".audit.url")) {
returnIndices.add(currRepoNum);
}
@@ -104,7 +103,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
public void invoke(Properties properties) throws IntegrityMonitorException {
logger.debug("Running 'RepositoryAudit.invoke'");
- InvokeData data = new InvokeData();
+ var data = new InvokeData();
logger.debug("RepositoryAudit.invoke: repoAuditIsActive = {}" + ", repoAuditIgnoreErrors = {}",
data.repoAuditIsActive, data.repoAuditIgnoreErrors);
@@ -179,7 +178,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
*/
// output file = ${dir}/out (this supports step '4a')
- File output = data.dir.resolve("out").toFile();
+ var output = data.dir.resolve("out").toFile();
// invoke process, and wait for response
int rval = data.runMaven(output);
@@ -319,7 +318,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
}
public void initTimeout() {
- String timeoutString = getProperty("audit.timeout", true);
+ var timeoutString = getProperty("audit.timeout", true);
if (timeoutString != null && !timeoutString.isEmpty()) {
try {
timeoutInSeconds = Long.valueOf(timeoutString);
@@ -345,7 +344,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
}
// create text file to write
- try (FileOutputStream fos = new FileOutputStream(dir.resolve("repository-audit.txt").toFile())) {
+ try (var fos = new FileOutputStream(dir.resolve("repository-audit.txt").toFile())) {
fos.write(version.getBytes());
}
@@ -372,7 +371,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
artifacts.add(new Artifact("org.apache.maven/maven-embedder/3.2.2"));
- StringBuilder sb = new StringBuilder();
+ var sb = new StringBuilder();
sb.append(
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n"
@@ -399,7 +398,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
+ " </execution>\n" + " </executions>\n" + " </plugin>\n"
+ " </plugins>\n" + " </build>\n" + "</project>\n");
- try (FileOutputStream fos = new FileOutputStream(pom.toFile())) {
+ try (var fos = new FileOutputStream(pom.toFile())) {
fos.write(sb.toString().getBytes());
}
}
@@ -455,9 +454,9 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
private void generateDownloadLogs(File output) throws IOException {
// place output in 'fileContents' (replacing the Return characters
// with Newline)
- byte[] outputData = new byte[(int) output.length()];
+ var outputData = new byte[(int) output.length()];
String fileContents;
- try (FileInputStream fis = new FileInputStream(output)) {
+ try (var fis = new FileInputStream(output)) {
//
// Ideally this should be in a loop or even better use
// Java 8 nio functionality.
@@ -469,7 +468,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
// generate log messages from 'Downloading' and 'Downloaded'
// messages within the 'mvn' output
- int index = 0;
+ var index = 0;
while ((index = fileContents.indexOf("\nDown", index)) > 0) {
index += 5;
if (fileContents.regionMatches(index, "loading: ", 0, 9)) {
@@ -502,7 +501,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
*/
static int runProcess(long timeoutInSeconds, File directory, File stdout, String... command)
throws IOException, InterruptedException {
- ProcessBuilder pb = new ProcessBuilder(command);
+ var pb = new ProcessBuilder(command);
if (directory != null) {
pb.directory(directory);
}
@@ -510,7 +509,7 @@ public class RepositoryAudit extends DroolsPdpIntegrityMonitor.AuditBase {
pb.redirectOutput(stdout);
}
- Process process = pb.start();
+ var process = pb.start();
if (process.waitFor(timeoutInSeconds, TimeUnit.SECONDS)) {
// process terminated before the timeout
return process.exitValue();
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java
index 3dbb8d3e..8f5e4e3c 100644
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java
+++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-state-management
* ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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,7 +21,6 @@
package org.onap.policy.drools.statemanagement;
import java.io.IOException;
-import java.util.Properties;
import org.onap.policy.common.im.AllSeemsWellException;
import org.onap.policy.common.im.IntegrityMonitorException;
import org.onap.policy.common.im.StateChangeNotifier;
@@ -238,8 +237,7 @@ public class StateManagementFeature implements StateManagementFeatureApi,
private static void initializeProperties(String configDir) {
//Get the state management properties
try {
- Properties props =
- PropertyUtil.getProperties(configDir + "/feature-state-management.properties");
+ var props = PropertyUtil.getProperties(configDir + "/feature-state-management.properties");
StateManagementProperties.initProperties(props);
logger.info("initializeProperties: resourceName= {}",
StateManagementProperties.getProperty(StateManagementProperties.NODE_NAME));