summaryrefslogtreecommitdiffstats
path: root/LogParser/src
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-07-26 20:58:24 +0900
committerkrishnajinka <kris.jinka@samsung.com>2018-07-28 11:47:46 +0900
commit1ecf9de8c889adb2dbc9ddd9a79d28e1da89d87b (patch)
treea946699b1ffec4845315e7e92e08d01b4ce927f7 /LogParser/src
parent1df87df1af0d215b9ff908dd15089393b9be270b (diff)
Fix Sonar issues in utils PDP ParseLog rework
Fix Major Sonar issues in ParseLog BackupMonitor and ONAP-PDP component. Issues related to nested control statements. Rework2 based on review comments Issue-ID: POLICY-1013 Change-Id: I10edb242b45a649df902a4e7c1aba0a285b8b7fb Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'LogParser/src')
-rw-r--r--LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java147
1 files changed, 73 insertions, 74 deletions
diff --git a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
index 75ccfd477..54e86d250 100644
--- a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
+++ b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java
@@ -3,6 +3,7 @@
* LogParser
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -377,27 +378,28 @@ public class ParseLog {
StringBuilder builder = new StringBuilder();
long length = file.length();
logger.debug("dataFileName: " + dataFileName);
- if (length > 0) {
- length--;
- randomAccessFile.seek(length);
- for (long seek = length; seek >= 0; --seek) {
- randomAccessFile.seek(seek);
- final char c = (char) randomAccessFile.read();
- builder.append(c);
- if (c == '\n') {
- builder = builder.reverse();
- logger.debug("builder.toString(): " + builder.toString());
- if (builder.toString().contains(last + dataFileName + lineRead)) {
- final String[] parseString = builder.toString().split(last + dataFileName + lineRead);
- final String returnValue = parseString[1].replace("\r", "");
- randomAccessFile.close();
- return returnValue.trim();
- }
- builder = new StringBuilder();
+ if (length == 0) {
+ return null;
+ }
+
+ length--;
+ randomAccessFile.seek(length);
+ for (long seek = length; seek >= 0; --seek) {
+ randomAccessFile.seek(seek);
+ final char c = (char) randomAccessFile.read();
+ builder.append(c);
+ if (c == '\n') {
+ builder = builder.reverse();
+ logger.debug("builder.toString(): " + builder.toString());
+ if (builder.toString().contains(last + dataFileName + lineRead)) {
+ final String[] parseString = builder.toString().split(last + dataFileName + lineRead);
+ final String returnValue = parseString[1].replace("\r", "");
+ return returnValue.trim();
}
+ builder = new StringBuilder();
}
}
- randomAccessFile.close();
+
}
return null;
}
@@ -820,23 +822,25 @@ public class ParseLog {
}
private static void setLogFileProperties(final String[] splitString) {
- if (splitString != null) {
- for (int i = 0; i < splitString.length; i++) {
-
- if (splitString[i].contains("debug")) {
- // get path of debug.log file
- setDebuglogFile(splitString[i]);
- } else if (splitString[i].contains("error")) {
- // get path of error.log file
- setErrorlogFile(splitString[i]);
+ if (splitString == null) {
+ return;
+ }
+
+ for (int i = 0; i < splitString.length; i++) {
+
+ if (splitString[i].contains("debug")) {
+ // get path of debug.log file
+ setDebuglogFile(splitString[i]);
+ } else if (splitString[i].contains("error")) {
+ // get path of error.log file
+ setErrorlogFile(splitString[i]);
+ } else {
+ // get path of default file
+ logFile = splitString[i];
+ if (logFile != null && !logFile.isEmpty()) {
+ logFile = logFile.trim();
} else {
- // get path of default file
- logFile = splitString[i];
- if (logFile != null && !logFile.isEmpty()) {
- logFile = logFile.trim();
- } else {
- logFile = null;
- }
+ logFile = null;
}
}
}
@@ -851,53 +855,48 @@ public class ParseLog {
public static Properties getPropertiesValue(final String fileName) {
final Properties config = new Properties();
final Path file = Paths.get(fileName);
- if (file.toFile().exists()) {
-
- if (file.toString().endsWith(".properties")) {
- InputStream in;
- try {
- in = new FileInputStream(file.toFile());
- config.load(in);
-
- resourceName = config.getProperty("RESOURCE_NAME");
- system = config.getProperty("SERVER");
- type = config.getProperty("LOGTYPE");
- systemLogFile = config.getProperty("PARSERLOGPATH");
- final String logFiles = config.getProperty("LOGPATH");
- final String cleanupInterval = config.getProperty("CHECK_INTERVAL");
- final String timeFrame = config.getProperty("TIME_FRAME");
-
- setCleanUpProperties(cleanupInterval, timeFrame);
-
- if (logFiles == null || logFiles.isEmpty()) {
- isMissingLogFile = true;
- return null;
- }
+ //ensure file exists and it is properties file
+ if (!(file.toFile().exists() && file.toString().endsWith(".properties"))) {
+ logger.debug("File doesn't exist in the specified Path Or it is not a properties file" + file.toString());
+ return null;
+ }
- final String[] splitString = getPaths(logFiles);
+ try (InputStream in = new FileInputStream(file.toFile())) {
+ config.load(in);
- setLogFileProperties(splitString);
+ resourceName = config.getProperty("RESOURCE_NAME");
+ system = config.getProperty("SERVER");
+ type = config.getProperty("LOGTYPE");
+ systemLogFile = config.getProperty("PARSERLOGPATH");
+ final String logFiles = config.getProperty("LOGPATH");
+ final String cleanupInterval = config.getProperty("CHECK_INTERVAL");
+ final String timeFrame = config.getProperty("TIME_FRAME");
- jdbcUrl = config.getProperty("JDBC_URL").replace("'", "");
- jdbcUser = config.getProperty("JDBC_USER");
- jdbcDriver = config.getProperty("JDBC_DRIVER");
- jdbcPassword = CryptoUtils.decryptTxtNoExStr(config.getProperty("JDBC_PASSWORD", ""));
- config.setProperty("javax.persistence.jdbc.password",
- CryptoUtils.decryptTxtNoExStr(config.getProperty("javax.persistence.jdbc.password", "")));
- return config;
+ setCleanUpProperties(cleanupInterval, timeFrame);
- } catch (final IOException e) {
- logger.error("Error porcessing Config file will be unable to create Health Check" + e);
- } catch (final Exception e) {
- logger.error("Error getPropertiesValue on TIME_FRAME", e);
- logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + defaultTimeFrame
- + " days");
- }
+ if (logFiles == null || logFiles.isEmpty()) {
+ isMissingLogFile = true;
+ return null;
}
- } else {
+ final String[] splitString = getPaths(logFiles);
- logger.debug("File doesn't exist in the specified Path " + file.toString());
+ setLogFileProperties(splitString);
+
+ jdbcUrl = config.getProperty("JDBC_URL").replace("'", "");
+ jdbcUser = config.getProperty("JDBC_USER");
+ jdbcDriver = config.getProperty("JDBC_DRIVER");
+ jdbcPassword = CryptoUtils.decryptTxtNoExStr(config.getProperty("JDBC_PASSWORD", ""));
+ config.setProperty("javax.persistence.jdbc.password",
+ CryptoUtils.decryptTxtNoExStr(config.getProperty("javax.persistence.jdbc.password", "")));
+ return config;
+
+ } catch (final IOException e) {
+ logger.error("Error porcessing Config file will be unable to create Health Check" + e);
+ } catch (final Exception e) {
+ logger.error("Error getPropertiesValue on TIME_FRAME", e);
+ logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + defaultTimeFrame
+ + " days");
}
return null;
}