Skip to content

Commit

Permalink
Add logging and refine search result mapping logic
Browse files Browse the repository at this point in the history
Introduced SLF4J logging in LegacySearchController to log incoming search queries. Enhanced SearchResultRowMapper to handle null check for "parentName" string before applying isBlank() to avoid potential null pointer exceptions.
  • Loading branch information
Gcolon021 committed Nov 13, 2024
1 parent c0bb7d3 commit e5dff93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.LegacyResponse;
import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.LegacySearchQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand All @@ -13,6 +15,7 @@
@Controller
public class LegacySearchController {

private static final Logger log = LoggerFactory.getLogger(LegacySearchController.class);
private final LegacySearchService legacySearchService;

@Autowired
Expand All @@ -22,6 +25,7 @@ public LegacySearchController(LegacySearchService legacySearchService) {

@RequestMapping(path = "/search")
public ResponseEntity<LegacyResponse> legacySearch(@RequestBody String jsonString) throws IOException {
log.info("legacySearch(): {}", jsonString);
LegacySearchQuery legacySearchQuery = LegacySearchQueryMapper.mapFromJson(jsonString);
return ResponseEntity
.ok(new LegacyResponse(legacySearchService.getSearchResults(legacySearchQuery.filter(), legacySearchQuery.pageable())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private SearchResult mapSearchResults(ResultSet rs) throws SQLException {

Result result = new Result(
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"),
rs.getString("parentName").isBlank() ? "All Variables" : rs.getString("parentName"), rs.getString("name"),
"categorical".equalsIgnoreCase(rs.getString("conceptType")), isContinuous
rs.getString("parentName") != null && rs.getString("parentName").isBlank() ? "All Variables" : rs.getString("parentName"),
rs.getString("name"), "categorical".equalsIgnoreCase(rs.getString("conceptType")), isContinuous
);

return new SearchResult(result);
Expand Down

0 comments on commit e5dff93

Please sign in to comment.