Skip to content

Commit

Permalink
4.8.14 dev v6 (#575)
Browse files Browse the repository at this point in the history
* Bug Fix for validation (#573)

* Bug Fix for validation

* Bug Fix for validation fields

* Updated timezone for date format

* Error msg changes

---------

Co-authored-by: karthik-tarento <[email protected]>
  • Loading branch information
Sahil-tarento and karthik-tarento authored May 27, 2024
1 parent 87249cd commit a89d92e
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/sunbird/common/util/CbExtServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,12 @@ public void setRedisWheeboxKey(String redisWheeboxKey) {
@Value("${bulk.upload.allowed.roles.creation}")
private String bulkUploadAllowedRolesCreation;

@Value("${user.bulk.upload.gender.value}")
private String bulkUploadGenderValue;

@Value("${user.bulk.upload.category.value}")
private String bulkUploadCategoryValue;

public boolean qListFromCacheEnabled() {
return qListFromCacheEnabled;
}
Expand Down Expand Up @@ -2663,4 +2669,20 @@ public List<String> getBulkUploadAllowedRolesCreation() {
public void setBulkUploadAllowedRolesCreation(String bulkUploadAllowedRolesCreation) {
this.bulkUploadAllowedRolesCreation = bulkUploadAllowedRolesCreation;
}

public List<String> getBulkUploadGenderValue() {
return Arrays.asList(bulkUploadGenderValue.split(",", -1));
}

public void setBulkUploadGenderValue(String bulkUploadGenderValue) {
this.bulkUploadGenderValue = bulkUploadGenderValue;
}

public List<String> getBulkUploadCategoryValue() {
return Arrays.asList(bulkUploadCategoryValue.split(",", -1));
}

public void setBulkUploadCategoryValue(String bulkUploadCategoryValue) {
this.bulkUploadCategoryValue = bulkUploadCategoryValue;
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/sunbird/common/util/ProjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ public static Boolean validateDate(String dateString){
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
}

public static Boolean validateRegexPatternWithNoSpecialCharacter(String regex) {
return regex.matches("^[a-zA-Z0-9 -()]*$");
}

public static Boolean validatePinCode(String regex) {
return regex.matches("^[0-9]{6}$");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,9 @@ public SBApiResponse profileMDOAdminUpdate(Map<String, Object> request, String u
existingProfileDetails.put(Constants.PROFILE_STATUS, Constants.NOT_VERIFIED);
}

String timeStamp = new SimpleDateFormat("dd-MM-yyyy HH.mm.ss").format(new java.util.Date());
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH.mm.ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+05:30"));
String timeStamp = sdf.format(new java.util.Date());
existingProfileDetails.put(Constants.PROFILE_STATUS_UPDATED_ON, timeStamp);
Map<String, Object> additionalProperties = (Map<String, Object>) existingProfileDetails
.get(Constants.ADDITIONAL_PROPERTIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.xssf.usermodel.XSSFRow;
Expand All @@ -29,6 +30,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
Expand Down Expand Up @@ -197,17 +199,30 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
} else {
invalidErrList.add("Invalid value for Designation column type. Expecting string format");
}
if (StringUtils.isNotBlank(userRegistration.getPosition())) {
if (!ProjectUtil.validateRegexPatternWithNoSpecialCharacter(userRegistration.getPosition())) {
invalidErrList.add("Invalid Designation: Designation should be added from default list and cannot contain special character");
}
}
}
if (nextRow.getCell(5) != null && nextRow.getCell(5).getCellType() != CellType.BLANK) {
if (nextRow.getCell(5).getCellType() == CellType.STRING) {
userRegistration.setGender(nextRow.getCell(5).getStringCellValue().trim());
if (userUtilityService.validateGender(nextRow.getCell(5).getStringCellValue().trim())) {
userRegistration.setGender(nextRow.getCell(5).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid Gender : Gender can be only among one of these " + serverProperties.getBulkUploadGenderValue());
}
} else {
invalidErrList.add("Invalid value for Gender column type. Expecting string format");
}
}
if (nextRow.getCell(6) != null && nextRow.getCell(6).getCellType() != CellType.BLANK) {
if (nextRow.getCell(6).getCellType() == CellType.STRING) {
userRegistration.setCategory(nextRow.getCell(6).getStringCellValue().trim());
if (userUtilityService.validateCategory(nextRow.getCell(6).getStringCellValue().trim())) {
userRegistration.setCategory(nextRow.getCell(6).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid Category : Category can be only among one of these " + serverProperties.getBulkUploadCategoryValue());
}
} else {
invalidErrList.add("Invalid value for Category column type. Expecting string format");
}
Expand All @@ -217,7 +232,20 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
if (ProjectUtil.validateDate(nextRow.getCell(7).getStringCellValue().trim())) {
userRegistration.setDob(nextRow.getCell(7).getStringCellValue().trim());
} else {
invalidErrList.add("Invalid format for Date of Birth type. Expecting in format dd-MM-yyyy");
invalidErrList.add("Invalid format for Date of Birth type. Expecting in format dd-mm-yyyy");
}
} else if (nextRow.getCell(7).getCellType() == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(nextRow.getCell(7))) {
Date date = nextRow.getCell(7).getDateCellValue();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
String dob = dateFormat.format(date);
if (ProjectUtil.validateDate(dob)) {
userRegistration.setDob(dob);
} else {
invalidErrList.add("Invalid format for Date of Birth type. Expecting in format dd-mm-yyyy");
}
} else {
invalidErrList.add("Cell is numeric but not a date.");
}
} else {
invalidErrList.add("Invalid value for Date of Birth column type. Expecting string format");
Expand All @@ -229,6 +257,11 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
} else {
invalidErrList.add("Invalid value for Mother Tongue column type. Expecting string format");
}
if (StringUtils.isNotBlank(userRegistration.getDomicileMedium())) {
if (!ProjectUtil.validateRegexPatternWithNoSpecialCharacter(userRegistration.getDomicileMedium())) {
invalidErrList.add("Invalid Mother Tongue: Mother Tongue should be added from default list and cannot contain special character");
}
}
}
if (nextRow.getCell(9) != null && nextRow.getCell(9).getCellType() != CellType.BLANK) {
if (nextRow.getCell(9).getCellType() == CellType.NUMERIC) {
Expand All @@ -252,6 +285,11 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
} else {
invalidErrList.add("Invalid value for Office Pin Code column type. Expecting number/string format");
}
if (StringUtils.isNotBlank(userRegistration.getPincode())) {
if (!ProjectUtil.validatePinCode(userRegistration.getPincode())) {
invalidErrList.add("Invalid Office Pin Code : Office Pin Code should be numeric and is of 6 digit.");
}
}
}
if (nextRow.getCell(11) != null && nextRow.getCell(11).getCellType() != CellType.BLANK) {
if (nextRow.getCell(11).getCellType() == CellType.NUMERIC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public void getUserDetailsFromDB(List<String> userIds, List<String> fields,
SBApiResponse recommendContent(String authUserToken, Map<String, Object> orgRequest);

Map<String, Object> getUserDetails(String key, String value);

boolean validateGender(String gender);

boolean validateCategory(String category);
}
11 changes: 11 additions & 0 deletions src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,4 +1052,15 @@ public Map<String, Object> getUserDetails(String key, String value) {
return null;
}

@Override
public boolean validateGender(String gender) {
List<String> genderValues = serverConfig.getBulkUploadGenderValue();
return genderValues != null && genderValues.contains(gender);
}

@Override
public boolean validateCategory(String category) {
List<String> categoryValues = serverConfig.getBulkUploadCategoryValue();
return categoryValues != null && categoryValues.contains(category);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,7 @@ cloud.public.store.container.name=igot
organisation.insights.fields={"Average Course Rating":"https://portal.karmayogi.nic.in/content-store/sb-cb-ext-dev/orgStore/01376822290813747263/1715340042117_star.svg","Content Available":"https://portal.karmayogi.nic.in/content-store/sb-cb-ext-dev/orgStore/01376822290813747263/1715340042117_star.svg","Enrolments So Far":"https://portal.karmayogi.nic.in/content-store/sb-cb-ext-dev/orgStore/01376822290813747263/1715340042117_star.svg","Certificates Issued So Far":"https://portal.karmayogi.nic.in/content-store/sb-cb-ext-dev/orgStore/01376822290813747263/1715340042117_star.svg"}
organisation.insights.property.fields={"valueColor": "#FFFFFF","labelColor": "#000000","linebreak":"true","background":"banner-metrics","iconColor": "#FFFFFF"}
organisation.insights.redis.key.mapping={"Average Course Rating":"dashboard_course_average_rating_by_course_org","Content Available":"dashboard_live_course_count_by_course_org","Enrolments So Far":"dashboard_enrolment_count_by_course_org","Certificates Issued So Far":"dashboard_certificates_generated_count_by_course_org"}
bulk.upload.allowed.roles.creation=CBP_ADMIN,CONTENT_CREATOR,CONTENT_REVIEWER,FRAC_ADMIN,FRAC_COMPETENCY_MEMBER,FRAC_COMPETENCY_REVIEWER,FRAC_REVIEWER_L1,FRAC_REVIEWER_L2,IFU_MEMBER,MDO_ADMIN,MDO_LEADER,PUBLIC,WAT_MEMBER,PROGRAM_COORDINATOR,MDO_DASHBOARD_USER
bulk.upload.allowed.roles.creation=CBP_ADMIN,CONTENT_CREATOR,CONTENT_REVIEWER,FRAC_ADMIN,FRAC_COMPETENCY_MEMBER,FRAC_COMPETENCY_REVIEWER,FRAC_REVIEWER_L1,FRAC_REVIEWER_L2,IFU_MEMBER,MDO_ADMIN,MDO_LEADER,PUBLIC,WAT_MEMBER,PROGRAM_COORDINATOR,MDO_DASHBOARD_USER

user.bulk.upload.gender.value=Male,Female,Others
user.bulk.upload.category.value=General,OBC,SC,ST,Others

0 comments on commit a89d92e

Please sign in to comment.