Skip to content

Commit

Permalink
4.8.15 dev v3 (#629)
Browse files Browse the repository at this point in the history
* Updating for calendar API (#619)

* 4.8.15 dev competencys (#627)

* Adding API for orgCompetencies

* Do code formatting
  • Loading branch information
Sahil-tarento authored Jun 28, 2024
1 parent 47cbac9 commit ab49a6d
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 14 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/sunbird/common/util/CbExtServerProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,12 @@ public void setRedisWheeboxKey(String redisWheeboxKey) {
@Value("#{${insights.mapping.key}}")
private Map<String, String> insightsMappingKey;

@Value("${sb.search.service.host}")
private String sbSearchServiceHost;

@Value("${sb.composite.v4.search}")
private String sbCompositeV4Search;

public boolean qListFromCacheEnabled() {
return qListFromCacheEnabled;
}
Expand Down Expand Up @@ -2696,4 +2702,20 @@ public Map<String, String> getInsightsMappingKey() {
public void setInsightsMappingKey(Map<String, String> insightsMappingKey) {
this.insightsMappingKey = insightsMappingKey;
}

public String getSbSearchServiceHost() {
return sbSearchServiceHost;
}

public void setSbSearchServiceHost(String sbSearchServiceHost) {
this.sbSearchServiceHost = sbSearchServiceHost;
}

public String getSbCompositeV4Search() {
return sbCompositeV4Search;
}

public void setSbCompositeV4Search(String sbCompositeV4Search) {
this.sbCompositeV4Search = sbCompositeV4Search;
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/sunbird/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ public class Constants {
public static final String SEQUENCE_NO = "seqno";
public static final String API_EXPLORE_COURSE_UPDATE = "api.explore.course.update";
public static final String API_EXPLORE_COURSE_DELETE = "api.explore.course.delete";
public static final String COMPETENCIES_ORG_COURSES_REDIS_KEY = "dashboard_core_competencies_by_user_org";
public static final String ORG_COMPETENCY_SEARCH_API = "api.org.competency.search";
public static final String SEARCH_COMPETENCY_THEMES = "competencyTheme";
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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import org.sunbird.common.model.FracApiResponse;
Expand Down Expand Up @@ -33,4 +34,9 @@ public ResponseEntity<?> listPositions(@RequestHeader(Constants.X_AUTH_TOKEN) St
FracApiResponse response = searchByService.listPositions(userToken);
return new ResponseEntity<>(response, HttpStatus.valueOf(response.getStatusInfo().getStatusCode()));
}

@GetMapping("/v1/competenciesByOrg/{orgId}")
public ResponseEntity<?> listOfCompetenciesByOrg(@PathVariable String orgId, @RequestHeader(Constants.X_AUTH_TOKEN) String userToken) {
return new ResponseEntity<>(searchByService.listCompetenciesByOrg(orgId, userToken), HttpStatus.OK);
}
}
86 changes: 73 additions & 13 deletions src/main/java/org/sunbird/searchby/service/SearchByService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.sunbird.searchby.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -16,18 +12,19 @@
import org.springframework.util.ObjectUtils;
import org.sunbird.cache.RedisCacheMgr;
import org.sunbird.common.model.FracApiResponse;
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.common.service.OutboundRequestHandlerServiceImpl;
import org.sunbird.common.util.AccessTokenValidator;
import org.sunbird.common.util.CbExtServerProperties;
import org.sunbird.common.util.Constants;
import org.sunbird.common.util.ProjectUtil;
import org.sunbird.core.logger.CbExtLogger;
import org.sunbird.searchby.model.CompetencyInfo;
import org.sunbird.searchby.model.FracCommonInfo;
import org.sunbird.searchby.model.ProviderInfo;
import org.sunbird.workallocation.model.FracStatusInfo;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;

@Service
@SuppressWarnings("unchecked")
Expand All @@ -40,13 +37,16 @@ public class SearchByService {

@Autowired
RedisCacheMgr redisCacheMgr;

@Autowired
ObjectMapper mapper;

@Autowired
OutboundRequestHandlerServiceImpl outboundRequestHandlerService;

@Autowired
AccessTokenValidator accessTokenValidator;

public Collection<CompetencyInfo> getCompetencyDetails(String authUserToken) throws Exception {
String strCompetencyMap = redisCacheMgr.getCache(Constants.COMPETENCY_CACHE_NAME);
Map<String, CompetencyInfo> competencyMap = new HashMap<>();
Expand Down Expand Up @@ -183,7 +183,7 @@ private Map<String, CompetencyInfo> updateCompetencyDetails(String authUserToken

Map<String, Object> fracSearchRes = outboundRequestHandlerService.fetchResultUsingPost(
cbExtServerProperties.getFracHost() + cbExtServerProperties.getFracSearchPath(), reqBody, headers);

List<Map<String, Object>> fracResponseList = (List<Map<String, Object>>) fracSearchRes
.get(Constants.RESPONSE_DATA);

Expand Down Expand Up @@ -408,4 +408,64 @@ private List<FracCommonInfo> getMasterPositionList(List<String> positionNameList
}
return positionList;
}

public SBApiResponse listCompetenciesByOrg(String orgId, String userToken) {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.ORG_COMPETENCY_SEARCH_API);
try {
String userId = validateAuthTokenAndFetchUserId(userToken);
if (org.apache.commons.lang3.StringUtils.isBlank(userId)) {
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg(Constants.USER_ID_DOESNT_EXIST);
response.setResponseCode(HttpStatus.BAD_REQUEST);
return response;
}
List<String> courseIdList = redisCacheMgr.hget(Constants.COMPETENCIES_ORG_COURSES_REDIS_KEY, cbExtServerProperties.getRedisInsightIndex(), orgId);
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(courseIdList)) {
Map<String, Object> competencyMap = listCompetencyDetails(Arrays.asList(courseIdList.get(0).split(",")));
logger.info("Initializing/Refreshing the Cache Value for Key : " + Constants.COMPETENCY_CACHE_NAME);
if (MapUtils.isNotEmpty(competencyMap)) {
response.setResult((Map<String, Object>) competencyMap.get(Constants.RESULT));
} else {
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg("Competency map is empty");
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg("Issue while fetching the competency for org: " + orgId);
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
logger.error("Issue while fetching the competency for org: " + orgId, e);
response.getParams().setStatus(Constants.FAILED);
response.getParams().setErrmsg(e.getMessage());
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
return response;
}

private Map<String, Object> listCompetencyDetails(List<String> identifiers) throws Exception {

HashMap<String, Object> reqBody = new HashMap<>();
HashMap<String, Object> req = new HashMap<>();
req.put(Constants.FACETS, Arrays.asList(Constants.COMPETENCIES_V5 + "." + Constants.COMPETENCY_AREA,
Constants.COMPETENCIES_V5 + "." + Constants.SEARCH_COMPETENCY_THEMES,
Constants.COMPETENCIES_V5 + "." + Constants.SEARCH_COMPETENCY_SUB_THEMES));
Map<String, Object> filters = new HashMap<>();
filters.put(Constants.IDENTIFIER, identifiers);
filters.put(Constants.STATUS, Arrays.asList(Constants.LIVE));
req.put(Constants.FILTERS, filters);
req.put(Constants.LIMIT, 0);
reqBody.put(Constants.REQUEST, req);

Map<String, Object> compositeSearchRes = outboundRequestHandlerService.fetchResultUsingPost(
cbExtServerProperties.getSbSearchServiceHost() + cbExtServerProperties.getSbCompositeV4Search(), reqBody,
null);

return compositeSearchRes;
}

private String validateAuthTokenAndFetchUserId(String authUserToken) {
return accessTokenValidator.fetchUserIdFromAccessToken(authUserToken);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,8 @@ user.bulk.upload.category.value=General,OBC,SC,ST
insights.mapping.key={"PROVIDER_INSIGHT":"organisation","MDO_INSIGHT":"mdo"}
mdo.insights.fields={"Total Users":"https://portal.karmayogi.nic.in/content-store/orgStore/01376822290813747263/1716545372950_Network.svg","Certificates":"https://portal.karmayogi.nic.in/content-store/orgStore/01376822290813747263/1715594032620_badges.svg","Enrolments":"https://portal.karmayogi.nic.in/content-store/orgStore/01376822290813747263/1716545463334_knowledge-resources.svg","Content Published":"https://portal.karmayogi.nic.in/content-store/orgStore/01376822290813747263/1716545105444_Program.svg","24hr Login":"https://portal.karmayogi.nic.in/content-store/orgStore/01376822290813747263/1716545326988_percent.svg"}
mdo.insights.property.fields={"valueColor": "#FFFFFF","labelColor": "#FFFFFF","linebreak":"false","background": "#1B4CA1","iconColor": "#FFFFFF"}
mdo.insights.redis.key.mapping={"Total Users":"dashboard_user_count_by_user_org","Certificates":"dashboard_certificates_generated_count_by_user_org","Enrolments":"dashboard_enrolment_count_by_user_org","Content Published":"dashboard_live_course_count_by_course_org","24hr Login":"dashboard_login_percent_last_24_hrs_by_user_org"}
mdo.insights.redis.key.mapping={"Total Users":"dashboard_user_count_by_user_org","Certificates":"dashboard_certificates_generated_count_by_user_org","Enrolments":"dashboard_enrolment_count_by_user_org","Content Published":"dashboard_live_course_count_by_course_org","24hr Login":"dashboard_login_percent_last_24_hrs_by_user_org"}

#SearchService
sb.search.service.host=http://search-service:9000
sb.composite.v4.search=/v4/search

0 comments on commit ab49a6d

Please sign in to comment.