From d6db94abe5e3782b0462d1e8c0c7190c65b14da8 Mon Sep 17 00:00:00 2001 From: karthik-tarento Date: Fri, 10 Jun 2022 14:14:36 +0530 Subject: [PATCH] Using Serialized object instead of HashMap for positions --- .../sunbird/common/model/FracApiResponse.java | 8 ++-- .../controller/SearchByController.java | 4 +- .../searchby/model/CompetencyInfo.java | 30 +------------ .../searchby/model/FracCommonInfo.java | 43 +++++++++++++++++++ .../sunbird/searchby/model/ProviderInfo.java | 1 + .../searchby/service/SearchByService.java | 43 ++++++++----------- 6 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 src/main/java/org/sunbird/searchby/model/FracCommonInfo.java diff --git a/src/main/java/org/sunbird/common/model/FracApiResponse.java b/src/main/java/org/sunbird/common/model/FracApiResponse.java index 7520b6605..0d5b244de 100644 --- a/src/main/java/org/sunbird/common/model/FracApiResponse.java +++ b/src/main/java/org/sunbird/common/model/FracApiResponse.java @@ -1,13 +1,13 @@ package org.sunbird.common.model; import java.util.List; -import java.util.Map; +import org.sunbird.searchby.model.FracCommonInfo; import org.sunbird.workallocation.model.FracStatusInfo; public class FracApiResponse { private FracStatusInfo statusInfo; - private List> responseData; + private List responseData; public FracStatusInfo getStatusInfo() { return statusInfo; @@ -17,11 +17,11 @@ public void setStatusInfo(FracStatusInfo statusInfo) { this.statusInfo = statusInfo; } - public List> getResponseData() { + public List getResponseData() { return responseData; } - public void setResponseData(List> responseData) { + public void setResponseData(List responseData) { this.responseData = responseData; } } diff --git a/src/main/java/org/sunbird/searchby/controller/SearchByController.java b/src/main/java/org/sunbird/searchby/controller/SearchByController.java index e508c9676..38546cada 100644 --- a/src/main/java/org/sunbird/searchby/controller/SearchByController.java +++ b/src/main/java/org/sunbird/searchby/controller/SearchByController.java @@ -29,8 +29,8 @@ public ResponseEntity browseByProvider(@RequestHeader(Constants.X_AUTH_TOKEN) } @GetMapping("/v1/listPositions") - public ResponseEntity listDesignations(@RequestHeader(Constants.X_AUTH_TOKEN) String userToken) { - FracApiResponse response = searchByService.listDesignations(userToken); + public ResponseEntity listPositions(@RequestHeader(Constants.X_AUTH_TOKEN) String userToken) { + FracApiResponse response = searchByService.listPositions(userToken); return new ResponseEntity<>(response, HttpStatus.valueOf(response.getStatusInfo().getStatusCode())); } } diff --git a/src/main/java/org/sunbird/searchby/model/CompetencyInfo.java b/src/main/java/org/sunbird/searchby/model/CompetencyInfo.java index d9e45661c..96e97e51d 100644 --- a/src/main/java/org/sunbird/searchby/model/CompetencyInfo.java +++ b/src/main/java/org/sunbird/searchby/model/CompetencyInfo.java @@ -2,26 +2,16 @@ import java.io.Serializable; -public class CompetencyInfo implements Serializable { +public class CompetencyInfo extends FracCommonInfo implements Serializable { private static final long serialVersionUID = 1L; - private String name; - private String id; + private String type; - private String description; private String status; private String source; private String competencyType; private String competencyArea; private Integer contentCount; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public Integer getContentCount() { return contentCount; } @@ -30,14 +20,6 @@ public void setContentCount(Integer contentCount) { this.contentCount = contentCount; } - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - public String getType() { return type; } @@ -46,14 +28,6 @@ public void setType(String type) { this.type = type; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - public String getStatus() { return status; } diff --git a/src/main/java/org/sunbird/searchby/model/FracCommonInfo.java b/src/main/java/org/sunbird/searchby/model/FracCommonInfo.java new file mode 100644 index 000000000..53aa8cb70 --- /dev/null +++ b/src/main/java/org/sunbird/searchby/model/FracCommonInfo.java @@ -0,0 +1,43 @@ +package org.sunbird.searchby.model; + +import java.io.Serializable; + +public class FracCommonInfo implements Serializable { + private static final long serialVersionUID = 1L; + private String name; + private String id; + private String description; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public FracCommonInfo() { + } + + public FracCommonInfo(String id, String name, String description) { + this.id = id; + this.name = name; + this.description = description; + } +} diff --git a/src/main/java/org/sunbird/searchby/model/ProviderInfo.java b/src/main/java/org/sunbird/searchby/model/ProviderInfo.java index 656468285..e41733002 100644 --- a/src/main/java/org/sunbird/searchby/model/ProviderInfo.java +++ b/src/main/java/org/sunbird/searchby/model/ProviderInfo.java @@ -3,6 +3,7 @@ import java.io.Serializable; public class ProviderInfo implements Serializable { + private static final long serialVersionUID = 1L; private String name; private String logoUrl; private String description; diff --git a/src/main/java/org/sunbird/searchby/service/SearchByService.java b/src/main/java/org/sunbird/searchby/service/SearchByService.java index 0c3ca6bc9..935c889f5 100644 --- a/src/main/java/org/sunbird/searchby/service/SearchByService.java +++ b/src/main/java/org/sunbird/searchby/service/SearchByService.java @@ -21,6 +21,7 @@ import org.sunbird.common.util.Constants; 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; @@ -65,26 +66,26 @@ public Collection getProviderDetails(String authUserToken) throws return providerMap.values(); } - public FracApiResponse listDesignations(String userToken) { + public FracApiResponse listPositions(String userToken) { FracApiResponse response = new FracApiResponse(); response.setStatusInfo(new FracStatusInfo()); response.getStatusInfo().setStatusCode(HttpStatus.OK.value()); - Map>> positionList = (Map>>) redisCacheMgr + Map> positionMap = (Map>) redisCacheMgr .getCache(Constants.POSITIONS_CACHE_NAME); - if (ObjectUtils.isEmpty(positionList) - || CollectionUtils.isEmpty(positionList.get(Constants.POSITIONS_CACHE_NAME))) { + if (ObjectUtils.isEmpty(positionMap) + || CollectionUtils.isEmpty(positionMap.get(Constants.POSITIONS_CACHE_NAME))) { logger.info("Initializing / Refreshing the Cache value for key : " + Constants.POSITIONS_CACHE_NAME); try { - positionList = updateDesignationDetails(userToken); - response.setResponseData(positionList.get(Constants.POSITIONS_CACHE_NAME)); + positionMap = updateDesignationDetails(userToken); + response.setResponseData(positionMap.get(Constants.POSITIONS_CACHE_NAME)); } catch (Exception e) { logger.error(e); response.getStatusInfo().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.getStatusInfo().setErrorMessage(e.getMessage()); } } else { - response.setResponseData(positionList.get(Constants.POSITIONS_CACHE_NAME)); + response.setResponseData(positionMap.get(Constants.POSITIONS_CACHE_NAME)); } return response; @@ -322,7 +323,7 @@ private Map updateProviderDetails(String authUserToken) th return providerMap; } - private Map>> updateDesignationDetails(String authUserToken) throws Exception { + private Map> updateDesignationDetails(String authUserToken) throws Exception { Map headers = new HashMap<>(); HashMap reqBody = new HashMap<>(); headers = new HashMap<>(); @@ -344,7 +345,7 @@ private Map>> updateDesignationDetails(String a reqBody.put(Constants.SEARCHES, searchList); List positionNameList = new ArrayList(); - List> positionList = getMasterPositionList(positionNameList); + List positionList = getMasterPositionList(positionNameList); Map fracSearchRes = outboundRequestHandlerService.fetchResultUsingPost( cbExtServerProperties.getFracHost() + cbExtServerProperties.getFracSearchPath(), reqBody, headers); @@ -353,11 +354,8 @@ private Map>> updateDesignationDetails(String a if (!CollectionUtils.isEmpty(fracResponseList)) { for (Map respObj : fracResponseList) { if (!positionNameList.contains((String) respObj.get(Constants.NAME))) { - Map fracInfo = new HashMap(); - fracInfo.put(Constants.DESCRIPTION, (String) respObj.get(Constants.DESCRIPTION)); - fracInfo.put(Constants.ID, (String) respObj.get(Constants.ID)); - fracInfo.put(Constants.NAME, (String) respObj.get(Constants.NAME)); - positionList.add(fracInfo); + positionList.add(new FracCommonInfo((String) respObj.get(Constants.ID), + (String) respObj.get(Constants.NAME), (String) respObj.get(Constants.DESCRIPTION))); positionNameList.add((String) respObj.get(Constants.NAME)); } } @@ -370,14 +368,14 @@ private Map>> updateDesignationDetails(String a } throw err; } - Map>> positionMap = new HashMap>>(); + Map> positionMap = new HashMap>(); positionMap.put(Constants.POSITIONS_CACHE_NAME, positionList); redisCacheMgr.putCache(Constants.POSITIONS_CACHE_NAME, positionMap); return positionMap; } - private List> getMasterPositionList(List positionNameList) throws Exception { - List> positionList = new ArrayList>(); + private List getMasterPositionList(List positionNameList) throws Exception { + List positionList = new ArrayList(); JsonNode jsonTree = new ObjectMapper().readTree(this.getClass().getClassLoader() .getResourceAsStream(cbExtServerProperties.getMasterPositionListFileName())); JsonNode positionsObj = jsonTree.get(Constants.POSITIONS); @@ -386,15 +384,8 @@ private List> getMasterPositionList(List positionNam while (positionsItr.hasNext()) { JsonNode position = positionsItr.next(); positionNameList.add(position.get(Constants.NAME).asText()); - Map positionObj = new HashMap() { - private static final long serialVersionUID = 1L; - { - put(Constants.ID, position.get(Constants.ID).asText()); - put(Constants.NAME, position.get(Constants.NAME).asText()); - put(Constants.DESCRIPTION, position.get(Constants.DESCRIPTION).asText()); - } - }; - positionList.add(positionObj); + positionList.add(new FracCommonInfo(position.get(Constants.ID).asText(), + position.get(Constants.NAME).asText(), position.get(Constants.DESCRIPTION).asText())); } return positionList; }