Skip to content

Commit

Permalink
updated code for user bulk upload (#631) (#634)
Browse files Browse the repository at this point in the history
Co-authored-by: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com>
  • Loading branch information
karthik-tarento and anilkumarkammalapalli authored Jul 4, 2024
1 parent a8456ed commit 1519379
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ public void processCSVBulkUploadV2(HashMap<String, String> inputDataMap) throws
}

for (CSVRecord record : csvRecords) {
totalRecordsCount++;
Map<String, String> updatedRecord = new LinkedHashMap<>(record.toMap());
List<String> errList = new ArrayList<>();
List<String> invalidErrList = new ArrayList<>();
Expand Down Expand Up @@ -603,6 +602,16 @@ public void processCSVBulkUploadV2(HashMap<String, String> inputDataMap) throws
userRegistration.setChannel(inputDataMap.get(Constants.ORG_NAME));
userRegistration.setSbOrgId(inputDataMap.get(Constants.ROOT_ORG_ID));

if (totalRecordsCount == 0 && errList.size() == 4) {
updatedRecord.put("Status", "FAILED");
updatedRecord.put("Error Details", String.join(", ", errList));
failedRecordsCount++;
break;
} else if (totalRecordsCount > 0 && errList.size() == 4) {
break;
}
totalRecordsCount++;

if (!errList.isEmpty()) {
failedRecordsCount++;
updatedRecord.put("Status", "FAILED");
Expand Down Expand Up @@ -630,7 +639,7 @@ public void processCSVBulkUploadV2(HashMap<String, String> inputDataMap) throws

updatedRecords.add(updatedRecord);
}

logger.info("total noOfSuccessfulRecords {}, total nofailedRecordsCount {}, and total totalRecordsCount {}", noOfSuccessfulRecords,failedRecordsCount,totalRecordsCount);
// Write back updated records to the same CSV file
fileWriter = new FileWriter(file);
bufferedWriter = new BufferedWriter(fileWriter);
Expand All @@ -656,20 +665,17 @@ public void processCSVBulkUploadV2(HashMap<String, String> inputDataMap) throws

status = uploadTheUpdatedCSVFile(file);


status = (failedRecordsCount == 0 && totalRecordsCount == noOfSuccessfulRecords && totalRecordsCount >= 1)
? Constants.SUCCESSFUL_UPPERCASE
: Constants.FAILED_UPPERCASE;

updateUserBulkUploadStatus(inputDataMap.get(Constants.ROOT_ORG_ID), inputDataMap.get(Constants.IDENTIFIER),
status, totalRecordsCount, noOfSuccessfulRecords, failedRecordsCount);
if (!(Constants.SUCCESSFUL.equalsIgnoreCase(status) && failedRecordsCount == 0
&& totalRecordsCount == noOfSuccessfulRecords && totalRecordsCount >= 1)) {
status = Constants.FAILED_UPPERCASE;
}

} else {
logger.info("Error in Process Bulk Upload: The File is not downloaded/present");
status = Constants.FAILED_UPPERCASE;
}
updateUserBulkUploadStatus(inputDataMap.get(Constants.ROOT_ORG_ID), inputDataMap.get(Constants.IDENTIFIER),
status, 0, 0, 0);
updateUserBulkUploadStatus(inputDataMap.get(Constants.ROOT_ORG_ID), inputDataMap.get(Constants.IDENTIFIER),
status, totalRecordsCount, noOfSuccessfulRecords, failedRecordsCount);
} catch (Exception e) {
logger.error(String.format("Error in Process Bulk Upload %s", e.getMessage()), e);
updateUserBulkUploadStatus(inputDataMap.get(Constants.ROOT_ORG_ID), inputDataMap.get(Constants.IDENTIFIER),
Expand Down

0 comments on commit 1519379

Please sign in to comment.