diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java deleted file mode 100644 index 47d9a854a9..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/EsbDataStruct.java +++ /dev/null @@ -1,202 +0,0 @@ -package io.metersphere.api.dto.automation; - -import io.metersphere.commons.constants.PropertyConstant; -import io.metersphere.commons.utils.LogUtil; -import lombok.Getter; -import lombok.Setter; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.dom4j.Document; -import org.dom4j.Element; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * //ESB数据格式 - * - * @author song.tianyang - * @Date 2021/3/15 4:37 下午 - * @Description - */ -@Getter -@Setter -public class EsbDataStruct { - private String uuid; - private String name; - private String value; - private String type; - private String systemName; - private String contentType; - private boolean required; - private String description; - private List children; - private String status = StringUtils.EMPTY; - - public void init() { - this.uuid = UUID.randomUUID().toString(); - this.systemName = StringUtils.EMPTY; - this.description = StringUtils.EMPTY; - this.value = StringUtils.EMPTY; - this.required = true; - this.contentType = StringUtils.EMPTY; - this.type = StringUtils.EMPTY; - this.children = new ArrayList<>(); - } - - public boolean initDefaultData(String name, String typeLength, String chineseName, String desc) { - this.init(); - if (StringUtils.isEmpty(name)) { - return false; - } - if (typeLength == null) { - typeLength = StringUtils.EMPTY; - } else { - typeLength = typeLength.trim(); - typeLength = typeLength.toLowerCase(); - } - - this.name = name; - - if (typeLength.startsWith(PropertyConstant.STRING)) { - this.type = PropertyConstant.STRING; - String lengthStr = typeLength.substring(6); - if (lengthStr.startsWith("(") && lengthStr.endsWith(")")) { - try { - int length = Integer.parseInt(lengthStr.substring(1, lengthStr.length() - 1)); - this.contentType = String.valueOf(length); - } catch (Exception e) { - } - - } - } else if (typeLength.startsWith(PropertyConstant.ARRAY)) { - this.type = PropertyConstant.ARRAY; - } else { - this.type = PropertyConstant.OBJECT; - } - - if (StringUtils.isEmpty(desc)) { - desc = StringUtils.EMPTY; - } - if (StringUtils.isNotEmpty(chineseName)) { - this.description = chineseName + ":" + desc; - } else { - this.description = desc; - } - - if (this.description.endsWith(":")) { - this.description = this.description.substring(0, this.description.length() - 1); - } - - return true; - } - - public EsbDataStruct copy(boolean copyChildren) { - EsbDataStruct returnObj = new EsbDataStruct(); - returnObj.name = this.name; - returnObj.value = this.value; - returnObj.type = this.type; - returnObj.systemName = this.systemName; - returnObj.contentType = this.contentType; - returnObj.required = this.required; - returnObj.description = this.description; - if (copyChildren) { - returnObj.children = this.children; - } else { - returnObj.children = new ArrayList<>(); - } - return returnObj; - } - - public Element genXmlElementByChildren(Element document) { - this.name = this.name.replace("&", "&").replace("<", "<").replace(">", ">") - .replace("\"", """).replace("©", "'"); - if (StringUtils.isEmpty(this.name)) { - return null; - } - - Element element = null; - try { - element = document.addElement(this.name); - if (StringUtils.equalsAnyIgnoreCase(type, PropertyConstant.STRING, PropertyConstant.ARRAY)) { - String attrString = StringUtils.EMPTY; - if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.STRING)) { - attrString = "s," + contentType; - } else if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.ARRAY)) { - attrString = "a," + contentType; - } - element.addAttribute("attr", attrString); - } - } catch (Exception e) { - LogUtil.error(e); - } - - if (element != null) { - if (this.children == null || this.children.isEmpty()) { - if (this.value == null) { - this.value = StringUtils.EMPTY; - } - element.addText(this.value); - } else { - for (EsbDataStruct child : children) { - child.genXmlElementByChildren(element); - } - } - } - return element; - } - - public Element genXmlElementByDocument(Document document) { - this.name = this.name.replace("&", "&").replace("<", "<").replace(">", ">") - .replace("\"", """).replace("©", "'"); - if (StringUtils.isEmpty(this.name)) { - return null; - } - - Element element = null; - try { - element = document.addElement(this.name); - if (StringUtils.equalsAnyIgnoreCase(type, PropertyConstant.STRING, PropertyConstant.ARRAY)) { - String attrString = StringUtils.EMPTY; - if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.STRING)) { - attrString = "s," + contentType; - } else if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.ARRAY)) { - attrString = "a," + contentType; - } - element.addAttribute("attr", attrString); - } - } catch (Exception e) { - LogUtil.error(e); - } - - if (element != null) { - if (this.children == null || this.children.isEmpty()) { - element.addText(this.value); - } else { - for (EsbDataStruct child : children) { - child.genXmlElementByChildren(element); - } - } - } - return element; - } - - public List getNameDeep() { - List returnList = new ArrayList<>(); - if (StringUtils.isNotEmpty(this.name)) { - returnList.add(this.name); - } - if (CollectionUtils.isNotEmpty(this.children)) { - for (EsbDataStruct child : this.children) { - List itemNameList = child.getNameDeep(); - for (String itemName : itemNameList) { - if (!returnList.contains(itemName)) { - returnList.add(itemName); - } - } - } - } - return returnList; - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java index 5854d7f603..c18ebc3298 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java @@ -57,9 +57,6 @@ public class SaveApiDefinitionRequest { private String tags; - //ESB参数。 可为null - private String esbDataStruct; - private String backEsbDataStruct; private String backScript; // 创建新版本时用到的 diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiTestCaseRequest.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiTestCaseRequest.java index ead501767e..e0fcca5384 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiTestCaseRequest.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiTestCaseRequest.java @@ -24,8 +24,4 @@ public class SaveApiTestCaseRequest extends ApiTestCase { private List follows; private String versionId; - - //ESB参数。 可为null - private String esbDataStruct; - private String backEsbDataStruct; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 9018243c18..45f033856a 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -1,6 +1,5 @@ package io.metersphere.api.dto.definition.request.sampler; -import io.metersphere.api.dto.automation.EsbDataStruct; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; @@ -79,11 +78,6 @@ public class MsTCPSampler extends MsTestElement { private String jsonDataStruct; private String rawDataStruct; private boolean customizeReq; - /** - * 新加两个参数,场景保存/修改时需要的参数。不会传递JMeter,只是用于最后的保留。 - */ - private List esbDataStruct; - private List backEsbDataStruct; @Override public void toHashTree(HashTree tree, List hashTree, MsParameter msParameter) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImport.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImport.java index 251d87f1c7..bb72d3f62a 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImport.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImport.java @@ -1,15 +1,13 @@ package io.metersphere.api.parse.api; -import io.metersphere.api.parse.api.ms.NodeTree; import io.metersphere.api.dto.mock.config.MockConfigImportDTO; +import io.metersphere.api.parse.api.ms.NodeTree; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; -import io.metersphere.base.domain.EsbApiParamsWithBLOBs; import lombok.Data; import java.util.ArrayList; import java.util.List; -import java.util.Map; @Data public class ApiDefinitionImport { @@ -20,9 +18,6 @@ public class ApiDefinitionImport { // 新版本带用例导出 private List cases = new ArrayList<>(); - //ESB文件导入的附属数据类 - private Map esbApiParamsMap; - //Mock数据相关 private List mocks; diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImportParserFactory.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImportParserFactory.java index 0a140f5f9e..37aae75187 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImportParserFactory.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/ApiDefinitionImportParserFactory.java @@ -14,8 +14,6 @@ public class ApiDefinitionImportParserFactory { return new Swagger2Parser(); } else if (StringUtils.equals(ApiImportPlatform.Har.name(), platform)) { return new HarParser(); - } else if (StringUtils.equals(ApiImportPlatform.ESB.name(), platform)) { - return new ESBParser(); } else if (StringUtils.equals(ApiImportPlatform.Jmeter.name(), platform)) { return new JmeterDefinitionParser(); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/ESBParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/ESBParser.java deleted file mode 100644 index 8479cd8c45..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/ESBParser.java +++ /dev/null @@ -1,775 +0,0 @@ -package io.metersphere.api.parse.api; - -import io.metersphere.api.dto.ApiTestImportRequest; -import io.metersphere.api.dto.automation.EsbDataStruct; -import io.metersphere.api.parse.api.esb.ESBExcelSheetInfo; -import io.metersphere.api.parse.api.esb.EsbExcelDataStruct; -import io.metersphere.api.parse.api.esb.EsbSheetDataStruct; -import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; -import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; -import io.metersphere.api.dto.scenario.KeyValue; -import io.metersphere.commons.constants.RequestTypeConstants; -import io.metersphere.service.definition.EsbApiParamService; -import io.metersphere.base.domain.ApiDefinitionWithBLOBs; -import io.metersphere.base.domain.EsbApiParamsWithBLOBs; -import io.metersphere.commons.constants.PropertyConstant; -import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.commons.utils.JSON; -import io.metersphere.commons.utils.LogUtil; -import io.metersphere.commons.utils.SessionUtils; -import io.swagger.models.Model; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.xssf.usermodel.*; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.text.DateFormat; -import java.util.*; -import java.util.regex.Pattern; - -/** - * @author song.tianyang - * @Date 2021/3/10 11:14 上午 - * @Description - */ -public class ESBParser extends EsbAbstractParser { - - private Map definitions = null; - - /** - * 导出模板 - * - * @param response - * @param fileName - */ - public static void export(HttpServletResponse response, String fileName) { - - XSSFWorkbook wb = null; - ServletOutputStream out = null; - try { - wb = getTemplate(); - out = response.getOutputStream(); - response.reset(); - response.setContentType("application/vnd.ms-excel"); - response.setCharacterEncoding(StandardCharsets.UTF_8.name()); - response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()) + ".xlsx"); - wb.write(out); - wb.close(); - } catch (IOException e) { - LogUtil.error(e); - } finally { - if (out != null) { - try { - out.close(); - } catch (Exception e) { - - } - } - if (wb != null) { - try { - wb.close(); - } catch (Exception e) { - - } - } - } - } - - private static XSSFWorkbook getTemplate() { - XSSFWorkbook workbook = new XSSFWorkbook(); - XSSFFont font = workbook.createFont(); - font.setFontHeightInPoints((short) 9); - Map cellStyleMap = createCellStyle(workbook); - XSSFSheet headSheet = workbook.createSheet("公共报文头"); - generateSheet(headSheet, font, cellStyleMap); - XSSFSheet bodySheet = workbook.createSheet("接口报文信息"); - generateSheet(bodySheet, font, cellStyleMap); - return workbook; - } - - private static Map createCellStyle(XSSFWorkbook workbook) { - Map cellStype = new HashMap<>(); - short[] colorIndexArr = {IndexedColors.LIGHT_GREEN.getIndex(), IndexedColors.ORCHID.getIndex(), IndexedColors.YELLOW.getIndex()}; - for (short colorIndex : colorIndexArr) { - XSSFCellStyle style = workbook.createCellStyle(); - style.setFillPattern(FillPatternType.SOLID_FOREGROUND); - style.setBorderBottom(BorderStyle.THIN); - style.setBorderLeft(BorderStyle.THIN); - style.setBorderRight(BorderStyle.THIN); - style.setBorderTop(BorderStyle.THIN); - - String name = StringUtils.EMPTY; - if (colorIndex == IndexedColors.LIGHT_GREEN.getIndex()) { - style.setFillForegroundColor(new XSSFColor(new java.awt.Color(204, 255, 204), null)); - name = "green"; - } else if (colorIndex == IndexedColors.ORCHID.getIndex()) { - style.setFillForegroundColor(new XSSFColor(new java.awt.Color(151, 50, 101), null)); - name = "pop"; - } else if (colorIndex == IndexedColors.YELLOW.getIndex()) { - style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 153), null)); - name = "yellow"; - } else { - name = PropertyConstant.DEFAULT; - } - cellStype.put(name, style); - } - return cellStype; - } - - private static void generateSheet(XSSFSheet sheet, XSSFFont font, Map cellStyleMap) { - if (sheet == null) { - return; - } - sheet.setColumnWidth(0, 4000); - sheet.setColumnWidth(1, 4000); - sheet.setColumnWidth(2, 4000); - sheet.setColumnWidth(3, 4000); - sheet.setColumnWidth(4, 880); - sheet.setColumnWidth(5, 4000); - sheet.setColumnWidth(6, 4000); - sheet.setColumnWidth(7, 4000); - sheet.setColumnWidth(8, 4000); - sheet.setColumnWidth(9, 4000); - - /** - * 模版生成: - * 字体大小:9 - * row1: 1交易码 2交易名称 (head的话是5)6(紫色[pop]背景空白单元格,下同) 7服务名称 8服务场景 - * row2: 1.请输入交易码(必填) 2请输入交易名称(必填) 7请输入服务名称(如果不填,则以交易名称为主) 8请输入服务场景(选填) - * row3: 合并7-10单元格,输入:请输入系统名称 背景色:黄色[yellow] - * row4: 1.英文名称2.中文名称3.数据类型/长度4.是否必输5.备注 7.英文名称8.数据类型/长度9.中文名称 10备注 背景色:黄色 - * row5: 整行都是青色【green】,1:输入 - * row6: 3:请输入STRING(具体长度) 或 ARRAY; 8:同3 - * row7:无 - * row8: 整行都是青色,1:输出 - * row9: 3:请输入STRING(具体长度) 或 ARRAY; 8:同3 - */ - XSSFRow row1 = sheet.createRow(0); - setCellValue("交易码", row1.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("交易名称", row1.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row1.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row1.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT)); -// if (isHead) { - setCellValue(StringUtils.EMPTY, row1.createCell(4), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("服务名称", row1.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("服务场景", row1.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row1.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row1.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row1.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - - - XSSFRow row2 = sheet.createRow(1); - setCellValue("请输入交易码(必填)", row2.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("请输入交易名称(必填)", row2.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row2.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row2.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT)); -// if (isHead) { - setCellValue(StringUtils.EMPTY, row2.createCell(4), font, cellStyleMap.get("pop")); - setCellValue("请输入服务名称(如果不填,则以交易名称为主)", row2.createCell(5), font, null); - setCellValue("请输入服务场景(选填)", row2.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row2.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row2.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row2.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - - - XSSFRow row3 = sheet.createRow(2); - setCellValue(StringUtils.EMPTY, row3.createCell(0), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(1), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(2), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(3), font, cellStyleMap.get("yellow")); -// if (isHead) { - setCellValue(StringUtils.EMPTY, row3.createCell(4), font, cellStyleMap.get("yellow")); - setCellValue("请输入系统名称", row3.createCell(5), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(6), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(7), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(8), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row3.createCell(9), font, cellStyleMap.get("yellow")); - CellRangeAddress region1 = new CellRangeAddress(2, 2, 0, 3); - sheet.addMergedRegion(region1); - CellRangeAddress region2 = new CellRangeAddress(2, 2, 5, 9); - sheet.addMergedRegion(region2); - - XSSFRow row4 = sheet.createRow(3); - setCellValue("英文名称", row4.createCell(0), font, cellStyleMap.get("yellow")); - setCellValue("中文名称", row4.createCell(1), font, cellStyleMap.get("yellow")); - setCellValue("数据类型/长度", row4.createCell(2), font, cellStyleMap.get("yellow")); -// if (isHead) { - setCellValue("备注", row4.createCell(3), font, cellStyleMap.get("yellow")); - setCellValue(StringUtils.EMPTY, row4.createCell(4), font, cellStyleMap.get("pop")); - setCellValue("英文名称", row4.createCell(5), font, cellStyleMap.get("yellow")); - setCellValue("数据类型/长度", row4.createCell(6), font, cellStyleMap.get("yellow")); - setCellValue("中文名称", row4.createCell(7), font, cellStyleMap.get("yellow")); - setCellValue("备注", row4.createCell(8), font, cellStyleMap.get("yellow")); - setCellValue("所在报文位置", row4.createCell(9), font, cellStyleMap.get("yellow")); - - XSSFRow row5 = sheet.createRow(4); - setCellValue("输入", row5.createCell(0), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(1), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(2), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(3), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(4), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(5), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(6), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(7), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(8), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row5.createCell(9), font, cellStyleMap.get("green")); - - XSSFRow row6 = sheet.createRow(5); - setCellValue(StringUtils.EMPTY, row6.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row6.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("请输入STRING(具体长度) 或 ARRAY", row6.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row6.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT)); -// if (isHead) { - setCellValue(StringUtils.EMPTY, row6.createCell(4), font, cellStyleMap.get("pop")); - setCellValue(StringUtils.EMPTY, row6.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("请输入STRING(具体长度) 或 ARRAY", row6.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row6.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row6.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row6.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - - - XSSFRow row7 = sheet.createRow(6); - setCellValue(StringUtils.EMPTY, row7.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row7.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row7.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT)); -// if (isHead) { - setCellValue(StringUtils.EMPTY, row7.createCell(4), font, cellStyleMap.get("pop")); - setCellValue(StringUtils.EMPTY, row7.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row7.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row7.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row7.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row7.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - - - XSSFRow row8 = sheet.createRow(7); - setCellValue("输出", row8.createCell(0), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(1), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(2), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(3), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(4), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(5), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(6), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(7), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(8), font, cellStyleMap.get("green")); - setCellValue(StringUtils.EMPTY, row8.createCell(9), font, cellStyleMap.get("green")); - - - XSSFRow row9 = sheet.createRow(8); - setCellValue(StringUtils.EMPTY, row9.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row9.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("请输入STRING(具体长度) 或 ARRAY", row9.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row9.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT)); -// if (isHead) { - setCellValue(StringUtils.EMPTY, row9.createCell(4), font, cellStyleMap.get("pop")); - setCellValue(StringUtils.EMPTY, row9.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue("请输入STRING(具体长度) 或 ARRAY", row9.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row9.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row9.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - setCellValue(StringUtils.EMPTY, row9.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT)); - - } - - private static void setCellValue(String textValue, Cell cell, XSSFFont font, XSSFCellStyle cellStyle) { - XSSFRichTextString richString = new XSSFRichTextString(textValue); - richString.applyFont(font); - if (cellStyle != null) { - cell.setCellStyle(cellStyle); - } - cell.setCellValue(richString); - } - - - @Override - public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) throws Exception { - EsbExcelDataStruct excelDataStruct = this.esbImport(source); - this.projectId = request.getProjectId(); - ApiDefinitionImport definitionImport = this.parseApiDefinitionImport(excelDataStruct, request); - return definitionImport; - } - - public EsbExcelDataStruct esbImport(InputStream source) throws IOException, InvalidFormatException { - Workbook workbook = WorkbookFactory.create(source); - int sheetCount = workbook.getNumberOfSheets(); - EsbSheetDataStruct headStruct = null; - List interfaceStruct = new ArrayList<>(); - if (sheetCount > 0) { - Sheet headSheet = workbook.getSheetAt(0); - headStruct = this.parseExcelSheet(headSheet, true); - for (int index = 1; index < sheetCount; index++) { - Sheet dataSheet = workbook.getSheetAt(index); - EsbSheetDataStruct bodyStruct = this.parseExcelSheet(dataSheet, false); - interfaceStruct.add(bodyStruct); - } - } - - EsbExcelDataStruct excelData = new EsbExcelDataStruct(); - excelData.setHeadData(headStruct); - excelData.setInterfaceList(interfaceStruct); - return excelData; - } - - private EsbSheetDataStruct parseExcelSheet(Sheet headSheet, boolean isHeadSheet) { - EsbSheetDataStruct importDataStruct = new EsbSheetDataStruct(); - if (headSheet == null) { - return importDataStruct; - } - ESBExcelSheetInfo sheetInfo = this.getEsbExcelSheetInfo(headSheet); - - int rowCount = headSheet.getLastRowNum(); - - //根据模版样式,如果不是报文头,则要取接口信息 - if (!isHeadSheet) { - Row interfaceInfoRow = headSheet.getRow(1); - if (interfaceInfoRow != null) { - List rowDataArr = this.getRowDataByStartIndexAndEndIndex(interfaceInfoRow, 0, sheetInfo.getCellCount() - 1); - if (rowDataArr.size() >= sheetInfo.getCellCount()) { - String interfaceCode = rowDataArr.get(sheetInfo.getSimpleCodeIndex()); - String interfaceName = rowDataArr.get(sheetInfo.getServiceNameIndex()); - String interfaceDesc = rowDataArr.get(sheetInfo.getServiceScenarioIndex()); - if (StringUtils.isEmpty(interfaceName)) { - interfaceName = rowDataArr.get(sheetInfo.getSimpleNameIndex()); - } - importDataStruct.setInterfaceInfo(interfaceCode, interfaceName, interfaceDesc); - } - } - } - //超过10行为空白,直接退出。 - //部分office/wpf生成的文件会出现几万多空行,容易造成内存溢出。这里进行判断,连续五行为空白时认为读取结束。 - int blankRowCount = 0; - boolean isRequest = true; - - for (int startRow = sheetInfo.getRequestMessageRow(); startRow < rowCount; startRow++) { - Row row = headSheet.getRow(startRow); - List rowDataArr = this.getRowDataByStartIndexAndEndIndex(row, 0, sheetInfo.getCellCount() - 1); - boolean isBlankRow = this.checkBlankRow(rowDataArr, sheetInfo.getCellCount()); - if (!isBlankRow) { - String cellFlag = rowDataArr.get(0); - if (StringUtils.equals(cellFlag, "输出")) { - isRequest = false; - } - } - if (isBlankRow) { - if (isRequest) { - isRequest = false; - } - blankRowCount++; - if (blankRowCount > 10) { - break; - } - } else { - blankRowCount = 0; - EsbDataStruct dataStruct = new EsbDataStruct(); - boolean initDataSuccess = dataStruct.initDefaultData( - rowDataArr.get(sheetInfo.getApiNameIndex()), rowDataArr.get(sheetInfo.getDataTypeIndex()), rowDataArr.get(sheetInfo.getChineNameIndex()), rowDataArr.get(sheetInfo.getDescIndex())); - if (!initDataSuccess) { - continue; - } - boolean isHead = isHeadSheet; - if (rowDataArr.size() > sheetInfo.getCellCount()) { - if (StringUtils.equals(rowDataArr.get(sheetInfo.getApiPositionIndex()), "SYS_HEAD")) { - isHead = true; - } - - } - if (isRequest) { - if (isHead) { - importDataStruct.getReqHeadList().add(dataStruct); - } else { - importDataStruct.getRequestList().add(dataStruct); - } - } else { - if (isHead) { - importDataStruct.getRspHeadList().add(dataStruct); - } else { - importDataStruct.getResponseList().add(dataStruct); - } - } - } - } - return importDataStruct; - } - - private boolean checkBlankRow(List rowDataArr, int rowCheckLength) { - if (rowDataArr == null || rowDataArr.size() < rowCheckLength) { - return true; - } - for (String str : rowDataArr) { - if (StringUtils.isNotEmpty(str)) { - return false; - } - } - return true; - } - - private List getRowDataByStartIndexAndEndIndex(Row row, int startCell, int endCell) { - List returnArray = new ArrayList<>(); - if (row == null) { - return returnArray; - } - for (int i = startCell; i <= endCell; i++) { - Cell cell = row.getCell(i); - if (cell != null) { - returnArray.add(getCellValue(cell)); - } else { - returnArray.add(StringUtils.EMPTY); - } - } - return returnArray; - } - - private String getCellValue(Cell cell) { - String returnCellValue = StringUtils.EMPTY; - if (cell.getCellType() == CellType.BLANK) { - returnCellValue = StringUtils.EMPTY; - } else if (cell.getCellType() == CellType.BOOLEAN) { - returnCellValue = String.valueOf(cell.getBooleanCellValue()); - } else if (cell.getCellType() == CellType.ERROR) { - returnCellValue = StringUtils.EMPTY; - } else if (cell.getCellType() == CellType.NUMERIC) { - returnCellValue = getValueOfNumericCell(cell); - } else if (cell.getCellType() == CellType.FORMULA) { - try { - returnCellValue = getValueOfNumericCell(cell); - } catch (IllegalStateException e) { - try { - returnCellValue = cell.getRichStringCellValue().toString(); - } catch (IllegalStateException e2) { - } - } catch (Exception e) { - LogUtil.error(e); - } - } else { - returnCellValue = cell.getRichStringCellValue().getString(); - } - if (returnCellValue == null) { - returnCellValue = StringUtils.EMPTY; - } - return returnCellValue; - } - - private String getValueOfNumericCell(Cell cell) { - Boolean isDate = DateUtil.isCellDateFormatted(cell); - Double d = cell.getNumericCellValue(); - String o = null; - if (isDate) { - o = DateFormat.getDateTimeInstance() - .format(cell.getDateCellValue()); - } else { - o = getRealStringValueOfDouble(d); - } - return o; - } - - // 处理科学计数法与普通计数法的字符串显示,尽最大努力保持精度 - private static String getRealStringValueOfDouble(Double d) { - String doubleStr = d.toString(); - boolean b = doubleStr.contains("E"); - int indexOfPoint = doubleStr.indexOf('.'); - if (b) { - int indexOfE = doubleStr.indexOf('E'); - // 小数部分 - BigInteger xs = new BigInteger(doubleStr.substring(indexOfPoint - + BigInteger.ONE.intValue(), indexOfE)); - // 指数 - int pow = Integer.valueOf(doubleStr.substring(indexOfE - + BigInteger.ONE.intValue())); - int xsLen = xs.toByteArray().length; - int scale = xsLen - pow > 0 ? xsLen - pow : 0; - doubleStr = String.format("%." + scale + "f", d); - } else { - Pattern p = Pattern.compile(".0$"); - java.util.regex.Matcher m = p.matcher(doubleStr); - if (m.find()) { - doubleStr = doubleStr.replace(".0", StringUtils.EMPTY); - } - } - return doubleStr; - } - - private ApiDefinitionImport parseApiDefinitionImport(EsbExcelDataStruct esbExcelDataStruct, ApiTestImportRequest importRequest) { - ApiDefinitionImport resultModel = new ApiDefinitionImport(); - List apiDataList = new ArrayList<>(); - -/* - ApiModule parentNode = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId()); -*/ - EsbSheetDataStruct headSheetData = esbExcelDataStruct.getHeadData(); - List interfaceDataList = esbExcelDataStruct.getInterfaceList(); - List savedNames = new ArrayList<>(); - Map esbApiParams = new HashMap<>(); - for (EsbSheetDataStruct interfaceData : interfaceDataList) { - String reqName = interfaceData.getServiceName(); - if (savedNames.contains(reqName)) { - continue; - } else { - savedNames.add(reqName); - } - - String esbSendRequest = "\r\n${SERVICE}"; - String reqDataStructStr = generateDataStrcut(headSheetData, interfaceData, true); - String respDataStrutStr = generateDataStrcut(headSheetData, interfaceData, false); - - String apiId = UUID.randomUUID().toString(); - ApiDefinitionWithBLOBs apiDefinition = new ApiDefinitionWithBLOBs(); - apiDefinition.setName(reqName); - apiDefinition.setMethod("ESB"); - apiDefinition.setId(apiId); - apiDefinition.setProjectId(this.projectId); - /* apiDefinition.setModuleId(importRequest.getModuleId()); - apiDefinition.setModulePath(importRequest.getModulePath());*/ - apiDefinition.setRequest(genTCPSampler(esbSendRequest, reqDataStructStr)); - if (StringUtils.equalsIgnoreCase("schedule", importRequest.getType())) { - apiDefinition.setUserId(importRequest.getUserId()); - } else { - apiDefinition.setUserId(SessionUtils.getUserId()); - } - apiDefinition.setProtocol(RequestTypeConstants.TCP); - /* buildModule(parentNode, apiDefinition, null);*/ - apiDataList.add(apiDefinition); - - EsbApiParamsWithBLOBs apiParams = new EsbApiParamsWithBLOBs(); - apiParams.setId(UUID.randomUUID().toString()); - apiParams.setResourceId(apiId); - - apiParams.setDataStruct(reqDataStructStr); - apiParams.setResponseDataStruct(respDataStrutStr); - esbApiParams.put(apiId, apiParams); - } - - resultModel.setData(apiDataList); - resultModel.setEsbApiParamsMap(esbApiParams); - - return resultModel; - } - - private String genTCPSampler(String sendRequest, String esbDataStruct) { - - MsTCPSampler tcpSampler = new MsTCPSampler(); - MsJSR223PreProcessor preProcessor = new MsJSR223PreProcessor(); - - tcpSampler.setTcpPreProcessor(preProcessor); - tcpSampler.setProtocol("ESB"); - tcpSampler.setClassname("TCPClientImpl"); - tcpSampler.setReUseConnection(false); - String script = "String report = ctx.getCurrentSampler().getRequestData();\n" + - " if(report!=null){\n" + - " //补足8位长度,前置补0\n" + - " String reportlengthStr = String.format(\"%08d\",report.length());\n" + - " report = reportlengthStr+report;\n" + - " ctx.getCurrentSampler().setRequestData(report);\n" + - " }"; -// frontScriptList.add(script); - if (tcpSampler.getTcpPreProcessor() != null) { - tcpSampler.getTcpPreProcessor().setScriptLanguage("groovy"); - tcpSampler.getTcpPreProcessor().setScript(script); - } - - - if (StringUtils.isNotEmpty(sendRequest)) { - tcpSampler.setRequest(sendRequest); - } - - if (StringUtils.isNotEmpty(esbDataStruct)) { - EsbApiParamService esbApiParamService = CommonBeanFactory.getBean(EsbApiParamService.class); - List keyValueList = esbApiParamService.genKeyValueListByDataStruct(tcpSampler, esbDataStruct); - tcpSampler.setParameters(keyValueList); - } - - return JSON.toJSONString(tcpSampler); - } - - private String generateDataStrcut(EsbSheetDataStruct head, EsbSheetDataStruct body, boolean isRequest) { - EsbDataStruct dataStruct = new EsbDataStruct(); - dataStruct.initDefaultData("SERVICE", null, null, null); - List headList = new ArrayList<>(); - List bodyList = new ArrayList<>(); - if (head != null) { - if (isRequest) { - headList.addAll(head.getReqHeadList()); - bodyList.addAll(head.getRequestList()); - } else { - headList.addAll(head.getRspHeadList()); - bodyList.addAll(head.getResponseList()); - } - } - if (body != null) { - if (isRequest) { - headList.addAll(body.getReqHeadList()); - bodyList.addAll(body.getRequestList()); - } else { - headList.addAll(body.getRspHeadList()); - bodyList.addAll(body.getResponseList()); - } - } - - if (!headList.isEmpty()) { - EsbDataStruct headStruct = new EsbDataStruct(); - headStruct.initDefaultData("SYS_HEAD", null, null, null); - dataStruct.getChildren().add(headStruct); - Map childrenEsbDataStructMap = new HashMap<>(); - //用来判断节点有没有在array节点内 - String lastArrayDataStrcutName = null; - for (EsbDataStruct headData : headList) { - if (StringUtils.equalsIgnoreCase(PropertyConstant.ARRAY, headData.getType())) { - if (lastArrayDataStrcutName == null) { - lastArrayDataStrcutName = headData.getName(); - EsbDataStruct arrayStrcut = new EsbDataStruct(); - arrayStrcut.initDefaultData(headData.getName(), headData.getType(), headData.getContentType(), headData.getDescription()); - headStruct.getChildren().add(arrayStrcut); - childrenEsbDataStructMap.put(lastArrayDataStrcutName, arrayStrcut); - } else { - lastArrayDataStrcutName = null; - } - } else { - if (lastArrayDataStrcutName == null) { - headStruct.getChildren().add(headData); - } else { - EsbDataStruct arrayStrcut = childrenEsbDataStructMap.get(lastArrayDataStrcutName); - if (arrayStrcut != null) { - arrayStrcut.getChildren().add(headData); - } - } - } - } - } - - if (!bodyList.isEmpty()) { - EsbDataStruct bodyStruct = new EsbDataStruct(); - bodyStruct.initDefaultData("BODY", null, null, null); - dataStruct.getChildren().add(bodyStruct); - Map childrenEsbDataStructMap = new HashMap<>(); - //用来判断节点有没有在array节点内 - String lastArrayDataStrcutName = null; - for (EsbDataStruct bodyData : bodyList) { - if (StringUtils.equalsIgnoreCase(PropertyConstant.ARRAY, bodyData.getType())) { - if (lastArrayDataStrcutName == null) { - lastArrayDataStrcutName = bodyData.getName(); - EsbDataStruct arrayStrcut = new EsbDataStruct(); - arrayStrcut.initDefaultData(bodyData.getName(), bodyData.getType(), bodyData.getContentType(), bodyData.getDescription()); - bodyStruct.getChildren().add(arrayStrcut); - childrenEsbDataStructMap.put(lastArrayDataStrcutName, arrayStrcut); - } else { - lastArrayDataStrcutName = null; - } - } else { - if (lastArrayDataStrcutName == null) { - bodyStruct.getChildren().add(bodyData); - } else { - EsbDataStruct arrayStrcut = childrenEsbDataStructMap.get(lastArrayDataStrcutName); - if (arrayStrcut != null) { - arrayStrcut.getChildren().add(bodyData); - } - } - } - } - } - List list = new ArrayList<>(); - list.add(dataStruct); - return JSON.toJSONString(list); - } - - private String getDefaultStringValue(String val) { - return StringUtils.isBlank(val) ? StringUtils.EMPTY : val; - } - - private ESBExcelSheetInfo getEsbExcelSheetInfo(Sheet sheet) { - String apiCodeCellName = "交易码"; - String apiNameCellName = "交易名称"; - String serviceNameCellName = "服务名称"; - String serviceScenarioCellName = "服务场景"; - - String englishCellName = "英文名称"; - String chineseCellName = "中文名称"; - String dataTypeCellName = "数据类型"; - String descCellName = "备注"; - - int maxContinuityEmptyCellCount = 10; - - ESBExcelSheetInfo sheetInfo = new ESBExcelSheetInfo(); - - int lastRowNum = sheet.getLastRowNum(); - - rowForeach: - for (int rowIndex = 0; rowIndex <= lastRowNum; rowIndex++) { - Row row = sheet.getRow(rowIndex); - if (row != null) { - if (rowIndex == 0) { - int lastCellNumber = row.getLastCellNum(); - - //连续空白数据的统计:超过连续maxContinuityEmptyCellCount个空白数据时,停止读取当前行。 - // (某些Excel进行读取时会有缺陷:单元格没有数据,但是因为格式进行过设置,会一直读取,容易造成内存溢出) - int continuityEmptyCount = 0; - - cellForeach: - for (int i = 0; i <= lastCellNumber; i++) { - Cell cell = row.getCell(i); - if (cell != null) { - String cellValue = this.getCellValue(cell).trim(); - if (StringUtils.isEmpty(cellValue)) { - continuityEmptyCount++; - if (continuityEmptyCount > maxContinuityEmptyCellCount) { - break cellForeach; - } - } else { - continuityEmptyCount = 0; - if (StringUtils.equals(cellValue, apiCodeCellName)) { - sheetInfo.setSimpleCodeIndex(i); - } else if (StringUtils.equals(cellValue, apiNameCellName)) { - sheetInfo.setSimpleNameIndex(i); - } else if (StringUtils.equals(cellValue, serviceNameCellName)) { - sheetInfo.setServiceNameIndex(i); - } else if (StringUtils.equals(cellValue, serviceScenarioCellName)) { - sheetInfo.setServiceScenarioIndex(i); - } - } - } - } - } else { - //根据第一行《服务名称》的起始列下标开始读取, 进行匹配(英文名称、数据类型/长度、中文名称、备注) - int startReadIndex = sheetInfo.getApiNameIndex(); - int lastCellNumber = row.getLastCellNum(); - - int continuityEmptyCount = 0; - cellForeach: - for (int i = startReadIndex; i < lastCellNumber; i++) { - Cell cell = row.getCell(i); - if (cell != null) { - String cellValue = this.getCellValue(cell).trim(); - if (StringUtils.isEmpty(cellValue)) { - continuityEmptyCount++; - if (continuityEmptyCount > maxContinuityEmptyCellCount) { - break cellForeach; - } - } else { - continuityEmptyCount = 0; - if (StringUtils.equals(cellValue, englishCellName)) { - sheetInfo.setApiNameIndex(i); - } else if (StringUtils.equals(cellValue, chineseCellName)) { - sheetInfo.setChineNameIndex(i); - } else if (StringUtils.contains(cellValue, dataTypeCellName)) { - sheetInfo.setDataTypeIndex(i); - } else if (StringUtils.equals(cellValue, descCellName)) { - sheetInfo.setDescIndex(i); - } - } - } - } - if (sheetInfo.installedApiInfoIndex()) { - sheetInfo.countApiPosisionIndex(); - sheetInfo.setRequestMessageRow(rowIndex + 1); - break rowForeach; - } - } - } - } - return sheetInfo; - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/EsbAbstractParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/EsbAbstractParser.java deleted file mode 100644 index 88ec261777..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/EsbAbstractParser.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.metersphere.api.parse.api; - - -import io.metersphere.api.parse.ApiImportAbstractParser; -import io.metersphere.base.domain.ApiDefinitionWithBLOBs; -import io.metersphere.base.domain.ApiModule; - -import java.util.List; - -/** - * @author song.tianyang - * @Date 2021/3/10 11:15 上午 - * @Description - */ -public abstract class EsbAbstractParser extends ApiImportAbstractParser { - - protected void buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition, List tags) { - if (tags != null) { - tags.forEach(tag -> { - ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId); - apiDefinition.setModuleId(module.getId()); - }); - } else { - apiDefinition.setModuleId(parentModule.getId()); - } - } - -} diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/ESBExcelSheetInfo.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/ESBExcelSheetInfo.java deleted file mode 100644 index 56401f870a..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/ESBExcelSheetInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.metersphere.api.parse.api.esb; - -import lombok.Getter; -import lombok.Setter; - -/** - * @author song.tianyang - * @Date 2021/5/6 3:25 下午 - * @Description - */ -@Getter -@Setter -public class ESBExcelSheetInfo { - //交易码下标 - private int simpleCodeIndex = 0; - //交易名称下标 - private int simpleNameIndex = 0; - //服务名下标 - private int serviceNameIndex = 0; - //服务场景下标 - private int serviceScenarioIndex = 0; - - //接口名字下标 - private int apiNameIndex = 0; - //数据类型下标 - private int dataTypeIndex = 0; - //中文名称 - private int chineNameIndex = 0; - //描述 - private int descIndex = 0; - //api位置 - private int apiPositionIndex = 0; - //每一行的单元格最大长度 - private int cellCount = 0; - //请求信息起始行 - private int requestMessageRow = 0; - //允许的最大空白行数(连续超过这个数字的空白行则认为sheet读取结束) - private int maxEmptyRowCount = 20; - - public boolean installedApiInfoIndex() { - return (apiNameIndex != 0 && dataTypeIndex != 0); - } - - public void countApiPosisionIndex() { - apiPositionIndex = apiNameIndex > apiPositionIndex ? apiNameIndex : apiPositionIndex; - apiPositionIndex = dataTypeIndex > apiPositionIndex ? dataTypeIndex : apiPositionIndex; - apiPositionIndex = chineNameIndex > apiPositionIndex ? chineNameIndex : apiPositionIndex; - apiPositionIndex = descIndex > apiPositionIndex ? descIndex : apiPositionIndex; - apiPositionIndex++; - cellCount = apiPositionIndex; - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/EsbExcelDataStruct.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/EsbExcelDataStruct.java deleted file mode 100644 index f8a4cc3cc7..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/EsbExcelDataStruct.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.metersphere.api.parse.api.esb; - -import lombok.Getter; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author song.tianyang - * @Date 2021/3/23 12:55 下午 - * @Description - */ -@Getter -@Setter -public class EsbExcelDataStruct { - private EsbSheetDataStruct headData; - private List interfaceList = new ArrayList<>(); -} diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/EsbSheetDataStruct.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/EsbSheetDataStruct.java deleted file mode 100644 index f8ac984fb0..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/esb/EsbSheetDataStruct.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.metersphere.api.parse.api.esb; - -import io.metersphere.api.dto.automation.EsbDataStruct; -import io.metersphere.commons.exception.MSException; -import lombok.Getter; -import lombok.Setter; -import org.apache.commons.lang3.StringUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author song.tianyang - * @Date 2021/3/22 9:42 下午 - * @Description - */ -@Getter -@Setter -public class EsbSheetDataStruct { - private String serviceName; - private String serviceDesc; - private List requestList = new ArrayList<>(); - private List responseList = new ArrayList<>(); - - //单个接口内也可能有报文头中要增加的数据 - private List reqHeadList = new ArrayList<>(); - private List rspHeadList = new ArrayList<>(); - - - public void setInterfaceInfo(String interfaceCode, String interfaceName, String interfaceDesc) { - if (StringUtils.isEmpty(interfaceCode) && StringUtils.isEmpty(interfaceName)) { - MSException.throwException("接口的交易码或服务名称不能都为空"); - } - if (StringUtils.isNotEmpty(interfaceCode)) { - this.serviceName = interfaceCode + ":" + interfaceName; - } else { - this.serviceName = interfaceName; - } - if (this.serviceName.endsWith(":")) { - this.serviceName = this.serviceName.substring(0, this.serviceName.length() - 1); - } - this.serviceDesc = interfaceDesc; - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/EsbDataParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/EsbDataParser.java deleted file mode 100644 index fb9afb380e..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/EsbDataParser.java +++ /dev/null @@ -1,97 +0,0 @@ -package io.metersphere.api.parse.scenario; - -import io.metersphere.api.dto.automation.EsbDataStruct; -import io.metersphere.commons.utils.LogUtil; -import org.apache.commons.lang3.StringUtils; -import org.dom4j.Document; -import org.dom4j.DocumentHelper; -import org.dom4j.io.OutputFormat; -import org.dom4j.io.XMLWriter; - -import java.io.IOException; -import java.io.StringWriter; -import java.nio.charset.StandardCharsets; -import java.util.List; - -/** - * @author song.tianyang - * @Date 2021/3/15 5:00 下午 - * @Description - */ -public class EsbDataParser { - public static String esbData2XmlByParamStruct(List esbDataList, String[] paramArr) { - String xmlString = StringUtils.EMPTY; - try { - if (esbDataList == null || esbDataList.isEmpty()) { - return xmlString; - } - Document document = DocumentHelper.createDocument(); - EsbDataStruct dataStruct = selectEsbDataStructByNameStruct(esbDataList, paramArr, 0); - if (dataStruct != null) { - dataStruct.genXmlElementByDocument(document); - xmlString = document.getRootElement().asXML(); - - // 设置XML文档格式 - OutputFormat outputFormat = OutputFormat.createPrettyPrint(); - // 设置XML编码方式,即是用指定的编码方式保存XML文档到字符串(String),这里也可以指定为GBK或是ISO8859-1 - outputFormat.setEncoding(StandardCharsets.UTF_8.name()); - //outputFormat.setSuppressDeclaration(true); //是否生产xml头 - outputFormat.setIndent(true); //设置是否缩进 - outputFormat.setNewlines(true); //设置是否换行 - - try { - // stringWriter字符串是用来保存XML文档的 - StringWriter stringWriter = new StringWriter(); - // xmlWriter是用来把XML文档写入字符串的(工具) - XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat); - // 把创建好的XML文档写入字符串 - xmlWriter.write(document); - - // 打印字符串,即是XML文档 - xmlString = stringWriter.toString(); - xmlWriter.close(); - } catch (IOException e) { - LogUtil.error(e); - } - } - } catch (Exception e) { - LogUtil.error(e); - } - if (StringUtils.isEmpty(xmlString)) { - xmlString = StringUtils.EMPTY; - } else { - xmlString = xmlString.replaceAll(" ", StringUtils.EMPTY); - } - return xmlString; - } - - //根据参数结构,递归查询数据 - private static EsbDataStruct selectEsbDataStructByNameStruct(List esbDataList, String[] paramArr, int index) { - EsbDataStruct returnData = null; - if (paramArr.length > index) { - String param = paramArr[index]; - for (EsbDataStruct dataStruct : esbDataList) { - if (StringUtils.equals(dataStruct.getName(), param)) { - int newIndex = index + 1; - if (paramArr.length > newIndex && dataStruct.getChildren() != null) { - EsbDataStruct childElement = selectEsbDataStructByNameStruct(dataStruct.getChildren(), paramArr, newIndex); - if (childElement != null) { - returnData = dataStruct.copy(false); - returnData.getChildren().add(childElement); - } - } else { - returnData = dataStruct.copy(true); - } - } else if (index == 0) { - //如果是第一个节点不符合,则遍历子节点是否有符合的。 - int newIndex = index; - EsbDataStruct itemData = selectEsbDataStructByNameStruct(dataStruct.getChildren(), paramArr, newIndex); - if (itemData != null) { - returnData = itemData; - } - } - } - } - return returnData; - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/EsbApiParamsMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/EsbApiParamsMapper.java deleted file mode 100644 index cce758e716..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/EsbApiParamsMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.metersphere.base.mapper; - -import io.metersphere.base.domain.EsbApiParams; -import io.metersphere.base.domain.EsbApiParamsExample; -import io.metersphere.base.domain.EsbApiParamsWithBLOBs; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -public interface EsbApiParamsMapper { - long countByExample(EsbApiParamsExample example); - - int deleteByExample(EsbApiParamsExample example); - - int deleteByPrimaryKey(String id); - - int insert(EsbApiParamsWithBLOBs record); - - int insertSelective(EsbApiParamsWithBLOBs record); - - List selectByExampleWithBLOBs(EsbApiParamsExample example); - - List selectByExample(EsbApiParamsExample example); - - EsbApiParamsWithBLOBs selectByPrimaryKey(String id); - - int updateByExampleSelective(@Param("record") EsbApiParamsWithBLOBs record, @Param("example") EsbApiParamsExample example); - - int updateByExampleWithBLOBs(@Param("record") EsbApiParamsWithBLOBs record, @Param("example") EsbApiParamsExample example); - - int updateByExample(@Param("record") EsbApiParams record, @Param("example") EsbApiParamsExample example); - - int updateByPrimaryKeySelective(EsbApiParamsWithBLOBs record); - - int updateByPrimaryKeyWithBLOBs(EsbApiParamsWithBLOBs record); - - int updateByPrimaryKey(EsbApiParams record); -} \ No newline at end of file diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/EsbApiParamsMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/EsbApiParamsMapper.xml deleted file mode 100644 index d05fa60626..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/EsbApiParamsMapper.xml +++ /dev/null @@ -1,264 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - id, resource_id - - - data_struct, fronted_script, response_data_struct, backed_script - - - - - - delete from esb_api_params - where id = #{id,jdbcType=VARCHAR} - - - delete from esb_api_params - - - - - - insert into esb_api_params (id, resource_id, data_struct, - fronted_script, response_data_struct, - backed_script) - values (#{id,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, #{dataStruct,jdbcType=LONGVARCHAR}, - #{frontedScript,jdbcType=LONGVARCHAR}, #{responseDataStruct,jdbcType=LONGVARCHAR}, - #{backedScript,jdbcType=LONGVARCHAR}) - - - insert into esb_api_params - - - id, - - - resource_id, - - - data_struct, - - - fronted_script, - - - response_data_struct, - - - backed_script, - - - - - #{id,jdbcType=VARCHAR}, - - - #{resourceId,jdbcType=VARCHAR}, - - - #{dataStruct,jdbcType=LONGVARCHAR}, - - - #{frontedScript,jdbcType=LONGVARCHAR}, - - - #{responseDataStruct,jdbcType=LONGVARCHAR}, - - - #{backedScript,jdbcType=LONGVARCHAR}, - - - - - - update esb_api_params - - - id = #{record.id,jdbcType=VARCHAR}, - - - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - - - data_struct = #{record.dataStruct,jdbcType=LONGVARCHAR}, - - - fronted_script = #{record.frontedScript,jdbcType=LONGVARCHAR}, - - - response_data_struct = #{record.responseDataStruct,jdbcType=LONGVARCHAR}, - - - backed_script = #{record.backedScript,jdbcType=LONGVARCHAR}, - - - - - - - - update esb_api_params - set id = #{record.id,jdbcType=VARCHAR}, - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - data_struct = #{record.dataStruct,jdbcType=LONGVARCHAR}, - fronted_script = #{record.frontedScript,jdbcType=LONGVARCHAR}, - response_data_struct = #{record.responseDataStruct,jdbcType=LONGVARCHAR}, - backed_script = #{record.backedScript,jdbcType=LONGVARCHAR} - - - - - - update esb_api_params - set id = #{record.id,jdbcType=VARCHAR}, - resource_id = #{record.resourceId,jdbcType=VARCHAR} - - - - - - update esb_api_params - - - resource_id = #{resourceId,jdbcType=VARCHAR}, - - - data_struct = #{dataStruct,jdbcType=LONGVARCHAR}, - - - fronted_script = #{frontedScript,jdbcType=LONGVARCHAR}, - - - response_data_struct = #{responseDataStruct,jdbcType=LONGVARCHAR}, - - - backed_script = #{backedScript,jdbcType=LONGVARCHAR}, - - - where id = #{id,jdbcType=VARCHAR} - - - update esb_api_params - set resource_id = #{resourceId,jdbcType=VARCHAR}, - data_struct = #{dataStruct,jdbcType=LONGVARCHAR}, - fronted_script = #{frontedScript,jdbcType=LONGVARCHAR}, - response_data_struct = #{responseDataStruct,jdbcType=LONGVARCHAR}, - backed_script = #{backedScript,jdbcType=LONGVARCHAR} - where id = #{id,jdbcType=VARCHAR} - - - update esb_api_params - set resource_id = #{resourceId,jdbcType=VARCHAR} - where id = #{id,jdbcType=VARCHAR} - - \ No newline at end of file diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java index c378cd6c54..5e4c4830b8 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java @@ -26,8 +26,6 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil { public static final String JSON_END = "}"; public static final String TYPE = "type"; public static final String HTTP = "HTTP"; - public static final String ESB = "ESB"; - public static final String BACK_ESB = "backEsbDataStruct"; public static final String BACK_SCRIPT = "backScript"; public static final String HEADS = "headers"; public static final String STATUS_CODE = "statusCode"; @@ -54,36 +52,9 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil { diffMap.put(TYPE, bloBsIsNew.getString(TYPE)); } } - if (bloBsIsNew.getString(TYPE).equals(ESB)) { - diffEsbResponse(bloBsIsNew, bloBsIsOld, diffMap); - if (diffMap.size() > 0) { - diffMap.put(TYPE, bloBsIsNew.getString(TYPE)); - } - } return JSON.toJSONString(diffMap); } - private static void diffEsbResponse(JSONObject bloBsIsNew, JSONObject bloBsIsOld, Map diffMap) { - //对比响应报文 - if (bloBsIsNew.get(BACK_ESB) != null && bloBsIsOld.get(BACK_ESB) != null) { - String backEsbDataStructNew = StringUtils.join(StringUtils.join(JSON_START, bloBsIsNew.get(BACK_ESB).toString()), JSON_END); - String backEsbDataStructOld = StringUtils.join(StringUtils.join(JSON_START, bloBsIsOld.get(BACK_ESB).toString()), JSON_END); - if (!StringUtils.equals(backEsbDataStructNew, backEsbDataStructOld)) { - diffMap.put(StringUtils.join(BACK_ESB, "1"), backEsbDataStructNew); - diffMap.put(StringUtils.join(BACK_ESB, "2"), backEsbDataStructOld); - } - } - - if (!StringUtils.equals(bloBsIsNew.getString(BACK_SCRIPT), bloBsIsOld.getString(BACK_SCRIPT))) { - String backScriptNew = StringUtils.join(StringUtils.join(JSON_START, bloBsIsNew.get(BACK_SCRIPT).toString()), JSON_END); - String backScriptOld = StringUtils.join(StringUtils.join(JSON_START, bloBsIsOld.get(BACK_SCRIPT).toString()), JSON_END); - if (!StringUtils.equals(backScriptNew, backScriptOld)) { - diffMap.put(StringUtils.join(BACK_SCRIPT, "1"), backScriptNew); - diffMap.put(StringUtils.join(BACK_SCRIPT, "2"), backScriptOld); - } - } - } - @Override public String diff(String newValue, String oldValue) { try { @@ -285,82 +256,50 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil { } private static void diffTcp(MsTCPSampler tcpNew, MsTCPSampler tcpOld, JsonDiff jsonDiff, Map diffMap) { - if ((ESB).equals(tcpNew.getProtocol()) && (ESB).equals(tcpOld.getProtocol())) { - diffMap.put(TYPE, ESB); - //对比参数 - String queryNewEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getEsbDataStruct())), JSON_END); - String queryOldEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getEsbDataStruct())), JSON_END); - if (!StringUtils.equals(queryNewEsb, queryOldEsb)) { - diffMap.put(StringUtils.join(QUERY, "1"), queryNewEsb); - diffMap.put(StringUtils.join(QUERY, "2"), queryOldEsb); + // 对比请求参数 + if (CollectionUtils.isNotEmpty(tcpNew.getParameters())) { + tcpNew.getParameters().remove(tcpNew.getParameters().size() - 1); + tcpOld.getParameters().remove(tcpOld.getParameters().size() - 1); + } + String queryNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getParameters())), JSON_END); + String queryOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getParameters())), JSON_END); + if (!StringUtils.equals(queryNew, queryOld)) { + String patch = jsonDiff.diff(queryOld, queryNew); + String diff = jsonDiff.apply(queryNew, patch); + if (StringUtils.isNotEmpty(diff)) { + diffMap.put(QUERY, diff); } - //报文模版 - String requestNewEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getRequest())), JSON_END); - String requestOldEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getRequest())), JSON_END); - if (!StringUtils.equals(requestNewEsb, requestOldEsb)) { - diffMap.put(StringUtils.join(REQUEST, "1"), requestNewEsb); - diffMap.put(StringUtils.join(REQUEST, "2"), requestOldEsb); + } + // 对比BODY-JSON参数 + if (!StringUtils.equals(tcpNew.getJsonDataStruct(), tcpOld.getJsonDataStruct())) { + String patch = jsonDiff.diff(tcpOld.getJsonDataStruct(), tcpNew.getJsonDataStruct()); + String diff = jsonDiff.apply(tcpNew.getJsonDataStruct(), patch); + if (StringUtils.isNotEmpty(diff) && !StringUtils.equals(patch, "{}")) { + diffMap.put("body_json", diff); } - // 其他设置 - List columns = ReflexObjectUtil.getColumns(tcpNew, DefinitionReference.esbColumns); - List columnsOld = ReflexObjectUtil.getColumns(tcpOld, DefinitionReference.esbColumns); - List diffColumns = getColumn(columns, columnsOld); - if (CollectionUtils.isNotEmpty(diffColumns)) { - diffMap.put("otherConfig", JSON.toJSONString(diffColumns)); - } - } else { - // 对比请求参数 - if (CollectionUtils.isNotEmpty(tcpNew.getParameters())) { - tcpNew.getParameters().remove(tcpNew.getParameters().size() - 1); - tcpOld.getParameters().remove(tcpOld.getParameters().size() - 1); - } - String queryNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getParameters())), JSON_END); - String queryOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getParameters())), JSON_END); - if (!StringUtils.equals(queryNew, queryOld)) { - String patch = jsonDiff.diff(queryOld, queryNew); - String diff = jsonDiff.apply(queryNew, patch); - if (StringUtils.isNotEmpty(diff)) { - diffMap.put(QUERY, diff); - } - } - // 对比BODY-JSON参数 - if (!StringUtils.equals(tcpNew.getJsonDataStruct(), tcpOld.getJsonDataStruct())) { - String patch = jsonDiff.diff(tcpOld.getJsonDataStruct(), tcpNew.getJsonDataStruct()); - String diff = jsonDiff.apply(tcpNew.getJsonDataStruct(), patch); - if (StringUtils.isNotEmpty(diff) && !StringUtils.equals(patch, "{}")) { - diffMap.put("body_json", diff); - } - } - // 对比BODY-XML参数 - String xmlNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getXmlDataStruct())), JSON_END); - String xmlOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getXmlDataStruct())), JSON_END); - if (!StringUtils.equals(xmlNew, xmlOld)) { - diffMap.put(StringUtils.join(BODY_XML, "_1"), JSON.toJSONString(tcpNew.getXmlDataStruct())); - diffMap.put(StringUtils.join(BODY_XML, "_2"), JSON.toJSONString(tcpOld.getXmlDataStruct())); - String patch = jsonDiff.diff(xmlOld, xmlNew); - String diffPatch = jsonDiff.apply(xmlNew, patch); - if (StringUtils.isNotEmpty(diffPatch)) { - diffMap.put(BODY_XML, diffPatch); - } - } - // 对比BODY-RAW参数 - if (!StringUtils.equals(tcpNew.getRawDataStruct(), tcpOld.getRawDataStruct())) { - diffMap.put(StringUtils.join(BODY_RAW, "_1"), tcpNew.getRawDataStruct()); - diffMap.put(StringUtils.join(BODY_RAW, "_2"), tcpOld.getRawDataStruct()); - } - // 对比pre参数 - if (tcpNew.getTcpPreProcessor() != null && !StringUtils.equals(tcpNew.getTcpPreProcessor().getScript(), tcpOld.getTcpPreProcessor().getScript())) { - diffMap.put(StringUtils.join(SCRIPT, "_1"), tcpNew.getTcpPreProcessor().getScript()); - diffMap.put(StringUtils.join(SCRIPT, "_2"), tcpOld.getTcpPreProcessor().getScript()); - } - // 其他设置 - List columns = ReflexObjectUtil.getColumns(tcpNew, DefinitionReference.esbColumns); - List columnsOld = ReflexObjectUtil.getColumns(tcpOld, DefinitionReference.esbColumns); - List diffColumns = getColumn(columns, columnsOld); - if (CollectionUtils.isNotEmpty(diffColumns)) { - diffMap.put("other_config", JSON.toJSONString(diffColumns)); + } + // 对比BODY-XML参数 + String xmlNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getXmlDataStruct())), JSON_END); + String xmlOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getXmlDataStruct())), JSON_END); + if (!StringUtils.equals(xmlNew, xmlOld)) { + diffMap.put(StringUtils.join(BODY_XML, "_1"), JSON.toJSONString(tcpNew.getXmlDataStruct())); + diffMap.put(StringUtils.join(BODY_XML, "_2"), JSON.toJSONString(tcpOld.getXmlDataStruct())); + String patch = jsonDiff.diff(xmlOld, xmlNew); + String diffPatch = jsonDiff.apply(xmlNew, patch); + if (StringUtils.isNotEmpty(diffPatch)) { + diffMap.put(BODY_XML, diffPatch); } } + // 对比BODY-RAW参数 + if (!StringUtils.equals(tcpNew.getRawDataStruct(), tcpOld.getRawDataStruct())) { + diffMap.put(StringUtils.join(BODY_RAW, "_1"), tcpNew.getRawDataStruct()); + diffMap.put(StringUtils.join(BODY_RAW, "_2"), tcpOld.getRawDataStruct()); + } + // 对比pre参数 + if (tcpNew.getTcpPreProcessor() != null && !StringUtils.equals(tcpNew.getTcpPreProcessor().getScript(), tcpOld.getTcpPreProcessor().getScript())) { + diffMap.put(StringUtils.join(SCRIPT, "_1"), tcpNew.getTcpPreProcessor().getScript()); + diffMap.put(StringUtils.join(SCRIPT, "_2"), tcpOld.getTcpPreProcessor().getScript()); + } } diff --git a/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java b/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java index 9d28fdff5b..c259ee764f 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/definition/ApiDefinitionController.java @@ -34,15 +34,12 @@ import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.notice.annotation.SendNotice; import io.metersphere.request.ResetOrderRequest; import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.definition.EsbApiParamService; -import io.metersphere.service.definition.EsbImportService; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -52,10 +49,6 @@ public class ApiDefinitionController { @Resource private ApiDefinitionService apiDefinitionService; @Resource - private EsbApiParamService esbApiParamService; - @Resource - private EsbImportService esbImportService; - @Resource private BaseEnvironmentService apiTestEnvironmentService; @Resource private ExecThreadPoolExecutor execThreadPoolExecutor; @@ -140,15 +133,6 @@ public class ApiDefinitionController { apiDefinitionService.deleteBatch(ids); } - @PostMapping(value = "/updateEsbRequest") - public SaveApiDefinitionRequest updateEsbRequest(@RequestBody SaveApiDefinitionRequest request) { - if (StringUtils.equals(request.getMethod(), "ESB")) { - //ESB的接口类型数据,采用TCP方式去发送。并将方法类型改为TCP。 并修改发送数据 - request = esbApiParamService.updateEsbRequest(request); - } - return request; - } - @PostMapping("/del-batch") @MsAuditLog(module = OperLogModule.API_DEFINITION, type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiDefinitionService.class) public void deleteBatchByParams(@RequestBody ApiBatchRequest request) { @@ -310,12 +294,6 @@ public class ApiDefinitionController { return JSONSchemaGenerator.getJson(jsonSchema); } - @GetMapping("/export-esb-template") - @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_EXPORT_API) - public void testCaseTemplateExport(HttpServletResponse response) { - esbImportService.templateExport(response); - } - @GetMapping("/mock-environment/{projectId}") public ApiTestEnvironmentWithBLOBs getMockEnvironment(@PathVariable String projectId) { return apiTestEnvironmentService.getMockEnvironmentByProjectId(projectId); diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index 93404a0b7a..c7775dc467 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -1,7 +1,6 @@ package io.metersphere.service; import io.metersphere.api.dto.ApiTestImportRequest; -import io.metersphere.api.dto.automation.EsbDataStruct; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.mock.*; import io.metersphere.api.dto.mock.config.MockConfigImportDTO; @@ -740,11 +739,6 @@ public class MockConfigService { paramNameList = this.parseByTcpTreeDataStruct(requestObj.optString("xmlDataStruct")); } else if (StringUtils.equalsIgnoreCase(reportType, "json") && requestObj.has("jsonDataStruct")) { paramNameList = this.parseByJsonDataStruct(requestObj.optString("jsonDataStruct")); - } else if (requestObj.has("protocol")) { - String protocol = requestObj.optString("protocol"); - if (StringUtils.equalsIgnoreCase("ESB", protocol) && requestObj.has("esbDataStruct")) { - paramNameList = this.parseByESBDataStruct(requestObj.optString("esbDataStruct")); - } } } } @@ -1005,20 +999,6 @@ public class MockConfigService { return returnList; } - private List parseByESBDataStruct(String dataString) { - List list = JSON.parseArray(dataString, EsbDataStruct.class); - List returnList = new ArrayList<>(); - for (EsbDataStruct dataStruct : list) { - List nameList = dataStruct.getNameDeep(); - for (String name : nameList) { - if (!returnList.contains(nameList)) { - returnList.add(name); - } - } - } - return returnList; - } - public MockExpectConfigDTO matchTcpMockExpect(String message, int port) { ProjectApplicationExample pae = new ProjectApplicationExample(); pae.createCriteria().andTypeEqualTo(ProjectApplicationType.MOCK_TCP_PORT.name()).andTypeValueEqualTo(String.valueOf(port)); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtil.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtil.java index 4cf41662c9..7e41354d09 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtil.java @@ -5,11 +5,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.definition.ApiDefinitionResult; -import io.metersphere.api.parse.api.ApiDefinitionImport; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiModuleMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; -import io.metersphere.base.mapper.EsbApiParamsMapper; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.enums.ApiTestDataStatus; @@ -24,7 +22,6 @@ import io.metersphere.xpack.api.service.ApiDefinitionSyncService; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.ibatis.session.SqlSession; import java.util.*; import java.util.stream.Collectors; @@ -403,22 +400,4 @@ public class ApiDefinitionImportUtil { return oldCaseMap; } - public static void delEsbData(ApiDefinitionImport apiImport, SqlSession sqlSession) { - if (apiImport.getEsbApiParamsMap() != null && apiImport.getEsbApiParamsMap().size() > 0) { - EsbApiParamsMapper esbApiParamsMapper = sqlSession.getMapper(EsbApiParamsMapper.class); - for (EsbApiParamsWithBLOBs model : apiImport.getEsbApiParamsMap().values()) { - EsbApiParamsExample example = new EsbApiParamsExample(); - example.createCriteria().andResourceIdEqualTo(model.getResourceId()); - List exitModelList = esbApiParamsMapper.selectByExampleWithBLOBs(example); - if (exitModelList.isEmpty()) { - esbApiParamsMapper.insert(model); - } else { - model.setId(exitModelList.get(0).getId()); - esbApiParamsMapper.updateByPrimaryKeyWithBLOBs(model); - } - } - } - } - - } diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java index d09f7b46ec..657c5b9d28 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java @@ -207,17 +207,15 @@ public class ApiDefinitionImportUtilService { } } else { - Map esbApiParamsMap = apiImport.getEsbApiParamsMap(); - - repeatList = dealRepeat(request, optionData, moduleMap, fullCoverage, idPathMap, chooseModule, esbApiParamsMap, toUpdateList, optionDataCases); + repeatList = dealRepeat(request, optionData, moduleMap, fullCoverage, idPathMap, chooseModule, toUpdateList, optionDataCases); } if (MapUtils.isNotEmpty(moduleMap)) { - moduleMap.forEach((k,v)-> apiModuleMapper.insert(v)); + moduleMap.forEach((k, v) -> apiModuleMapper.insert(v)); } int num = 0; if (!CollectionUtils.isEmpty(optionData) && optionData.get(0) != null && optionData.get(0).getProjectId() != null) { - num = getNextNum(optionData.get(0).getProjectId(),extApiDefinitionMapper); + num = getNextNum(optionData.get(0).getProjectId(), extApiDefinitionMapper); } //如果需要导入的数据为空。此时清空mock信息 if (optionData.isEmpty()) { @@ -259,34 +257,15 @@ public class ApiDefinitionImportUtilService { //如果EsbData需要存储,则需要进行接口是否更新的判断 ApiDefinitionImportParamDTO apiDefinitionImportParam = new ApiDefinitionImportParamDTO(item, request, apiImport.getMocks(), toUpdateList, caseList); apiDefinitionImportParam.setRepeatList(sameRefIds); - if (apiImport.getEsbApiParamsMap() != null) { - String apiId = item.getId(); - EsbApiParamsWithBLOBs model = apiImport.getEsbApiParamsMap().get(apiId); - request.setModeId("fullCoverage");//标准版ESB数据导入不区分是否覆盖,默认都为覆盖 - - ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam); - if (model != null) { - apiImport.getEsbApiParamsMap().remove(apiId); - model.setResourceId(item.getId()); - apiImport.getEsbApiParamsMap().put(item.getId(), model); - } - if (apiImportSendNoticeDTO != null) { - apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO); - } - } else { - ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam); - if (apiImportSendNoticeDTO != null) { - apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO); - } + ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam); + if (apiImportSendNoticeDTO != null) { + apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO); } if (i % 300 == 0) { sqlSession.flushStatements(); } } - //判断EsbData是否需要存储 - ApiDefinitionImportUtil.delEsbData(apiImport, sqlSession); - if (!CollectionUtils.isEmpty(apiImport.getMocks())) { MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class); mockConfigService.importMock(apiImport, sqlSession, request); @@ -336,14 +315,14 @@ public class ApiDefinitionImportUtilService { //允许覆盖模块,用导入的重复数据的最后一条覆盖查询的所有重复数据; case 在覆盖的时候,是拼接到原来的case,name唯一;不覆盖,就用原来的 if (fullCoverageApi) { if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) { - startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap, null); + startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } } else { //覆盖但不覆盖模块 if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) { //过滤同一层级重复模块,导入文件没有新增接口无需创建接口模块 moduleMap = judgeModuleMap(moduleMap, optionMap, repeatDataMap); - startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,null); + startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } } } else { @@ -387,12 +366,12 @@ public class ApiDefinitionImportUtilService { if (fullCoverage) { if (fullCoverageApi) { if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) { - startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap, null); + startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } } else { //不覆盖模块 if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) { - startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,null); + startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } } } else { @@ -473,7 +452,7 @@ public class ApiDefinitionImportUtilService { private static void startCoverModule(List toUpdateList, List optionData, Map methodPathMap, Map> repeatDataMap, String updateVersionId, List optionDataCases, - Map> oldCaseMap, Map esbApiParamsMap) { + Map> oldCaseMap) { //临时记录修改数据后导入的数据 List coverApiList = new ArrayList<>(); //临时记录需要更新的系统数据 @@ -501,7 +480,6 @@ public class ApiDefinitionImportUtilService { buildCaseList(oldCaseMap, caseNameMap, definitionWithBLOBs, optionDataCases); } //在指定版本中更新接口内容并变更接口模块为当前导入选择的模块下创建导入文件中接口指定的模块 - updateEsb(esbApiParamsMap, definitionWithBLOBs.getId(), apiDefinitionWithBLOBs.getId()); ApiDefinitionWithBLOBs api = new ApiDefinitionWithBLOBs(); BeanUtils.copyBean(api, apiDefinitionWithBLOBs); api.setId(definitionWithBLOBs.getId()); @@ -568,6 +546,7 @@ public class ApiDefinitionImportUtilService { } return moduleMap; } + private static void addNewVersionApi(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs, ApiDefinitionWithBLOBs v, String version) { apiDefinitionWithBLOBs.setVersionId(version); apiDefinitionWithBLOBs.setNum(v.getNum()); @@ -726,7 +705,7 @@ public class ApiDefinitionImportUtilService { } private List dealRepeat(ApiTestImportRequest request, List optionData, Map moduleMap, Boolean fullCoverage, Map idPathMap, ApiModuleDTO chooseModule, - Map esbApiParamsMap, List toUpdateList, List optionDataCases) { + List toUpdateList, List optionDataCases) { String chooseModuleId = request.getModuleId(); List repeatApiDefinitionWithBLOBs = getApiDefinitionWithBLOBsList(request, optionData); //重复接口的case @@ -758,11 +737,11 @@ public class ApiDefinitionImportUtilService { //处理数据 if (fullCoverage) { if (fullCoverageApi) { - startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,esbApiParamsMap); + startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } else { //过滤同一层级重复模块,导入文件没有新增接口无需创建接口模块 moduleMap = judgeModuleMap(moduleMap, optionMap, repeatDataMap); - startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,esbApiParamsMap); + startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } } else { //不覆盖 @@ -776,7 +755,7 @@ public class ApiDefinitionImportUtilService { repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getModulePath()))); optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getModulePath()), api -> api)); if (fullCoverage) { - startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,esbApiParamsMap); + startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap); } else { //不覆盖,同一接口不做更新 if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) { @@ -834,7 +813,7 @@ public class ApiDefinitionImportUtilService { private static void startCover(List toUpdateList, List optionData, Map methodPathMap, Map> repeatDataMap, String updateVersionId, List optionDataCases, - Map> oldCaseMap, Map esbApiParamsMap) { + Map> oldCaseMap) { List coverApiList = new ArrayList<>(); List updateApiList = new ArrayList<>(); repeatDataMap.forEach((k, v) -> { @@ -853,7 +832,6 @@ public class ApiDefinitionImportUtilService { i += 1; continue; } - updateEsb(esbApiParamsMap, definitionWithBLOBs.getId(), apiDefinitionWithBLOBs.getId()); //组合case if (MapUtils.isNotEmpty(caseNameMap)) { buildCaseList(oldCaseMap, caseNameMap, definitionWithBLOBs, optionDataCases); @@ -868,7 +846,7 @@ public class ApiDefinitionImportUtilService { updateApiList.add(definitionWithBLOBs); } if (i == v.size()) { - if (latestApi!=null) { + if (latestApi != null) { boolean hasChange; if (apiDefinitionWithBLOBs.getProtocol().equals("HTTP")) { hasChange = ApiDefinitionImportUtil.checkIsSynchronize(latestApi, apiDefinitionWithBLOBs); @@ -1029,19 +1007,6 @@ public class ApiDefinitionImportUtilService { } } - - - private static void updateEsb(Map esbApiParamsMap, String newId, String oldId) { - if (MapUtils.isNotEmpty(esbApiParamsMap)) { - EsbApiParamsWithBLOBs esbApiParamsWithBLOBs = esbApiParamsMap.get(oldId); - if (esbApiParamsWithBLOBs != null) { - esbApiParamsMap.remove(oldId); - esbApiParamsWithBLOBs.setResourceId(newId); - esbApiParamsMap.put(newId, esbApiParamsWithBLOBs); - } - } - } - private ApiImportSendNoticeDTO _importCreate(ApiDefinitionMapper batchMapper, ApiDefinitionImportParamDTO apiDefinitionImportParamDTO) { ApiDefinitionWithBLOBs apiDefinition = apiDefinitionImportParamDTO.getApiDefinition(); ApiTestImportRequest apiTestImportRequest = apiDefinitionImportParamDTO.getApiTestImportRequest(); @@ -1151,8 +1116,6 @@ public class ApiDefinitionImportUtilService { } - - private static List setRequestAndAddNewCase(ApiDefinitionWithBLOBs apiDefinition, List caseList, boolean newCreate) { boolean createCase = false; if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestTypeConstants.HTTP)) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 57b7736ca6..1e44428a86 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -107,8 +107,6 @@ public class ApiDefinitionService { @Resource private ApiTestCaseMapper apiTestCaseMapper; @Resource - private EsbApiParamService esbApiParamService; - @Resource private TcpApiParamService tcpApiParamService; @Resource private ApiModuleMapper apiModuleMapper; @@ -131,8 +129,6 @@ public class ApiDefinitionService { @Resource private BaseProjectService baseProjectService; @Resource - private EsbApiParamsMapper esbApiParamsMapper; - @Resource private ApiExecutionInfoService apiExecutionInfoService; @Lazy @Resource @@ -451,7 +447,6 @@ public class ApiDefinitionService { apiTestCaseService.deleteTestCase(api.getId()); extApiDefinitionExecResultMapper.deleteByResourceId(api.getId()); apiDefinitionMapper.deleteByPrimaryKey(api.getId()); - esbApiParamService.deleteByResourceId(api.getId()); MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class); mockConfigService.deleteMockConfigByApiId(api.getId()); // 删除自定义字段关联关系 @@ -474,7 +469,6 @@ public class ApiDefinitionService { public void deleteBatch(List apiIds) { ApiDefinitionExample example = new ApiDefinitionExample(); example.createCriteria().andIdIn(apiIds); - esbApiParamService.deleteByResourceIdIn(apiIds); apiDefinitionMapper.deleteByExample(example); apiTestCaseService.deleteBatchByDefinitionId(apiIds); // 删除附件关系 @@ -720,10 +714,7 @@ public class ApiDefinitionService { private ApiDefinitionWithBLOBs updateTest(SaveApiDefinitionRequest request) { checkNameExist(request, false); - if (StringUtils.equals(request.getMethod(), "ESB")) { - //ESB的接口类型数据,采用TCP方式去发送。并将方法类型改为TCP。 并修改发送数据 - request = esbApiParamService.handleEsbRequest(request); - } else if (StringUtils.equals(request.getMethod(), "TCP")) { + if (StringUtils.equals(request.getMethod(), "TCP")) { request = tcpApiParamService.handleTcpRequest(request); } final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs(); @@ -877,10 +868,6 @@ public class ApiDefinitionService { private ApiDefinitionResult createTest(SaveApiDefinitionRequest request) { checkNameExist(request, false); - if (StringUtils.equals(request.getMethod(), "ESB")) { - //ESB的接口类型数据,采用TCP方式去发送。并将方法类型改为TCP。 并修改发送数据 - request = esbApiParamService.handleEsbRequest(request); - } final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs(); test.setId(request.getId()); test.setName(request.getName()); @@ -1304,9 +1291,6 @@ public class ApiDefinitionService { res.setCasePassingRate("-"); res.setCaseStatus("-"); } - if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) { - esbApiParamService.handleApiEsbParams(res); - } } } } @@ -1561,25 +1545,6 @@ public class ApiDefinitionService { public String getLogDetails(String id) { ApiDefinitionWithBLOBs bloBs = apiDefinitionMapper.selectByPrimaryKey(id); if (bloBs != null) { - if (StringUtils.equals(bloBs.getMethod(), "ESB")) { - EsbApiParamsExample example = new EsbApiParamsExample(); - example.createCriteria().andResourceIdEqualTo(id); - List list = esbApiParamsMapper.selectByExampleWithBLOBs(example); - JSONObject request = JSONUtil.parseObject(bloBs.getRequest()); - Object backEsbDataStruct = request.get("backEsbDataStruct"); - Map map = new HashMap<>(); - if (backEsbDataStruct != null) { - map.put("backEsbDataStruct", backEsbDataStruct); - if (CollectionUtils.isNotEmpty(list)) { - map.put("backScript", list.get(0).getBackedScript()); - } - map.put(PropertyConstant.TYPE, "ESB"); - } - request.remove("backEsbDataStruct"); - bloBs.setRequest(request.toString()); - String response = JSON.toJSONString(map); - bloBs.setResponse(response); - } List columns = ReflexObjectUtil.getColumns(bloBs, DefinitionReference.definitionColumns); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns); return JSON.toJSONString(details); @@ -1666,17 +1631,10 @@ public class ApiDefinitionService { ApiDefinitionResult result = null; if (CollectionUtils.isNotEmpty(list)) { result = list.get(0); - this.checkApiAttachInfo(result); } return result; } - private void checkApiAttachInfo(ApiDefinitionResult result) { - if (StringUtils.equalsIgnoreCase("esb", result.getMethod())) { - esbApiParamService.handleApiEsbParams(result); - } - } - public long countEffectiveByProjectId(String projectId, String versionId) { if (StringUtils.isEmpty(projectId)) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiModuleService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiModuleService.java index fd7e029cfc..1e8d1d577f 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiModuleService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiModuleService.java @@ -14,10 +14,8 @@ import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiModule; import io.metersphere.base.domain.ApiModuleExample; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; -import io.metersphere.base.domain.EsbApiParamsWithBLOBs; import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiModuleMapper; -import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper; import io.metersphere.base.mapper.ext.ExtApiModuleMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; @@ -668,8 +666,7 @@ public class ApiModuleService extends NodeTreeService { if (protocol.equals("HTTP")) { return dealHttp(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, urlRepeat, importCases); } else { - Map esbApiParamsMap = apiImport.getEsbApiParamsMap(); - return delOtherProtocol(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, importCases, esbApiParamsMap); + return delOtherProtocol(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, importCases); } } @@ -677,7 +674,7 @@ public class ApiModuleService extends NodeTreeService { private UpdateApiModuleDTO delOtherProtocol(List data, Map> pidChildrenMap, Map idPathMap, Map idModuleMap, ApiTestImportRequest request, - Boolean fullCoverage, List importCases, Map esbApiParamsMap) { + Boolean fullCoverage, List importCases) { List optionData = new ArrayList<>(); //去重,TCP,SQL,DUBBO 模块下名称唯一 removeRepeatOrigin(data, fullCoverage, optionData); @@ -735,11 +732,6 @@ public class ApiModuleService extends NodeTreeService { if (fullCoverage == null) { fullCoverage = false; } - - //标准版ESB数据导入不区分是否覆盖,默认都为覆盖 - if (apiImport.getEsbApiParamsMap() != null) { - fullCoverage = true; - } return fullCoverage; } diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index 57d6476763..022e0288f8 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -80,8 +80,6 @@ public class ApiTestCaseService { @Resource private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper; @Resource - private EsbApiParamService esbApiParamService; - @Resource private ExtApiScenarioMapper extApiScenarioMapper; @Resource private ApiTestEnvironmentMapper apiTestEnvironmentMapper; @@ -125,13 +123,7 @@ public class ApiTestCaseService { moduleIds.add(request.getModuleId()); request.setModuleIds(moduleIds); } - List returnList = extApiTestCaseMapper.list(request); - for (ApiTestCaseResult res : returnList) { - if (StringUtils.equalsIgnoreCase(res.getApiMethod(), "esb")) { - esbApiParamService.handleApiEsbParams(res); - } - } - return returnList; + return extApiTestCaseMapper.list(request); } public List selectByIds(ApiTestCaseRequest request) { @@ -281,13 +273,7 @@ public class ApiTestCaseService { } public ApiTestCaseInfo get(String id) { - ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id); - if (model != null) { - if (StringUtils.equalsIgnoreCase(model.getApiMethod(), "esb")) { - esbApiParamService.handleApiEsbParams(model); - } - } - return model; + return extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id); } public ApiTestCaseInfo getResult(String id) { @@ -332,7 +318,6 @@ public class ApiTestCaseService { testPlanApiCaseService.deleteByCaseId(testId); extApiDefinitionExecResultMapper.deleteByResourceId(testId); apiTestCaseMapper.deleteByPrimaryKey(testId); - esbApiParamService.deleteByResourceId(testId); // 删除附件关系 extFileAssociationService.deleteByResourceId(testId); deleteFollows(testId); @@ -404,10 +389,6 @@ public class ApiTestCaseService { private ApiTestCase updateTest(SaveApiTestCaseRequest request) { checkNameExist(request); request.setRequest(tcpApiParamService.parseMsTestElement(request.getRequest())); - if (StringUtils.isNotEmpty(request.getEsbDataStruct())) { - request = esbApiParamService.handleEsbRequest(request); - } - final ApiTestCaseWithBLOBs test = apiTestCaseMapper.selectByPrimaryKey(request.getId()); if (test != null) { test.setName(request.getName()); @@ -460,9 +441,6 @@ public class ApiTestCaseService { checkNameExist(request); FileUtils.createBodyFiles(request.getId(), bodyFiles); request.setRequest(tcpApiParamService.parseMsTestElement(request.getRequest())); - if (StringUtils.isNotEmpty(request.getEsbDataStruct()) || StringUtils.isNotEmpty(request.getBackEsbDataStruct())) { - request = esbApiParamService.handleEsbRequest(request); - } FileUtils.copyBdyFile(request.getApiDefinitionId(), request.getId()); final ApiTestCaseWithBLOBs test = new ApiTestCaseWithBLOBs(); @@ -631,11 +609,6 @@ public class ApiTestCaseService { public Map getRequest(ApiTestCaseRequest request) { List list = extApiTestCaseMapper.getRequest(request); - for (ApiTestCaseInfo model : list) { - if (StringUtils.equalsIgnoreCase(model.getApiMethod(), "esb")) { - esbApiParamService.handleApiEsbParams(model); - } - } return list.stream().collect(Collectors.toMap(ApiTestCaseWithBLOBs::getId, ApiTestCaseWithBLOBs::getRequest)); } @@ -822,11 +795,6 @@ public class ApiTestCaseService { } else { list = extApiTestCaseMapper.getCaseInfo(request); } - for (ApiTestCaseInfo model : list) { - if (StringUtils.equalsIgnoreCase(model.getApiMethod(), "esb")) { - esbApiParamService.handleApiEsbParams(model); - } - } // 排序 FixedOrderComparator fixedOrderComparator = new FixedOrderComparator(request.getIds()); fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/EsbApiParamService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/EsbApiParamService.java deleted file mode 100644 index 5e9ba32735..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/EsbApiParamService.java +++ /dev/null @@ -1,354 +0,0 @@ -package io.metersphere.service.definition; - -import io.metersphere.api.dto.automation.EsbDataStruct; -import io.metersphere.api.dto.automation.SaveApiScenarioRequest; -import io.metersphere.api.dto.definition.ApiDefinitionResult; -import io.metersphere.api.dto.definition.ApiTestCaseResult; -import io.metersphere.api.dto.definition.SaveApiDefinitionRequest; -import io.metersphere.api.dto.definition.SaveApiTestCaseRequest; -import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; -import io.metersphere.api.dto.scenario.KeyValue; -import io.metersphere.api.parse.scenario.EsbDataParser; -import io.metersphere.base.domain.ApiTestCaseWithBLOBs; -import io.metersphere.base.domain.EsbApiParamsExample; -import io.metersphere.base.domain.EsbApiParamsWithBLOBs; -import io.metersphere.base.mapper.EsbApiParamsMapper; -import io.metersphere.commons.utils.JSON; -import io.metersphere.commons.utils.LogUtil; -import io.metersphere.plugin.core.MsTestElement; -import io.metersphere.commons.utils.JSONUtil; -import org.json.JSONArray; -import org.json.JSONObject; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author song.tianyang - * @Date 2021/3/16 4:57 下午 - * @Description - */ -@Service -@Transactional(rollbackFor = Exception.class) -public class EsbApiParamService { - @Resource - private EsbApiParamsMapper esbApiParamsMapper; - - public EsbApiParamsWithBLOBs createEsbApiParam(String resourceId, String esbDataStruct, String backedEsbDataStrcut, String backedScript) { - EsbApiParamsWithBLOBs model = null; - EsbApiParamsExample example = new EsbApiParamsExample(); - example.createCriteria().andResourceIdEqualTo(resourceId); - List list = esbApiParamsMapper.selectByExampleWithBLOBs(example); - if (list.isEmpty()) { - String uuid = UUID.randomUUID().toString(); - model = new EsbApiParamsWithBLOBs(); - model.setId(uuid); - model.setResourceId(resourceId); - model.setDataStruct(esbDataStruct); - model.setResponseDataStruct(backedEsbDataStrcut); - model.setBackedScript(backedScript); - esbApiParamsMapper.insert(model); - } else { - model = list.get(0); - model.setDataStruct(esbDataStruct); - model.setResponseDataStruct(backedEsbDataStrcut); - model.setBackedScript(backedScript); - esbApiParamsMapper.updateByPrimaryKeyWithBLOBs(model); - } - return model; - } - - public EsbApiParamsWithBLOBs getEsbParamBLOBsByResourceID(String resourceId) { - EsbApiParamsExample example = new EsbApiParamsExample(); - example.createCriteria().andResourceIdEqualTo(resourceId); - List list = esbApiParamsMapper.selectByExampleWithBLOBs(example); - if (list.isEmpty()) { - return null; - } else { - return list.get(0); - } - } - - public void deleteByResourceId(String resourceId) { - EsbApiParamsExample example = new EsbApiParamsExample(); - example.createCriteria().andResourceIdEqualTo(resourceId); - esbApiParamsMapper.deleteByExample(example); - } - - public void handleApiEsbParams(ApiDefinitionResult res) { - if (res == null) { - return; - } - EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId()); - if (esbParamBlobs == null) { - return; - } - if (StringUtils.isNotEmpty(res.getRequest())) { - JSONObject jsonObj = this.addEsbInfoToJsonString(esbParamBlobs, res.getRequest()); - if (jsonObj != null) { - res.setRequest(jsonObj.toString()); - } - - } - } - - public void handleApiEsbParams(ApiTestCaseWithBLOBs res) { - if (res == null) { - return; - } - EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId()); - if (esbParamBlobs == null) { - return; - } - if (StringUtils.isNotEmpty(res.getRequest())) { - JSONObject jsonObj = this.addEsbInfoToJsonString(esbParamBlobs, res.getRequest()); - if (jsonObj != null) { - res.setRequest(jsonObj.toString()); - } - - } - } - - private JSONObject addEsbInfoToJsonString(EsbApiParamsWithBLOBs esbParamBlobs, String requestString) { - JSONObject returnObj = null; - try { - returnObj = JSONUtil.parseObject(requestString); - JSONArray esbDataArray = JSONUtil.parseArray(esbParamBlobs.getDataStruct()); - if (esbDataArray == null) { - returnObj.put("esbDataStruct", StringUtils.EMPTY); - } else { - returnObj.put("esbDataStruct", esbDataArray); - } - JSONArray responseDataArray = JSONUtil.parseArray(esbParamBlobs.getResponseDataStruct()); - if (responseDataArray == null) { - returnObj.put("backEsbDataStruct", StringUtils.EMPTY); - } else { - returnObj.put("backEsbDataStruct", responseDataArray); - } - returnObj.put("esbFrontedScript", esbParamBlobs.getFrontedScript()); - JSONObject backedScriptObj = JSONUtil.parseObject(esbParamBlobs.getBackedScript()); - returnObj.put("backScript", backedScriptObj); - } catch (Exception e) { - LogUtil.error(e); - } - return returnObj; - } - - public void handleApiEsbParams(ApiTestCaseResult res) { - if (res == null) { - return; - } - EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId()); - if (esbParamBlobs == null) { - return; - } - if (StringUtils.isNotEmpty(res.getRequest())) { - JSONObject jsonObj = this.addEsbInfoToJsonString(esbParamBlobs, res.getRequest()); - if (jsonObj != null) { - res.setRequest(jsonObj.toString()); - } - - } - } - - public SaveApiDefinitionRequest updateEsbRequest(SaveApiDefinitionRequest request) { - try { - //修改request.parameters - //用户交互感受:ESB的发送数据以报文模板为主框架,同时前端不再有key-value的表格数据填充。 - //业务逻辑: 发送ESB接口数据时,使用报文模板中的数据,同时报文模板中的${取值}目的是为了拼接数据结构(比如xml的子节点) - //代码实现: 此处打算解析前端传来的EsbDataStruct数据结构,将数据结构按照报文模板中的${取值}为最高优先级组装keyValue对象。这样Jmeter会自动拼装为合适的xml - if (StringUtils.isNotEmpty(request.getEsbDataStruct())) { - MsTCPSampler tcpSampler = (MsTCPSampler) request.getRequest(); - List keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct()); - tcpSampler.setParameters(keyValueList); - request.setRequest(tcpSampler); - } - //更新EsbApiParams类 -// EsbApiParamsWithBLOBs esbApiParams = this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackScript()); - } catch (Exception e) { - LogUtil.error(e); - } - return request; - } - - public SaveApiDefinitionRequest handleEsbRequest(SaveApiDefinitionRequest request) { - try { - //修改request.parameters - //用户交互感受:ESB的发送数据以报文模板为主框架,同时前端不再有key-value的表格数据填充。 - //业务逻辑: 发送ESB接口数据时,使用报文模板中的数据,同时报文模板中的${取值}目的是为了拼接数据结构(比如xml的子节点) - //代码实现: 此处打算解析前端传来的EsbDataStruct数据结构,将数据结构按照报文模板中的${取值}为最高优先级组装keyValue对象。这样Jmeter会自动拼装为合适的xml - if (StringUtils.isNotEmpty(request.getEsbDataStruct())) { - MsTCPSampler tcpSampler = (MsTCPSampler) request.getRequest(); - tcpSampler.setProtocol("ESB"); - List keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct()); - tcpSampler.setParameters(keyValueList); - } - //更新EsbApiParams类 - this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackScript()); - } catch (Exception e) { - LogUtil.error(e); - } - return request; - } - -// public RunDefinitionRequest handleEsbRequest(RunDefinitionRequest request) { -// try { -// //修改request.parameters -// //用户交互感受:ESB的发送数据以报文模板为主框架,同时前端不再有key-value的表格数据填充。 -// //业务逻辑: 发送ESB接口数据时,使用报文模板中的数据,同时报文模板中的${取值}目的是为了拼接数据结构(比如xml的子节点) -// //代码实现: 此处打算解析前端传来的EsbDataStruct数据结构,将数据结构按照报文模板中的${取值}为最高优先级组装keyValue对象。这样Jmeter会自动拼装为合适的xml -// if (StringUtils.isNotEmpty(request.getEsbDataStruct())) { -// if(request.getTestElement() instanceof MsTestPlan){ -// MsTestPlan testPlan = (MsTestPlan)request.getTestElement(); -// for (MsTestElement testElement: testPlan.getHashTree()) { -// if(testElement instanceof MsThreadGroup){ -// MsThreadGroup group = (MsThreadGroup)testElement; -// for (MsTestElement groupElement: testPlan.getHashTree()) { -// if(groupElement instanceof MsScenario){ -// MsScenario scenario = (MsScenario)groupElement; -// for (MsTestElement scenarioElement: scenario.getHashTree()) { -// if(scenarioElement instanceof MsTCPSampler){ -// MsTCPSampler tcpSampler = (MsTCPSampler) scenarioElement; -// List keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct()); -// tcpSampler.setParameters(keyValueList); -// } -// } -// } -// } -// } -// } -// } -// } -// -// //更新EsbApiParams类 -// EsbApiParamsWithBLOBs esbApiParams = this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackScript()); -// } catch (Exception e) { -// LogUtil.error(e); -// } -// return request; -// } - - //通过esb数据结构生成keyValue集合,以及发送参数 - public List genKeyValueListByDataStruct(MsTCPSampler tcpSampler, String esbDataStruct) { - List keyValueList = new ArrayList<>(); - String sendRequest = tcpSampler.getRequest(); - String paramRegexStr = "\\$\\{([^}]*)\\}"; - try { - if (StringUtils.isNotEmpty(sendRequest)) { - List paramList = new ArrayList<>(); - List dataStructRequestList = JSON.parseArray(esbDataStruct, EsbDataStruct.class); - Pattern regex = Pattern.compile(paramRegexStr); - Matcher matcher = regex.matcher(sendRequest); - while (matcher.find()) { - paramList.add(matcher.group(1)); - } - for (String param : paramList) { - String value = this.genValueFromEsbDataStructByParam(dataStructRequestList, param); - if (StringUtils.isNotEmpty(value)) { - KeyValue kv = new KeyValue(); - kv.setName(param); - kv.setValue(value); - kv.setRequired(true); - keyValueList.add(kv); - } - } - } - } catch (Exception e) { - LogUtil.error(e); - } - return keyValueList; - } - - public List genKeyValueListByDataStruct(MsTCPSampler tcpSampler, List dataStructRequestList) { - List keyValueList = new ArrayList<>(); - String sendRequest = tcpSampler.getRequest(); - String paramRegexStr = "\\$\\{([^}]*)\\}"; - try { - if (StringUtils.isNotEmpty(sendRequest)) { - List paramList = new ArrayList<>(); - Pattern regex = Pattern.compile(paramRegexStr); - Matcher matcher = regex.matcher(sendRequest); - while (matcher.find()) { - paramList.add(matcher.group(1)); - } - for (String param : paramList) { - String value = this.genValueFromEsbDataStructByParam(dataStructRequestList, param); - if (StringUtils.isNotEmpty(value)) { - KeyValue kv = new KeyValue(); - kv.setName(param); - kv.setValue(value); - kv.setRequired(true); - keyValueList.add(kv); - } - } - } - } catch (Exception e) { - LogUtil.error(e); - } - return keyValueList; - } - - //通过报文模版中的变量参数,解析报文数据结构,生成对应的xml数据 - private String genValueFromEsbDataStructByParam(List dataStructRequestList, String param) { - String returnValue = StringUtils.EMPTY; - if (StringUtils.isNotEmpty(param)) { - //多层结构使用"."来表示。aaa.bb.cc 代表的是dataStructRequestList中,aaa节点下,bb节点下的cc节点数据 - String[] paramArr = param.split("\\."); - returnValue = EsbDataParser.esbData2XmlByParamStruct(dataStructRequestList, paramArr); - } - - return returnValue; - } - - public SaveApiTestCaseRequest handleEsbRequest(SaveApiTestCaseRequest request) { - try { - //修改request.parameters, 将树结构类型数据转化为表格类型数据,供执行时参数的提取 - if (StringUtils.isNotEmpty(request.getEsbDataStruct())) { - MsTCPSampler tcpSampler = (MsTCPSampler) request.getRequest(); - List keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct()); - tcpSampler.setParameters(keyValueList); - } - //更新EsbApiParams类 - this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackEsbDataStruct()); - } catch (Exception e) { - LogUtil.error(e); - } - return request; - } - - public void handleEsbRequest(MsTCPSampler tcpSampler) { - try { - //修改request.parameters, 将树结构类型数据转化为表格类型数据,供执行时参数的提取 - if (tcpSampler.getEsbDataStruct() != null) { - List keyValueList = this.genKeyValueListByDataStruct(tcpSampler, tcpSampler.getEsbDataStruct()); - tcpSampler.setParameters(keyValueList); - } - } catch (Exception e) { - LogUtil.error(e); - } - } - - public void deleteByResourceIdIn(List apiIds) { - EsbApiParamsExample example = new EsbApiParamsExample(); - example.createCriteria().andResourceIdIn(apiIds); - esbApiParamsMapper.deleteByExample(example); - } - - public void checkScenarioRequests(SaveApiScenarioRequest request) { - if (request.getScenarioDefinition() != null) { - List hashTreeList = request.getScenarioDefinition().getHashTree(); - for (MsTestElement testElement : hashTreeList) { - if (testElement instanceof MsTCPSampler) { - this.handleEsbRequest((MsTCPSampler) testElement); - } - } - } - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/EsbImportService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/EsbImportService.java deleted file mode 100644 index 40de3fdf5c..0000000000 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/EsbImportService.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.metersphere.service.definition; - -import io.metersphere.api.parse.api.ESBParser; -import io.metersphere.commons.exception.MSException; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.servlet.http.HttpServletResponse; - -/** - * @author song.tianyang - * @Date 2021/3/22 7:02 下午 - * @Description - */ -@Service -@Transactional(rollbackFor = Exception.class) -public class EsbImportService { - - public void templateExport(HttpServletResponse response) { - try { - ESBParser.export(response, "EsbTemplate"); - } catch (Exception e) { - MSException.throwException(e); - } - } -} diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/TcpApiParamService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/TcpApiParamService.java index 71eaca2aad..256aaab45a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/TcpApiParamService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/TcpApiParamService.java @@ -3,17 +3,14 @@ package io.metersphere.service.definition; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.definition.SaveApiDefinitionRequest; import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; -import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.parse.scenario.TcpTreeTableDataParser; import io.metersphere.commons.utils.LogUtil; import io.metersphere.plugin.core.MsTestElement; import io.metersphere.utils.LoggerUtil; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; import java.util.List; /** @@ -24,8 +21,6 @@ import java.util.List; @Service @Transactional(rollbackFor = Exception.class) public class TcpApiParamService { - @Resource - private EsbApiParamService esbApiParamService; public SaveApiDefinitionRequest handleTcpRequest(SaveApiDefinitionRequest request) { MsTCPSampler tcpSampler = this.handleTcpRequest(request.getRequest()); @@ -56,27 +51,19 @@ public class TcpApiParamService { try { if (testElement instanceof MsTCPSampler) { tcpSampler = (MsTCPSampler) testElement; - String protocol = tcpSampler.getProtocol(); - if (StringUtils.equalsIgnoreCase(protocol, "esb")) { - if (CollectionUtils.isNotEmpty(tcpSampler.getEsbDataStruct())) { - List keyValueList = esbApiParamService.genKeyValueListByDataStruct(tcpSampler, tcpSampler.getEsbDataStruct()); - tcpSampler.setParameters(keyValueList); - } - } else { - String reportType = tcpSampler.getReportType(); - if (StringUtils.isNotEmpty(reportType)) { - switch (reportType) { - case "raw": - tcpSampler.setRequest(tcpSampler.getRawDataStruct()); - break; - case "xml": - String xmlDataStruct = this.genValueFromEsbDataStructByParam(tcpSampler.getXmlDataStruct()); - tcpSampler.setRequest(xmlDataStruct); - break; - case "json": - tcpSampler.setRequest(tcpSampler.getJsonDataStruct()); - break; - } + String reportType = tcpSampler.getReportType(); + if (StringUtils.isNotEmpty(reportType)) { + switch (reportType) { + case "raw": + tcpSampler.setRequest(tcpSampler.getRawDataStruct()); + break; + case "xml": + String xmlDataStruct = this.genValueFromEsbDataStructByParam(tcpSampler.getXmlDataStruct()); + tcpSampler.setRequest(xmlDataStruct); + break; + case "json": + tcpSampler.setRequest(tcpSampler.getJsonDataStruct()); + break; } } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index 959d8e91c4..71a15a0ef8 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -52,7 +52,6 @@ import io.metersphere.request.ResetOrderRequest; import io.metersphere.sechedule.ApiScenarioTestJob; import io.metersphere.sechedule.SwaggerUrlImportJob; import io.metersphere.service.*; -import io.metersphere.service.definition.EsbApiParamService; import io.metersphere.service.definition.TcpApiParamService; import io.metersphere.service.ext.ExtApiScheduleService; import io.metersphere.service.ext.ExtFileAssociationService; @@ -109,8 +108,6 @@ public class ApiScenarioService { @Resource private ApiScenarioReportMapper apiScenarioReportMapper; @Resource - private EsbApiParamService esbApiParamService; - @Resource private UserMapper userMapper; @Resource private ApiScenarioEnvService apiScenarioEnvService; @@ -287,8 +284,6 @@ public class ApiScenarioService { scenario.setOrder(ServiceUtils.getNextOrder(scenario.getProjectId(), extApiScenarioMapper::getLastOrder)); scenario.setRefId(request.getId()); scenario.setLatest(true); - //检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。 - esbApiParamService.checkScenarioRequests(request); apiScenarioMapper.insert(scenario); apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario); @@ -360,9 +355,6 @@ public class ApiScenarioService { public ApiScenario update(SaveApiScenarioRequest request, List bodyFiles, List scenarioFiles) { checkNameExist(request, false); checkScenarioNum(request); - - //检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。 - esbApiParamService.checkScenarioRequests(request); //如果场景有TCP步骤的话,也要做参数计算处理 tcpApiParamService.checkTestElement(request.getScenarioDefinition()); final ApiScenarioWithBLOBs scenario = buildSaveScenario(request); diff --git a/api-test/frontend/src/api/definition.js b/api-test/frontend/src/api/definition.js index 38e8b96aab..50dadf3a03 100644 --- a/api-test/frontend/src/api/definition.js +++ b/api-test/frontend/src/api/definition.js @@ -171,8 +171,3 @@ export function createDefinition(file, files, params) { let url = '/api/definition/create'; return fileUpload(url, file, files, params); } - -export function exportEsbTemp(name) { - let url = '/api/definition/export-esb-template'; - return fileDownload(url, name); -} diff --git a/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue b/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue index 3015db44ce..b1ac050f9f 100644 --- a/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue +++ b/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue @@ -30,18 +30,20 @@ - {{ $t('project.version.name') }}: {{ request.versionName }} + + {{ $t('project.version.name') }}: {{ request.versionName }} + @@ -118,17 +120,8 @@ :headers="request.headers" :is-read-only="isCompReadOnly" :request="request" /> -

{{ $t('api_test.definition.request.res_param') }}

-
- -
-
- - - - - - -
+ + + + + +
@@ -257,8 +238,6 @@ export default { MsApiRequestForm: () => import('../../../definition/components/request/http/ApiHttpRequestForm'), MsRequestResultTail: () => import('../../../definition/components/response/RequestResultTail'), MsRun: () => import('../../../definition/components/Run'), - MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'), - MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'), }, data() { return { @@ -278,6 +257,7 @@ export default { }; }, created() { + this.request.protocol = this.request.protocol === 'ESB' ? 'TCP' : this.request.protocol; // 历史数据兼容 if (!this.request.requestResult) { this.request.requestResult = [{ responseResult: {} }]; diff --git a/api-test/frontend/src/business/definition/api-definition.js b/api-test/frontend/src/business/definition/api-definition.js index db6c288bce..c60c683de3 100644 --- a/api-test/frontend/src/business/definition/api-definition.js +++ b/api-test/frontend/src/business/definition/api-definition.js @@ -79,10 +79,7 @@ export function getProtocolFilter(protocolType) { { text: 'CONNECT', value: 'CONNECT' }, ]; } else if (protocolType === 'TCP') { - return [ - { text: 'TCP', value: 'TCP' }, - { text: 'ESB', value: 'ESB' }, - ]; + return [{ text: 'TCP', value: 'TCP' }]; } else if (protocolType === 'SQL') { return [{ text: 'SQL', value: 'SQL' }]; } else if (protocolType === 'DUBBO') { diff --git a/api-test/frontend/src/business/definition/components/case/ApiCaseHeader.vue b/api-test/frontend/src/business/definition/components/case/ApiCaseHeader.vue index 5c3128dff0..a0ed5e4b67 100644 --- a/api-test/frontend/src/business/definition/components/case/ApiCaseHeader.vue +++ b/api-test/frontend/src/business/definition/components/case/ApiCaseHeader.vue @@ -111,6 +111,7 @@ export default { this.$EventBus.$off('showXpackCaseBtn'); }, created() { + this.api.method = this.api.method === 'ESB' ? 'TCP' : this.api.method; this.isXpack = !!hasLicense(); if (this.isXpack) { this.$EventBus.$on('showXpackCaseBtn', (showUpdateRule) => { diff --git a/api-test/frontend/src/business/definition/components/case/ApiCaseItem.vue b/api-test/frontend/src/business/definition/components/case/ApiCaseItem.vue index bca6214c87..ed1ee82d64 100644 --- a/api-test/frontend/src/business/definition/components/case/ApiCaseItem.vue +++ b/api-test/frontend/src/business/definition/components/case/ApiCaseItem.vue @@ -183,16 +183,7 @@ :show-pre-script="true" :request="apiCase.request" :response="apiCase.responseData" - v-if="api.method === 'TCP'" /> - + v-if="api.method === 'TCP' || api.method === 'ESB'" />

{{ $t('api_test.definition.request.res_param') }}

-
- -
-
- -
+ @@ -334,8 +313,6 @@ export default { MsChangeHistory, ApiCaseHeader, MsApiReportStatus: () => import('../../../automation/report/ApiReportStatus'), - MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'), - MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'), }, data() { return { diff --git a/api-test/frontend/src/business/definition/components/complete/ApiBaseInfo.vue b/api-test/frontend/src/business/definition/components/complete/ApiBaseInfo.vue index 32e1c0c9e7..c909bf6274 100644 --- a/api-test/frontend/src/business/definition/components/complete/ApiBaseInfo.vue +++ b/api-test/frontend/src/business/definition/components/complete/ApiBaseInfo.vue @@ -12,19 +12,9 @@ - - - - - - - - - - - - - + + + @@ -272,14 +262,6 @@ export default { }, created() { this.basicForm = this.form; - if (hasLicense()) { - if (this.methodTypes.length == 1) { - let esbMethodType = {}; - esbMethodType.key = 'ESB'; - esbMethodType.value = 'ESB'; - this.methodTypes.push(esbMethodType); - } - } }, }; diff --git a/api-test/frontend/src/business/definition/components/complete/EditCompleteTCPApi.vue b/api-test/frontend/src/business/definition/components/complete/EditCompleteTCPApi.vue index 5fe48e2ca6..3599c95413 100644 --- a/api-test/frontend/src/business/definition/components/complete/EditCompleteTCPApi.vue +++ b/api-test/frontend/src/business/definition/components/complete/EditCompleteTCPApi.vue @@ -52,20 +52,12 @@ -
-

{{ $t('api_test.definition.request.req_param') }}

- -
-
-

{{ $t('api_test.definition.request.req_param') }}

- -

{{ $t('api_test.definition.request.res_param') }}

- -
+

{{ $t('api_test.definition.request.req_param') }}

+ @@ -112,7 +104,8 @@ import { delDefinitionByRefId, getDefinitionById, getDefinitionByIdAndRefId, - getDefinitionVersions, updateDefinitionFollows, + getDefinitionVersions, + updateDefinitionFollows, } from '@/api/definition'; import MsTcpBasicApi from './TCPBasicApi'; import MsTcpFormatParameters from '../request/tcp/TcpFormatParameters'; @@ -125,8 +118,8 @@ import { createComponent } from '.././jmeter/components'; import { TYPE_TO_C } from '@/business/automation/scenario/Setting'; import MsDialogFooter from 'metersphere-frontend/src/components/MsDialogFooter'; import { useApiStore } from '@/store'; -import {apiTestCaseCount} from '@/api/api-test-case'; -import {getDefaultVersion, setLatestVersionById} from 'metersphere-frontend/src/api/version'; +import { apiTestCaseCount } from '@/api/api-test-case'; +import { getDefaultVersion, setLatestVersionById } from 'metersphere-frontend/src/api/version'; const store = useApiStore(); const { Body } = require('@/business/definition/model/ApiTestModel'); @@ -140,9 +133,7 @@ export default { MsTcpFormatParameters, MsChangeHistory, TCPApiVersionDiff, - MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'), MxVersionHistory: () => import('metersphere-frontend/src/components/version/MxVersionHistory'), - MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'), }, props: { request: {}, @@ -175,7 +166,7 @@ export default { newApiProtocol: 'TCP', createNewVersionVisible: false, latestVersionId: '', - hasLatest: false + hasLatest: false, }; }, created: function () { @@ -186,14 +177,6 @@ export default { if (this.apiProtocol == null || this.apiProtocol == '') { this.apiProtocol = 'TCP'; } - if (hasLicense()) { - if (this.methodTypes.length == 1) { - let esbMethodType = {}; - esbMethodType.key = 'ESB'; - esbMethodType.value = 'ESB'; - this.methodTypes.push(esbMethodType); - } - } definitionFollow(this.basisData.id).then((response) => { this.basisData.follows = response.data; for (let i = 0; i < response.data.length; i++) { @@ -244,25 +227,9 @@ export default { if (this.basisData.tags instanceof Array) { this.basisData.tags = JSON.stringify(this.basisData.tags); } - if (this.basisData.method === 'ESB') { - let validataResult = this.$refs.esbDefinition.validateEsbDataStruct(this.request.esbDataStruct); - if (!validataResult) { - return; - } - if (this.request.esbDataStruct != null) { - this.esbDataStruct = JSON.stringify(this.request.esbDataStruct); - this.basisData.esbDataStruct = this.esbDataStruct; - } - if (this.request.backEsbDataStruct != null) { - this.basisData.backEsbDataStruct = JSON.stringify(this.request.backEsbDataStruct); - } - if (this.request.backScript != null) { - this.basisData.backScript = JSON.stringify(this.request.backScript); - } - } else { - if (this.$refs.tcpFormatParameter) { - this.$refs.tcpFormatParameter.validateXmlDataStruct(); - } + + if (this.$refs.tcpFormatParameter) { + this.$refs.tcpFormatParameter.validateXmlDataStruct(); } this.$emit('saveApi', this.basisData); if (this.$refs.versionHistory) { @@ -276,25 +243,9 @@ export default { if (this.basisData.tags instanceof Array) { this.basisData.tags = JSON.stringify(this.basisData.tags); } - if (this.basisData.method === 'ESB') { - let validataResult = this.$refs.esbDefinition.validateEsbDataStruct(this.request.esbDataStruct); - if (!validataResult) { - return; - } - if (this.request.esbDataStruct != null) { - this.esbDataStruct = JSON.stringify(this.request.esbDataStruct); - this.basisData.esbDataStruct = this.esbDataStruct; - } - if (this.request.backEsbDataStruct != null) { - this.basisData.backEsbDataStruct = JSON.stringify(this.request.backEsbDataStruct); - } - if (this.request.backScript != null) { - this.basisData.backScript = JSON.stringify(this.request.backScript); - } - } else { - if (this.$refs.tcpFormatParameter) { - this.$refs.tcpFormatParameter.validateXmlDataStruct(); - } + + if (this.$refs.tcpFormatParameter) { + this.$refs.tcpFormatParameter.validateXmlDataStruct(); } this.$emit('runTest', this.basisData); } @@ -346,11 +297,10 @@ export default { } }, getDefaultVersion() { - getDefaultVersion(getCurrentProjectID()) - .then(response => { - this.latestVersionId = response.data; - this.getVersionHistory(); - }); + getDefaultVersion(getCurrentProjectID()).then((response) => { + this.latestVersionId = response.data; + this.getVersionHistory(); + }); }, getVersionHistory() { @@ -362,7 +312,7 @@ export default { } let latestVersionData = response.data.filter((v) => v.versionId === this.latestVersionId); if (latestVersionData.length > 0) { - this.hasLatest = false + this.hasLatest = false; } else { this.hasLatest = true; } @@ -558,8 +508,8 @@ export default { projectId: getCurrentProjectID(), type: 'API', versionId: row.id, - resourceId: this.basisData.id - } + resourceId: this.basisData.id, + }; setLatestVersionById(param).then(() => { this.$success(this.$t('commons.modify_success')); this.checkout(row); diff --git a/api-test/frontend/src/business/definition/components/complete/version/TCPApiVersionDiff.vue b/api-test/frontend/src/business/definition/components/complete/version/TCPApiVersionDiff.vue index 4456381938..df442f9de9 100644 --- a/api-test/frontend/src/business/definition/components/complete/version/TCPApiVersionDiff.vue +++ b/api-test/frontend/src/business/definition/components/complete/version/TCPApiVersionDiff.vue @@ -47,19 +47,6 @@ -
-

{{ $t('api_test.definition.request.req_param') }}

- -

{{ $t('api_test.definition.request.res_param') }}

- - -
- @@ -123,17 +110,6 @@

{{ $t('api_test.definition.request.req_param') }}

-
-

{{ $t('api_test.definition.request.req_param') }}

- -

{{ $t('api_test.definition.request.res_param') }}

- -
@@ -191,8 +167,6 @@ export default { TabPaneCount, FormRichTextItem, DependenciesList, - MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'), - MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'), }, props: { oldData: { diff --git a/api-test/frontend/src/business/definition/components/esb/EsbResponseResult.vue b/api-test/frontend/src/business/definition/components/esb/EsbResponseResult.vue deleted file mode 100644 index d603391622..0000000000 --- a/api-test/frontend/src/business/definition/components/esb/EsbResponseResult.vue +++ /dev/null @@ -1,273 +0,0 @@ - - - - - diff --git a/api-test/frontend/src/business/definition/components/esb/EsbTable.vue b/api-test/frontend/src/business/definition/components/esb/EsbTable.vue deleted file mode 100644 index 685c57dd83..0000000000 --- a/api-test/frontend/src/business/definition/components/esb/EsbTable.vue +++ /dev/null @@ -1,330 +0,0 @@ - - - - - diff --git a/api-test/frontend/src/business/definition/components/esb/MxEsbDefinition.vue b/api-test/frontend/src/business/definition/components/esb/MxEsbDefinition.vue deleted file mode 100644 index c18b63d93f..0000000000 --- a/api-test/frontend/src/business/definition/components/esb/MxEsbDefinition.vue +++ /dev/null @@ -1,390 +0,0 @@ - - - - - diff --git a/api-test/frontend/src/business/definition/components/esb/MxEsbDefinitionResponse.vue b/api-test/frontend/src/business/definition/components/esb/MxEsbDefinitionResponse.vue deleted file mode 100644 index 70fa46d504..0000000000 --- a/api-test/frontend/src/business/definition/components/esb/MxEsbDefinitionResponse.vue +++ /dev/null @@ -1,156 +0,0 @@ - - - - - diff --git a/api-test/frontend/src/business/definition/components/import/ApiImport.vue b/api-test/frontend/src/business/definition/components/import/ApiImport.vue index 3666692d69..c51c50e918 100644 --- a/api-test/frontend/src/business/definition/components/import/ApiImport.vue +++ b/api-test/frontend/src/business/definition/components/import/ApiImport.vue @@ -39,7 +39,7 @@ clearable checkStrictly /> - + @@ -78,11 +78,6 @@ - - - {{ $t('test_track.case.import.download_template') }} - - @@ -187,7 +182,6 @@ - - diff --git a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParams.java b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParams.java deleted file mode 100644 index d865910b42..0000000000 --- a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParams.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.metersphere.base.domain; - -import lombok.Data; - -import java.io.Serializable; - -@Data -public class EsbApiParams implements Serializable { - private String id; - - private String resourceId; - - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParamsExample.java b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParamsExample.java deleted file mode 100644 index 9e4d90ca9e..0000000000 --- a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParamsExample.java +++ /dev/null @@ -1,340 +0,0 @@ -package io.metersphere.base.domain; - -import java.util.ArrayList; -import java.util.List; - -public class EsbApiParamsExample { - protected String orderByClause; - - protected boolean distinct; - - protected List oredCriteria; - - public EsbApiParamsExample() { - oredCriteria = new ArrayList(); - } - - public void setOrderByClause(String orderByClause) { - this.orderByClause = orderByClause; - } - - public String getOrderByClause() { - return orderByClause; - } - - public void setDistinct(boolean distinct) { - this.distinct = distinct; - } - - public boolean isDistinct() { - return distinct; - } - - public List getOredCriteria() { - return oredCriteria; - } - - public void or(Criteria criteria) { - oredCriteria.add(criteria); - } - - public Criteria or() { - Criteria criteria = createCriteriaInternal(); - oredCriteria.add(criteria); - return criteria; - } - - public Criteria createCriteria() { - Criteria criteria = createCriteriaInternal(); - if (oredCriteria.size() == 0) { - oredCriteria.add(criteria); - } - return criteria; - } - - protected Criteria createCriteriaInternal() { - Criteria criteria = new Criteria(); - return criteria; - } - - public void clear() { - oredCriteria.clear(); - orderByClause = null; - distinct = false; - } - - protected abstract static class GeneratedCriteria { - protected List criteria; - - protected GeneratedCriteria() { - super(); - criteria = new ArrayList(); - } - - public boolean isValid() { - return criteria.size() > 0; - } - - public List getAllCriteria() { - return criteria; - } - - public List getCriteria() { - return criteria; - } - - protected void addCriterion(String condition) { - if (condition == null) { - throw new RuntimeException("Value for condition cannot be null"); - } - criteria.add(new Criterion(condition)); - } - - protected void addCriterion(String condition, Object value, String property) { - if (value == null) { - throw new RuntimeException("Value for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value)); - } - - protected void addCriterion(String condition, Object value1, Object value2, String property) { - if (value1 == null || value2 == null) { - throw new RuntimeException("Between values for " + property + " cannot be null"); - } - criteria.add(new Criterion(condition, value1, value2)); - } - - public Criteria andIdIsNull() { - addCriterion("id is null"); - return (Criteria) this; - } - - public Criteria andIdIsNotNull() { - addCriterion("id is not null"); - return (Criteria) this; - } - - public Criteria andIdEqualTo(String value) { - addCriterion("id =", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotEqualTo(String value) { - addCriterion("id <>", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThan(String value) { - addCriterion("id >", value, "id"); - return (Criteria) this; - } - - public Criteria andIdGreaterThanOrEqualTo(String value) { - addCriterion("id >=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThan(String value) { - addCriterion("id <", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLessThanOrEqualTo(String value) { - addCriterion("id <=", value, "id"); - return (Criteria) this; - } - - public Criteria andIdLike(String value) { - addCriterion("id like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdNotLike(String value) { - addCriterion("id not like", value, "id"); - return (Criteria) this; - } - - public Criteria andIdIn(List values) { - addCriterion("id in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdNotIn(List values) { - addCriterion("id not in", values, "id"); - return (Criteria) this; - } - - public Criteria andIdBetween(String value1, String value2) { - addCriterion("id between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andIdNotBetween(String value1, String value2) { - addCriterion("id not between", value1, value2, "id"); - return (Criteria) this; - } - - public Criteria andResourceIdIsNull() { - addCriterion("resource_id is null"); - return (Criteria) this; - } - - public Criteria andResourceIdIsNotNull() { - addCriterion("resource_id is not null"); - return (Criteria) this; - } - - public Criteria andResourceIdEqualTo(String value) { - addCriterion("resource_id =", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotEqualTo(String value) { - addCriterion("resource_id <>", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdGreaterThan(String value) { - addCriterion("resource_id >", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdGreaterThanOrEqualTo(String value) { - addCriterion("resource_id >=", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdLessThan(String value) { - addCriterion("resource_id <", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdLessThanOrEqualTo(String value) { - addCriterion("resource_id <=", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdLike(String value) { - addCriterion("resource_id like", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotLike(String value) { - addCriterion("resource_id not like", value, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdIn(List values) { - addCriterion("resource_id in", values, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotIn(List values) { - addCriterion("resource_id not in", values, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdBetween(String value1, String value2) { - addCriterion("resource_id between", value1, value2, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotBetween(String value1, String value2) { - addCriterion("resource_id not between", value1, value2, "resourceId"); - return (Criteria) this; - } - } - - public static class Criteria extends GeneratedCriteria { - - protected Criteria() { - super(); - } - } - - public static class Criterion { - private String condition; - - private Object value; - - private Object secondValue; - - private boolean noValue; - - private boolean singleValue; - - private boolean betweenValue; - - private boolean listValue; - - private String typeHandler; - - public String getCondition() { - return condition; - } - - public Object getValue() { - return value; - } - - public Object getSecondValue() { - return secondValue; - } - - public boolean isNoValue() { - return noValue; - } - - public boolean isSingleValue() { - return singleValue; - } - - public boolean isBetweenValue() { - return betweenValue; - } - - public boolean isListValue() { - return listValue; - } - - public String getTypeHandler() { - return typeHandler; - } - - protected Criterion(String condition) { - super(); - this.condition = condition; - this.typeHandler = null; - this.noValue = true; - } - - protected Criterion(String condition, Object value, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.typeHandler = typeHandler; - if (value instanceof List) { - this.listValue = true; - } else { - this.singleValue = true; - } - } - - protected Criterion(String condition, Object value) { - this(condition, value, null); - } - - protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { - super(); - this.condition = condition; - this.value = value; - this.secondValue = secondValue; - this.typeHandler = typeHandler; - this.betweenValue = true; - } - - protected Criterion(String condition, Object value, Object secondValue) { - this(condition, value, secondValue, null); - } - } -} \ No newline at end of file diff --git a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParamsWithBLOBs.java b/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParamsWithBLOBs.java deleted file mode 100644 index a00b545868..0000000000 --- a/framework/sdk-parent/domain/src/main/java/io/metersphere/base/domain/EsbApiParamsWithBLOBs.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.metersphere.base.domain; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import java.io.Serializable; - -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class EsbApiParamsWithBLOBs extends EsbApiParams implements Serializable { - private String dataStruct; - - private String frontedScript; - - private String responseDataStruct; - - private String backedScript; - - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java index 648547eebc..95aed8d749 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/ApiImportPlatform.java @@ -1,5 +1,5 @@ package io.metersphere.commons.constants; public enum ApiImportPlatform { - Metersphere, Postman, Swagger2, Plugin, Jmeter, Har, ESB + Metersphere, Postman, Swagger2, Plugin, Jmeter, Har } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java index 0279e4f0d9..9bea6a5519 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/vo/api/DefinitionReference.java @@ -8,7 +8,6 @@ public class DefinitionReference { public static Map caseColumns = new LinkedHashMap<>(); public static Map jdbcColumns = new LinkedHashMap<>(); public static Map httpColumns = new LinkedHashMap<>(); - public static Map esbColumns = new LinkedHashMap<>(); public static Map authColumns = new LinkedHashMap<>(); static { @@ -16,7 +15,6 @@ public class DefinitionReference { caseColumns.clear(); jdbcColumns.clear(); httpColumns.clear(); - esbColumns.clear(); authColumns.clear(); definitionColumns.put("name", "接口名称"); definitionColumns.put("createUser", "创建人"); @@ -64,18 +62,5 @@ public class DefinitionReference { authColumns.put("username", "用户名"); authColumns.put("password", "密码"); authColumns.put("encrypt", "加密"); - - //tcp esb 其他设置 - esbColumns.put("classname", "TCPClient"); - esbColumns.put("ctimeout", "连接(ms)"); - esbColumns.put("timeout", "响应(ms)"); - esbColumns.put("soLinger", "SO LINGER"); - esbColumns.put("eolByte", "行尾(EOL)子节值"); - esbColumns.put("username", "用户名"); - esbColumns.put("password", "密码"); - esbColumns.put("reUseConnection", "Re-use connection"); - esbColumns.put("closeConnection", "关闭连接"); - esbColumns.put("nodelay", "设置无延迟"); - esbColumns.put("connectEncoding", "Connect encoding"); } } \ No newline at end of file diff --git a/project-management/frontend/src/common/js/api-definition.js b/project-management/frontend/src/common/js/api-definition.js index a10e8a1ca3..856c2c314a 100644 --- a/project-management/frontend/src/common/js/api-definition.js +++ b/project-management/frontend/src/common/js/api-definition.js @@ -1,84 +1,81 @@ -import {Assertions} from "../../business/menu/function/ext/ApiTestModel"; -import {getUUID} from "metersphere-frontend/src/utils"; +import { Assertions } from "../../business/menu/function/ext/ApiTestModel"; +import { getUUID } from "metersphere-frontend/src/utils"; export function getProtocolFilter(protocolType) { if (protocolType === "HTTP") { return [ - {text: 'GET', value: 'GET'}, - {text: 'POST', value: 'POST'}, - {text: 'PUT', value: 'PUT'}, - {text: 'PATCH', value: 'PATCH'}, - {text: 'DELETE', value: 'DELETE'}, - {text: 'OPTIONS', value: 'OPTIONS'}, - {text: 'HEAD', value: 'HEAD'}, - {text: 'CONNECT', value: 'CONNECT'}, + { text: "GET", value: "GET" }, + { text: "POST", value: "POST" }, + { text: "PUT", value: "PUT" }, + { text: "PATCH", value: "PATCH" }, + { text: "DELETE", value: "DELETE" }, + { text: "OPTIONS", value: "OPTIONS" }, + { text: "HEAD", value: "HEAD" }, + { text: "CONNECT", value: "CONNECT" }, ]; } else if (protocolType === "TCP") { - return [ - {text: 'TCP', value: 'TCP'}, - {text: 'ESB', value: 'ESB'} - ]; + return [{ text: "TCP", value: "TCP" }]; } else if (protocolType === "SQL") { - return [ - {text: 'SQL', value: 'SQL'}, - ]; + return [{ text: "SQL", value: "SQL" }]; } else if (protocolType === "DUBBO") { - return [ - {text: 'dubbo://', value: 'dubbo://'}, - ]; + return [{ text: "dubbo://", value: "dubbo://" }]; } else { return [ - {text: 'GET', value: 'GET'}, - {text: 'POST', value: 'POST'}, - {text: 'PUT', value: 'PUT'}, - {text: 'PATCH', value: 'PATCH'}, - {text: 'DELETE', value: 'DELETE'}, - {text: 'OPTIONS', value: 'OPTIONS'}, - {text: 'HEAD', value: 'HEAD'}, - {text: 'CONNECT', value: 'CONNECT'}, - {text: 'DUBBO', value: 'DUBBO'}, - {text: 'dubbo://', value: 'dubbo://'}, - {text: 'SQL', value: 'SQL'}, - {text: 'TCP', value: 'TCP'}, + { text: "GET", value: "GET" }, + { text: "POST", value: "POST" }, + { text: "PUT", value: "PUT" }, + { text: "PATCH", value: "PATCH" }, + { text: "DELETE", value: "DELETE" }, + { text: "OPTIONS", value: "OPTIONS" }, + { text: "HEAD", value: "HEAD" }, + { text: "CONNECT", value: "CONNECT" }, + { text: "DUBBO", value: "DUBBO" }, + { text: "dubbo://", value: "dubbo://" }, + { text: "SQL", value: "SQL" }, + { text: "TCP", value: "TCP" }, ]; } } export function parse(item) { if (item.jsonPath) { - item.jsonPath.forEach(node => { + item.jsonPath.forEach((node) => { if (node.enable === undefined) { node.enable = item.enable; } - }) + }); } if (item.jsr223) { - item.jsr223.forEach(node => { + item.jsr223.forEach((node) => { if (node.enable === undefined) { node.enable = item.enable; } - }) + }); } if (item.regex) { - item.regex.forEach(node => { + item.regex.forEach((node) => { if (node.enable === undefined) { node.enable = item.enable; } }); } if (item.xpath2) { - item.xpath2.forEach(node => { + item.xpath2.forEach((node) => { if (node.enable === undefined) { node.enable = item.enable; } - }) + }); } if (item.duration && item.duration.value > 0) { if (item.duration.enable === undefined) { item.duration.enable = item.enable; } } - if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) { + if ( + item.document && + item.document.data && + (item.document.data.json.length > 0 || item.document.data.xml.length > 0) + ) { if (item.document.enable === undefined) { item.document.enable = item.enable; } @@ -86,7 +83,7 @@ export function parse(item) { } export function hisDataProcessing(array, request) { - let assertions = new Assertions({id: getUUID()}); + let assertions = new Assertions({ id: getUUID() }); if (!request.hashTree) { request.hashTree = []; } @@ -118,16 +115,23 @@ export function hisDataProcessing(array, request) { if (item.duration && item.duration.value > 0) { assertions.duration = item.duration; } - if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) { + if ( + item.document && + item.document.data && + (item.document.data.json.length > 0 || + item.document.data.xml.length > 0) + ) { assertions.document = item.document; } } } } - assertionsIndex.forEach(item => { - const rmIndex = request.hashTree.findIndex((d) => d.id === item.id && d.resourceId === item.resourceId); + assertionsIndex.forEach((item) => { + const rmIndex = request.hashTree.findIndex( + (d) => d.id === item.id && d.resourceId === item.resourceId + ); request.hashTree.splice(rmIndex, 1); - }) + }); request.hashTree.push(assertions); } @@ -136,14 +140,31 @@ export function stepCompute(array, request) { let preSize = 0; let postSize = 0; let ruleSize = 0; - array.forEach(item => { - if (["JSR223PreProcessor", "JDBCPreProcessor", "ConstantTimer"].indexOf(item.type) !== -1) { + array.forEach((item) => { + if ( + ["JSR223PreProcessor", "JDBCPreProcessor", "ConstantTimer"].indexOf( + item.type + ) !== -1 + ) { preSize++; - } else if (["JSR223PostProcessor", "JDBCPostProcessor", "Extract"].indexOf(item.type) !== -1) { + } else if ( + ["JSR223PostProcessor", "JDBCPostProcessor", "Extract"].indexOf( + item.type + ) !== -1 + ) { postSize++; } else if (item.type === "Assertions") { - ruleSize = (item.jsonPath.length + item.jsr223.length + item.regex.length + item.xpath2.length); - if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) { + ruleSize = + item.jsonPath.length + + item.jsr223.length + + item.regex.length + + item.xpath2.length; + if ( + item.document && + item.document.data && + (item.document.data.json.length > 0 || + item.document.data.xml.length > 0) + ) { ruleSize++; } if (item.duration && item.duration.value > 0) { @@ -151,42 +172,49 @@ export function stepCompute(array, request) { } ruleSize += item.text ? item.text.length : 0; } - }) + }); request.preSize = preSize; request.postSize = postSize; request.ruleSize = ruleSize; - } export function mergeDocumentData(originalData, childMap) { - originalData.forEach(item => { + originalData.forEach((item) => { if (childMap && childMap.has(item.id)) { let sourceData = JSON.parse(JSON.stringify(item.children)); item.children = JSON.parse(JSON.stringify(childMap.get(item.id))); - item.children.forEach(target => { - let index = sourceData.findIndex(source => source.id === target.id); + item.children.forEach((target) => { + let index = sourceData.findIndex((source) => source.id === target.id); if (index !== -1) { - target.children = sourceData[index].children + target.children = sourceData[index].children; } - }) + }); if (item.children && item.children.length > 0) { mergeDocumentData(item.children, childMap); } } - - }) + }); } export function mergeRequestDocumentData(request) { if (request && request.hashTree && request.hashTree.length > 0) { - let index = request.hashTree.findIndex(item => item.type === 'Assertions'); + let index = request.hashTree.findIndex( + (item) => item.type === "Assertions" + ); if (index !== -1) { - if (request.hashTree[index].document && request.hashTree[index].document.originalData && request.hashTree[index].document.tableData.size && request.hashTree[index].document.tableData.size !== 0) { - mergeDocumentData(request.hashTree[index].document.originalData, request.hashTree[index].document.tableData); - request.hashTree[index].document.data.json = request.hashTree[index].document.originalData; + if ( + request.hashTree[index].document && + request.hashTree[index].document.originalData && + request.hashTree[index].document.tableData.size && + request.hashTree[index].document.tableData.size !== 0 + ) { + mergeDocumentData( + request.hashTree[index].document.originalData, + request.hashTree[index].document.tableData + ); + request.hashTree[index].document.data.json = + request.hashTree[index].document.originalData; } } } - } -