2 * Copyright 2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.cli.fw.cmd;
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;
25 import java.util.ArrayList;
26 import java.util.List;
30 * Validate schema command.
32 @OnapCommandSchema(name = "schema-validate", version="cli-1.0", schema = "schema-validate.yaml")
33 public class OnapSchemaValidateCommand extends OnapCommand {
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);
46 List<String> error = OnapCommandUtils.loadSchema(new OnapCommand() {
48 protected void run() throws OnapCommandException {
50 }, location, true, true);
53 error.addAll(OnapCommandUtils.loadHTTPSchemaSection(new OnapHttpCommand(),
56 List<String> slNumber = new ArrayList<>();
57 for (int i = 1; i <= error.size(); i++) {
58 slNumber.add(String.valueOf(i));
60 this.getResult().getRecords().get(0).setValues(slNumber);
61 this.getResult().getRecords().get(1).setValues(error);