Skip to content

Commit

Permalink
Adding the validation condition (#569) (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-tarento authored May 24, 2024
1 parent 61d359c commit 342aad6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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 @@ -155,7 +155,7 @@ public static Boolean validateExternalSystemId(String externalSystemId) {
}

public static Boolean validateExternalSystem(String externalSystem) {
return externalSystem.matches("[a-zA-Z ]{0,255}$");
return externalSystem.matches("^(?=.*[a-zA-Z .-])[a-zA-Z0-9 .-]{1,255}$"); // Allow only alphanumeric, alphabets and restrict if only numeric character
}

public static void updateErrorDetails(SBApiResponse response, String errMsg, HttpStatus responseCode) {
Expand Down Expand Up @@ -198,4 +198,8 @@ public static Boolean validateDate(String dateString){
}
return false;
}

public static Boolean validateEmployeeId(String employeeId) {
return employeeId.matches("^(?=.*\\d|[a-zA-Z]{30})[a-zA-Z0-9 .-]{1,30}$"); // Allow only alphanumeric, numeric and restrict if only alphabets character
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
} else {
invalidErrList.add("Invalid value for Employee ID column type. Expecting string/number format");
}
if (StringUtils.isNotBlank(userRegistration.getEmployeeId())) {
if (!ProjectUtil.validateEmployeeId(userRegistration.getEmployeeId())) {
invalidErrList.add("Invalid Employee ID : Employee ID can contain alphanumeric characters or numeric character and have a max length of 30");
}
}
}
if (nextRow.getCell(10) != null && nextRow.getCell(10).getCellType() != CellType.BLANK) {
if (nextRow.getCell(10).getCellType() == CellType.NUMERIC) {
Expand Down Expand Up @@ -267,7 +272,7 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
if (nextRow.getCell(12).getCellType() == CellType.STRING) {
userRegistration.setExternalSystem(nextRow.getCell(12).getStringCellValue().trim());
if (!ProjectUtil.validateExternalSystem(userRegistration.getExternalSystem())) {
invalidErrList.add("Invalid External System : External System Name can contain only alphabets and can have a max length of 255");
invalidErrList.add("Invalid External System Name : External System Name can contain only alphabets and alphanumeric and can have a max length of 255");
}
} else {
invalidErrList.add("Invalid value for External System Name column type. Expecting string format");
Expand Down

0 comments on commit 342aad6

Please sign in to comment.