Update Schema refresh to report product version
[cli.git] / framework / src / main / java / org / onap / cli / fw / cmd / OnapSchemaValidateCommand.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.cli.fw.cmd;
18
19 import org.onap.cli.fw.OnapCommand;
20 import org.onap.cli.fw.OnapCommandSchema;
21 import org.onap.cli.fw.error.OnapCommandException;
22 import org.onap.cli.fw.input.OnapCommandParameter;
23 import org.onap.cli.fw.utils.OnapCommandUtils;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30  * Validate schema command.
31  */
32 @OnapCommandSchema(name = "schema-validate", version="cli-1.0", schema = "schema-validate.yaml")
33 public class OnapSchemaValidateCommand extends OnapCommand {
34
35     @Override
36     protected void run() throws OnapCommandException {
37         Map<String, OnapCommandParameter> paramMap = getParametersMap();
38         OnapCommandParameter locationParam = paramMap.get("schema-location");
39         String location = String.valueOf(locationParam.getValue());
40         OnapCommandParameter interSchemaParam = paramMap.get("internal-schema");
41         boolean isInternalSchema = Boolean.valueOf(String.valueOf(interSchemaParam.getValue()));
42         if (isInternalSchema) {
43             location = location.substring(1);
44         }
45
46         List<String> error = OnapCommandUtils.loadSchema(new OnapCommand() {
47             @Override
48             protected void run() throws OnapCommandException {
49             }
50         }, location, true, true);
51
52
53          error.addAll(OnapCommandUtils.loadHTTPSchemaSection(new OnapHttpCommand(),
54                 location, true));
55
56         List<String> slNumber = new ArrayList<>();
57         for (int i = 1; i <= error.size(); i++) {
58             slNumber.add(String.valueOf(i));
59         }
60         this.getResult().getRecords().get(0).setValues(slNumber);
61         this.getResult().getRecords().get(1).setValues(error);
62     }
63
64 }