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-7437] Switch study to dataset for concept node detail
- Loading branch information
Luke Sikina
committed
Oct 10, 2024
1 parent
5bfbf4c
commit 0d7e848
Showing
15 changed files
with
290 additions
and
42 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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/edu/harvard/dbmi/avillach/dictionary/dataset/Dataset.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,18 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dataset; | ||
|
||
import jakarta.annotation.Nullable; | ||
|
||
import java.util.Map; | ||
|
||
public record Dataset( | ||
String ref, String fullName, String abbreviation, String description, @Nullable Map<String, String> meta | ||
) { | ||
|
||
public Dataset(String ref, String fullName, String abbreviation, String description) { | ||
this(ref, fullName, abbreviation, description, null); | ||
} | ||
|
||
public Dataset withMeta(Map<String, String> meta) { | ||
return new Dataset(ref, fullName, abbreviation, description, meta); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetMapper.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,18 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dataset; | ||
|
||
import org.springframework.jdbc.core.RowMapper; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
@Component | ||
public class DatasetMapper implements RowMapper<Dataset> { | ||
@Override | ||
public Dataset mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
return new Dataset( | ||
rs.getString("ref"), rs.getString("full_name"), | ||
rs.getString("abbreviation"), rs.getString("description") | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetRepository.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,53 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.dataset; | ||
|
||
import edu.harvard.dbmi.avillach.dictionary.concept.model.Concept; | ||
import edu.harvard.dbmi.avillach.dictionary.util.MapExtractor; | ||
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.Map; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public class DatasetRepository { | ||
private final NamedParameterJdbcTemplate template; | ||
private final DatasetMapper mapper; | ||
private final MapExtractor metaExtractor = new MapExtractor("key", "value"); | ||
|
||
@Autowired | ||
public DatasetRepository(NamedParameterJdbcTemplate template, DatasetMapper mapper) { | ||
this.template = template; | ||
this.mapper = mapper; | ||
} | ||
|
||
public Optional<Dataset> getDataset(String ref) { | ||
String sql = """ | ||
SELECT | ||
ref, full_name, abbreviation, description | ||
FROM | ||
dataset | ||
WHERE | ||
dataset.REF = :ref | ||
"""; | ||
|
||
MapSqlParameterSource params = new MapSqlParameterSource().addValue("ref", ref); | ||
|
||
return template.query(sql, params, mapper).stream().findAny(); | ||
} | ||
|
||
public Map<String, String> getDatasetMeta(String ref) { | ||
String sql = """ | ||
SELECT | ||
key, value | ||
FROM | ||
dataset_meta | ||
LEFT JOIN dataset ON dataset_meta.dataset_id = dataset.dataset_id | ||
WHERE | ||
dataset.REF = :ref | ||
"""; | ||
MapSqlParameterSource params = new MapSqlParameterSource().addValue("ref", ref); | ||
return template.query(sql, params, metaExtractor); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetService.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.dataset; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class DatasetService { | ||
|
||
private final DatasetRepository repository; | ||
|
||
|
||
@Autowired | ||
public DatasetService(DatasetRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public Optional<Dataset> getDataset(String ref) { | ||
Map<String, String> meta = repository.getDatasetMeta(ref); | ||
return repository.getDataset(ref).map(ds -> ds.withMeta(meta)); | ||
} | ||
} |
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
Oops, something went wrong.