2 * Copyright 2018 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.product;
19 import java.io.InputStream;
20 import java.util.HashSet;
21 import java.util.List;
25 import org.onap.cli.fw.cmd.OnapCommand;
26 import org.onap.cli.fw.conf.OnapCommandConstants;
27 import org.onap.cli.fw.error.OnapCommandException;
28 import org.onap.cli.fw.schema.OnapCommandSchema;
29 import org.onap.cli.fw.schema.OnapCommandSchemaInfo;
30 import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
31 import org.yaml.snakeyaml.Yaml;
37 @OnapCommandSchema(schema = "product-list.yaml")
38 public class OnapProductsListCommand extends OnapCommand {
41 protected void run() throws OnapCommandException {
42 List<OnapCommandSchemaInfo> schemas = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(false);
44 Set<String> rslt = new HashSet<>();
46 for (OnapCommandSchemaInfo schema : schemas) {
47 if (schema.isIgnore()) {
51 rslt.add(schema.getProduct());
54 for (String product : rslt) {
55 this.getResult().getRecordsMap().get("product").getValues().add(product);
57 InputStream stream = this.getClass().getResourceAsStream("/" + OnapCommandConstants.SCHEMA_DIRECTORY +
58 "/" + product + OnapCommandConstants.PRODUCT_REGISTRY_YAML);
61 Map<String, ?> map = (Map<String, ?>) new Yaml().load(stream);
62 Map<String, String> productMap = (Map<String, String>) map.get("product");
63 String description = (String) productMap.get(OnapCommandConstants.DESCRIPTION);
64 this.getResult().getRecordsMap().get("description").getValues().add(description.trim());
66 this.getResult().getRecordsMap().get("description").getValues().add("");