Skip to content

Commit

Permalink
Merged changes from cbrelease-4.8.14
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Jun 11, 2024
2 parents 604c6b8 + fa63744 commit 0219fc7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 22 deletions.
27 changes: 24 additions & 3 deletions src/main/java/org/sunbird/cache/RedisCacheMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,33 @@ public String getContentFromCache(String key) {
}
}

public Boolean isKeyExist(String key) {
public boolean keyExists(String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.exists(Constants.REDIS_COMMON_KEY + key);
} catch (Exception e) {
logger.error(e);
return null;
logger.error("An Error Occurred while fetching value from Redis", e);
return false;
}
}

public boolean valueExists(String key, String value) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.sismember(Constants.REDIS_COMMON_KEY + key, value);
} catch (Exception e) {
logger.error("An Error Occurred while fetching value from Redis", e);
return false;
}
}

public void putCacheAsStringArray(String key, String[] values, Integer ttl) {
try (Jedis jedis = jedisPool.getResource()) {
if(null == ttl)
ttl = cache_ttl;
jedis.sadd(Constants.REDIS_COMMON_KEY + key, values);
jedis.expire(Constants.REDIS_COMMON_KEY + key, ttl);
logger.debug("Cache_key_value " + Constants.REDIS_COMMON_KEY + key + " is saved in redis");
} catch (Exception e) {
logger.error("An error occurred while saving data into Redis",e);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ public class Constants {
public static final String PROFILE_GROUP_STATUS = "profileGroupStatus";
public static final String PROFILE_DESIGNATION_STATUS = "profileDesignationStatus";
public static final String NOT_MY_USER = "NOT-MY-USER";
public static final String SPACE = " ";
public static final String REQUEST_TYPE = "requestType";
public static final String INSIGHT_FIELD_KEY = ".insights.fields";
public static final String INSIGHT_REDIS_KEY_MAPPING = ".insights.redis.key.mapping";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.sunbird.cache.RedisCacheMgr;
import org.sunbird.cassandra.utils.CassandraOperation;
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.common.util.CbExtServerProperties;
Expand Down Expand Up @@ -47,6 +49,9 @@ public class UserBulkUploadService {
@Autowired
StorageService storageService;

@Autowired
RedisCacheMgr redisCacheMgr;

public void initiateUserBulkUploadProcess(String inputData) {
logger.info("UserBulkUploadService:: initiateUserBulkUploadProcess: Started");
long duration = 0;
Expand Down Expand Up @@ -200,8 +205,8 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
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 (!ProjectUtil.validateRegexPatternWithNoSpecialCharacter(userRegistration.getPosition()) || this.validateFieldValue(Constants.POSITION, userRegistration.getPosition())) {
invalidErrList.add("Invalid Designation: Designation should be added from default list and/or cannot contain special character");
}
}
}
Expand Down Expand Up @@ -232,23 +237,19 @@ 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 dd-mm-yyyy format");
}
} 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 if (nextRow.getCell(7).getCellType() == CellType.NUMERIC || 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("Cell is numeric but not a date.");
invalidErrList.add("Invalid format for Date of Birth type. Expecting in dd-mm-yyyy format");
}
} else {
invalidErrList.add("Invalid value for Date of Birth column type. Expecting string format");
invalidErrList.add("Invalid value for Date of Birth column type. Expecting string type in dd-mm-yyyy format");
}
}
if (nextRow.getCell(8) != null && nextRow.getCell(8).getCellType() != CellType.BLANK) {
Expand All @@ -258,8 +259,8 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
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 (!ProjectUtil.validateRegexPatternWithNoSpecialCharacter(userRegistration.getDomicileMedium()) || this.validateFieldValue(Constants.LANGUAGES, userRegistration.getDomicileMedium())) {
invalidErrList.add("Invalid Mother Tongue: Mother Tongue should be added from default list and/or cannot contain special character");
}
}
}
Expand All @@ -275,6 +276,9 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
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(userRegistration.getEmployeeId().contains(Constants.SPACE)){
invalidErrList.add("Invalid Employee ID : Employee Id cannot contain spaces");
}
}
}
if (nextRow.getCell(10) != null && nextRow.getCell(10).getCellType() != CellType.BLANK) {
Expand Down Expand Up @@ -473,4 +477,23 @@ private List<String> validateReceivedKafkaMessage(HashMap<String, String> inputD
return errList;
}

private boolean validateFieldValue(String fieldKey, String fieldValue) {
if(redisCacheMgr.keyExists(fieldKey)){
return !redisCacheMgr.valueExists(fieldKey, fieldValue);
} else{
Set<String> designationsSet = new HashSet<>();
Map<String,Object> propertiesMap = new HashMap<>();
propertiesMap.put(Constants.CONTEXT_TYPE, fieldKey);
List<Map<String, Object>> fieldValueList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertiesMap, Collections.singletonList(Constants.CONTEXT_NAME));
if(!CollectionUtils.isEmpty(fieldValueList)) {
String columnName = fieldValueList.get(0).get("contextname") != null ? "contextname" : "contextName";
for(Map<String, Object> languageMap : fieldValueList){
designationsSet.add((String)languageMap.get(columnName));
}
}
redisCacheMgr.putCacheAsStringArray(fieldKey, designationsSet.toArray(new String[0]), null);
return !designationsSet.contains(fieldValue);
}
}

}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ org.search.response.default.limit=100
lms.system.settings.verified.profile.fields.path=v1/system/settings/get/verifiedProfileFields
user.bulk.upload.group.value=GROUP A,GROUP B,GROUP C,GROUP D,Contractual Staff,Others
content.search.primary.category.filter=Course,Program,Standalone Assessment,Blended Program
spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=5MB
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB

assessment.hierarchy.namespace=dev_hierarchy_store
assessment.hierarchy.table=questionset_hierarchy
Expand Down

0 comments on commit 0219fc7

Please sign in to comment.