diff --git a/src/main/java/org/sunbird/common/util/ProjectUtil.java b/src/main/java/org/sunbird/common/util/ProjectUtil.java index b006910bf..67aba05a1 100644 --- a/src/main/java/org/sunbird/common/util/ProjectUtil.java +++ b/src/main/java/org/sunbird/common/util/ProjectUtil.java @@ -134,8 +134,8 @@ public static Boolean validateContactPattern(String contactNumber) { return Boolean.FALSE; } - public static Boolean validateFullName(String firstName ) { - return firstName.matches("^[a-zA-Z]+(?:['\\s][a-zA-Z]+)*(? tags) { diff --git a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java index e43186de1..469e350d3 100644 --- a/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java +++ b/src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java @@ -754,6 +754,10 @@ public SBApiResponse userSignup(Map request) { public SBApiResponse bulkUpload(MultipartFile mFile, String orgId, String channel, String userId, String userAuthToken) { SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_USER_BULK_UPLOAD); try { + if (isFileExistForProcessingForMDO(orgId)) { + setErrorDataForMdo(response, "Failed to upload for another request as previous request is in processing state, please try after some time."); + return response; + } SBApiResponse uploadResponse = storageService.uploadFile(mFile, serverConfig.getBulkUploadContainerName()); if (!HttpStatus.OK.equals(uploadResponse.getResponseCode())) { setErrorData(response, String.format("Failed to upload file. Error: %s", @@ -1946,6 +1950,26 @@ public List adminApprovalFields() { return new ArrayList<>(); } + private boolean isFileExistForProcessingForMDO(String mdoId) { + Map bulkUplaodPrimaryKey = new HashMap(); + bulkUplaodPrimaryKey.put(Constants.ROOT_ORG_ID, mdoId); + List fields = Arrays.asList(Constants.ROOT_ORG_ID, Constants.IDENTIFIER, Constants.STATUS); + + List> bulkUploadMdoList = cassandraOperation.getRecordsByPropertiesWithoutFiltering( + Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER_BULK_UPLOAD, bulkUplaodPrimaryKey, fields); + if (CollectionUtils.isEmpty(bulkUploadMdoList)) { + return false; + } + return bulkUploadMdoList.stream() + .anyMatch(entry -> Constants.STATUS_IN_PROGRESS_UPPERCASE.equalsIgnoreCase((String) entry.get(Constants.STATUS))); + } + + private void setErrorDataForMdo(SBApiResponse response, String errMsg) { + response.getParams().setStatus(Constants.FAILED); + response.getParams().setErrmsg(errMsg); + response.setResponseCode(HttpStatus.TOO_MANY_REQUESTS); + } + /** * Updates the user profile with version 2. diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index a2ade0641..5ab3d9cc4 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.sunbird.cache.RedisCacheMgr; import org.sunbird.cassandra.utils.CassandraOperation; import org.sunbird.common.model.SBApiResponse; import org.sunbird.common.util.CbExtServerProperties; @@ -46,9 +45,6 @@ public class UserBulkUploadService { @Autowired StorageService storageService; - @Autowired - RedisCacheMgr redisCacheMgr; - public void initiateUserBulkUploadProcess(String inputData) { logger.info("UserBulkUploadService:: initiateUserBulkUploadProcess: Started"); long duration = 0; @@ -255,22 +251,16 @@ private void processBulkUpload(HashMap inputDataMap) throws IOEx } else { invalidErrList.addAll(validateEmailContactAndDomain(userRegistration)); if (invalidErrList.isEmpty()) { - if (redisCacheMgr.isKeyExist(userRegistration.getPhone()+ "" +userRegistration.getEmail())) { - logger.error("Key is already present in Redis Key: " + userRegistration.getPhone()+ "" +userRegistration.getEmail()); + userRegistration.setUserAuthToken(inputDataMap.get(Constants.X_AUTH_TOKEN)); + String responseCode = userUtilityService.createBulkUploadUser(userRegistration); + if (!Constants.OK.equalsIgnoreCase(responseCode)) { + failedRecordsCount++; + statusCell.setCellValue(Constants.FAILED_UPPERCASE); + errorDetails.setCellValue(responseCode); } else { - redisCacheMgr.putCache(userRegistration.getPhone().trim()+ "" +userRegistration.getEmail(), - ""); - userRegistration.setUserAuthToken(inputDataMap.get(Constants.X_AUTH_TOKEN)); - String responseCode = userUtilityService.createBulkUploadUser(userRegistration); - if (!Constants.OK.equalsIgnoreCase(responseCode)) { - failedRecordsCount++; - statusCell.setCellValue(Constants.FAILED_UPPERCASE); - errorDetails.setCellValue(responseCode); - } else { - noOfSuccessfulRecords++; - statusCell.setCellValue(Constants.SUCCESS_UPPERCASE); - errorDetails.setCellValue(""); - } + noOfSuccessfulRecords++; + statusCell.setCellValue(Constants.SUCCESS_UPPERCASE); + errorDetails.setCellValue(""); } } else { failedRecordsCount++; diff --git a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java index ff6e918fb..68a834e36 100644 --- a/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java +++ b/src/main/java/org/sunbird/user/service/UserUtilityServiceImpl.java @@ -574,7 +574,8 @@ public boolean isUserExist(String key, String value) { @Override public boolean validateGroup(String group) { - return (!CollectionUtils.isEmpty(serverConfig.getBulkUploadGroupValue())) ? serverConfig.getBulkUploadGroupValue().stream().anyMatch(group::equalsIgnoreCase) : false; + List groupValues = serverConfig.getBulkUploadGroupValue(); + return groupValues != null && groupValues.contains(group); } @Override