Add validation for sample file schema 97/37997/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Fri, 23 Mar 2018 07:45:14 +0000 (13:15 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Fri, 23 Mar 2018 07:45:14 +0000 (13:15 +0530)
Issue-ID: CLI-105

Change-Id: I748662f8f3760d9b38f1920bfadf82a210ddc3de
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java

index c2bfc1d..6f1741e 100644 (file)
@@ -45,6 +45,7 @@ public class OnapCommandConstants {
     //schema
     public static final String OPEN_CLI_SCHEMA_VERSION = "open_cli_schema_version";
     public static final String OPEN_CLI_SCHEMA_VERSION_VALUE_1_0 = "1.0";
+
     public static final String NAME = "name";
     public static final String DESCRIPTION = "description";
 
@@ -148,6 +149,8 @@ public class OnapCommandConstants {
     public static final String SAMPLE_GEN_ENABLED = "cli.sample.gen.enable";
     public static final String SAMPLE_GEN_TARGET_FOLDER = "cli.sample.gen.target";
 
+    public static final String OPEN_CLI_SAMPLE_VERSION = "open_cli_sample_version";
+    public static final String OPEN_CLI_SAMPLE_VERSION_VALUE_1_0 = "1.0";
     public static final String VERIFY_SAMPLES_DIRECTORY = "open-cli-sample";
     public static final String VERIFY_SAMPLES_FILE_PATTERN = VERIFY_SAMPLES_DIRECTORY + YAML_PATTERN;
     public static final String VERIFY_SAMPLES_MOCK_PATTERN = VERIFY_SAMPLES_DIRECTORY + JSON_PATTERN;
index 1732772..d0789d7 100644 (file)
@@ -303,6 +303,22 @@ public class OnapCommandDiscoveryUtils {
     private static void updateSchemaInfoWithSample(Resource sampleResourse,
                                                       List<OnapCommandSchemaInfo> schemaInfos) throws OnapCommandInvalidSchema, IOException {
         Map<String, ?> infoMap = loadSchema(sampleResourse);
+
+        if (infoMap == null) {
+            return;
+        }
+
+        Object sampleVersion = infoMap.get(OPEN_CLI_SAMPLE_VERSION);
+        if (sampleVersion == null) {
+            OnapCommandUtils.LOG.info("Invalid Sample yaml " + sampleResourse.getURI().toString());
+            return;
+        }
+
+        if (!sampleVersion.toString().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SAMPLE_VERSION_VALUE_1_0)) {
+            OnapCommandUtils.LOG.info("Unsupported Sample version found " + sampleResourse.getURI().toString());
+            return;
+        }
+
         String cmdName = (String) infoMap.get(OnapCommandConstants.VERIFY_CMD_NAME);
         String version = (String) infoMap.get(OnapCommandConstants.VERIFY_CMD_VERSION);