fix(用例管理): 导入各种校验
--bug=1036820 --user=王旭 【用例管理】导入用例-输入框/文本框/多值输入框 未校验长度限制 https://www.tapd.cn/55049933/s/1482932
This commit is contained in:
parent
9c8a7ff16e
commit
60ba5d8fb4
|
@ -548,7 +548,11 @@ custom_field_member_tip=[%s] must be current project member
|
||||||
custom_field_select_tip=[%s] must be %s
|
custom_field_select_tip=[%s] must be %s
|
||||||
custom_field_int_tip=[%s] must be integer
|
custom_field_int_tip=[%s] must be integer
|
||||||
custom_field_float_tip=[%s] must be number
|
custom_field_float_tip=[%s] must be number
|
||||||
check_import_excel_error=Check import excel error
|
check_import_excel_error=Verification failed, please check if the file is correct
|
||||||
|
custom_field_multip_input_tip=The number of [%s] cannot exceed 15
|
||||||
|
custom_field_multip_input_length_tip=The length of [%s] cannot exceed 64 characters
|
||||||
|
custom_field_input_length_tip=The length of [%s] cannot exceed 255 characters
|
||||||
|
custom_field_textarea_length_tip=The length of [%s] cannot exceed 1000 characters
|
||||||
#关联
|
#关联
|
||||||
relate_source_id_not_blank=Source id cannot be empty
|
relate_source_id_not_blank=Source id cannot be empty
|
||||||
relate_source_id_length_range=The association source ID must be between {min} and {max}
|
relate_source_id_length_range=The association source ID must be between {min} and {max}
|
||||||
|
|
|
@ -545,7 +545,11 @@ custom_field_member_tip=[%s]必须当前项目成员
|
||||||
custom_field_select_tip=[%s]必须为%s
|
custom_field_select_tip=[%s]必须为%s
|
||||||
custom_field_int_tip=[%s]必须为整型
|
custom_field_int_tip=[%s]必须为整型
|
||||||
custom_field_float_tip=[%s]必须为数字
|
custom_field_float_tip=[%s]必须为数字
|
||||||
check_import_excel_error=检查导入Excel错误
|
check_import_excel_error=校验失败,请检查文件是否正确
|
||||||
|
custom_field_multip_input_tip=[%s]个数不能超过15个
|
||||||
|
custom_field_multip_input_length_tip=[%s]长度不能超过64个字符
|
||||||
|
custom_field_input_length_tip=[%s]长度不能超过255个字符
|
||||||
|
custom_field_textarea_length_tip=[%s]长度不能超过1000个字符
|
||||||
#关联
|
#关联
|
||||||
relate_source_id_not_blank=关联来源ID不能为空
|
relate_source_id_not_blank=关联来源ID不能为空
|
||||||
relate_source_id_length_range=关联来源ID必须在{min}和{max}之间
|
relate_source_id_length_range=关联来源ID必须在{min}和{max}之间
|
||||||
|
|
|
@ -546,7 +546,11 @@ custom_field_member_tip=[%s]必須當前項目成員
|
||||||
custom_field_select_tip=[%s]必須為%s
|
custom_field_select_tip=[%s]必須為%s
|
||||||
custom_field_int_tip=[%s]必須為整型
|
custom_field_int_tip=[%s]必須為整型
|
||||||
custom_field_float_tip=[%s]必須為數字
|
custom_field_float_tip=[%s]必須為數字
|
||||||
check_import_excel_error=檢查導入Excel錯誤
|
check_import_excel_error=校驗失敗,請檢查文件是否正確
|
||||||
|
custom_field_multip_input_tip=[%s]個數不能超過15個
|
||||||
|
custom_field_multip_input_length_tip=[%s]長度不能超過64個字符
|
||||||
|
custom_field_input_length_tip=[%s]長度不能超過255個字符
|
||||||
|
custom_field_textarea_length_tip=[%s]長度不能超過1000個字符
|
||||||
#关联
|
#关联
|
||||||
relate_source_id_not_blank=關聯來源ID不能為空
|
relate_source_id_not_blank=關聯來源ID不能為空
|
||||||
relate_source_id_length_range=關聯來源ID必須在{min}和{max}之間
|
relate_source_id_length_range=關聯來源ID必須在{min}和{max}之間
|
||||||
|
|
|
@ -9,11 +9,14 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wx
|
* @author wx
|
||||||
*/
|
*/
|
||||||
public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidator {
|
public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidator {
|
||||||
|
protected static final int MULTIP_INPUT_COUNT = 15;
|
||||||
|
protected static final int MULTIP_INPUT_LENGTH = 64;
|
||||||
|
|
||||||
public CustomFieldMultipleTextValidator() {
|
public CustomFieldMultipleTextValidator() {
|
||||||
this.isKVOption = true;
|
this.isKVOption = true;
|
||||||
|
@ -23,10 +26,18 @@ public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidat
|
||||||
public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException {
|
public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException {
|
||||||
validateRequired(customField, value);
|
validateRequired(customField, value);
|
||||||
if (StringUtils.isNotBlank(value)) {
|
if (StringUtils.isNotBlank(value)) {
|
||||||
try {
|
List<String> multipTexts = parse2Array(customField.getFieldName(), value);
|
||||||
parse2Array(customField.getFieldName(), value);
|
if (multipTexts.size() > MULTIP_INPUT_COUNT) {
|
||||||
} catch (Exception e) {
|
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_multip_input_tip"), customField.getFieldName()));
|
||||||
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_array_tip"), customField.getFieldName()));
|
}
|
||||||
|
AtomicBoolean isOverLength = new AtomicBoolean(false);
|
||||||
|
multipTexts.forEach(multipText -> {
|
||||||
|
if (multipText.length() > MULTIP_INPUT_LENGTH) {
|
||||||
|
isOverLength.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (isOverLength.get()) {
|
||||||
|
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_multip_input_length_tip"), customField.getFieldName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,27 @@
|
||||||
package io.metersphere.functional.excel.validate;
|
package io.metersphere.functional.excel.validate;
|
||||||
|
|
||||||
import io.metersphere.functional.excel.exception.CustomFieldValidateException;
|
import io.metersphere.functional.excel.exception.CustomFieldValidateException;
|
||||||
|
import io.metersphere.sdk.constants.CustomFieldType;
|
||||||
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
|
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wx
|
* @author wx
|
||||||
*/
|
*/
|
||||||
public class CustomFieldTextValidator extends AbstractCustomFieldValidator {
|
public class CustomFieldTextValidator extends AbstractCustomFieldValidator {
|
||||||
|
protected static final int INPUT_LENGTH = 255;
|
||||||
|
protected static final int TEXTAREA_LENGTH = 1000;
|
||||||
|
|
||||||
public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException {
|
public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException {
|
||||||
validateRequired(customField, value);
|
validateRequired(customField, value);
|
||||||
|
if (StringUtils.equalsIgnoreCase(CustomFieldType.INPUT.name(), customField.getType()) && value.length() > INPUT_LENGTH) {
|
||||||
|
//输入框 255
|
||||||
|
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_input_length_tip"), customField.getFieldName()));
|
||||||
|
}
|
||||||
|
if (StringUtils.equalsIgnoreCase(CustomFieldType.TEXTAREA.name(), customField.getType()) && value.length() > TEXTAREA_LENGTH) {
|
||||||
|
//文本域 1000
|
||||||
|
CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_textarea_length_tip"), customField.getFieldName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue