Skip to content

Commit

Permalink
New line character validation for all fields in user bulk upload File (
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeragksgh authored Aug 8, 2024
1 parent fac9497 commit dc6015d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/org/sunbird/common/util/ProjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ private void processBulkUpload(HashMap<String, String> 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");
}
Expand All @@ -194,6 +197,9 @@ private void processBulkUpload(HashMap<String, String> 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)) {
Expand All @@ -205,6 +211,9 @@ private void processBulkUpload(HashMap<String, String> 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());
}
Expand All @@ -217,6 +226,9 @@ private void processBulkUpload(HashMap<String, String> 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");
}
Expand All @@ -230,6 +242,9 @@ private void processBulkUpload(HashMap<String, String> 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());
}
Expand All @@ -241,6 +256,9 @@ private void processBulkUpload(HashMap<String, String> 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());
}
Expand All @@ -267,10 +285,16 @@ private void processBulkUpload(HashMap<String, String> 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");
}
Expand All @@ -296,6 +320,9 @@ private void processBulkUpload(HashMap<String, String> 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) {
Expand All @@ -310,6 +337,9 @@ private void processBulkUpload(HashMap<String, String> 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) {
Expand All @@ -325,13 +355,19 @@ private void processBulkUpload(HashMap<String, String> 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) {
userRegistration.setExternalSystem(nextRow.getCell(12).getStringCellValue().trim());
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");
}
Expand Down

0 comments on commit dc6015d

Please sign in to comment.