From d68c257267d22b54ee56e62753d9ea982417ade5 Mon Sep 17 00:00:00 2001 From: jianxing Date: Tue, 25 Jul 2023 11:06:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8Bxmind=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=EF=BC=8C=E6=B2=A1=E6=9C=89=E8=AE=BE=E7=BD=AE=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=B3=BB=E7=BB=9F=E5=AD=97=E6=AE=B5=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1028087 --user=陈建星 【测试跟踪】github#25753,导入用例如果xmind中没有设置优先级导入后默认固定为P0,导入也应从默认模板中获取默认值 https://www.tapd.cn/55049933/s/1396651 --- .../metersphere/service/TestCaseService.java | 23 +++++++++------- .../io/metersphere/xmind/XmindCaseParser.java | 27 +++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 89b85e1c8f..9edf55b163 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -1127,6 +1127,7 @@ public class TestCaseService { try { request.setTestCaseNames(testCaseNames); request.setUseCustomId(useCunstomId); + request.setCustomFields(getProjectCustomFields(projectId)); XmindCaseParser xmindParser = new XmindCaseParser(request); errList = xmindParser.parse(multipartFile); List testCase = xmindParser.getTestCase(); @@ -1234,17 +1235,9 @@ public class TestCaseService { try { //根据本地语言环境选择用哪种数据对象进行存放读取的数据 Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal(); - TrackTestCaseTemplateService trackTestCaseTemplateService = CommonBeanFactory.getBean(TrackTestCaseTemplateService.class); - TestCaseTemplateDao testCaseTemplate = trackTestCaseTemplateService.getTemplate(projectId); - List customFields = null; - if (testCaseTemplate == null) { - customFields = new ArrayList<>(); - } else { - customFields = testCaseTemplate.getCustomFields(); - } request.setUserIds(userIds); request.setTestCaseNames(testCaseNames); - request.setCustomFields(customFields); + request.setCustomFields(getProjectCustomFields(projectId)); request.setSavedCustomIds(savedIds); request.setUseCustomId(useCustomId); Set mergeInfoSet = new TreeSet<>(); @@ -1269,6 +1262,18 @@ public class TestCaseService { return getImportResponse(errList, isUpdated); } + private static List getProjectCustomFields(String projectId) { + TrackTestCaseTemplateService trackTestCaseTemplateService = CommonBeanFactory.getBean(TrackTestCaseTemplateService.class); + TestCaseTemplateDao testCaseTemplate = trackTestCaseTemplateService.getTemplate(projectId); + List customFields = null; + if (testCaseTemplate == null) { + customFields = new ArrayList<>(); + } else { + customFields = testCaseTemplate.getCustomFields(); + } + return customFields; + } + public void saveImportData(List testCases, TestCaseImportRequest request, Map> testCaseCustomFieldMap) { saveImportData( testCases, request, testCaseCustomFieldMap, null); diff --git a/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java b/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java index 61ccb5a195..6983381662 100644 --- a/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java +++ b/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java @@ -5,6 +5,8 @@ import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.JSON; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.dto.CustomFieldDao; import io.metersphere.excel.domain.ExcelErrData; import io.metersphere.excel.domain.TestCaseExcelData; import io.metersphere.excel.utils.ExcelImportType; @@ -344,6 +346,8 @@ public class XmindCaseParser { testCase.setMaintainer(request.getUserId()); testCase.setPriority(priorityList.get(0)); + setDefaultCustomFieldVal(testCase); + String tc = title.replace(":", ":"); String[] tcArrs = tc.split(":"); if (tcArrs.length < 1) { @@ -409,6 +413,29 @@ public class XmindCaseParser { } } + private void setDefaultCustomFieldVal(TestCaseWithBLOBs testCase) { + try { + for (CustomFieldDao customField : request.getCustomFields()) { + if (StringUtils.isBlank(customField.getDefaultValue())) { + continue; + } + String defaultVal = JSON.parseObject(customField.getDefaultValue()).toString(); + if (StringUtils.isBlank(defaultVal)) { + continue; + } + if (StringUtils.equals(customField.getName(), "用例等级")) { + testCase.setPriority(defaultVal); + } else if (StringUtils.equals(customField.getName(), "用例状态")) { + testCase.setStatus(defaultVal); + } else if (StringUtils.equals(customField.getName(), "责任人")) { + testCase.setMaintainer(defaultVal); + } + } + } catch (Exception e) { + LogUtil.error(e); + } + } + /** * 导入思维导图处理 */