From e967cb0539fd292e271cc59feacbdccbae6b9cb9 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 26 Jan 2021 17:19:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=BA=E6=99=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB=E5=90=8E?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/request/MsScenario.java | 34 ++++++------- .../service/HistoricalDataUpgradeService.java | 48 ++++--------------- .../components/case/ApiCaseList.vue | 3 ++ .../components/ApiDefinitionStepButton.vue | 12 +++++ .../definition/components/step/JmxStep.vue | 12 +++++ 5 files changed, 50 insertions(+), 59 deletions(-) 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(); },