From 1b22cc7e344f45ecb14af616c3457c9cc599567d Mon Sep 17 00:00:00 2001 From: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:54:11 +0530 Subject: [PATCH] 4.8.10 report fix (#413) * Added the changes for query and the API changes for report change * Added the live check for courses when populating data --- .../utils/CassandraOperationImpl.java | 6 ++- .../cbp/service/CbPlanServiceImpl.java | 40 +++++++++++-------- .../service/MasterDataServiceImpl.java | 9 ++--- .../storage/controller/StorageController.java | 7 ++-- .../storage/service/StorageService.java | 2 +- .../storage/service/StorageServiceImpl.java | 22 +--------- 6 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/sunbird/cassandra/utils/CassandraOperationImpl.java b/src/main/java/org/sunbird/cassandra/utils/CassandraOperationImpl.java index 6e4b632c1..abed658c9 100644 --- a/src/main/java/org/sunbird/cassandra/utils/CassandraOperationImpl.java +++ b/src/main/java/org/sunbird/cassandra/utils/CassandraOperationImpl.java @@ -321,7 +321,11 @@ public List> getRecordsWithInClause(String keyspaceName, Str for (Map propertyMap : propertyMaps) { for (Map.Entry entry : propertyMap.entrySet()) { key = entry.getKey(); - values.add(entry.getValue()); + if (entry.getValue() instanceof List) { + values.addAll((List) entry.getValue()); + } else { + values.add(entry.getValue()); + } } selectQuery.and(QueryBuilder.in(key, values.toArray())); } diff --git a/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java b/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java index 4865e8217..c15ccb349 100644 --- a/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java +++ b/src/main/java/org/sunbird/cbp/service/CbPlanServiceImpl.java @@ -636,21 +636,25 @@ private Map populateReadData(Map cbPlan) throws List> enrichContentInfoMap = new ArrayList<>(); for (String contentId : contentTypeInfo) { Map contentResponse = contentService.readContentFromCache(contentId, null); - Map enrichContentMap = new HashMap<>(); - enrichContentMap.put(Constants.NAME, contentResponse.get(Constants.NAME)); - enrichContentMap.put(Constants.COMPETENCIES_V5, contentResponse.get(Constants.COMPETENCIES_V5)); - enrichContentMap.put(Constants.AVG_RATING, contentResponse.get(Constants.AVG_RATING)); - enrichContentMap.put(Constants.IDENTIFIER, contentResponse.get(Constants.IDENTIFIER)); - enrichContentMap.put(Constants.DESCRIPTION, contentResponse.get(Constants.DESCRIPTION)); - enrichContentMap.put(Constants.ADDITIONAL_TAGS, contentResponse.get(Constants.ADDITIONAL_TAGS)); - enrichContentMap.put(Constants.CONTENT_TYPE_KEY, contentResponse.get(Constants.CONTENT_TYPE_KEY)); - enrichContentMap.put(Constants.PRIMARY_CATEGORY, contentResponse.get(Constants.PRIMARY_CATEGORY)); - enrichContentMap.put(Constants.DURATION, contentResponse.get(Constants.DURATION)); - enrichContentMap.put(Constants.COURSE_APP_ICON, contentResponse.get(Constants.COURSE_APP_ICON)); - enrichContentMap.put(Constants.POSTER_IMAGE, contentResponse.get(Constants.POSTER_IMAGE)); - enrichContentMap.put(Constants.ORGANISATION, contentResponse.get(Constants.ORGANISATION)); - enrichContentMap.put(Constants.CREATOR_LOGO, contentResponse.get(Constants.CREATOR_LOGO)); - enrichContentInfoMap.add(enrichContentMap); + if (MapUtils.isNotEmpty(contentResponse)) { + if (Constants.LIVE.equalsIgnoreCase((String) contentResponse.get(Constants.STATUS))) { + Map enrichContentMap = new HashMap<>(); + enrichContentMap.put(Constants.NAME, contentResponse.get(Constants.NAME)); + enrichContentMap.put(Constants.COMPETENCIES_V5, contentResponse.get(Constants.COMPETENCIES_V5)); + enrichContentMap.put(Constants.AVG_RATING, contentResponse.get(Constants.AVG_RATING)); + enrichContentMap.put(Constants.IDENTIFIER, contentResponse.get(Constants.IDENTIFIER)); + enrichContentMap.put(Constants.DESCRIPTION, contentResponse.get(Constants.DESCRIPTION)); + enrichContentMap.put(Constants.ADDITIONAL_TAGS, contentResponse.get(Constants.ADDITIONAL_TAGS)); + enrichContentMap.put(Constants.CONTENT_TYPE_KEY, contentResponse.get(Constants.CONTENT_TYPE_KEY)); + enrichContentMap.put(Constants.PRIMARY_CATEGORY, contentResponse.get(Constants.PRIMARY_CATEGORY)); + enrichContentMap.put(Constants.DURATION, contentResponse.get(Constants.DURATION)); + enrichContentMap.put(Constants.COURSE_APP_ICON, contentResponse.get(Constants.COURSE_APP_ICON)); + enrichContentMap.put(Constants.POSTER_IMAGE, contentResponse.get(Constants.POSTER_IMAGE)); + enrichContentMap.put(Constants.ORGANISATION, contentResponse.get(Constants.ORGANISATION)); + enrichContentMap.put(Constants.CREATOR_LOGO, contentResponse.get(Constants.CREATOR_LOGO)); + enrichContentInfoMap.add(enrichContentMap); + } + } } if (CollectionUtils.isNotEmpty(enrichContentInfoMap)) { enrichData.put(Constants.CONTENT_LIST, enrichContentInfoMap); @@ -893,7 +897,11 @@ public SBApiResponse listCbPlan(SunbirdApiRequest request, String userOrgId, Str if (!courseInfoMap.containsKey(contentId)) { Map courseInfo = contentService.readContentFromCache(contentId, Collections.emptyList()); - courseInfoMap.put(contentId, courseInfo); + if (MapUtils.isNotEmpty(courseInfo)) { + if (Constants.LIVE.equalsIgnoreCase((String) courseInfo.get(Constants.STATUS))) { + courseInfoMap.put(contentId, courseInfo); + } + } } courseMapList.add(courseInfoMap.get(contentId)); } diff --git a/src/main/java/org/sunbird/searchby/service/MasterDataServiceImpl.java b/src/main/java/org/sunbird/searchby/service/MasterDataServiceImpl.java index f53193130..e2b1dd0e3 100644 --- a/src/main/java/org/sunbird/searchby/service/MasterDataServiceImpl.java +++ b/src/main/java/org/sunbird/searchby/service/MasterDataServiceImpl.java @@ -193,11 +193,10 @@ public Map getProfilePageMetaData() { try { String[] contextTypes = cbExtServerProperties.getContextTypes(); List> listProperty = new ArrayList<>(); - for (String contextType : contextTypes) { - Map properties = new HashMap<>(); - properties.put(Constants.CONTEXT_TYPE.toLowerCase(), contextType); - listProperty.add(properties); - } + Map properties = new HashMap<>(); + properties.put(Constants.CONTEXT_TYPE.toLowerCase(), Arrays.asList(contextTypes)); + listProperty.add(properties); + List> listOfMasterData = cassandraOperation.getRecordsWithInClause(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_MASTER_DATA, listProperty, new ArrayList<>()); if (CollectionUtils.isEmpty(listOfMasterData)) { diff --git a/src/main/java/org/sunbird/storage/controller/StorageController.java b/src/main/java/org/sunbird/storage/controller/StorageController.java index 9bebf1536..1801ecb22 100644 --- a/src/main/java/org/sunbird/storage/controller/StorageController.java +++ b/src/main/java/org/sunbird/storage/controller/StorageController.java @@ -66,8 +66,9 @@ public ResponseEntity downloadFileSPV(@PathVariable("reportType") String repo return storageService.downloadFile(reportType, date, fileName, userToken); } - @GetMapping("/v1/spvReportInfo") - public ResponseEntity getFileInfoSPV(@RequestHeader(Constants.X_AUTH_TOKEN) String userToken) { - return storageService.getFileInfoSpv(userToken); + @GetMapping("/v1/spvReportInfo/{date}") + public ResponseEntity getFileInfoSPV(@RequestHeader(Constants.X_AUTH_TOKEN) String userToken, + @PathVariable("date") String date) { + return storageService.getFileInfoSpv(userToken, date); } } diff --git a/src/main/java/org/sunbird/storage/service/StorageService.java b/src/main/java/org/sunbird/storage/service/StorageService.java index 17804db99..6462cecca 100644 --- a/src/main/java/org/sunbird/storage/service/StorageService.java +++ b/src/main/java/org/sunbird/storage/service/StorageService.java @@ -25,5 +25,5 @@ public interface StorageService { ResponseEntity downloadFile(String reportType, String date, String fileName, String userToken); - ResponseEntity getFileInfoSpv(String userToken); + ResponseEntity getFileInfoSpv(String userToken, String date); } diff --git a/src/main/java/org/sunbird/storage/service/StorageServiceImpl.java b/src/main/java/org/sunbird/storage/service/StorageServiceImpl.java index 752f400b3..8c62e2a26 100644 --- a/src/main/java/org/sunbird/storage/service/StorageServiceImpl.java +++ b/src/main/java/org/sunbird/storage/service/StorageServiceImpl.java @@ -316,7 +316,7 @@ public ResponseEntity downloadFile(String reportType, String date, String fil } @Override - public ResponseEntity getFileInfoSpv(String userToken) { + public ResponseEntity getFileInfoSpv(String userToken, String date) { String userId = accessTokenValidator.fetchUserIdFromAccessToken(userToken); if (StringUtils.isEmpty(userId)) { logger.error("Failed to get user"); @@ -338,13 +338,10 @@ public ResponseEntity getFileInfoSpv(String userToken) { Map> reportTypeInfo = new HashMap<>(); for (Map.Entry entry : reportFileNameMap.entrySet()) { Map resourceMap = new HashMap<>(); - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - String todayFormattedDate = now.format(dateFormat); String fileName = entry.getValue(); String reportType = entry.getValue().replace(".csv", ""); - String objectKey = serverProperties.getReportDownloadFolderName() + "/" + serverProperties.getSpvSubFolderName() + "/" + todayFormattedDate + "/" + reportType + "/" + fileName; + String objectKey = serverProperties.getReportDownloadFolderName() + "/" + serverProperties.getSpvSubFolderName() + "/" + date + "/" + reportType + "/" + fileName; try { Model.Blob blob = storageService.getObject(serverProperties.getReportDownloadContainerName(), objectKey, Option.apply(Boolean.FALSE)); if (blob != null) { @@ -353,21 +350,6 @@ public ResponseEntity getFileInfoSpv(String userToken) { } } catch (Exception e) { logger.error("Failed to read the downloaded file for url: " + objectKey); - LocalDateTime yesterday = now.minusDays(1); - String yesterdayFormattedDate = yesterday.format(dateFormat); - objectKey = serverProperties.getReportDownloadFolderName() + "/" + serverProperties.getSpvSubFolderName() + "/" + yesterdayFormattedDate + "/" + reportType + "/" + fileName; - try { - Model.Blob blob = storageService.getObject(serverProperties.getReportDownloadContainerName(), objectKey, Option.apply(Boolean.FALSE)); - if (blob != null) { - resourceMap.put("lastModified", blob.lastModified()); - resourceMap.put("fileMetaData", blob.metadata()); - } else { - resourceMap.put("msg", "No Report Available"); - logger.info("Unable to fetch fileInfo"); - } - } catch (Exception ex) { - logger.error("Failed to read the downloaded file for url: " + objectKey); - } } reportTypeInfo.put(fileName, resourceMap); }