2 * Copyright 2020 Simran Singhal.
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.robot.schema;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
24 import org.onap.cli.fw.robot.cmd.OnapRobotCommand;
25 import org.onap.cli.fw.robot.conf.OnapCommandRobotConstants;
26 import org.onap.cli.fw.cmd.conf.OnapCommandCmdConstants;
27 import org.onap.cli.fw.conf.OnapCommandConfig;
28 import org.onap.cli.fw.error.OnapCommandException;
29 import org.onap.cli.fw.utils.OnapCommandUtils;
30 import java.util.stream.Collectors;
32 public class OnapCommandSchemaRobotLoader {
34 private OnapCommandSchemaRobotLoader() {
35 // to follow standards !
45 * @throws OnapCommandException
48 public static List<String> parseRobotSchema(OnapRobotCommand robot,
49 final Map<String, ?> values,
50 boolean validate) throws OnapCommandException { //NOSONAR
51 ArrayList<String> errorList = new ArrayList<>();
52 Map<String, ?> valMap = (Map<String, ?>) values.get(OnapCommandRobotConstants.ROBOT);
56 OnapCommandUtils.validateTags(errorList, valMap, OnapCommandConfig.getCommaSeparatedList(OnapCommandCmdConstants.CMD_SECTIONS),
57 OnapCommandConfig.getCommaSeparatedList(OnapCommandCmdConstants.CMD_MANDATORY_SECTIONS), OnapCommandRobotConstants.ROBOT);
59 for (Map.Entry<String, ?> entry1 : valMap.entrySet()) {
60 String key1 = entry1.getKey();
63 case OnapCommandCmdConstants.COMMAND:
64 Object o = valMap.get(key1);
65 if (o instanceof List) {
66 robot.setCommand((List<String>) o);
68 robot.setCommand(Arrays.asList((String) o));
72 case OnapCommandCmdConstants.ENVIRONMENT:
73 Map<String, String> envMap = (Map<String, String>) valMap.get(key1);
74 robot.setEnvs(envMap);
77 case OnapCommandCmdConstants.WD:
78 robot.setWd((String)valMap.get(key1));
81 case OnapCommandCmdConstants.OUTPUT:
82 robot.setOutput((String)valMap.get(key1));
85 case OnapCommandCmdConstants.ERROR:
86 robot.setError((String)valMap.get(key1));
89 case OnapCommandCmdConstants.RESULT_MAP:
90 robot.setResultMap((Map<String, String>) valMap.get(key1));
93 case OnapCommandCmdConstants.SUCCESS_EXIT_CODE:
94 List<String> list = (ArrayList) valMap.get(key1);
95 robot.setSuccessStatusCodes(list.stream().map(Integer::parseInt).collect(Collectors.toList()));
98 case OnapCommandCmdConstants.PASS_CODE:
99 robot.setPassCodes((ArrayList) valMap.get(key1));
101 default : // Do nothing