diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index 49f2f9b423..bcc8004eba 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -548,7 +548,11 @@ custom_field_member_tip=[%s] must be current project member custom_field_select_tip=[%s] must be %s custom_field_int_tip=[%s] must be integer 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_length_range=The association source ID must be between {min} and {max} diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index d0796b673b..fd8adea814 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -545,7 +545,11 @@ custom_field_member_tip=[%s]必须当前项目成员 custom_field_select_tip=[%s]必须为%s custom_field_int_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_length_range=关联来源ID必须在{min}和{max}之间 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 6714283b11..d8dc8ffce9 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -546,7 +546,11 @@ custom_field_member_tip=[%s]必須當前項目成員 custom_field_select_tip=[%s]必須為%s custom_field_int_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_length_range=關聯來源ID必須在{min}和{max}之間 diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleTextValidator.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleTextValidator.java index 17d573da8b..0753c90ff3 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleTextValidator.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldMultipleTextValidator.java @@ -9,11 +9,14 @@ import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; /** * @author wx */ public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidator { + protected static final int MULTIP_INPUT_COUNT = 15; + protected static final int MULTIP_INPUT_LENGTH = 64; public CustomFieldMultipleTextValidator() { this.isKVOption = true; @@ -23,10 +26,18 @@ public class CustomFieldMultipleTextValidator extends AbstractCustomFieldValidat public void validate(TemplateCustomFieldDTO customField, String value) throws CustomFieldValidateException { validateRequired(customField, value); if (StringUtils.isNotBlank(value)) { - try { - parse2Array(customField.getFieldName(), value); - } catch (Exception e) { - CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_array_tip"), customField.getFieldName())); + List multipTexts = parse2Array(customField.getFieldName(), value); + if (multipTexts.size() > MULTIP_INPUT_COUNT) { + CustomFieldValidateException.throwException(String.format(Translator.get("custom_field_multip_input_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())); } } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldTextValidator.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldTextValidator.java index 872249b346..f098be935c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldTextValidator.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/validate/CustomFieldTextValidator.java @@ -1,14 +1,27 @@ package io.metersphere.functional.excel.validate; 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 org.apache.commons.lang3.StringUtils; /** * @author wx */ 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 { 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())); + } } }