From dc6015d44107dc007eacf8f24d6db47919a5f422 Mon Sep 17 00:00:00 2001 From: Sreerag K S <58926794+sreeragksgh@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:05:55 +0530 Subject: [PATCH] New line character validation for all fields in user bulk upload File (#660) --- .../org/sunbird/common/util/ProjectUtil.java | 6 +++- .../service/UserBulkUploadService.java | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/sunbird/common/util/ProjectUtil.java b/src/main/java/org/sunbird/common/util/ProjectUtil.java index 0602f451b..2f44ed419 100644 --- a/src/main/java/org/sunbird/common/util/ProjectUtil.java +++ b/src/main/java/org/sunbird/common/util/ProjectUtil.java @@ -27,7 +27,7 @@ public class ProjectUtil { public static CbExtLogger logger = new CbExtLogger(ProjectUtil.class.getName()); - public static String DEFAULT_BULK_UPLOAD_VERIFICATION_REGEX = "^[a-zA-Z\\s,]+$"; + public static String DEFAULT_BULK_UPLOAD_VERIFICATION_REGEX ="^(?!.*\\n)[a-zA-Z\\s,]+$"; /** * This method will check incoming value is null or empty it will do empty check @@ -210,4 +210,8 @@ public static Boolean validateRegexPatternWithNoSpecialCharacter(String regex) { public static Boolean validatePinCode(String regex) { return regex.matches("^[0-9]{6}$"); } + + public static Boolean validatesNewLine(String value) { + return value.matches(".*\\n.*"); + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index 89d8a4c8e..dc413aee9 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -178,6 +178,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { if (nextRow.getCell(1).getCellType() == CellType.STRING) { userRegistration.setEmail(nextRow.getCell(1).getStringCellValue().trim()); + if (ProjectUtil.validatesNewLine(userRegistration.getEmail())) { + invalidErrList.add("Invalid Email: Email address contains newline characters"); + } } else { invalidErrList.add("Invalid value for Email column type. Expecting string format"); } @@ -194,6 +197,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { invalidErrList.add("Invalid value for Mobile Number column type. Expecting number/string format"); } + if (ProjectUtil.validatesNewLine(userRegistration.getPhone())) { + invalidErrList.add("Invalid Phone: Phone Number contains newline characters"); + } } if (StringUtils.isNotBlank(phone)) { if (!ProjectUtil.validateContactPattern(phone)) { @@ -205,6 +211,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { if (nextRow.getCell(3).getCellType() == CellType.STRING) { userRegistration.setGroup(nextRow.getCell(3).getStringCellValue().trim()); + if (ProjectUtil.validatesNewLine(userRegistration.getGroup())) { + invalidErrList.add("Invalid Group: Group contains newline characters"); + } if (!userUtilityService.validateGroup(userRegistration.getGroup())) { invalidErrList.add("Invalid Group : Group can be only among one of these " + serverProperties.getBulkUploadGroupValue()); } @@ -217,6 +226,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { if (nextRow.getCell(4).getCellType() == CellType.STRING) { userRegistration.setPosition(nextRow.getCell(4).getStringCellValue().trim()); + if (ProjectUtil.validatesNewLine(userRegistration.getPosition())) { + invalidErrList.add("Invalid Position: Position contains newline characters"); + } } else { invalidErrList.add("Invalid value for Designation column type. Expecting string format"); } @@ -230,6 +242,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx if (nextRow.getCell(5).getCellType() == CellType.STRING) { if (userUtilityService.validateGender(nextRow.getCell(5).getStringCellValue().trim())) { userRegistration.setGender(nextRow.getCell(5).getStringCellValue().trim()); + if (ProjectUtil.validatesNewLine(userRegistration.getGender())) { + invalidErrList.add("Invalid Gender: Gender contains newline characters"); + } } else { invalidErrList.add("Invalid Gender : Gender can be only among one of these " + serverProperties.getBulkUploadGenderValue()); } @@ -241,6 +256,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx if (nextRow.getCell(6).getCellType() == CellType.STRING) { if (userUtilityService.validateCategory(nextRow.getCell(6).getStringCellValue().trim())) { userRegistration.setCategory(nextRow.getCell(6).getStringCellValue().trim()); + if (ProjectUtil.validatesNewLine(userRegistration.getCategory())) { + invalidErrList.add("Invalid Category: Category contains newline characters"); + } } else { invalidErrList.add("Invalid Category : Category can be only among one of these " + serverProperties.getBulkUploadCategoryValue()); } @@ -267,10 +285,16 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { invalidErrList.add("Invalid value for Date of Birth column type. Expecting string type in dd-mm-yyyy format"); } + if (ProjectUtil.validatesNewLine(userRegistration.getDob())) { + invalidErrList.add("Invalid DOB: DOB contains newline characters"); + } } if (nextRow.getCell(8) != null && nextRow.getCell(8).getCellType() != CellType.BLANK) { if (nextRow.getCell(8).getCellType() == CellType.STRING) { userRegistration.setDomicileMedium(nextRow.getCell(8).getStringCellValue().trim()); + if (ProjectUtil.validatesNewLine(userRegistration.getDomicileMedium())) { + invalidErrList.add("Invalid Domicile Medium: Domicile Medium contains newline characters"); + } } else { invalidErrList.add("Invalid value for Mother Tongue column type. Expecting string format"); } @@ -296,6 +320,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx invalidErrList.add("Invalid Employee ID : Employee Id cannot contain spaces"); } } + if (ProjectUtil.validatesNewLine(userRegistration.getEmployeeId())) { + invalidErrList.add("Invalid Employee ID: Employee ID contains newline characters"); + } } if (nextRow.getCell(10) != null && nextRow.getCell(10).getCellType() != CellType.BLANK) { if (nextRow.getCell(10).getCellType() == CellType.NUMERIC) { @@ -310,6 +337,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx invalidErrList.add("Invalid Office Pin Code : Office Pin Code should be numeric and is of 6 digit."); } } + if (ProjectUtil.validatesNewLine(userRegistration.getPincode())) { + invalidErrList.add("Invalid Pin Code: Pin Code contains newline characters"); + } } if (nextRow.getCell(11) != null && nextRow.getCell(11).getCellType() != CellType.BLANK) { if (nextRow.getCell(11).getCellType() == CellType.NUMERIC) { @@ -325,6 +355,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { invalidErrList.add("Invalid value for External System ID column type. Expecting string/number format"); } + if (ProjectUtil.validatesNewLine(userRegistration.getExternalSystemId())) { + invalidErrList.add("Invalid External System ID: External System ID contains newline characters"); + } } if (nextRow.getCell(12) != null && !StringUtils.isBlank(nextRow.getCell(12).toString())) { if (nextRow.getCell(12).getCellType() == CellType.STRING) { @@ -332,6 +365,9 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx if (!ProjectUtil.validateExternalSystem(userRegistration.getExternalSystem())) { invalidErrList.add("Invalid External System Name : External System Name can contain only alphabets and alphanumeric and can have a max length of 255"); } + if (ProjectUtil.validatesNewLine(userRegistration.getExternalSystem())) { + invalidErrList.add("Invalid External System Name: External System Name contains newline characters"); + } } else { invalidErrList.add("Invalid value for External System Name column type. Expecting string format"); }