From 25e740d2a107064de3aafc132331c7fdbb126354 Mon Sep 17 00:00:00 2001 From: tarentomaheshvakkund <139739142+tarentomaheshvakkund@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:42:19 +0530 Subject: [PATCH] 4.8.16 merge conflicts (#648) * KB-3998 | DEV | Assessment | BE | Analysis and code changes for the randomization of the options/choices. (#645) 1. Created a custom method to shuffle the options. * Commiting for top 10 learners api (#644) * Commiting for top 10 learners api * Commiting for top 10 learners api --------- Co-authored-by: pathiktarento1089 <123535830+pathiktarento1089@users.noreply.github.com> --- .../service/AssessmentUtilServiceV2Impl.java | 16 +++++- .../org/sunbird/common/util/Constants.java | 2 + .../controller/HallOfFameController.java | 8 +++ .../halloffame/service/HallOfFameService.java | 7 ++- .../service/HallOfFameServiceImpl.java | 50 ++++++++++++++++++- 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sunbird/assessment/service/AssessmentUtilServiceV2Impl.java b/src/main/java/org/sunbird/assessment/service/AssessmentUtilServiceV2Impl.java index 7faaa501d..600f55675 100644 --- a/src/main/java/org/sunbird/assessment/service/AssessmentUtilServiceV2Impl.java +++ b/src/main/java/org/sunbird/assessment/service/AssessmentUtilServiceV2Impl.java @@ -259,7 +259,7 @@ public Map filterQuestionMapDetail(Map questionM if (choicesObj.containsKey(Constants.OPTIONS)) { List> optionsMapList = (List>) choicesObj .get(Constants.OPTIONS); - updatedChoicesMap.put(Constants.OPTIONS, optionsMapList); + updatedChoicesMap.put(Constants.OPTIONS, shuffleOptions(optionsMapList)); } updatedQuestionMap.put(Constants.CHOICES, updatedChoicesMap); } @@ -782,4 +782,18 @@ private static void calculatePassPercentage(Double sectionMarks, Integer totalMa resultMap.put(Constants.TOTAL, total); } } + + /** + * Shuffles the list of option maps. + * + * @param optionsMapList The list of option maps to be shuffled. + * @return A new list containing the shuffled option maps. + */ + public static List> shuffleOptions(List> optionsMapList) { + // Create a copy of the original list to avoid modifying the input list + List> shuffledList = new ArrayList<>(optionsMapList); + // Shuffle the list using Collections.shuffle() + Collections.shuffle(shuffledList); + return shuffledList; + } } \ No newline at end of file diff --git a/src/main/java/org/sunbird/common/util/Constants.java b/src/main/java/org/sunbird/common/util/Constants.java index fe608c406..881de6690 100644 --- a/src/main/java/org/sunbird/common/util/Constants.java +++ b/src/main/java/org/sunbird/common/util/Constants.java @@ -1099,6 +1099,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 TOP_10_LEARNERS ="top10Learners"; + public static final String TABLE_TOP_10_LEARNER ="mdo_top_learners"; public static final String CSV_FILE = ".csv"; public static final String XLSX_FILE = ".xlsx"; diff --git a/src/main/java/org/sunbird/halloffame/controller/HallOfFameController.java b/src/main/java/org/sunbird/halloffame/controller/HallOfFameController.java index efab8b737..40c74000b 100644 --- a/src/main/java/org/sunbird/halloffame/controller/HallOfFameController.java +++ b/src/main/java/org/sunbird/halloffame/controller/HallOfFameController.java @@ -34,4 +34,12 @@ public ResponseEntity> fetchHallOfFameData() { SBApiResponse response = hallOfFameService.learnerLeaderBoard(rootOrgId, authToken); return new ResponseEntity<>(response, response.getResponseCode()); } + + @GetMapping("/v1/top/learners") + public ResponseEntity fetchingTopLearners + (@RequestHeader(Constants.X_AUTH_TOKEN) String authToken, + @RequestHeader(Constants.X_AUTH_USER_ORG_ID) String rootOrgId) throws Exception { + SBApiResponse response = hallOfFameService.fetchingTop10Learners(rootOrgId, authToken); + return new ResponseEntity<>(response, response.getResponseCode()); + } } diff --git a/src/main/java/org/sunbird/halloffame/service/HallOfFameService.java b/src/main/java/org/sunbird/halloffame/service/HallOfFameService.java index e57ae718a..cb372fd70 100644 --- a/src/main/java/org/sunbird/halloffame/service/HallOfFameService.java +++ b/src/main/java/org/sunbird/halloffame/service/HallOfFameService.java @@ -8,6 +8,9 @@ * @author mahesh.vakkund */ public interface HallOfFameService { - public Map fetchHallOfFameData() ; - public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken) ; + public Map fetchHallOfFameData(); + + public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken); + + public SBApiResponse fetchingTop10Learners(String rootOrgId, String authToken); } diff --git a/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java b/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java index 93abd7f17..5b467b90b 100644 --- a/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java +++ b/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import org.sunbird.cassandra.utils.CassandraOperation; import org.sunbird.common.model.SBApiResponse; import org.sunbird.common.util.AccessTokenValidator; @@ -15,7 +16,6 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.stream.Collectors; /** * @author mahesh.vakkund @@ -28,6 +28,7 @@ public class HallOfFameServiceImpl implements HallOfFameService { private Logger logger = LoggerFactory.getLogger(getClass().getName()); @Autowired AccessTokenValidator accessTokenValidator; + @Override public Map fetchHallOfFameData() { Map resultMap = new HashMap<>(); @@ -112,6 +113,53 @@ public SBApiResponse learnerLeaderBoard(String rootOrgId, String authToken) { return response; } + @Override + public SBApiResponse fetchingTop10Learners(String rootOrgId, String authToken) { + SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.TOP_10_LEARNERS); + try { + if (StringUtils.isEmpty(rootOrgId)) { + setBadRequestResponse(response, Constants.ORG_ID_MISSING); + return response; + } + String userId = validateAuthTokenAndFetchUserId(authToken); + if (StringUtils.isBlank(userId)) { + setBadRequestResponse(response, Constants.USER_ID_DOESNT_EXIST); + return response; + } + Map propertiesMap = new HashMap<>(); + propertiesMap.put(Constants.USER_ID_LOWER, userId); + + List> userRowNum = cassandraOperation.getRecordsByPropertiesWithoutFiltering( + Constants.SUNBIRD_KEY_SPACE_NAME, + Constants.TABLE_LEARNER_LEADER_BOARD_LOOK_UP, + propertiesMap, + null + ); + if (CollectionUtils.isEmpty(userRowNum)) { + setNotFoundResponse(response, Constants.USER_ID_DOESNT_EXIST); + return response; + } + Map propMap = new HashMap<>(); + int res = (Integer) userRowNum.get(0).get(Constants.DB_COLUMN_ROW_NUM); + List ranksFilter = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + propMap.put(Constants.DB_COLUMN_ROW_NUM, ranksFilter); + propMap.put(Constants.ORGID, rootOrgId); + + List> result = cassandraOperation.getRecordsByPropertiesWithoutFiltering( + Constants.SUNBIRD_KEY_SPACE_NAME, + Constants.TABLE_TOP_10_LEARNER, + propMap, + null + ); + response.put(Constants.RESULT, result); + return response; + + } catch (Exception e) { + setInternalServerErrorResponse(response); + } + return response; + } + private void setBadRequestResponse(SBApiResponse response, String errMsg) { response.getParams().setStatus(Constants.FAILED); response.getParams().setErrmsg(errMsg);