diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java index f6dd3f5ad0..9027f0408a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java @@ -192,7 +192,7 @@ public class ApiDefinitionMockService { apiDefinitionMock.setUpdateTime(System.currentTimeMillis()); apiDefinitionMock.setCreateUser(userId); if (CollectionUtils.isNotEmpty(request.getTags())) { - apiDefinitionMock.setTags(apiTestCaseService.parseTags(request.getTags())); + apiDefinitionMock.setTags(ServiceUtils.parseTags(request.getTags())); } apiDefinitionMock.setEnable(true); ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionMock.getApiDefinitionId()); @@ -439,7 +439,7 @@ public class ApiDefinitionMockService { if (CollectionUtils.isNotEmpty(v.getTags())) { List orgTags = v.getTags(); orgTags.addAll(request.getTags()); - v.setTags(apiTestCaseService.parseTags(orgTags.stream().distinct().toList())); + v.setTags(ServiceUtils.parseTags(orgTags.stream().distinct().toList())); } else { v.setTags(request.getTags()); } @@ -449,7 +449,7 @@ public class ApiDefinitionMockService { }); } } else { - updateMock.setTags(apiTestCaseService.parseTags(request.getTags())); + updateMock.setTags(ServiceUtils.parseTags(request.getTags())); mapper.updateByExampleSelective(updateMock, example); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index bdd07c0cab..52df63e36a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -207,7 +207,7 @@ public class ApiDefinitionService extends MoveNodeService { apiDefinition.setUpdateTime(System.currentTimeMillis()); apiDefinition.setRefId(apiDefinition.getId()); if (CollectionUtils.isNotEmpty(request.getTags())) { - apiDefinition.setTags(apiTestCaseService.parseTags(request.getTags())); + apiDefinition.setTags(ServiceUtils.parseTags(request.getTags())); } apiDefinitionMapper.insertSelective(apiDefinition); ApiDefinitionBlob apiDefinitionBlob = new ApiDefinitionBlob(); @@ -261,7 +261,7 @@ public class ApiDefinitionService extends MoveNodeService { ApiDefinition originApiDefinition = checkApiDefinition(request.getId()); ApiDefinition apiDefinition = new ApiDefinition(); BeanUtils.copyBean(apiDefinition, request); - apiDefinition.setTags(apiTestCaseService.parseTags(apiDefinition.getTags())); + apiDefinition.setTags(ServiceUtils.parseTags(apiDefinition.getTags())); checkResponseNameCode(request.getResponse()); if (originApiDefinition.getProtocol().equals(ModuleConstants.NODE_PROTOCOL_HTTP)) { checkUpdateExist(apiDefinition, originApiDefinition); @@ -614,7 +614,7 @@ public class ApiDefinitionService extends MoveNodeService { if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) { List tags = collect.get(id).getTags(); tags.addAll(request.getTags()); - apiDefinition.setTags(apiTestCaseService.parseTags(tags.stream().distinct().toList())); + apiDefinition.setTags(ServiceUtils.parseTags(tags.stream().distinct().toList())); } else { apiDefinition.setTags(request.getTags()); } @@ -629,7 +629,7 @@ public class ApiDefinitionService extends MoveNodeService { } else { //替换标签 ApiDefinition apiDefinition = new ApiDefinition(); - apiDefinition.setTags(apiTestCaseService.parseTags(request.getTags())); + apiDefinition.setTags(ServiceUtils.parseTags(request.getTags())); apiDefinition.setProjectId(request.getProjectId()); apiDefinition.setUpdateTime(System.currentTimeMillis()); apiDefinition.setUpdateUser(userId); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index f7c2a256d5..100e377242 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -108,9 +108,7 @@ public class ApiTestCaseService extends MoveNodeService { @Resource private FunctionalCaseTestMapper functionalCaseTestMapper; - private static final String CASE_TABLE = "api_test_case"; - private static final int MAX_TAG_SIZE = 10; private void checkProjectExist(String projectId) { Project project = projectMapper.selectByPrimaryKey(projectId); @@ -179,7 +177,7 @@ public class ApiTestCaseService extends MoveNodeService { testCase.setCreateTime(System.currentTimeMillis()); testCase.setUpdateTime(System.currentTimeMillis()); if (CollectionUtils.isNotEmpty(request.getTags())) { - testCase.setTags(this.parseTags(request.getTags())); + testCase.setTags(ServiceUtils.parseTags(request.getTags())); } apiTestCaseMapper.insertSelective(testCase); @@ -285,7 +283,7 @@ public class ApiTestCaseService extends MoveNodeService { testCase.setUpdateUser(userId); testCase.setUpdateTime(System.currentTimeMillis()); if (CollectionUtils.isNotEmpty(request.getTags())) { - testCase.setTags(this.parseTags(request.getTags())); + testCase.setTags(ServiceUtils.parseTags(request.getTags())); } else { testCase.setTags(null); } @@ -513,7 +511,7 @@ public class ApiTestCaseService extends MoveNodeService { if (CollectionUtils.isNotEmpty(v.getTags())) { List orgTags = v.getTags(); orgTags.addAll(request.getTags()); - v.setTags(this.parseTags(orgTags.stream().distinct().toList())); + v.setTags(ServiceUtils.parseTags(orgTags.stream().distinct().toList())); } else { v.setTags(request.getTags()); } @@ -523,7 +521,7 @@ public class ApiTestCaseService extends MoveNodeService { }); } } else { - updateCase.setTags(this.parseTags(request.getTags())); + updateCase.setTags(ServiceUtils.parseTags(request.getTags())); mapper.updateByExampleSelective(updateCase, example); } } @@ -924,18 +922,4 @@ public class ApiTestCaseService extends MoveNodeService { public List getReference(ReferenceRequest request) { return extApiDefinitionMapper.getReference(request); } - - /** - * 解析Tag,只保留默认长度 - * - * @param tags 标签集合 - */ - public List parseTags(List tags) { - if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) { - List returnTags = new ArrayList<>(tags); - return returnTags.subList(0, MAX_TAG_SIZE); - } else { - return tags; - } - } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 5905f4ef00..a326fd54f6 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -323,7 +323,7 @@ public class ApiScenarioService extends MoveNodeService { if (CollectionUtils.isNotEmpty(v.getTags())) { List orgTags = v.getTags(); orgTags.addAll(request.getTags()); - v.setTags(apiTestCaseService.parseTags(orgTags.stream().distinct().toList())); + v.setTags(ServiceUtils.parseTags(orgTags.stream().distinct().toList())); } else { v.setTags(request.getTags()); } @@ -333,7 +333,7 @@ public class ApiScenarioService extends MoveNodeService { }); } } else { - updateScenario.setTags(apiTestCaseService.parseTags(request.getTags().stream().distinct().toList())); + updateScenario.setTags(ServiceUtils.parseTags(request.getTags().stream().distinct().toList())); mapper.updateByExampleSelective(updateScenario, example); } } @@ -384,7 +384,7 @@ public class ApiScenarioService extends MoveNodeService { public ApiScenario add(ApiScenarioAddRequest request, String creator) { checkAddExist(request); - request.setTags(apiTestCaseService.parseTags(request.getTags())); + request.setTags(ServiceUtils.parseTags(request.getTags())); ApiScenario scenario = getAddApiScenario(request, creator); scenario.setStepTotal(request.getSteps().size()); apiScenarioMapper.insert(scenario); @@ -706,7 +706,7 @@ public class ApiScenarioService extends MoveNodeService { public ApiScenario update(ApiScenarioUpdateRequest request, String updater) { checkResourceExist(request.getId()); checkUpdateExist(request); - request.setTags(apiTestCaseService.parseTags(request.getTags())); + request.setTags(ServiceUtils.parseTags(request.getTags())); // 更新基础信息 ApiScenario scenario = BeanUtils.copyBean(new ApiScenario(), request); scenario.setUpdateUser(updater); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index 45267eaeae..9dc4dd9835 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -168,8 +168,6 @@ public class BugService { public static final Long INTERVAL_POS = 5000L; - private static final int MAX_TAG_SIZE = 10; - /** * 缺陷列表查询 * @@ -197,8 +195,7 @@ public class BugService { * @return 缺陷 */ public Bug addOrUpdate(BugEditRequest request, List files, String currentUser, String currentOrgId, boolean isUpdate) { - // 前置校验: 标签长度 - this.checkTagLength(request.getTags()); + request.setTags(ServiceUtils.parseTags(request.getTags())); /* * 缺陷创建或者修改逻辑: * 1. 判断所属项目是否关联第三方平台; @@ -439,9 +436,6 @@ public class BugService { * @param currentUser 当前用户 */ public void batchUpdate(BugBatchUpdateRequest request, String currentUser) { - //校验标签长度 - this.checkTagLength(request.getTags()); - List batchIds = getBatchIdsByRequest(request); // 批量日志{修改之前} List logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, "/bug/batch-update", @@ -457,17 +451,16 @@ public class BugService { bugTagMap.forEach((k, v) -> { Bug record = new Bug(); record.setId(k); - record.setTags(ListUtils.union(v, request.getTags())); + record.setTags(ServiceUtils.parseTags(ListUtils.union(v, request.getTags()))); record.setUpdateUser(currentUser); record.setUpdateTime(System.currentTimeMillis()); - //校验标签长度 - this.checkTagLength(record.getTags()); //入库 batchMapper.updateByPrimaryKeySelective(record); }); sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } else { + request.setTags(ServiceUtils.parseTags(request.getTags())); // 标签(覆盖) request.setUpdateUser(currentUser); request.setUpdateTime(System.currentTimeMillis()); @@ -1861,17 +1854,6 @@ public class BugService { return t -> keySet.add(function.apply(t)); } - /** - * 校验TAG长度 - * - * @param tags 标签集合 - */ - private void checkTagLength(List tags) { - if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) { - throw new MSException(Translator.getWithArgs("bug_tags_size_large_than", String.valueOf(MAX_TAG_SIZE))); - } - } - /** * 构建缺陷本地附件 * diff --git a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java index 3d06c8964a..8df68fd6f2 100644 --- a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java +++ b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java @@ -259,10 +259,10 @@ public class BugControllerTests extends BaseTest { MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest()); request.setProjectId("default-project-for-bug"); - // 标签超过10个 + // V3.1需求:标签超过10个不会报错,只会留下前10个 request.setTags(List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")); paramMap = getMultiPartParam(request, file); - this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is5xxServerError()); + this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is2xxSuccessful()); request.setTags(null); // 处理人为空 request.setTitle("default-bug-title"); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index dc84424806..5554d49924 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -185,9 +185,6 @@ public class FunctionalCaseService { @Resource private FunctionalCaseNoticeService functionalCaseNoticeService; - - private static final int MAX_TAG_SIZE = 10; - public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List files, String userId, String organizationId) { String caseId = IDGenerator.nextStr(); //添加功能用例 @@ -986,11 +983,9 @@ public class FunctionalCaseService { if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) { List tags = collect.get(id).getTags(); tags.addAll(request.getTags()); - checkTagsLength(tags); - List newTags = tags.stream().distinct().collect(Collectors.toList()); - functionalCase.setTags(newTags); + functionalCase.setTags(ServiceUtils.parseTags(tags)); } else { - functionalCase.setTags(request.getTags()); + functionalCase.setTags(ServiceUtils.parseTags(request.getTags())); } functionalCase.setId(id); functionalCase.setUpdateTime(System.currentTimeMillis()); @@ -1012,17 +1007,6 @@ public class FunctionalCaseService { } - /** - * 校验追加标签长度 - * - * @param tags - */ - private void checkTagsLength(List tags) { - if (tags.size() > MAX_TAG_SIZE) { - throw new MSException(Translator.getWithArgs("tags_length_large_than", String.valueOf(MAX_TAG_SIZE))); - } - } - public Map moduleCount(FunctionalCasePageRequest request, boolean delete) { if (StringUtils.isNotEmpty(request.getTestPlanId())) { this.checkTestPlanRepeatCase(request); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/utils/ServiceUtils.java b/backend/services/system-setting/src/main/java/io/metersphere/system/utils/ServiceUtils.java index 4ec9cc0dfb..efa55e15f6 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/utils/ServiceUtils.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/utils/ServiceUtils.java @@ -10,6 +10,8 @@ import jakarta.validation.Validator; import org.apache.commons.collections.CollectionUtils; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -125,4 +127,21 @@ public class ServiceUtils { } return newName; } + + + /** + * 解析Tag,只保留默认长度 + * + * @param tags 标签集合 + */ + private static final int MAX_TAG_SIZE = 10; + + public static List parseTags(List tags) { + if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) { + List returnTags = new ArrayList<>(tags.stream().distinct().toList()); + return returnTags.subList(0, MAX_TAG_SIZE); + } else { + return tags; + } + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index a1eb6ae75a..88dea33f66 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -104,8 +104,6 @@ public class TestPlanService extends TestPlanBaseUtilsService { @Resource private TestPlanReportCaseService testPlanReportCaseService; - private static final int MAX_TAG_SIZE = 10; - @Resource private TestPlanReportService testPlanReportService; @Resource @@ -174,7 +172,6 @@ public class TestPlanService extends TestPlanBaseUtilsService { private TestPlan savePlanDTO(TestPlanCreateRequest createOrCopyRequest, String operator) { //检查模块的合法性 checkModule(createOrCopyRequest.getModuleId()); - this.checkTagsLength(createOrCopyRequest.getTags()); if (StringUtils.equalsIgnoreCase(createOrCopyRequest.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP) && !StringUtils.equalsIgnoreCase(createOrCopyRequest.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { throw new MSException(Translator.get("test_plan.group.error")); @@ -182,7 +179,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { TestPlan createTestPlan = new TestPlan(); BeanUtils.copyBean(createTestPlan, createOrCopyRequest); - + createTestPlan.setTags(ServiceUtils.parseTags(createTestPlan.getTags())); if (!StringUtils.equals(createTestPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { TestPlan groupPlan = testPlanGroupService.validateGroupCapacity(createTestPlan.getGroupId(), 1); // 判断测试计划组是否存在 @@ -398,8 +395,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { //判断标签的变化 if (CollectionUtils.isNotEmpty(request.getTags())) { List tags = new ArrayList<>(request.getTags()); - this.checkTagsLength(tags); - updateTestPlan.setTags(tags); + updateTestPlan.setTags(ServiceUtils.parseTags(tags)); } else { updateTestPlan.setTags(new ArrayList<>()); } @@ -772,11 +768,9 @@ public class TestPlanService extends TestPlanBaseUtilsService { if (CollectionUtils.isNotEmpty(collect.get(id).getTags())) { List tags = collect.get(id).getTags(); tags.addAll(request.getTags()); - checkTagsLength(tags); - List newTags = tags.stream().distinct().collect(Collectors.toList()); - testPlan.setTags(newTags); + testPlan.setTags(ServiceUtils.parseTags(tags)); } else { - testPlan.setTags(request.getTags()); + testPlan.setTags(ServiceUtils.parseTags(request.getTags())); } testPlan.setId(id); testPlan.setUpdateTime(System.currentTimeMillis()); @@ -788,7 +782,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { } else { //替换标签 TestPlan testPlan = new TestPlan(); - testPlan.setTags(request.getTags()); + testPlan.setTags(ServiceUtils.parseTags(request.getTags())); testPlan.setProjectId(request.getProjectId()); testPlan.setUpdateTime(System.currentTimeMillis()); testPlan.setUpdateUser(userId); @@ -798,18 +792,6 @@ public class TestPlanService extends TestPlanBaseUtilsService { } - - /** - * 校验追加标签长度 - * - * @param tags - */ - private void checkTagsLength(List tags) { - if (CollectionUtils.size(tags) > MAX_TAG_SIZE) { - throw new MSException(Translator.getWithArgs("tags_length_large_than", String.valueOf(MAX_TAG_SIZE))); - } - } - //通过项目删除测试计划 public void deleteByProjectId(String projectId) { diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index aab1843a50..6376c51dd2 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -2380,16 +2380,43 @@ public class TestPlanTests extends BaseTest { @Order(307) public void testBatchEditTestPlan() throws Exception { TestPlanBatchEditRequest request = new TestPlanBatchEditRequest(); - request.setTags(Arrays.asList("tag1", "tag2")); - request.setAppend(true); request.setType("ALL"); request.setProjectId("songtianyang-fix-wx"); request.setSelectIds(Arrays.asList("wx_test_plan_id_1")); - this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); request.setAppend(false); request.setTags(Arrays.asList("tag3", "tag4")); - request.setSelectIds(Arrays.asList("wx_test_plan_id_1")); this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); + //检查标签是否覆盖 + TestPlan testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1"); + Assertions.assertEquals(2, CollectionUtils.size(testPlan.getTags())); + Assertions.assertTrue(testPlan.getTags().contains("tag3")); + Assertions.assertTrue(testPlan.getTags().contains("tag4")); + + request.setAppend(true); + request.setTags(Arrays.asList("tag1", "tag2")); + this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); + testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1"); + Assertions.assertEquals(4, CollectionUtils.size(testPlan.getTags())); + Assertions.assertTrue(testPlan.getTags().contains("tag1")); + Assertions.assertTrue(testPlan.getTags().contains("tag2")); + Assertions.assertTrue(testPlan.getTags().contains("tag3")); + Assertions.assertTrue(testPlan.getTags().contains("tag4")); + + //超过10个 + request.setTags(Arrays.asList("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag0", "tag11")); + this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); + testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1"); + Assertions.assertEquals(10, CollectionUtils.size(testPlan.getTags())); + Assertions.assertTrue(testPlan.getTags().contains("tag1")); + Assertions.assertTrue(testPlan.getTags().contains("tag2")); + Assertions.assertTrue(testPlan.getTags().contains("tag3")); + Assertions.assertTrue(testPlan.getTags().contains("tag4")); + Assertions.assertTrue(testPlan.getTags().contains("tag5")); + Assertions.assertTrue(testPlan.getTags().contains("tag6")); + Assertions.assertTrue(testPlan.getTags().contains("tag7")); + Assertions.assertTrue(testPlan.getTags().contains("tag8")); + Assertions.assertTrue(testPlan.getTags().contains("tag9")); + Assertions.assertTrue(testPlan.getTags().contains("tag0")); } @Test