Skip to content

Commit

Permalink
Merged PR #524 from 4.8.11
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Apr 3, 2024
2 parents d7b196f + 64c0dde commit 140d2ec
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/sunbird/common/util/ProjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)*(?<!\\.|\\s)$");
public static Boolean validateFullName(String firstName) {
return firstName.matches("^(?!.*\\n)[a-zA-Z]+(?:['\\s][a-zA-Z]+)*(?<!\\.|\\s)$");
}

public static Boolean validateTag(List<String> tags) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/sunbird/profile/service/ProfileServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,10 @@ public SBApiResponse userSignup(Map<String, Object> 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",
Expand Down Expand Up @@ -1946,6 +1950,26 @@ public List<String> adminApprovalFields() {
return new ArrayList<>();
}

private boolean isFileExistForProcessingForMDO(String mdoId) {
Map<String, Object> bulkUplaodPrimaryKey = new HashMap<String, Object>();
bulkUplaodPrimaryKey.put(Constants.ROOT_ORG_ID, mdoId);
List<String> fields = Arrays.asList(Constants.ROOT_ORG_ID, Constants.IDENTIFIER, Constants.STATUS);

List<Map<String, Object>> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -255,22 +251,16 @@ private void processBulkUpload(HashMap<String, String> 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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> groupValues = serverConfig.getBulkUploadGroupValue();
return groupValues != null && groupValues.contains(group);
}

@Override
Expand Down

0 comments on commit 140d2ec

Please sign in to comment.