From a89d92e1ea92cd67f99e6f8dbd9635002d406cb0 Mon Sep 17 00:00:00 2001 From: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com> Date: Mon, 27 May 2024 17:37:51 +0530 Subject: [PATCH] 4.8.14 dev v6 (#575) * 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 --- .../common/util/CbExtServerProperties.java | 22 ++++++++++ .../org/sunbird/common/util/ProjectUtil.java | 8 ++++ .../profile/service/ProfileServiceImpl.java | 4 +- .../service/UserBulkUploadService.java | 44 +++++++++++++++++-- .../user/service/UserUtilityService.java | 4 ++ .../user/service/UserUtilityServiceImpl.java | 11 +++++ src/main/resources/application.properties | 5 ++- 7 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sunbird/common/util/CbExtServerProperties.java b/src/main/java/org/sunbird/common/util/CbExtServerProperties.java index df7eea210..34ab70f6e 100644 --- a/src/main/java/org/sunbird/common/util/CbExtServerProperties.java +++ b/src/main/java/org/sunbird/common/util/CbExtServerProperties.java @@ -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; } @@ -2663,4 +2669,20 @@ public List getBulkUploadAllowedRolesCreation() { public void setBulkUploadAllowedRolesCreation(String bulkUploadAllowedRolesCreation) { this.bulkUploadAllowedRolesCreation = bulkUploadAllowedRolesCreation; } + + public List getBulkUploadGenderValue() { + return Arrays.asList(bulkUploadGenderValue.split(",", -1)); + } + + public void setBulkUploadGenderValue(String bulkUploadGenderValue) { + this.bulkUploadGenderValue = bulkUploadGenderValue; + } + + public List getBulkUploadCategoryValue() { + return Arrays.asList(bulkUploadCategoryValue.split(",", -1)); + } + + public void setBulkUploadCategoryValue(String bulkUploadCategoryValue) { + this.bulkUploadCategoryValue = bulkUploadCategoryValue; + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/common/util/ProjectUtil.java b/src/main/java/org/sunbird/common/util/ProjectUtil.java index 61a65ec29..b08105c4a 100644 --- a/src/main/java/org/sunbird/common/util/ProjectUtil.java +++ b/src/main/java/org/sunbird/common/util/ProjectUtil.java @@ -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}$"); + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index 6b917a28c..92e18b2e9 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -1817,7 +1817,9 @@ public SBApiResponse profileMDOAdminUpdate(Map 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 additionalProperties = (Map) existingProfileDetails .get(Constants.ADDITIONAL_PROPERTIES); diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index 53942940c..3a1eab063 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -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; @@ -29,6 +30,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.*; @Service @@ -197,17 +199,30 @@ private void processBulkUpload(HashMap 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"); } @@ -217,7 +232,20 @@ private void processBulkUpload(HashMap 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"); @@ -229,6 +257,11 @@ private void processBulkUpload(HashMap 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) { @@ -252,6 +285,11 @@ private void processBulkUpload(HashMap 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) { diff --git a/src/main/java/org/sunbird/user/service/UserUtilityService.java b/src/main/java/org/sunbird/user/service/UserUtilityService.java index 155808e5e..7a5ec4d5d 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityService.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityService.java @@ -53,4 +53,8 @@ public void getUserDetailsFromDB(List userIds, List fields, SBApiResponse recommendContent(String authUserToken, Map orgRequest); Map getUserDetails(String key, String value); + + boolean validateGender(String gender); + + boolean validateCategory(String category); } \ No newline at end of file diff --git a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java index db678dcc3..ef9bfe57f 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java @@ -1052,4 +1052,15 @@ public Map getUserDetails(String key, String value) { return null; } + @Override + public boolean validateGender(String gender) { + List genderValues = serverConfig.getBulkUploadGenderValue(); + return genderValues != null && genderValues.contains(gender); + } + + @Override + public boolean validateCategory(String category) { + List categoryValues = serverConfig.getBulkUploadCategoryValue(); + return categoryValues != null && categoryValues.contains(category); + } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0f3bcbff7..31c239207 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 \ No newline at end of file +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 \ No newline at end of file