From ff346c9b84f1f3a61c6f3d1f54ecfa20fe397ca9 Mon Sep 17 00:00:00 2001 From: anilkumarkammalapalli <121931293+anilkumarkammalapalli@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:24:00 +0530 Subject: [PATCH] 4.8.15 dev v4 (#635) * updated code for user bulk upload * added code for process both csv and xlsx * added code for process both csv and xlsx * added code for process both csv and xlsx --- .../org/sunbird/common/util/Constants.java | 2 ++ .../service/UserBulkUploadService.java | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index a65541647..9f3b9eab6 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -1097,6 +1097,8 @@ public class Constants { public static final String SEARCH_COMPETENCY_SUB_THEMES = "competencySubTheme"; public static final String MCQ_MCA_W = "mcq-mca-w"; public static final String MCQ_SCA_TF = "mcq-sca-tf"; + public static final String CSV_FILE = ".csv"; + public static final String XLSX_FILE = ".xlsx"; private Constants() { throw new IllegalStateException("Utility class"); diff --git a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java index 710f75f5a..89d8a4c8e 100644 --- a/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java +++ b/src/main/java/org/sunbird/profile/service/UserBulkUploadService.java @@ -69,9 +69,19 @@ public void initiateUserBulkUploadProcess(String inputData) { if (errList.isEmpty()) { updateUserBulkUploadStatus(inputDataMap.get(Constants.ROOT_ORG_ID), inputDataMap.get(Constants.IDENTIFIER), Constants.STATUS_IN_PROGRESS_UPPERCASE, 0, 0, 0); - storageService.downloadFile(inputDataMap.get(Constants.FILE_NAME)); - //processBulkUpload(inputDataMap); - processCSVBulkUploadV2(inputDataMap); + String fileName = inputDataMap.get(Constants.FILE_NAME); + logger.info("fileName {} ", fileName); + storageService.downloadFile(fileName); + switch (getFileExtension(fileName)) { + case Constants.CSV_FILE: + processCSVBulkUploadV2(inputDataMap); + break; + case Constants.XLSX_FILE: + processBulkUpload(inputDataMap); + break; + default: + logger.error("Unsupported file type: {}", fileName); + } } else { logger.error(String.format("Error in the Kafka Message Received : %s", errList)); } @@ -788,5 +798,9 @@ private boolean validateFieldValue(String fieldKey, String fieldValue) { return !designationsSet.contains(fieldValue); } } + private String getFileExtension(String fileName) { + int lastIndexOfDot= fileName.lastIndexOf('.'); + return lastIndexOfDot == -1 ? "" : fileName.substring(lastIndexOfDot); + } } \ No newline at end of file