aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main/java/org/onap/cli/fw/store
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/main/java/org/onap/cli/fw/store')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java8
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java29
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java21
3 files changed, 28 insertions, 30 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
index 5938a11d..58797152 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
@@ -56,7 +56,7 @@ public class OnapCommandArtifactStore {
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
- private static String SEPARATOR = "__";
+ private static final String SEPARATOR = "__";
public static class Artifact {
private String name;
@@ -255,8 +255,10 @@ public class OnapCommandArtifactStore {
if (!aFile.exists()) {
throw new OnapCommandArtifactNotFound(name, category);
}
- if(!aFile.delete()){
- log.error("Failed to delete the artifact {}", aFile.getAbsolutePath());
+ try {
+ Files.delete(Paths.get(storePath));
+ } catch (IOException e) {
+ log.error("Failed to delete the artifact " + aFile.getAbsolutePath());
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
index b0ebbda5..15996a8f 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
@@ -19,6 +19,9 @@ package org.onap.cli.fw.store;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -56,7 +59,7 @@ public class OnapCommandExecutionStore {
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
- private static String SEPARATOR = "__";
+ private static final String SEPARATOR = "__";
private enum SearchMode {
FIND,
@@ -65,11 +68,11 @@ public class OnapCommandExecutionStore {
}
- private static SearchMode SEARCH_MODE = SearchMode.FILE;
+ private static SearchMode searchMode = SearchMode.FILE;
static {
String mode = OnapCommandConfig.getPropertyValue(OnapCommandConstants.OPEN_CLI_EXECUTION_SEARCH_MODE);
if (mode.equalsIgnoreCase(SearchMode.FIND.name()))
- SEARCH_MODE = SearchMode.FIND;
+ searchMode = SearchMode.FIND;
}
public static class ExecutionStoreContext {
@@ -279,9 +282,11 @@ public class OnapCommandExecutionStore {
FileUtils.touch(new File(context.getStorePath() + File.separator + COMPLETED));
else
FileUtils.touch(new File(context.getStorePath() + File.separator + FAILED));
-
- if(!new File(context.getStorePath() + File.separator + IN_PROGRESS).delete()){
- log.error("Failed to delete {}", context.getStorePath() + File.separator + IN_PROGRESS);
+ Path path= Paths.get(context.getStorePath() + File.separator + IN_PROGRESS);
+ try {
+ Files.delete(path);
+ } catch (IOException e) {
+ log.error("Failed to delete "+ context.getStorePath() + File.separator + IN_PROGRESS);
}
} catch (IOException e) {
log.error("Failed to store the execution end details {}", context.storePath);
@@ -334,7 +339,7 @@ public class OnapCommandExecutionStore {
try {
List <String> dirs = new ArrayList<>();
- if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.FILE)) {
+ if (System.getProperty("os.name").toLowerCase().startsWith("windows") || searchMode.equals(SearchMode.FILE)) {
for (File f: new File(getBasePath()).listFiles()) {
if(search.containsKey(EXECUTIONID)) {
if (f.getName().startsWith(search.get(EXECUTIONID)))
@@ -347,7 +352,6 @@ public class OnapCommandExecutionStore {
if (f.getName().startsWith(search.get(REQUESTID)))
dirs.add(f.getAbsolutePath());
- continue;
}
else
@@ -449,12 +453,9 @@ public class OnapCommandExecutionStore {
}
private File getExecutionDir(String executionId) throws OnapCommandExecutionNotFound {
- File []f = new File(getBasePath()).listFiles(new FilenameFilter() {
-
- @Override
- public boolean accept(File dir, String name) {
- return name.startsWith(executionId);
- }
+ File []f = new File(getBasePath()).listFiles((dir, name) -> {
+ if (name.startsWith(executionId)) return true;
+ return false;
});
if (f.length == 0) {
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
index 139521e4..677c45ea 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
@@ -21,6 +21,8 @@ import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_PROFILE_JSON;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -96,11 +98,9 @@ public class OnapCommandProfileStore {
}
public void remove(String productVersion, String paramName) {
- if (paramCache.containsKey(productVersion)) {
- if (paramCache.get(productVersion).containsKey(paramName)) {
+ if (paramCache.containsKey(productVersion) && paramCache.get(productVersion).containsKey(paramName)) {
paramCache.get(productVersion).remove(paramName);
}
- }
this.persist();
}
@@ -205,23 +205,18 @@ public class OnapCommandProfileStore {
public void removeProfile(String profile) {
String dataDir = getDataStorePath();
File file = new File(dataDir + File.separator + profile + DATA_PATH_PROFILE_JSON);
- if (file.exists()) {
- if(!file.delete()){
- log.error("Failed to delete profile {}", file.getAbsolutePath());
+ try {
+ Files.delete(Paths.get(dataDir + File.separator + profile + DATA_PATH_PROFILE_JSON));
+ } catch (IOException e) {
+ log.error("Failed to delete profile {}"+file.getAbsolutePath());
}
- }
}
public List<String> getProfiles() {
List<String> profiles = new ArrayList<>();
String dataDir = getDataStorePath();
- for (File file: new File(dataDir).listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(DATA_PATH_PROFILE_JSON);
- }
- })) {
+ for (File file: new File(dataDir).listFiles((dir, name) -> name.endsWith(DATA_PATH_PROFILE_JSON))) {
String profile = file.getName().substring(0, file.getName().indexOf(DATA_PATH_PROFILE_JSON));
profiles.add(profile);
}