diff --git a/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java b/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java index d0afa5d36e..692d873f69 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiEnvironmentRunningParamService.java @@ -26,7 +26,7 @@ public class ApiEnvironmentRunningParamService { @Resource ApiTestEnvironmentMapper testEnvironmentMapper; - public void addParam(String environmentId, Map varMap) { + public void addParam(String environmentId, Map varMap) { if (MapUtils.isEmpty(varMap)) { return; } @@ -42,7 +42,7 @@ public class ApiEnvironmentRunningParamService { if (commonConfig.containsKey("variables")) { JSONArray variables = commonConfig.getJSONArray("variables"); - for (Map.Entry entry: varMap.entrySet()){ + for (Map.Entry entry : varMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); @@ -51,9 +51,9 @@ public class ApiEnvironmentRunningParamService { JSONObject jsonObj = variables.getJSONObject(i); if (jsonObj.containsKey("name") && StringUtils.equals(jsonObj.getString("name"), key)) { contains = true; - if(jsonObj.containsKey("value") && StringUtils.equals(jsonObj.getString("value"), value)){ + if (jsonObj.containsKey("value") && StringUtils.equals(jsonObj.getString("value"), value)) { break; - }else { + } else { envNeedUpdate = true; jsonObj.put("value", value); } @@ -77,7 +77,7 @@ public class ApiEnvironmentRunningParamService { } } else { JSONArray variables = new JSONArray(); - for (Map.Entry entry: varMap.entrySet()){ + for (Map.Entry entry : varMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); @@ -97,7 +97,7 @@ public class ApiEnvironmentRunningParamService { } else { JSONObject commonConfig = new JSONObject(); JSONArray variables = new JSONArray(); - for (Map.Entry entry: varMap.entrySet()) { + for (Map.Entry entry : varMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); JSONObject itemObj = new JSONObject(); @@ -112,7 +112,7 @@ public class ApiEnvironmentRunningParamService { commonConfig.put("variables", variables); configObj.put("commonConfig", commonConfig); } - if(envNeedUpdate){ + if (envNeedUpdate) { environment.setConfig(configObj.toJSONString()); testEnvironmentMapper.updateByPrimaryKeyWithBLOBs(environment); } @@ -124,36 +124,34 @@ public class ApiEnvironmentRunningParamService { public void parseEvn(String envStr) { String[] envStringArr = envStr.split("\n"); - Map> envVarsMap = new HashMap<>(); + Map> envVarsMap = new HashMap<>(); for (String env : envStringArr) { if (StringUtils.contains(env, "=")) { String[] envItem = env.split("="); - if (envItem.length > 1) { - String jmeterVarKey = envItem[0]; - if (this.checkValidity(jmeterVarKey, "MS.ENV.")) { - String[] envAndKeyArr = jmeterVarKey.substring("MS.ENV.".length()).split("\\."); - String envId = envAndKeyArr[0]; - String[] keyArr = ArrayUtils.remove(envAndKeyArr, 0); - String key = StringUtils.join(keyArr, "."); - String value = StringUtils.substring(env, jmeterVarKey.length() + 1); - if (StringUtils.isNoneEmpty(envId, key, value)) { - if(envVarsMap.containsKey(envId)){ - envVarsMap.get(envId).put(key,value); - }else { - Map varMap = new HashMap<>(); - varMap.put(key,value); - envVarsMap.put(envId,varMap); - } + String jmeterVarKey = envItem[0]; + if (this.checkValidity(jmeterVarKey, "MS.ENV.")) { + String[] envAndKeyArr = jmeterVarKey.substring("MS.ENV.".length()).split("\\."); + String envId = envAndKeyArr[0]; + String[] keyArr = ArrayUtils.remove(envAndKeyArr, 0); + String key = StringUtils.join(keyArr, "."); + String value = StringUtils.substring(env, jmeterVarKey.length() + 1); + if (StringUtils.isNoneEmpty(envId, key)) { + if (envVarsMap.containsKey(envId)) { + envVarsMap.get(envId).put(key, value); + } else { + Map varMap = new HashMap<>(); + varMap.put(key, value); + envVarsMap.put(envId, varMap); } } } } } - if(MapUtils.isNotEmpty(envVarsMap)){ - for (Map.Entry> entry: envVarsMap.entrySet()){ + if (MapUtils.isNotEmpty(envVarsMap)) { + for (Map.Entry> entry : envVarsMap.entrySet()) { String envId = entry.getKey(); - Map vars = entry.getValue(); + Map vars = entry.getValue(); this.addParam(envId, vars); } }