From 519871fb154f851606025a59a0b6d48438312cab Mon Sep 17 00:00:00 2001 From: shankaragoudab <140387294+shankaragoudab@users.noreply.github.com> Date: Mon, 6 May 2024 11:44:26 +0530 Subject: [PATCH] hall of fame api changes (#546) hall of fame api changes --- .../service/HallOfFameServiceImpl.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java b/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java index c10a043a8..93abd7f17 100644 --- a/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java +++ b/src/main/java/org/sunbird/halloffame/service/HallOfFameServiceImpl.java @@ -36,20 +36,24 @@ public Map fetchHallOfFameData() { int lastMonthValue = lastMonthDate.getMonthValue(); int lastMonthYearValue = lastMonthDate.getYear(); - String formattedDateLastMonth = currentDate.minusMonths(1).format(DateTimeFormatter.ofPattern("MMMM yyyy")); + String formattedDateLastMonth = lastMonthDate.format(DateTimeFormatter.ofPattern("MMMM yyyy")); Map propertyMap = new HashMap<>(); propertyMap.put(Constants.MONTH, lastMonthValue); propertyMap.put(Constants.YEAR, lastMonthYearValue); - List> dptList = cassandraOperation.getRecordsByPropertiesWithoutFiltering( - Constants.KEYSPACE_SUNBIRD, Constants.MDO_KARMA_POINTS, propertyMap, null); - if (dptList.isEmpty()) { - formattedDateLastMonth = currentDate.minusMonths(2).format(DateTimeFormatter.ofPattern("MMMM yyyy")); - propertyMap.clear(); - propertyMap.put(Constants.MONTH, currentDate.minusMonths(2).getMonthValue()); - propertyMap.put(Constants.YEAR, currentDate.minusMonths(2).getYear()); + List> dptList = new ArrayList<>(); + while (dptList.isEmpty()) { dptList = cassandraOperation.getRecordsByPropertiesWithoutFiltering( Constants.KEYSPACE_SUNBIRD, Constants.MDO_KARMA_POINTS, propertyMap, null); + if (dptList.isEmpty()) { + lastMonthDate = lastMonthDate.minusMonths(1); + lastMonthValue = lastMonthDate.getMonthValue(); + lastMonthYearValue = lastMonthDate.getYear(); + formattedDateLastMonth = lastMonthDate.format(DateTimeFormatter.ofPattern("MMMM yyyy")); + propertyMap.clear(); + propertyMap.put(Constants.MONTH, lastMonthValue); + propertyMap.put(Constants.YEAR, lastMonthYearValue); + } } resultMap.put(Constants.MDO_LIST, dptList); resultMap.put(Constants.TITLE, formattedDateLastMonth);