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.error.OnapCommandProfileNotFound;
27 import org.onap.cli.fw.input.cache.OnapCommandParamEntity;
28 import org.onap.cli.fw.schema.OnapCommandSchema;
29 import org.onap.cli.fw.store.OnapCommandProfileStore;
32 * Refresh external schema.
35 @OnapCommandSchema(schema = "profile-set.yaml")
36 public class OnapProfileSetCommand extends OnapCommand {
39 protected void run() throws OnapCommandException {
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 Map<String, String> params = (Map<String, 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<>();
60 for (OnapCommandParamEntity paramsExisting : cache.getInstance().loadParamFromCache(profile)) {
61 map.put(paramsExisting.getProduct() + ":" + paramsExisting.getName(), paramsExisting);
63 } catch (OnapCommandProfileNotFound e) {
64 //ignore amd proceed to create
67 for (Map.Entry<String, String> entry: params.entrySet()) {
68 String name = prefix + entry.getKey();
69 OnapCommandParamEntity entity = new OnapCommandParamEntity();
70 entity.setProduct(product);
72 entity.setValue(entry.getValue());
74 map.put(entity.getProduct() + ":" + entity.getName(), entity);
77 List<OnapCommandParamEntity> es = new ArrayList<>();
78 for (OnapCommandParamEntity e : map.values()) {
82 cache.persistProfile( es, profile);