Skip to content

Commit

Permalink
Merge pull request #234 from sunbird-cb/userBulkUploadChanges-4.8.2
Browse files Browse the repository at this point in the history
changes for group and external system
  • Loading branch information
pkranga authored May 30, 2023
2 parents c832da5 + 3fb2a88 commit 85aebba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/sunbird/common/util/ProjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public static String firstLetterCapitalWithSingleSpace(final String words) {
*/

public static Boolean validateEmailPattern(String email) {
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z"
+ "A-Z]{2,7}$";
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
Boolean retValue = Boolean.FALSE;
Pattern pat = Pattern.compile(emailRegex);
if (pat.matcher(email).matches()) {
Expand Down Expand Up @@ -153,15 +152,15 @@ public static Boolean validateLastName( String lastName ) {

public static Boolean validateTag(List<String> tags) {
for (String tag : tags) {
if (!tag.matches("[a-zA-Z ]*")) {
if (!tag.matches("^[a-zA-Z]+(?: [a-zA-Z]+)*$")) {
return false;
}
}
return true;
}

public static Boolean validateExternalSystemId(String externalSystemId) {
return externalSystemId.matches("[a-zA-Z0-9]{0,30}$");
return externalSystemId.matches("^(?=.{1,30}$)[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$");
}

public static Boolean validateExternalSystem(String externalSystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
invalidErrList.add("Invalid Tag");
}
}
if (nextRow.getCell(6) != null && !StringUtils.isBlank(nextRow.getCell(6).toString())) {
userRegistration.setExternalSystemId(nextRow.getCell(6).getStringCellValue());
if (!ProjectUtil.validateExternalSystemId(userRegistration.getExternalSystemId())) {
if (nextRow.getCell(6) != null && nextRow.getCell(6).getCellType() != CellType.BLANK) {
if (nextRow.getCell(6).getCellType() == CellType.NUMERIC) {
userRegistration.setExternalSystemId(NumberToTextConverter.toText(nextRow.getCell(6).getNumericCellValue()));
} else if (nextRow.getCell(6).getCellType() == CellType.STRING) {
userRegistration.setExternalSystemId(nextRow.getCell(6).getStringCellValue());
}
if (!StringUtils.isEmpty(userRegistration.getExternalSystemId()) && !ProjectUtil.validateExternalSystemId(userRegistration.getExternalSystemId())) {
invalidErrList.add("Invalid External System ID");
}
}
Expand Down Expand Up @@ -296,12 +300,8 @@ private List<String> validateEmailContactAndDomain(UserRegistration userRegistra
if (!ProjectUtil.validateEmailPattern(userRegistration.getEmail())) {
errList.add("Invalid Email Id");
} else {
if (!userUtilityService.isDomainAccepted(userRegistration.getEmail())) {
errList.add("Invalid Email Domain");
} else {
if (userUtilityService.isUserExist(Constants.EMAIL, userRegistration.getEmail())) {
errList.add(Constants.EMAIL_EXIST_ERROR);
}
if (userUtilityService.isUserExist(Constants.EMAIL, userRegistration.getEmail())) {
errList.add(Constants.EMAIL_EXIST_ERROR);
}
}
if (!ProjectUtil.validateContactPattern(userRegistration.getPhone())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@ public void getUserDetailsFromDB(List<String> userIds, List<String> fields,
public void enrichUserInfo(List<String> fields, Map<String, Map<String, String>> userInfoMap);

boolean isUserExist(String key, String value);

Boolean isDomainAccepted(String email);

boolean validateGroup(String group);
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,6 @@ public boolean isUserExist(String key, String value) {
return true;
}


@Override
public Boolean isDomainAccepted(String email) {
String emailDomain = email.split("@")[1];
return props.getUserRegistrationDomain().contains(emailDomain);
}

@Override
public boolean validateGroup(String group) {
return (!CollectionUtils.isEmpty(serverConfig.getBulkUploadGroupValue())) ? serverConfig.getBulkUploadGroupValue().stream().anyMatch(group::equalsIgnoreCase) : false;
Expand Down

0 comments on commit 85aebba

Please sign in to comment.