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 java.util.ArrayList;
20 import java.util.List;
23 import org.onap.cli.fw.conf.OnapCommandConstants;
24 import org.onap.cli.fw.error.OnapCommandException;
25 import org.onap.cli.fw.input.OnapCommandParameter;
26 import org.onap.cli.fw.registrar.OnapCommandRegistrar;
27 import org.onap.cli.fw.schema.OnapCommandSchema;
28 import org.onap.cli.fw.schema.OnapCommandSchemaLoader;
29 import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
32 * Validate schema command.
34 @OnapCommandSchema(schema = "schema-validate.yaml")
35 public class OnapSchemaValidateCommand extends OnapCommand {
38 protected void run() throws OnapCommandException {
39 Map<String, OnapCommandParameter> paramMap = getParametersMap();
41 OnapCommandParameter locationParam = paramMap.get("schema-location");
42 String location = String.valueOf(locationParam.getValue());
44 OnapCommandParameter interSchemaParam = paramMap.get("internal-schema");
45 boolean isInternalSchema = Boolean.parseBoolean(String.valueOf(interSchemaParam.getValue()));
47 if (isInternalSchema && location.startsWith("/")) {
48 location = location.substring(1);
51 OnapCommandParameter versionParam = paramMap.get("ocs-version");
52 String ocsVersion = String.valueOf(versionParam.getValue());
54 String type = OnapCommandDiscoveryUtils.identitySchemaProfileType(
55 OnapCommandSchemaLoader.validateSchemaVersion(location, ocsVersion));
57 OnapCommand cmd = null;
58 if (type.equals(OnapCommandConstants.BASIC_SCHEMA_PROFILE)) {
59 cmd = new OnapCommand() {
61 protected void run() throws OnapCommandException {
62 //This is used for enabling the validation, so no run implemented
66 cmd = OnapCommandDiscoveryUtils.loadCommandClass(OnapCommandRegistrar.getRegistrar().getProfilePlugin(type));
69 List<String> error = cmd.initializeSchema(location, true);
70 List<String> slNumber = new ArrayList<>();
71 for (int i = 1; i <= error.size(); i++) {
72 slNumber.add(String.valueOf(i));
74 this.getResult().getRecordsMap().get("sl-no").setValues(slNumber);
75 this.getResult().getRecordsMap().get("error").setValues(error);