fix(用例管理): 导入用例标签长度和个数限制
--bug=1035924 --user=王旭 【用例管理】功能用例-导入用例的标签长度和个数未限制 https://www.tapd.cn/55049933/s/1466448
This commit is contained in:
parent
e9b4ff2c80
commit
054c890a19
|
@ -321,6 +321,8 @@ scenario_name_is_null=Scenario name cannot be empty
|
|||
create_user=Create user
|
||||
test_case_status=Case status
|
||||
id_not_rightful=ID is not rightful
|
||||
tags_count=Tags count can not exceed 15
|
||||
tag_length=Tag length cannot exceed 64 characters
|
||||
project_reference_multiple_plateform=Projects point to multiple third-party platforms
|
||||
# mock
|
||||
mock_warning=No matching Mock expectation was found
|
||||
|
|
|
@ -322,6 +322,8 @@ test_case_status_saved=已保存
|
|||
create_user=创建人
|
||||
test_case_status=用例状态
|
||||
id_not_rightful=ID 不合法
|
||||
tags_count=标签数量不能超过15个
|
||||
tag_length=标签长度不能超过64个字符
|
||||
project_reference_multiple_plateform=项目指向多个第三方平台
|
||||
# mock
|
||||
mock_warning=未找到匹配的Mock期望
|
||||
|
|
|
@ -321,6 +321,8 @@ test_case_status_saved=已保存
|
|||
create_user=創建人
|
||||
test_case_status=用例狀態
|
||||
id_not_rightful=ID 不合法
|
||||
tags_count=標簽數量不能超過15個
|
||||
tag_length=標簽長度不能超過64個字符
|
||||
project_reference_multiple_plateform=項目指向多個第三方平臺
|
||||
# mock
|
||||
mock_warning=未找到匹配的Mock期望
|
||||
|
|
|
@ -11,7 +11,9 @@ import io.metersphere.functional.excel.exception.CustomFieldValidateException;
|
|||
import io.metersphere.functional.excel.validate.AbstractCustomFieldValidator;
|
||||
import io.metersphere.functional.excel.validate.CustomFieldValidatorFactory;
|
||||
import io.metersphere.functional.request.FunctionalCaseImportRequest;
|
||||
import io.metersphere.functional.service.FunctionalCaseService;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.excel.ExcelValidateHelper;
|
||||
|
@ -56,7 +58,9 @@ public class FunctionalCaseCheckEventListener extends AnalysisEventListener<Map<
|
|||
protected List<ExcelErrData<FunctionalCaseExcelData>> errList = new ArrayList<>();
|
||||
private static final String ERROR_MSG_SEPARATOR = ";";
|
||||
private HashMap<String, AbstractCustomFieldValidator> customFieldValidatorMap;
|
||||
|
||||
protected static final int TAGS_COUNT = 15;
|
||||
protected static final int TAG_LENGTH = 15;
|
||||
private FunctionalCaseService functionalCaseService;
|
||||
|
||||
public FunctionalCaseCheckEventListener(FunctionalCaseImportRequest request, Class clazz, List<TemplateCustomFieldDTO> customFields, Set<ExcelMergeInfo> mergeInfoSet) {
|
||||
this.mergeInfoSet = mergeInfoSet;
|
||||
|
@ -64,6 +68,7 @@ public class FunctionalCaseCheckEventListener extends AnalysisEventListener<Map<
|
|||
//当前项目模板的自定义字段
|
||||
customFieldsMap = customFields.stream().collect(Collectors.toMap(TemplateCustomFieldDTO::getFieldName, i -> i));
|
||||
customFieldValidatorMap = CustomFieldValidatorFactory.getValidatorMap();
|
||||
functionalCaseService = CommonBeanFactory.getBean(FunctionalCaseService.class);
|
||||
|
||||
}
|
||||
|
||||
|
@ -202,8 +207,31 @@ public class FunctionalCaseCheckEventListener extends AnalysisEventListener<Map<
|
|||
validateCustomField(data, errMsg);
|
||||
//校验id
|
||||
validateIdExist(data, errMsg);
|
||||
//标签长度校验
|
||||
validateTags(data, errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验标签长度 个数
|
||||
*
|
||||
* @param data
|
||||
* @param errMsg
|
||||
*/
|
||||
private void validateTags(FunctionalCaseExcelData data, StringBuilder errMsg) {
|
||||
List<String> tags = functionalCaseService.handleImportTags(data.getTags());
|
||||
if (tags.size() > TAGS_COUNT) {
|
||||
errMsg.append(Translator.get("tags_count"))
|
||||
.append(ERROR_MSG_SEPARATOR);
|
||||
return;
|
||||
}
|
||||
tags.forEach(tag -> {
|
||||
if (tag.length() > TAG_LENGTH) {
|
||||
errMsg.append(Translator.get("tag_length"))
|
||||
.append(ERROR_MSG_SEPARATOR);
|
||||
}
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验Excel中是否有ID
|
||||
|
|
|
@ -81,7 +81,8 @@ public class FunctionalCaseImportEventListener extends AnalysisEventListener<Map
|
|||
private SessionUser user;
|
||||
private int successCount = 0;
|
||||
private Map<String, String> pathMap = new HashMap<>();
|
||||
|
||||
protected static final int TAGS_COUNT = 15;
|
||||
protected static final int TAG_LENGTH = 15;
|
||||
|
||||
public FunctionalCaseImportEventListener(FunctionalCaseImportRequest request, Class clazz, List<TemplateCustomFieldDTO> customFields, Set<ExcelMergeInfo> mergeInfoSet, SessionUser user) {
|
||||
this.mergeInfoSet = mergeInfoSet;
|
||||
|
@ -395,6 +396,30 @@ public class FunctionalCaseImportEventListener extends AnalysisEventListener<Map
|
|||
validateCustomField(data, errMsg);
|
||||
//校验id
|
||||
validateIdExist(data, errMsg);
|
||||
//标签长度校验
|
||||
validateTags(data, errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验标签长度 个数
|
||||
*
|
||||
* @param data
|
||||
* @param errMsg
|
||||
*/
|
||||
private void validateTags(FunctionalCaseExcelData data, StringBuilder errMsg) {
|
||||
List<String> tags = functionalCaseService.handleImportTags(data.getTags());
|
||||
if (tags.size() > TAGS_COUNT) {
|
||||
errMsg.append(Translator.get("tags_count"))
|
||||
.append(ERROR_MSG_SEPARATOR);
|
||||
return;
|
||||
}
|
||||
tags.forEach(tag -> {
|
||||
if (tag.length() > TAG_LENGTH) {
|
||||
errMsg.append(Translator.get("tag_length"))
|
||||
.append(ERROR_MSG_SEPARATOR);
|
||||
}
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ public class FunctionalCaseService {
|
|||
private void copyAttachment(FunctionalCaseAddRequest request, String userId, List<String> uploadFileIds, String caseId) {
|
||||
//获取用例已经上传的文件ID
|
||||
Map<String, FunctionalCaseAttachmentDTO> attachmentDTOMap = request.getAttachments().stream().collect(Collectors.toMap(FunctionalCaseAttachmentDTO::getId, t -> t));
|
||||
List<String> attachmentFileIds = request.getAttachments().stream().filter(t-> !t.isDeleted()).map(FunctionalCaseAttachmentDTO::getId).filter(t -> !uploadFileIds.contains(t)).toList();
|
||||
List<String> attachmentFileIds = request.getAttachments().stream().filter(t -> !t.isDeleted()).map(FunctionalCaseAttachmentDTO::getId).filter(t -> !uploadFileIds.contains(t)).toList();
|
||||
if (CollectionUtils.isEmpty(attachmentFileIds)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1020,7 +1020,7 @@ public class FunctionalCaseService {
|
|||
* @param tags 标签
|
||||
* @return
|
||||
*/
|
||||
private List<String> handleImportTags(String tags) {
|
||||
public List<String> handleImportTags(String tags) {
|
||||
List<String> split = List.of(tags.split("[,;]"));
|
||||
return split.stream().map(String::trim).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue