aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main/java/org
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-09-18 10:07:17 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-09-18 10:08:04 +0530
commit1a4b4030e10b53ffc80d977908cd6097d843f7a8 (patch)
treeb441fe2781e685264cab85e9dd376741cfd6af4b /framework/src/main/java/org
parent81d56617f980394d45be5fee716c507eeea739f2 (diff)
Add exception for profile persist layer
CLI-43 Change-Id: I6b2b969cc3a56dbee60d2b9056a6a7f8f793a8b4 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java/org')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java33
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java33
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java18
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java14
4 files changed, 90 insertions, 8 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java
new file mode 100644
index 00000000..62fd84fa
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.onap.cli.fw.error;
+
+/**
+ * Command profile persistence failed.
+ *
+ */
+public class OnapCommandLoadProfileFailed extends OnapCommandException {
+
+ private static final long serialVersionUID = 8580121615330415123L;
+
+ /**
+ * Command result empty.
+ */
+ public OnapCommandLoadProfileFailed(String error) {
+ super("0x1301", "Failed to load profile details, " + error);
+ }
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java
new file mode 100644
index 00000000..f49e35c6
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.onap.cli.fw.error;
+
+/**
+ * Command profile persistence failed.
+ *
+ */
+public class OnapCommandPersistProfileFailed extends OnapCommandException {
+
+ private static final long serialVersionUID = 8580121615330415123L;
+
+ /**
+ * Command result empty.
+ */
+ public OnapCommandPersistProfileFailed(String error) {
+ super("0x1302", "Failed to persist profile details, " + error);
+ }
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
index 6ce09179..6f043665 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Map;
import org.onap.cli.fw.conf.Constants;
+import org.onap.cli.fw.error.OnapCommandLoadProfileFailed;
+import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
import org.onap.cli.fw.utils.OnapCommandUtils;
public class OnapCommandParameterCache {
@@ -32,6 +34,8 @@ public class OnapCommandParameterCache {
private String profileName = Constants.PARAM_CACHE_FILE_NAME;
+ private boolean isLastPersistFailed = false;
+
private OnapCommandParameterCache() {
}
@@ -77,6 +81,7 @@ public class OnapCommandParameterCache {
private void persist() {
List<Param> params = new ArrayList<>();
+
for (String p: this.paramCache.keySet()) {
for (String name: this.paramCache.get(p).keySet()) {
@@ -89,11 +94,20 @@ public class OnapCommandParameterCache {
}
}
- OnapCommandUtils.persistParams(params, this.profileName);
+ try {
+ OnapCommandUtils.persistParams(params, this.profileName);
+ } catch (OnapCommandPersistProfileFailed e) {
+ isLastPersistFailed = true;
+ }
}
private void load() {
- List<Param> params = OnapCommandUtils.loadParamFromCache(this.profileName);
+ List<Param> params;
+ try {
+ params = OnapCommandUtils.loadParamFromCache(this.profileName);
+ } catch (OnapCommandLoadProfileFailed e) {
+ params = new ArrayList<>();
+ }
for (Param p : params) {
this.add(p.getProduct(), p.getName(), p.getValue());
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index 4cde5088..639e9636 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -23,6 +23,8 @@ import static org.onap.cli.fw.conf.Constants.AUTH_VALUES;
import static org.onap.cli.fw.conf.Constants.BODY;
import static org.onap.cli.fw.conf.Constants.BOOLEAN_VALUE;
import static org.onap.cli.fw.conf.Constants.CLIENT;
+import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
+import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_HOST_URL;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASS_WORD;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_USERNAME;
@@ -36,8 +38,6 @@ import static org.onap.cli.fw.conf.Constants.DIRECTION;
import static org.onap.cli.fw.conf.Constants.ENTITY;
import static org.onap.cli.fw.conf.Constants.EXCEPTION;
import static org.onap.cli.fw.conf.Constants.EXECUTOR;
-import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
-import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.EXTERNAL_DISCOVERY_FILE;
import static org.onap.cli.fw.conf.Constants.EXTERNAL_SCHEMA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.EXTERNAL_SCHEMA_PATH_PATERN;
@@ -125,9 +125,11 @@ import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection;
import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
+import org.onap.cli.fw.error.OnapCommandLoadProfileFailed;
import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterNotFound;
import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
+import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
import org.onap.cli.fw.error.OnapCommandResultEmpty;
import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
@@ -1626,7 +1628,7 @@ public class OnapCommandUtils {
}
}
- public static void persistParams(List<Param> params, String profileName) {
+ public static void persistParams(List<Param> params, String profileName) throws OnapCommandPersistProfileFailed {
if (params != null) {
try {
Resource[] resources = getExternalResources(DATA_DIRECTORY);
@@ -1637,7 +1639,7 @@ public class OnapCommandUtils {
mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
}
} catch (IOException e1) {
- // pass // NOSONAR
+ throw new OnapCommandPersistProfileFailed(e1.getMessage());
}
}
}
@@ -1700,7 +1702,7 @@ public class OnapCommandUtils {
return schemas;
}
- public static List<Param> loadParamFromCache(String profileName) {
+ public static List<Param> loadParamFromCache(String profileName) throws OnapCommandLoadProfileFailed {
List<Param> params = new ArrayList<>();
try {
@@ -1713,7 +1715,7 @@ public class OnapCommandUtils {
params.addAll(Arrays.asList(list));
}
} catch (IOException e) {
- // pass // NOSONAR
+ throw new OnapCommandLoadProfileFailed(e.getMessage());
}
return params;