From e5dff93e0055f01c8553ea7ee4872524792a2043 Mon Sep 17 00:00:00 2001 From: GeorgeC Date: Wed, 13 Nov 2024 09:52:02 -0500 Subject: [PATCH] Add logging and refine search result mapping logic 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. --- .../dictionary/legacysearch/LegacySearchController.java | 4 ++++ .../dictionary/legacysearch/SearchResultRowMapper.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchController.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchController.java index 6c5e853..c26bf84 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchController.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/LegacySearchController.java @@ -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; @@ -13,6 +15,7 @@ @Controller public class LegacySearchController { + private static final Logger log = LoggerFactory.getLogger(LegacySearchController.class); private final LegacySearchService legacySearchService; @Autowired @@ -22,6 +25,7 @@ public LegacySearchController(LegacySearchService legacySearchService) { @RequestMapping(path = "/search") public ResponseEntity 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()))); diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/SearchResultRowMapper.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/SearchResultRowMapper.java index 7bac7ea..1ec7c21 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/SearchResultRowMapper.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/SearchResultRowMapper.java @@ -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);