aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSubhash Kumar Singh <Subhash.Kumar.Singh@huawei.com>2017-08-20 01:51:33 +0530
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-23 00:19:20 +0530
commit624bc630a0d211a2a3493cfd0f7d4f66acf41e3f (patch)
tree36851acca299f5f375469d09730c96165cfebfba
parent083731a68423fab33baaaea86a2e00293ee401ad (diff)
Replace if-else check with switch case
Replace if-else check in schema load with switch case. Issue-Id: CLI-24 Change-Id: I0990b9ea8a1ebb9a2f739cfe527ba2e051ade03c Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java583
2 files changed, 324 insertions, 261 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
index d559f7aa..a3724275 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
@@ -57,7 +57,7 @@ public class Constants {
//http
public static final String URI = "uri";
public static final String BODY = "body";
- public static final String MERHOD = "method";
+ public static final String METHOD_TYPE = "method";
public static final String HEADERS = "headers";
public static final String QUERIES = "queries";
public static final String COOKIES = "cookies";
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index b6e64f2a..9b56dece 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -25,7 +25,6 @@ import org.onap.cli.fw.ad.OnapCredentials;
import org.onap.cli.fw.ad.OnapService;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.cmd.OnapSwaggerCommand;
-import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandDiscoveryFailed;
import org.onap.cli.fw.error.OnapCommandException;
@@ -119,7 +118,7 @@ import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_MANDATORY_LIST;
import static org.onap.cli.fw.conf.Constants.IS_OPTIONAL;
import static org.onap.cli.fw.conf.Constants.IS_SECURED;
import static org.onap.cli.fw.conf.Constants.LONG_OPTION;
-import static org.onap.cli.fw.conf.Constants.MERHOD;
+import static org.onap.cli.fw.conf.Constants.METHOD_TYPE;
import static org.onap.cli.fw.conf.Constants.METHOD;
import static org.onap.cli.fw.conf.Constants.MODE;
import static org.onap.cli.fw.conf.Constants.MODE_VALUES;
@@ -364,276 +363,324 @@ public class OnapCommandUtils {
for (String key : sections) {
- if (NAME.equals(key) && values.containsKey(key)) {
- Object val = values.get(key);
- if (val != null) {
- cmd.setName(val.toString());
- }
- } else if (DESCRIPTION.equals(key) && values.containsKey(key)) {
- Object val = values.get(key);
- if (val != null) {
- cmd.setDescription(val.toString());
- }
- } else if (SERVICE.equals(key) && values.containsKey(key)) {
- Map<String, String> map = (Map<String, String>) values.get(key);
+ switch (key) {
+ case NAME:
+ Object val = values.get(key);
+ if (val != null) {
+ cmd.setName(val.toString());
+ }
+ break;
- if (validate) {
- validateTags(exceptionList, (Map<String, Object>)values.get(key),
- OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_MANDATORY_LIST), SERVICE);
-
- HashMap<String, String> validationMap = new HashMap<>();
- validationMap.put(AUTH, AUTH_VALUES);
- validationMap.put(MODE, MODE_VALUES);
-
- for (String secKey : validationMap.keySet()) {
- if (map.containsKey(secKey)) {
- Object obj = map.get(secKey);
- if (obj == null) {
- exceptionList.add("Attribute '" + secKey + "' under '" + SERVICE + "' is empty");
- } else {
- String value = String.valueOf(obj);
- if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
- exceptionList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
- + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key))); //
+ case DESCRIPTION:
+ Object description = values.get(key);
+ if (description != null) {
+ cmd.setDescription(description.toString());
+ }
+ break;
+
+ case SERVICE:
+ Map<String, String> serviceMap = (Map<String, String>) values.get(key);
+
+ if (serviceMap != null) {
+ if (validate) {
+ validateTags(exceptionList, (Map<String, Object>) values.get(key),
+ OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_MANDATORY_LIST), SERVICE);
+
+ HashMap<String, String> validationMap = new HashMap<>();
+ validationMap.put(AUTH, AUTH_VALUES);
+ validationMap.put(MODE, MODE_VALUES);
+
+ for (String secKey : validationMap.keySet()) {
+ if (serviceMap.containsKey(secKey)) {
+ Object obj = serviceMap.get(secKey);
+ if (obj == null) {
+ exceptionList.add("Attribute '" + secKey + "' under '" + SERVICE + "' is empty");
+ } else {
+ String value = String.valueOf(obj);
+ if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
+ exceptionList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
+ + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key))); //
+ }
+ }
}
}
}
- }
- }
- if (map != null) {
- OnapService srv = new OnapService();
-
- for (Map.Entry<String, String> entry1 : map.entrySet()) {
- String key1 = entry1.getKey();
-
- if (NAME.equals(key1)) {
- srv.setName(map.get(key1));
- } else if (VERSION.equals(key1)) {
- srv.setVersion(map.get(key1));
- } else if (AUTH.equals(key1)) {
- Object obj = map.get(key1);
- srv.setAuthType(obj.toString());
- } else if (Constants.MODE.equals(key1)) {
- Object obj = map.get(key1);
- srv.setMode(obj.toString());
- }
- }
+ OnapService srv = new OnapService();
- cmd.setService(srv);
- }
- } else if (DEFAULT_PARAMETERS.equals(key)) {
+ for (Map.Entry<String, String> entry1 : serviceMap.entrySet()) {
+ String key1 = entry1.getKey();
- Map<String, List<String>> defParameters = (Map) values.get(DEFAULT_PARAMETERS);
- List<String> includeParams = new ArrayList<>();
- List<String> excludeParams = new ArrayList<>();
+ switch (key1) {
+ case NAME:
+ srv.setName(serviceMap.get(key1));
+ break;
- if (values.containsKey(DEFAULT_PARAMETERS) && defParameters == null) {
- // if default parameter section is available then it must have either include
- // or exclude sub-section.
- throwOrCollect(new OnapCommandInvalidSchema(SCHEMA_INVALID_DEFAULT_PARAMS_SECTION),
- exceptionList, validate);
- }
+ case VERSION:
+ srv.setVersion(serviceMap.get(key1));
+ break;
+ case AUTH:
+ Object obj = serviceMap.get(key1);
+ srv.setAuthType(obj.toString());
+ break;
- if (defParameters != null) {
- // validate default parameters
- if (defParameters.containsKey(DEFAULT_PARAMETERS_INCLUDE)) {
- includeParams = defParameters.get(DEFAULT_PARAMETERS_INCLUDE);
+ case MODE:
+ Object mode = serviceMap.get(key1);
+ srv.setMode(mode.toString());
+ break;
+ }
+ }
+ cmd.setService(srv);
}
+ break;
- List<String> invInclude = includeParams.stream()
- .filter(p -> !defaultParamNames.contains(p))
- .collect(Collectors.toList());
+ case DEFAULT_PARAMETERS:
+ Map<String, List<String>> defParameters = (Map) values.get(DEFAULT_PARAMETERS);
+ List<String> includeParams = new ArrayList<>();
+ List<String> excludeParams = new ArrayList<>();
- if (defParameters.containsKey(DEFAULT_PARAMETERS_EXCLUDE)) {
- excludeParams = defParameters.get(DEFAULT_PARAMETERS_EXCLUDE);
+ if (values.containsKey(DEFAULT_PARAMETERS) && defParameters == null) {
+ // if default parameter section is available then it must have either include
+ // or exclude sub-section.
+ throwOrCollect(new OnapCommandInvalidSchema(SCHEMA_INVALID_DEFAULT_PARAMS_SECTION),
+ exceptionList, validate);
}
- List<String> invExclude = excludeParams.stream().filter(p -> !defaultParamNames.contains(p))
- .collect(Collectors.toList());
+ if (defParameters != null) {
+ // validate default parameters
+ if (defParameters.containsKey(DEFAULT_PARAMETERS_INCLUDE)) {
+ includeParams = defParameters.get(DEFAULT_PARAMETERS_INCLUDE);
+ }
- if (!invExclude.isEmpty() || !invInclude.isEmpty()) {
+ List<String> invInclude = includeParams.stream()
+ .filter(p -> !defaultParamNames.contains(p))
+ .collect(Collectors.toList());
- throwOrCollect(new OnapCommandInvalidDefaultParameter(Stream.concat(invInclude.stream(),
- invExclude.stream()).collect(Collectors.toList())),
- exceptionList, validate);
- }
+ if (defParameters.containsKey(DEFAULT_PARAMETERS_EXCLUDE)) {
+ excludeParams = defParameters.get(DEFAULT_PARAMETERS_EXCLUDE);
+ }
- if (!includeParams.isEmpty()) {
- filteredDefaultParams.addAll(includeParams);
- } else if (!excludeParams.isEmpty()) {
- List<String> finalExcludeParams = excludeParams;
- defaultParamNames.stream().filter(p -> !finalExcludeParams.contains(p))
- .forEach(filteredDefaultParams::add);
- }
- } else {
- filteredDefaultParams.addAll(defaultParamNames);
- }
- try {
- processNoAuth(filteredDefaultParams, cmd, includeParams, excludeParams);
- } catch (OnapCommandException e) {
- throwOrCollect(e, exceptionList, validate);
- }
- } else if (PARAMETERS.equals(key) && values.containsKey(key)) {
+ List<String> invExclude = excludeParams.stream().filter(p -> !defaultParamNames.contains(p))
+ .collect(Collectors.toList());
- List<Map<String, String>> parameters = (List) values.get(key);
- if (parameters != null) {
- Set<String> names = new HashSet<>();
- Set<String> inputShortOptions = new HashSet<>();
- Set<String> inputLongOptions = new HashSet<>();
+ if (!invExclude.isEmpty() || !invInclude.isEmpty()) {
- for (Map<String, String> map : parameters) {
- OnapCommandParameter param = new OnapCommandParameter();
+ throwOrCollect(new OnapCommandInvalidDefaultParameter(Stream.concat(invInclude.stream(),
+ invExclude.stream()).collect(Collectors.toList())),
+ exceptionList, validate);
+ }
- if (validate) {
- validateTags(exceptionList, map, OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_MANDATORY_LIST), PARAMETERS);
+ if (!includeParams.isEmpty()) {
+ filteredDefaultParams.addAll(includeParams);
+ } else if (!excludeParams.isEmpty()) {
+ List<String> finalExcludeParams = excludeParams;
+ defaultParamNames.stream().filter(p -> !finalExcludeParams.contains(p))
+ .forEach(filteredDefaultParams::add);
}
+ } else {
+ filteredDefaultParams.addAll(defaultParamNames);
+ }
+ try {
+ processNoAuth(filteredDefaultParams, cmd, includeParams, excludeParams);
+ } catch (OnapCommandException e) {
+ throwOrCollect(e, exceptionList, validate);
+ }
+ break;
- for (Map.Entry<String, String> entry1 : map.entrySet()) {
- String key2 = entry1.getKey();
+ case PARAMETERS:
- if (NAME.equals(key2)) {
- if (names.contains(map.get(key2))) {
- throwOrCollect(new OnapCommandParameterNameConflict(map.get(key2)), exceptionList, validate);
- }
- names.add(map.get(key2));
- param.setName(map.get(key2));
- } else if (DESCRIPTION.equals(key2)) {
- param.setDescription(map.get(key2));
- } else if (SHORT_OPTION.equals(key2)) {
- if (shortOptions.contains(map.get(key2))) {
- throwOrCollect(new OnapCommandParameterOptionConflict(map.get(key2)), exceptionList, validate);
- }
- shortOptions.add(map.get(key2));
- param.setShortOption(map.get(key2));
- } else if (LONG_OPTION.equals(key2)) {
- if (longOptions.contains(map.get(key2))) {
- throwOrCollect(new OnapCommandParameterOptionConflict(map.get(key2)), exceptionList, validate);
- }
- longOptions.add(map.get(key2));
- param.setLongOption(map.get(key2));
- } else if (DEFAULT_VALUE.equals(key2)) {
- Object obj = map.get(key2);
- param.setDefaultValue(obj.toString());
- } else if (TYPE.equals(key2)) {
- try {
- param.setParameterType(ParameterType.get(map.get(key2)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
- }
- } else if (IS_OPTIONAL.equals(key2)) {
- if (validate) {
- if (!validateBoolean(String.valueOf(map.get(key2)))) {
- exceptionList.add(invalidBooleanValueMessage(map.get(NAME),
- IS_SECURED, map.get(key2)));
- }
- }
- if ("true".equalsIgnoreCase(String.valueOf(map.get(key2)))) {
- param.setOptional(true);
- } else {
- param.setOptional(false);
- }
- } else if (IS_SECURED.equals(key2)) {
- if (validate) {
- if (!validateBoolean(String.valueOf(map.get(key2)))) {
- exceptionList.add(invalidBooleanValueMessage(map.get(NAME),
- IS_SECURED, map.get(key2)));
- }
- }
+ List<Map<String, String>> parameters = (List) values.get(key);
- if ("true".equalsIgnoreCase(String.valueOf(map.get(key2)))) {
- param.setSecured(true);
- } else {
- param.setSecured(false);
- }
- }
- }
+ if (parameters != null) {
+ Set<String> names = new HashSet<>();
+ Set<String> inputShortOptions = new HashSet<>();
+ Set<String> inputLongOptions = new HashSet<>();
- // Add the element to command :
- // 1. if parameter is available in filtered parameter list.
- // 2. otherwise, parameter p is available in command yaml file.
- if (filteredDefaultParams.contains(param.getName()) || !defaultParamNames.contains(param.getName())) {
- cmd.getParameters().add(param);
- }
- }
- }
- } else if (RESULTS.equals(key) && values.containsKey(key)) {
- Map<String, ?> valueMap = (Map<String, ?>) values.get(key);
- if (valueMap != null) {
- OnapCommandResult result = new OnapCommandResult();
- for (Map.Entry<String, ?> entry1 : valueMap.entrySet()) {
- String key3 = entry1.getKey();
-
- if (DIRECTION.equals(key3)) {
- try {
- result.setPrintDirection(PrintDirection.get((String) valueMap.get(key3)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
+ for (Map<String, String> parameter : parameters) {
+ OnapCommandParameter param = new OnapCommandParameter();
+
+ if (validate) {
+ validateTags(exceptionList, parameter, OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_MANDATORY_LIST), PARAMETERS);
}
- } else if (ATTRIBUTES.equals(key3)) {
- List<Map<String, String>> attrs = (ArrayList) valueMap.get(key3);
-
- for (Map<String, String> map : attrs) {
- OnapCommandResultAttribute attr = new OnapCommandResultAttribute();
- if (validate) {
- validateTags(exceptionList, map, OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_MANDATORY_LIST), ATTRIBUTES);
- }
- Set<String> resultParamNames = new HashSet<>();
+ for (Map.Entry<String, String> entry1 : parameter.entrySet()) {
+ String key2 = entry1.getKey();
- for (Map.Entry<String, String> entry4 : map.entrySet()) {
- String key4 = entry4.getKey();
+ switch (key2) {
+ case NAME:
+ if (names.contains(parameter.get(key2))) {
+ throwOrCollect(new OnapCommandParameterNameConflict(parameter.get(key2)), exceptionList, validate);
+ }
+ names.add(parameter.get(key2));
+ param.setName(parameter.get(key2));
+ break;
- if (NAME.equals(key4)) {
- if (resultParamNames.contains(map.get(key4))) {
- exceptionList.add("Attribute name='" + map.get(key4) + "' under '"
- + ATTRIBUTES + ":' is already used, Take different one.");
+ case DESCRIPTION:
+ param.setDescription(parameter.get(key2));
+ break;
- } else {
- attr.setName(map.get(key4));
- resultParamNames.add(map.get(key4));
+ case SHORT_OPTION:
+ if (shortOptions.contains(parameter.get(key2))) {
+ throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
}
- } else if (DESCRIPTION.equals(key4)) {
- attr.setDescription(map.get(key4));
- } else if (SCOPE.equals(key4)) {
- try {
- attr.setScope(OnapCommandResultAttributeScope.get(map.get(key4)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
+ shortOptions.add(parameter.get(key2));
+ param.setShortOption(parameter.get(key2));
+ break;
+
+ case LONG_OPTION:
+ if (longOptions.contains(parameter.get(key2))) {
+ throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
}
- } else if (TYPE.equals(key4)) {
+ longOptions.add(parameter.get(key2));
+ param.setLongOption(parameter.get(key2));
+ break;
+
+ case DEFAULT_VALUE:
+ Object obj = parameter.get(key2);
+ param.setDefaultValue(obj.toString());
+ break;
+
+ case TYPE:
try {
- attr.setType(ParameterType.get(map.get(key4)));
+ param.setParameterType(ParameterType.get(parameter.get(key2)));
} catch (OnapCommandException ex) {
throwOrCollect(ex, exceptionList, validate);
}
- } else if (IS_SECURED.equals(key4)) {
+ break;
+
+ case IS_OPTIONAL:
if (validate) {
- if (!validateBoolean(String.valueOf(map.get(key4)))) {
- exceptionList.add(invalidBooleanValueMessage(ATTRIBUTES,
- IS_SECURED, map.get(key4)));
+ if (!validateBoolean(String.valueOf(parameter.get(key2)))) {
+ exceptionList.add(invalidBooleanValueMessage(parameter.get(NAME),
+ IS_SECURED, parameter.get(key2)));
}
}
- if ("true".equals(String.valueOf(map.get(key4)))) {
- attr.setSecured(true);
+ if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
+ param.setOptional(true);
} else {
- attr.setSecured(false);
+ param.setOptional(false);
}
- }
+ break;
+ case IS_SECURED:
+ if (validate) {
+ if (!validateBoolean(String.valueOf(parameter.get(key2)))) {
+ exceptionList.add(invalidBooleanValueMessage(parameter.get(NAME),
+ IS_SECURED, parameter.get(key2)));
+ }
+ }
+
+ if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
+ param.setSecured(true);
+ } else {
+ param.setSecured(false);
+ }
+ break;
}
- result.getRecords().add(attr);
+ }
+
+ // Add the element to command :
+ // 1. if parameter is available in filtered parameter list.
+ // 2. otherwise, parameter p is available in command yaml file.
+ if (filteredDefaultParams.contains(param.getName()) || !defaultParamNames.contains(param.getName())) {
+ cmd.getParameters().add(param);
}
}
}
- cmd.setResult(result);
- }
+ break;
+
+ case RESULTS:
+ Map<String, ?> valueMap = (Map<String, ?>) values.get(key);
+ if (valueMap != null) {
+ OnapCommandResult result = new OnapCommandResult();
+ for (Map.Entry<String, ?> entry1 : valueMap.entrySet()) {
+ String key3 = entry1.getKey();
+
+ switch (key3) {
+ case DIRECTION:
+ try {
+ result.setPrintDirection(PrintDirection.get((String) valueMap.get(key3)));
+ } catch (OnapCommandException ex) {
+ throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case ATTRIBUTES:
+ List<Map<String, String>> attrs = (ArrayList) valueMap.get(key3);
+
+ for (Map<String, String> map : attrs) {
+ OnapCommandResultAttribute attr = new OnapCommandResultAttribute();
+ if (validate) {
+ validateTags(exceptionList, map, OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_MANDATORY_LIST), ATTRIBUTES);
+ }
+
+ Set<String> resultParamNames = new HashSet<>();
+
+ for (Map.Entry<String, String> entry4 : map.entrySet()) {
+ String key4 = entry4.getKey();
+
+ switch (key4) {
+ case NAME:
+ if (resultParamNames.contains(map.get(key4))) {
+ exceptionList.add("Attribute name='" + map.get(key4) + "' under '"
+ + ATTRIBUTES + ":' is already used, Take different one.");
+
+ } else {
+ attr.setName(map.get(key4));
+ resultParamNames.add(map.get(key4));
+ }
+ break;
+
+ case DESCRIPTION:
+ attr.setDescription(map.get(key4));
+ break;
+
+ case SCOPE:
+ try {
+ attr.setScope(OnapCommandResultAttributeScope.get(map.get(key4)));
+ } catch (OnapCommandException ex) {
+ throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case TYPE:
+ try {
+ attr.setType(ParameterType.get(map.get(key4)));
+ } catch (OnapCommandException ex) {
+ throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case IS_SECURED:
+ if (validate) {
+ if (!validateBoolean(String.valueOf(map.get(key4)))) {
+ exceptionList.add(invalidBooleanValueMessage(ATTRIBUTES,
+ IS_SECURED, map.get(key4)));
+ }
+ }
+ if ("true".equals(String.valueOf(map.get(key4)))) {
+ attr.setSecured(true);
+ } else {
+ attr.setSecured(false);
+ }
+ break;
+ }
+
+ }
+ result.getRecords().add(attr);
+ }
+ break;
+ }
+ }
+ cmd.setResult(result);
+ }
+ break;
}
}
return exceptionList;
@@ -837,45 +884,61 @@ public class OnapCommandUtils {
}
for (Map.Entry<String, ?> entry1 : valMap.entrySet()) {
String key1 = entry1.getKey();
- if (REQUEST.equals(key1)) {
- Map<String, ?> map = (Map<String, ?>) valMap.get(key1);
-
- for (Map.Entry<String, ?> entry2 : map.entrySet()) {
- try {
- String key2 = entry2.getKey();
- if (URI.equals(key2)) {
- Object obj = map.get(key2);
- cmd.getInput().setUri(obj.toString());
- } else if (MERHOD.equals(key2)) {
- Object obj = map.get(key2);
- cmd.getInput().setMethod(obj.toString());
- } else if (BODY.equals(key2)) {
- Object obj = map.get(key2);
- cmd.getInput().setBody(obj.toString());
- } else if (HEADERS.equals(key2)) {
- Map<String, String> head = (Map<String, String>) map.get(key2);
- cmd.getInput().setReqHeaders(head);
- } else if (QUERIES.equals(key2)) {
- Map<String, String> query = (Map<String, String>) map.get(key2);
-
- cmd.getInput().setReqQueries(query);
+
+ switch (key1) {
+ case REQUEST:
+ Map<String, ?> map = (Map<String, ?>) valMap.get(key1);
+
+ for (Map.Entry<String, ?> entry2 : map.entrySet()) {
+ try {
+ String key2 = entry2.getKey();
+
+ switch (key2) {
+ case URI:
+ Object obj = map.get(key2);
+ cmd.getInput().setUri(obj.toString());
+ break;
+ case METHOD_TYPE:
+ Object method = map.get(key2);
+ cmd.getInput().setMethod(method.toString());
+ break;
+ case BODY:
+ Object body = map.get(key2);
+ cmd.getInput().setBody(body.toString());
+ break;
+ case HEADERS:
+ Map<String, String> head = (Map<String, String>) map.get(key2);
+ cmd.getInput().setReqHeaders(head);
+ break;
+ case QUERIES:
+ Map<String, String> query = (Map<String, String>) map.get(key2);
+
+ cmd.getInput().setReqQueries(query);
+ break;
+ }
+ }catch (Exception ex) {
+ throwOrCollect(new OnapCommandInvalidSchema(schemaName, ex), errorList, validate);
}
- }catch (Exception ex) {
- throwOrCollect(new OnapCommandInvalidSchema(schemaName, ex), errorList, validate);
}
- }
- } else if (SUCCESS_CODES.equals(key1)) {
- if (validate) {
- validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1));
- }
- cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
- } else if (RESULT_MAP.equals(key1)) {
- if (validate) {
- validateHttpResultMap(errorList, values);
- }
- cmd.setResultMap((Map<String, String>) valMap.get(key1));
- } else if (SAMPLE_RESPONSE.equals(key1)) {
- // (mrkanag) implement sample response handling
+ break;
+
+ case SUCCESS_CODES:
+ if (validate) {
+ validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1));
+ }
+ cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
+ break;
+
+ case RESULT_MAP:
+ if (validate) {
+ validateHttpResultMap(errorList, values);
+ }
+ cmd.setResultMap((Map<String, String>) valMap.get(key1));
+ break;
+
+ case SAMPLE_RESPONSE:
+ // (mrkanag) implement sample response handling
+ break;
}
}
}