diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 54ac08e65a..435c1a75d0 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -59,6 +59,20 @@ public class MsScenario extends MsTestElement { if (!this.isEnable()) { return; } + if (this.getReferenced() != null && this.getReferenced().equals("Deleted")) { + return; + } else if (this.getReferenced() != null && this.getReferenced().equals("REF")) { + try { + ApiAutomationService apiAutomationService = CommonBeanFactory.getBean(ApiAutomationService.class); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ApiScenarioWithBLOBs scenario = apiAutomationService.getApiScenario(this.getId()); + JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); + hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference>() {}); + } catch (Exception ex) { + ex.printStackTrace(); + } + } config.setStep(this.name); config.setStepType("SCENARIO"); config.setEnableCookieShare(enableCookieShare); @@ -72,26 +86,6 @@ public class MsScenario extends MsTestElement { if (CollectionUtils.isNotEmpty(this.getVariables())) { config.setVariables(this.variables); } - if (this.getReferenced() != null && this.getReferenced().equals("Deleted")) { - return; - } else if (this.getReferenced() != null && this.getReferenced().equals("REF")) { - try { - ApiAutomationService apiAutomationService = CommonBeanFactory.getBean(ApiAutomationService.class); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - ApiScenarioWithBLOBs scenario = apiAutomationService.getApiScenario(this.getId()); - JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); - LinkedList elements = mapper.readValue(element.getString("hashTree"), new TypeReference>() { - }); - if (hashTree == null) { - hashTree = elements; - } else { - hashTree.addAll(elements); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } // 场景变量和环境变量 tree.add(arguments(config)); addCsvDataSet(tree); diff --git a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java index e1f1aca8d1..e880362bab 100644 --- a/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java +++ b/backend/src/main/java/io/metersphere/api/service/HistoricalDataUpgradeService.java @@ -39,8 +39,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.net.URL; +import java.nio.channels.FileChannel; import java.util.*; @Service @@ -276,45 +279,12 @@ public class HistoricalDataUpgradeService { private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; //文件的拷贝 - private static void copyFile(String sourcePath, String newPath) { - File readfile = new File(sourcePath); - File newFile = new File(newPath); - BufferedWriter bufferedWriter = null; - Writer writer = null; - FileOutputStream fileOutputStream = null; - BufferedReader bufferedReader = null; - try { - fileOutputStream = new FileOutputStream(newFile, true); - writer = new OutputStreamWriter(fileOutputStream, "UTF-8"); - bufferedWriter = new BufferedWriter(writer); - - bufferedReader = new BufferedReader(new FileReader(readfile)); - - String line = null; - while ((line = bufferedReader.readLine()) != null) { - bufferedWriter.write(line); - bufferedWriter.newLine(); - bufferedWriter.flush(); - } - } catch (IOException e) { + public static void copyFile(String sourcePath, String newPath) { + try (FileChannel inChannel = new FileInputStream(new File(sourcePath)).getChannel(); + FileChannel outChannel = new FileOutputStream(new File(newPath)).getChannel();) { + inChannel.transferTo(0, inChannel.size(), outChannel); + } catch (Exception e) { e.printStackTrace(); - } finally { - try { - if (bufferedWriter != null) { - bufferedWriter.close(); - } - if (bufferedReader != null) { - bufferedReader.close(); - } - if (writer != null) { - writer.close(); - } - if (fileOutputStream != null) { - fileOutputStream.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } } } diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue index 094be233ce..8ed2b03d41 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -234,6 +234,9 @@ } else { request = JSON.parse(this.api.request); } + if (!request.hashTree) { + request.hashTree = []; + } let obj = {apiDefinitionId: this.api.id, name: '', priority: 'P0', active: true, tags: []}; obj.request = request; this.apiCaseList.unshift(obj); diff --git a/frontend/src/business/components/api/definition/components/request/components/ApiDefinitionStepButton.vue b/frontend/src/business/components/api/definition/components/request/components/ApiDefinitionStepButton.vue index 63fc721786..3fa34a1452 100644 --- a/frontend/src/business/components/api/definition/components/request/components/ApiDefinitionStepButton.vue +++ b/frontend/src/business/components/api/definition/components/request/components/ApiDefinitionStepButton.vue @@ -27,18 +27,30 @@ methods: { addPre() { let jsr223PreProcessor = createComponent("JSR223PreProcessor"); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(jsr223PreProcessor); }, addPost() { let jsr223PostProcessor = createComponent("JSR223PostProcessor"); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(jsr223PostProcessor); }, addAssertions() { let assertions = new Assertions(); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(assertions); }, addExtract() { let jsonPostProcessor = new Extract(); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(jsonPostProcessor); }, } diff --git a/frontend/src/business/components/api/definition/components/step/JmxStep.vue b/frontend/src/business/components/api/definition/components/step/JmxStep.vue index 875f31810f..e26bbabd8d 100644 --- a/frontend/src/business/components/api/definition/components/step/JmxStep.vue +++ b/frontend/src/business/components/api/definition/components/step/JmxStep.vue @@ -105,21 +105,33 @@ methods: { addPre() { let jsr223PreProcessor = createComponent("JSR223PreProcessor"); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(jsr223PreProcessor); this.reload(); }, addPost() { let jsr223PostProcessor = createComponent("JSR223PostProcessor"); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(jsr223PostProcessor); this.reload(); }, addAssertions() { let assertions = new Assertions(); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(assertions); this.reload(); }, addExtract() { let jsonPostProcessor = new Extract(); + if (!this.request.hashTree) { + this.request.hashTree = []; + } this.request.hashTree.push(jsonPostProcessor); this.reload(); },