Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -349,7 +350,8 @@ public String searchUserByPhone(

@Operation(summary = "Provide the list of beneficiaries using Elasticsearch")
@RequestMapping(value = "/searchUser", method = RequestMethod.POST, headers = "Authorization")
public String searchUser(@RequestBody String request, HttpServletRequest httpRequest) {
public String searchUser(@RequestBody String request, HttpServletRequest httpRequest, @RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "100") int size) {
OutputResponse response = new OutputResponse();
try {
logger.info("Universal search request received");
Expand Down Expand Up @@ -379,7 +381,7 @@ public String searchUser(@RequestBody String request, HttpServletRequest httpReq
}

logger.info("Searching with query: {}, userId: {}, is1097: {}", searchQuery, userID, is1097);
String result = iemrSearchUserService.searchUser(searchQuery, userID, auth, is1097);
String result = iemrSearchUserService.searchUser(searchQuery, userID, auth, is1097, page, size);

if (result == null || result.trim().isEmpty()) {
response.setError(200, "No beneficiaries found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ String findByBeneficiaryPhoneNo(BenPhoneMap benPhoneMap, Integer pageNo, Integer

String findBeneficiary(BeneficiaryModel request, String auth) throws Exception;

String searchUser(String searchQuery, Integer userId, String auth, Boolean is1097) throws Exception;
String searchUser(String searchQuery, Integer userId, String auth, Boolean is1097, int page, int size) throws Exception;

String findBeneficiaryES(BeneficiaryModel i_beneficiary, Integer userId, String auth) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private void setBeneficiaryGender(List<BeneficiaryModel> iBeneficiary) {
* Universal search using Elasticsearch
*/
@Override
public String searchUser(String searchQuery, Integer userId, String auth, Boolean is1097) throws Exception {
public String searchUser(String searchQuery, Integer userId, String auth, Boolean is1097, int page, int size) throws Exception {

try {
if (searchQuery == null || searchQuery.trim().isEmpty()) {
Expand All @@ -339,7 +339,7 @@ public String searchUser(String searchQuery, Integer userId, String auth, Boolea
logger.info("Universal search with query: {}, userId: {}", searchQuery, userId);

Map<String, Object> response = identityBeneficiaryService.searchBeneficiariesUsingES(
searchQuery, userId, auth, is1097);
searchQuery, userId, auth, is1097, page, size);

ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public List<BeneficiariesDTO> getBeneficiaryListByFamilyId(String familyId, Stri
public List<BeneficiariesDTO> getBeneficiaryListByGovId(String identity, String auth, Boolean is1097)
throws IEMRException;

public Map<String, Object> searchBeneficiariesUsingES(String query, Integer userId, String auth, Boolean is1097) throws IEMRException;
public Map<String, Object> searchBeneficiariesUsingES(String query, Integer userId, String auth, Boolean is1097, int page, int size) throws IEMRException;


}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public List<BeneficiariesDTO> getBeneficiaryListByIDs(HashSet benIdList, String
String s = data1.get("data").getAsString();
JsonArray responseArray = parser.parse(s).getAsJsonArray();


for (JsonElement jsonElement : responseArray) {

BeneficiariesDTO callRequest = inputMapper.gson().fromJson(jsonElement.toString(),
Expand All @@ -116,42 +115,49 @@ public List<BeneficiariesDTO> getBeneficiaryListByIDs(HashSet benIdList, String
* Call Identity API's Elasticsearch universal search
*/
@Override
public Map<String, Object> searchBeneficiariesUsingES(String query, Integer userId, String auth, Boolean is1097)
public Map<String, Object> searchBeneficiariesUsingES(String query, Integer userId, String auth, Boolean is1097,
int page, int size)
throws IEMRException {

Map<String, Object> response = new HashMap<>();

try {
HashMap<String, Object> headers = new HashMap<>();
if (auth != null && !auth.isEmpty()) {
headers.put("Authorization", auth);
}

String baseUrl = ConfigProperties
.getPropertyByName("identity-api-url-searchByES")
.replace(
IDENTITY_BASE_URL,
(Boolean.TRUE.equals(is1097)) ? identity1097BaseURL : identityBaseURL
);
try {
HashMap<String, Object> headers = new HashMap<>();
if (auth != null && !auth.isEmpty()) {
headers.put("Authorization", auth);
}

String baseUrl = ConfigProperties
.getPropertyByName("identity-api-url-searchByES")
.replace(
IDENTITY_BASE_URL,
(Boolean.TRUE.equals(is1097)) ? identity1097BaseURL : identityBaseURL);

StringBuilder url = new StringBuilder(baseUrl)
.append("?query=").append(URLEncoder.encode(query, StandardCharsets.UTF_8));
.append("?query=").append(URLEncoder.encode(query, StandardCharsets.UTF_8))
.append("&page=").append(page)
.append("&size=").append(size);

if (userId != null) {
url.append("&userId=").append(userId);
}

logger.info("Calling Identity ES search URL: {}", url);

String result = httpUtils.get(url.toString());

if (result == null || result.isEmpty()) {
response.put("data", Collections.emptyList());
response.put("statusCode", 200);
response.put("status", "Success");
response.put("errorMessage", "Success");
return response;
}
String result = httpUtils.get(url.toString());

if (result == null || result.isEmpty()) {
response.put("data", Collections.emptyList());
response.put("totalResults", 0);
response.put("currentPage", page);
response.put("pageSize", size);
response.put("totalPages", 0);
response.put("hasMore", false);
response.put("statusCode", 200);
response.put("status", "Success");
response.put("errorMessage", "Success");
return response;
}

ObjectMapper mapper = new ObjectMapper();

Expand All @@ -167,10 +173,18 @@ public Map<String, Object> searchBeneficiariesUsingES(String query, Integer user
throw new IEMRException(errMsg);
}

response.put("data", rootNode.path("data"));
response.put("statusCode", 200);
response.put("status", "Success");
response.put("errorMessage", "Success");
response.put("data", rootNode.path("data"));
response.put("totalResults", rootNode.path("totalResults").asLong(0));
response.put("currentPage", rootNode.path("currentPage").asInt(page));
response.put("pageSize", rootNode.path("pageSize").asInt(size));
response.put("totalPages", rootNode.path("totalPages").asInt(0));
response.put("hasMore", rootNode.path("hasMore").asBoolean(false));
response.put("statusCode", 200);
response.put("status", "Success");
response.put("errorMessage", "Success");

logger.info("ES Search completed: {} results on page {} of {}",
rootNode.path("data").size(), page + 1, rootNode.path("totalPages").asInt(0));

return response;

Expand Down Expand Up @@ -208,7 +222,6 @@ public List<BeneficiariesPartialDTO> getPartialBeneficiaryListByIDs(HashSet benI
String s = data1.get("data").getAsString();
JsonArray responseArray = parser.parse(s).getAsJsonArray();


for (JsonElement jsonElement : responseArray) {

BeneficiariesPartialDTO callRequest = inputMapper.gson().fromJson(jsonElement.toString(),
Expand Down Expand Up @@ -573,7 +586,6 @@ public List<BeneficiariesDTO> searchBeneficiaryList(String identitySearchDTO, St
String s = data1.get("data").getAsString();
JsonArray responseArray = parser.parse(s).getAsJsonArray();


for (JsonElement jsonElement : responseArray) {

BeneficiariesDTO callRequest = inputMapper.gson().fromJson(jsonElement.toString(), BeneficiariesDTO.class);
Expand Down
Loading