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.profile;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
24 import org.onap.cli.fw.cmd.OnapCommand;
25 import org.onap.cli.fw.error.OnapCommandException;
26 import org.onap.cli.fw.input.cache.OnapCommandParamEntity;
27 import org.onap.cli.fw.schema.OnapCommandSchema;
28 import org.onap.cli.fw.store.OnapCommandProfileStore;
31 * Refresh external schema.
34 @OnapCommandSchema(schema = "profile-unset.yaml")
35 public class OnapProfileUnsetCommand extends OnapCommand {
38 protected void run() throws OnapCommandException {
39 //mrkanag add feature to remove the profile at product or service or command level
40 String product = getParametersMap().get("product").getValue().toString();
41 String profile = getParametersMap().get("profile").getValue().toString();
42 String service = getParametersMap().get("service").getValue().toString();
43 String command = getParametersMap().get("command").getValue().toString();
45 List<String> params = (List<String>)getParametersMap().get("parameter").getValue();
47 OnapCommandProfileStore cache = OnapCommandProfileStore.getInstance();
50 if (service.length() > 0) {
51 prefix += service + ":";
53 if (command.length() > 0) {
54 prefix += command + ":";
57 Map<String, OnapCommandParamEntity> map = new HashMap<>();
59 for (OnapCommandParamEntity paramsExisting : cache.getInstance().loadParamFromCache(profile)) {
60 map.put(paramsExisting.getProduct() + ":" + paramsExisting.getName(), paramsExisting);
63 for (String name: params) {
66 if (map.containsKey(product + ":" + name))
67 map.remove(product + ":" + name);
70 List<OnapCommandParamEntity> es = new ArrayList<>();
71 for (OnapCommandParamEntity e : map.values()) {
75 cache.persistProfile( es, profile);