forked from Luke-Sikina/picsure-search-refinement
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ALS-7694] Add DashboardDrawer feature with controller, service, and …
…repository (#55) * Add Dashboard Drawer feature - Introduce DashboardDrawerController for drawer-related endpoints - Implement DashboardDrawerService to handle drawer logic - Create DashboardDrawerRepository for database interactions - Define DashboardDrawer and DashboardDrawerList records - Add DashboardDrawerRowMapper for result set mapping - Update DashboardRepository SQL to include dataset_id - Modify application properties to include dashboard layout configuration * Update application-bdc.properties with dashboard and filtering configs - Added `dashboard.enable.bdc_hack` property - Added `dashboard.layout.type` property - Moved `filtering.unfilterable_concepts` property - Ensured newline at end of file * Add 'program_name' column to Dashboard repository - Updated SQL query to include 'program_name' field. - Joined 'dataset_meta' table for 'program_name' metadata. - Added 'program_name' to the column list in DashboardService. * Refactor service and controller to handle Optional returns - Refactor `DashboardDrawerService` methods to return `Optional` - Update controller methods to handle `Optional` results with appropriate HTTP responses - Modify repository methods to return `Optional` for single item queries - Ensure consistency and error handling improvements across the service and controller layers
- Loading branch information
Showing
11 changed files
with
222 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; | ||
|
||
import java.util.List; | ||
|
||
public record DashboardDrawer( | ||
int datasetId, String studyFullname, String studyAbbreviation, List<String> consentGroups, String studySummary, List<String> studyFocus, | ||
String studyDesign, String sponsor | ||
) { | ||
} |
24 changes: 24 additions & 0 deletions
24
.../java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Controller | ||
@RequestMapping("/dashboard-drawer") | ||
public class DashboardDrawerController { | ||
|
||
@Autowired | ||
private DashboardDrawerService dashboardDrawerService; | ||
|
||
@GetMapping | ||
public ResponseEntity<DashboardDrawerList> findAll() { | ||
return dashboardDrawerService.findAll().map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<DashboardDrawer> findByDatasetId(@PathVariable Integer id) { | ||
return dashboardDrawerService.findByDatasetId(id).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; | ||
|
||
import java.util.List; | ||
|
||
public record DashboardDrawerList(List<DashboardDrawer> dashboardDrawerList) { | ||
} |
82 changes: 82 additions & 0 deletions
82
.../java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.*; | ||
|
||
@Repository | ||
public class DashboardDrawerRepository { | ||
|
||
private final NamedParameterJdbcTemplate template; | ||
|
||
private static final Logger log = LoggerFactory.getLogger(DashboardDrawerRepository.class); | ||
|
||
@Autowired | ||
public DashboardDrawerRepository(NamedParameterJdbcTemplate template) { | ||
this.template = template; | ||
} | ||
|
||
public List<DashboardDrawer> getDashboardDrawerRows() { | ||
String materializedViewSql = """ | ||
select * from dictionary_db.dict.dataset_meta_materialized_view dmmv; | ||
"""; | ||
|
||
String fallbackSql = """ | ||
SELECT d.dataset_id, | ||
MAX(d.full_name) study_fullname, | ||
MAX(d.abbreviation) study_abbreviation, | ||
ARRAY_AGG(DISTINCT c.description) consent_groups, | ||
MAX(d.description) study_summary, | ||
ARRAY_AGG(DISTINCT dm.value) FILTER (where dm.key IN ('study_focus')) study_focus, | ||
MAX(DISTINCT dm.value) FILTER (where dm.key IN ('study_design')) study_design, | ||
MAX(DISTINCT dm.value) FILTER (where dm.key IN ('sponsor')) sponsor | ||
FROM dataset d | ||
JOIN dataset_meta dm ON d.dataset_id = dm.dataset_id | ||
JOIN consent c ON d.dataset_id = c.dataset_id | ||
GROUP BY d.dataset_id | ||
"""; | ||
|
||
try { | ||
return template.query(materializedViewSql, new DashboardDrawerRowMapper()); | ||
} catch (Exception e) { | ||
log.debug("Materialized view not available, using fallback query. Error: {}", e.getMessage()); | ||
return template.query(fallbackSql, new DashboardDrawerRowMapper()); | ||
} | ||
} | ||
|
||
public Optional<DashboardDrawer> getDashboardDrawerRows(Integer datasetId) { | ||
String materializedViewSql = """ | ||
select * from dictionary_db.dict.dataset_meta_materialized_view dmmv where dmmv.dataset_id = :datasetId; | ||
"""; | ||
|
||
String fallbackSql = """ | ||
SELECT d.dataset_id dataset_id, | ||
MAX(d.full_name) study_fullname, | ||
MAX(d.abbreviation) study_abbreviation, | ||
ARRAY_AGG(DISTINCT c.description) consent_groups, | ||
MAX(d.description) study_summary, | ||
ARRAY_AGG(DISTINCT dm.value) FILTER (where dm.key IN ('study_focus')) study_focus, | ||
MAX(DISTINCT dm.value) FILTER (where dm.key IN ('study_design')) study_design, | ||
MAX(DISTINCT dm.value) FILTER (where dm.key IN ('sponsor')) sponsor | ||
FROM dataset d | ||
JOIN dataset_meta dm ON d.dataset_id = dm.dataset_id | ||
JOIN consent c ON d.dataset_id = c.dataset_id | ||
where d.dataset_id = :datasetId | ||
GROUP BY d.dataset_id | ||
"""; | ||
MapSqlParameterSource params = new MapSqlParameterSource(); | ||
params.addValue("datasetId", datasetId); | ||
|
||
try { | ||
return template.query(materializedViewSql, params, new DashboardDrawerRowMapper()).stream().findFirst(); | ||
} catch (Exception e) { | ||
log.debug("Materialized view not available, using fallback query. Error: {}", e.getMessage()); | ||
return template.query(fallbackSql, params, new DashboardDrawerRowMapper()).stream().findFirst(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...n/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerRowMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; | ||
|
||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Array; // For handling SQL Array | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class DashboardDrawerRowMapper implements RowMapper<DashboardDrawer> { | ||
|
||
@Override | ||
public DashboardDrawer mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
return new DashboardDrawer( | ||
rs.getInt("dataset_id"), rs.getString("study_fullname"), rs.getString("study_abbreviation"), | ||
convertSqlArrayToList(rs.getArray("consent_groups")), rs.getString("study_summary"), | ||
convertSqlArrayToList(rs.getArray("study_focus")), rs.getString("study_design"), rs.getString("sponsor") | ||
); | ||
} | ||
|
||
private List<String> convertSqlArrayToList(Array sqlArray) throws SQLException { | ||
if (sqlArray == null) { | ||
return List.of(); | ||
} else { | ||
Object[] arrayContents = (Object[]) sqlArray.getArray(); | ||
// Check if the array contains a single empty value | ||
if (arrayContents.length == 1 && "".equals(arrayContents[0])) { | ||
return List.of(); | ||
} else { | ||
return Arrays.asList((String[]) sqlArray.getArray()); | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ain/java/edu/harvard/dbmi/avillach/dictionary/dashboarddrawer/DashboardDrawerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dashboarddrawer; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class DashboardDrawerService { | ||
|
||
private final DashboardDrawerRepository repository; | ||
private final String dashboardLayout; | ||
|
||
@Autowired | ||
public DashboardDrawerService(DashboardDrawerRepository repository, @Value("${dashboard.layout.type}") String dashboardLayout) { | ||
this.repository = repository; | ||
this.dashboardLayout = dashboardLayout; | ||
} | ||
|
||
/** | ||
* Retrieves the Dashboard Drawer for all datasets. | ||
* | ||
* @return All Dashboard Instances and their metadata. | ||
*/ | ||
public Optional<DashboardDrawerList> findAll() { | ||
if (dashboardLayout.equalsIgnoreCase("bdc")) { | ||
List<DashboardDrawer> records = repository.getDashboardDrawerRows(); | ||
return Optional.of(new DashboardDrawerList(records)); | ||
} | ||
|
||
return Optional.of(new DashboardDrawerList(new ArrayList<>())); | ||
} | ||
|
||
/** | ||
* Retrieves the Dashboard Drawer for a specific dataset. | ||
* | ||
* | ||
* @param datasetId the ID of the dataset to fetch. | ||
* @return a single Dashboard instance with drawer-specific metadata. | ||
*/ | ||
public Optional<DashboardDrawer> findByDatasetId(Integer datasetId) { | ||
if ("bdc".equalsIgnoreCase(dashboardLayout)) { | ||
return repository.getDashboardDrawerRows(datasetId); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters