Skip to content

Commit

Permalink
avniproject/avni-webapp#1390 | enhance: display count for SubjectSear…
Browse files Browse the repository at this point in the history
…chRequest
  • Loading branch information
vedfordev committed Dec 13, 2024
1 parent a6c219b commit cb71524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public LinkedHashMap<String, Object> search(SubjectSearchRequest subjectSearchRe
logger.info("Searching for individuals");
List<Map<String, Object>> searchResults = subjectSearchRepository.search(subjectSearchRequest, new SubjectSearchQueryBuilder());
long resultsEnd = new DateTime().getMillis();
BigInteger totalCount = subjectSearchRequest.getIncludeDisplayCount().booleanValue() == true ? subjectSearchRepository.getTotalCount(subjectSearchRequest, new SubjectSearchQueryBuilder()) : new BigInteger("-1");
logger.info(String.format("Subject search: Time Taken: %dms. Sorted: %s", (resultsEnd - startTime), subjectSearchRequest.getPageElement().getSortColumn()));
return constructIndividual(searchResults);
return constructIndividual(searchResults,totalCount);
}

private LinkedHashMap<String, Object> constructIndividual(List<Map<String, Object>> individualList) {
private LinkedHashMap<String, Object> constructIndividual(List<Map<String, Object>> individualList,BigInteger totalCount) {
LinkedHashMap<String, Object> recordsMap = new LinkedHashMap<String, Object>();
List<Long> individualIds = individualList.stream()
.map(individualRecord -> Long.valueOf((Integer) individualRecord.get("id")))
Expand All @@ -64,6 +65,7 @@ private LinkedHashMap<String, Object> constructIndividual(List<Map<String, Objec
.collect(Collectors.toList()));
individualRecord.put("addressLevel", titleLineages.get(((BigInteger) individualRecord.get("addressId")).longValue()));
}).collect(Collectors.toList());
recordsMap.put("totalElements", totalCount);
recordsMap.put("listOfRecords", listOfRecords);
return recordsMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class SubjectSearchRequest {
private String name;
private IntegerRange age;
private Boolean includeVoided;
private Boolean includeDisplayCount;
private List<Integer> addressIds = new ArrayList<>();
private List<Concept> concept;
private List<String> gender;
Expand Down Expand Up @@ -56,6 +57,14 @@ public void setIncludeVoided(Boolean includeVoided) {
this.includeVoided = includeVoided;
}

public Boolean getIncludeDisplayCount() {
return includeDisplayCount;
}

public void setIncludeDisplayCount(Boolean includeDisplayCount) {
this.includeDisplayCount = includeDisplayCount;
}

public List<Integer> getAddressIds() {
return addressIds;
}
Expand Down

0 comments on commit cb71524

Please sign in to comment.