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 1/3] 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 From d04b0238170fd65a9f3f8c7028b2cafbd52e9073 Mon Sep 17 00:00:00 2001 From: SaipradeepR <53404427+SaipradeepR@users.noreply.github.com> Date: Sat, 6 Jul 2024 10:34:08 +0530 Subject: [PATCH 2/3] Changing access of non-primary key to a primary key in Cassandra Query Changing access of non-primary key to a primary key in Cassandra Query --- .../org/sunbird/ehrms/service/EhrmsProfileDetailImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sunbird/ehrms/service/EhrmsProfileDetailImpl.java b/src/main/java/org/sunbird/ehrms/service/EhrmsProfileDetailImpl.java index 6e899dc43..6260d8ffa 100644 --- a/src/main/java/org/sunbird/ehrms/service/EhrmsProfileDetailImpl.java +++ b/src/main/java/org/sunbird/ehrms/service/EhrmsProfileDetailImpl.java @@ -49,7 +49,7 @@ public SBApiResponse fetchEhrmsProfileDetail(String userId, String authToken) { SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.EHRMS); try { Map propertyMap = new HashMap<>(); - propertyMap.put(Constants.USER_ID_LOWER, userId); + propertyMap.put(Constants.ID, userId); Map result = cassandraOperation.getRecordsByProperties( Constants.KEYSPACE_SUNBIRD, Constants.USER, @@ -137,4 +137,4 @@ private Map prepareErrorResponse(String responseBodyString) { } return errResponseBody; } -} \ No newline at end of file +} From 03bc99f9da8a07b55d010d277b5d124ddd83ebf3 Mon Sep 17 00:00:00 2001 From: Sreerag K S <58926794+sreeragksgh@users.noreply.github.com> Date: Fri, 12 Jul 2024 10:50:31 +0530 Subject: [PATCH 3/3] New API to Fetch WhiteListed Domains for email - KB-5850 (#641) * New API for fetching whitelisted domains * Updated changes * Review changes * Response structure changes * review changes --- .../org/sunbird/common/util/Constants.java | 2 + .../UserRegistrationController.java | 6 +++ .../service/UserRegistrationService.java | 2 + .../service/UserRegistrationServiceImpl.java | 54 +++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index 430842e85..eb7d1aa1f 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -1064,6 +1064,8 @@ public class Constants { 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 API_APPROVED_DOMAINS = "api.approved.domains"; + public static final String DOMAINS = "domains"; private Constants() { throw new IllegalStateException("Utility class"); diff --git a/src/main/java/org/sunbird/user/registration/controller/UserRegistrationController.java b/src/main/java/org/sunbird/user/registration/controller/UserRegistrationController.java index 5a9d6bfae..5c1d6d2c5 100644 --- a/src/main/java/org/sunbird/user/registration/controller/UserRegistrationController.java +++ b/src/main/java/org/sunbird/user/registration/controller/UserRegistrationController.java @@ -44,4 +44,10 @@ public ResponseEntity generateOTP(@RequestBody Map(response, response.getResponseCode()); } + + @GetMapping("/user/email/approved/domains") + public ResponseEntity getApprovedDomain() throws Exception { + SBApiResponse response = userRegService.getApprovedDomains(); + return new ResponseEntity<>(response, response.getResponseCode()); + } } diff --git a/src/main/java/org/sunbird/user/registration/service/UserRegistrationService.java b/src/main/java/org/sunbird/user/registration/service/UserRegistrationService.java index ea46c1868..27ae9b78c 100644 --- a/src/main/java/org/sunbird/user/registration/service/UserRegistrationService.java +++ b/src/main/java/org/sunbird/user/registration/service/UserRegistrationService.java @@ -48,4 +48,6 @@ public interface UserRegistrationService { public SBApiResponse generateOTP(Map otpRequests); + public SBApiResponse getApprovedDomains(); + } diff --git a/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java b/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java index c6a69643d..d091f88d9 100644 --- a/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java +++ b/src/main/java/org/sunbird/user/registration/service/UserRegistrationServiceImpl.java @@ -5,6 +5,7 @@ import java.io.InputStreamReader; import java.util.*; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.RandomStringUtils; @@ -305,6 +306,34 @@ public void initiateCreateUserFlow(String registrationCode) { } } + public SBApiResponse getApprovedDomains() { + SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_APPROVED_DOMAINS); + String errMsg = ""; + try { + Set approvedDomains = getApprovedDomainsFromDB(); + if (CollectionUtils.isNotEmpty(approvedDomains)) { + Map result = new HashMap<>(); + result.put(Constants.DOMAINS, approvedDomains); + LOGGER.info("Fetched pre-approved and approved domains successfully"); + response.setResult(result); + response.getResult().put(Constants.RESPONSE, Constants.SUCCESS.toUpperCase()); + } else { + errMsg = "Failed to Fetch Approved Domains"; + } + } catch (Exception e) { + LOGGER.error(String.format("Exception in %s : %s", "getApprovedDomains", e.getMessage()), e); + errMsg = "Failed to process message. Exception: " + e.getMessage(); + } + + if (StringUtils.isNotBlank(errMsg)) { + LOGGER.error("Failed to Fetch Approved Domains, error message : ", errMsg); + response.getParams().setStatus(Constants.FAILED); + response.getParams().setErrmsg(errMsg); + response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR); + } + return response; + } + private SBApiResponse createDefaultResponse(String api) { SBApiResponse response = new SBApiResponse(); response.setId(api); @@ -588,4 +617,29 @@ private Boolean isApprovedDomains(String emailDomain, String domainType) { Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap, Arrays.asList(Constants.CONTEXT_TYPE, Constants.CONTEXT_NAME)); return CollectionUtils.isNotEmpty(listOfDomains); } + + private Set getApprovedDomainsFromDB() { + Set domains = new HashSet<>(); + + Set preApprovedDomains = fetchDomainsByContextType(Constants.USER_REGISTRATION_PRE_APPROVED_DOMAIN); + domains.addAll(preApprovedDomains); + + Set approvedDomains = fetchDomainsByContextType(Constants.USER_REGISTRATION_DOMAIN); + domains.addAll(approvedDomains); + + return domains; + } + + private Set fetchDomainsByContextType(String contextType) { + Map propertyMap = new HashMap<>(); + propertyMap.put(Constants.CONTEXT_TYPE, contextType); + + List> records = cassandraOperation.getRecordsByPropertiesWithoutFiltering( + Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, propertyMap, Arrays.asList(Constants.CONTEXT_NAME)); + + return records.stream() + .map(map -> (String) map.get(Constants.CONTEXT_NAME)) + .collect(Collectors.toSet()); + } + }