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.
Refactor metadata management and logging
Replaced single Metadata class with CategoricalMetadata and ContinuousMetadata classes to handle different metadata types separately. Introduced MetadataResultSetUtil for organizing metadata related utilities and refactored existing logic to use this new utility. Removed unnecessary logging from LegacySearchQueryMapper and cleaned up redundant annotations.
- Loading branch information
Showing
9 changed files
with
168 additions
and
117 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
1 change: 0 additions & 1 deletion
1
src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/model/ConceptShell.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
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
107 changes: 107 additions & 0 deletions
107
src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/MetadataResultSetUtil.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,107 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.legacysearch; | ||
|
||
import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.CategoricalMetadata; | ||
import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.ContinuousMetadata; | ||
import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.Result; | ||
import edu.harvard.dbmi.avillach.dictionary.util.JsonBlobParser; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
|
||
@Component | ||
public class MetadataResultSetUtil { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(MetadataResultSetUtil.class); | ||
private final JsonBlobParser jsonBlobParser; | ||
|
||
@Autowired | ||
public MetadataResultSetUtil(JsonBlobParser jsonBlobParser) { | ||
this.jsonBlobParser = jsonBlobParser; | ||
} | ||
|
||
public Result mapContinuousMetadata(ResultSet rs) throws SQLException { | ||
String hashedVarId = hashVarId(rs.getString("conceptPath")); | ||
String description = getDescription(rs); | ||
String parentName = getParentName(rs); | ||
String parentDisplay = getParentDisplay(rs); | ||
String max = String.valueOf(jsonBlobParser.parseMax(rs.getString("values"))); | ||
String min = String.valueOf(jsonBlobParser.parseMin(rs.getString("values"))); | ||
|
||
ContinuousMetadata metadata = new ContinuousMetadata( | ||
rs.getString("stigmatized"), rs.getString("display"), description, min, rs.getString("conceptPath"), parentName, | ||
rs.getString("conceptPath"), rs.getString("name"), parentDisplay, description, // changed | ||
"{}", "", parentName, max, description, rs.getString("dataset"), hashedVarId, rs.getString("conceptType"), rs.getString("name"), | ||
rs.getString("dataset"), rs.getString("stigmatized"), rs.getString("display"), rs.getString("studyAcronym"), | ||
rs.getString("dsFullName"), parentName, parentDisplay, rs.getString("conceptPath"), min, max | ||
); | ||
return new Result( | ||
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"), | ||
parentName == null || parentName.isBlank() ? "All Variables" : parentName, rs.getString("name"), false, true | ||
); | ||
} | ||
|
||
private static String getParentDisplay(ResultSet rs) throws SQLException { | ||
return rs.getString("parentDisplay") == null || rs.getString("parentDisplay").isBlank() ? "" : rs.getString("parentDisplay"); | ||
} | ||
|
||
private static String getParentName(ResultSet rs) throws SQLException { | ||
return rs.getString("parentName") == null || rs.getString("parentName").isBlank() ? "" : rs.getString("parentName"); | ||
} | ||
|
||
private static String getDescription(ResultSet rs) throws SQLException { | ||
return rs.getString("description") == null || rs.getString("description").isBlank() ? "" : rs.getString("description"); | ||
} | ||
|
||
public Result mapCategoricalMetadata(ResultSet rs) throws SQLException { | ||
String hashedVarId = hashVarId(rs.getString("conceptPath")); | ||
String description = getDescription(rs); | ||
String parentName = getParentName(rs); | ||
String parentDisplay = getParentDisplay(rs); | ||
|
||
CategoricalMetadata metadata = new CategoricalMetadata( | ||
rs.getString("stigmatized"), rs.getString("display"), description, "", rs.getString("conceptPath"), parentName, | ||
rs.getString("conceptPath"), rs.getString("name"), parentDisplay, description, // changed | ||
"{}", "", parentName, "", description, rs.getString("dataset"), hashedVarId, rs.getString("conceptType"), rs.getString("name"), | ||
rs.getString("dataset"), rs.getString("stigmatized"), rs.getString("display"), rs.getString("studyAcronym"), | ||
rs.getString("dsFullName"), parentName, parentDisplay, rs.getString("conceptPath") | ||
); | ||
|
||
return new Result( | ||
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"), | ||
parentName == null || parentName.isBlank() ? "All Variables" : parentName, rs.getString("name"), true, false | ||
); | ||
} | ||
|
||
private static String hashVarId(String hpdsPath) { | ||
String hashedVarId = ""; | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance("SHA-256"); | ||
byte[] encodedHash = digest.digest(hpdsPath.getBytes(StandardCharsets.UTF_8)); | ||
hashedVarId = bytesToHex(encodedHash); | ||
} catch (NoSuchAlgorithmException e) { | ||
log.error(e.getMessage()); | ||
} | ||
|
||
return hashedVarId; | ||
} | ||
|
||
private static String bytesToHex(byte[] hash) { | ||
StringBuilder hexString = new StringBuilder(2 * hash.length); | ||
for (byte b : hash) { | ||
String hex = Integer.toHexString(0xff & b); | ||
if (hex.length() == 1) { | ||
hexString.append('0'); | ||
} | ||
hexString.append(hex); | ||
} | ||
return hexString.toString(); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
...ain/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/model/CategoricalMetadata.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,23 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.legacysearch.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record CategoricalMetadata( | ||
@JsonProperty("columnmeta_is_stigmatized") String columnmetaIsStigmatized, @JsonProperty("columnmeta_name") String columnmetaName, | ||
@JsonProperty("description") String description, @JsonProperty("columnmeta_min") String columnmetaMin, | ||
@JsonProperty("HPDS_PATH") String hpdsPath, @JsonProperty("derived_group_id") String derivedGroupId, | ||
@JsonProperty("columnmeta_hpds_path") String columnmetaHpdsPath, @JsonProperty("columnmeta_var_id") String columnmetaVarId, | ||
@JsonProperty("columnmeta_var_group_description") String columnmetaVarGroupDescription, | ||
@JsonProperty("derived_var_description") String derivedVarDescription, | ||
@JsonProperty("derived_variable_level_data") String derivedVariableLevelData, @JsonProperty("data_hierarchy") String dataHierarchy, | ||
@JsonProperty("derived_group_description") String derivedGroupDescription, @JsonProperty("columnmeta_max") String columnmetaMax, | ||
@JsonProperty("columnmeta_description") String columnmetaDescription, @JsonProperty("derived_study_id") String derivedStudyId, | ||
@JsonProperty("hashed_var_id") String hashedVarId, @JsonProperty("columnmeta_data_type") String columnmetaDataType, | ||
@JsonProperty("derived_var_id") String derivedVarId, @JsonProperty("columnmeta_study_id") String columnmetaStudyId, | ||
@JsonProperty("is_stigmatized") String isStigmatized, @JsonProperty("derived_var_name") String derivedVarName, | ||
@JsonProperty("derived_study_abv_name") String derivedStudyAbvName, | ||
@JsonProperty("derived_study_description") String derivedStudyDescription, | ||
@JsonProperty("columnmeta_var_group_id") String columnmetaVarGroupId, @JsonProperty("derived_group_name") String derivedGroupName, | ||
@JsonProperty("columnmeta_HPDS_PATH") String columnmetaHpdsPathAlternate | ||
) implements Metadata { | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/model/ContinuousMetadata.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.legacysearch.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ContinuousMetadata( | ||
@JsonProperty("columnmeta_is_stigmatized") String columnmetaIsStigmatized, @JsonProperty("columnmeta_name") String columnmetaName, | ||
@JsonProperty("description") String description, @JsonProperty("columnmeta_min") String columnmetaMin, | ||
@JsonProperty("HPDS_PATH") String hpdsPath, @JsonProperty("derived_group_id") String derivedGroupId, | ||
@JsonProperty("columnmeta_hpds_path") String columnmetaHpdsPath, @JsonProperty("columnmeta_var_id") String columnmetaVarId, | ||
@JsonProperty("columnmeta_var_group_description") String columnmetaVarGroupDescription, | ||
@JsonProperty("derived_var_description") String derivedVarDescription, | ||
@JsonProperty("derived_variable_level_data") String derivedVariableLevelData, @JsonProperty("data_hierarchy") String dataHierarchy, | ||
@JsonProperty("derived_group_description") String derivedGroupDescription, @JsonProperty("columnmeta_max") String columnmetaMax, | ||
@JsonProperty("columnmeta_description") String columnmetaDescription, @JsonProperty("derived_study_id") String derivedStudyId, | ||
@JsonProperty("hashed_var_id") String hashedVarId, @JsonProperty("columnmeta_data_type") String columnmetaDataType, | ||
@JsonProperty("derived_var_id") String derivedVarId, @JsonProperty("columnmeta_study_id") String columnmetaStudyId, | ||
@JsonProperty("is_stigmatized") String isStigmatized, @JsonProperty("derived_var_name") String derivedVarName, | ||
@JsonProperty("derived_study_abv_name") String derivedStudyAbvName, | ||
@JsonProperty("derived_study_description") String derivedStudyDescription, | ||
@JsonProperty("columnmeta_var_group_id") String columnmetaVarGroupId, @JsonProperty("derived_group_name") String derivedGroupName, | ||
@JsonProperty("columnmeta_HPDS_PATH") String columnmetaHpdsPathAlternate, @JsonProperty("min") String min, | ||
@JsonProperty("max") String max | ||
) implements Metadata { | ||
} |
52 changes: 1 addition & 51 deletions
52
src/main/java/edu/harvard/dbmi/avillach/dictionary/legacysearch/model/Metadata.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 |
---|---|---|
@@ -1,54 +1,4 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.legacysearch.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @param columnmetaIsStigmatized | ||
* @param columnmetaName | ||
* @param description | ||
* @param columnmetaMin | ||
* @param hpdsPath | ||
* @param derivedGroupId | ||
* @param columnmetaHpdsPath | ||
* @param columnmetaVarId | ||
* @param columnmetaVarGroupDescription | ||
* @param derivedVarDescription | ||
* @param derivedVariableLevelData | ||
* @param dataHierarchy | ||
* @param derivedGroupDescription | ||
* @param columnmetaMax | ||
* @param columnmetaDescription | ||
* @param derivedStudyId | ||
* @param hashedVarId | ||
* @param columnmetaDataType | ||
* @param derivedVarId | ||
* @param columnmetaStudyId | ||
* @param isStigmatized | ||
* @param derivedVarName | ||
* @param derivedStudyAbvName | ||
* @param derivedStudyDescription | ||
* @param columnmetaVarGroupId | ||
* @param derivedGroupName | ||
* @param columnmetaHpdsPathAlternate | ||
*/ | ||
public record Metadata( | ||
@JsonProperty("columnmeta_is_stigmatized") String columnmetaIsStigmatized, @JsonProperty("columnmeta_name") String columnmetaName, | ||
@JsonProperty("description") String description, @JsonProperty("columnmeta_min") String columnmetaMin, | ||
@JsonProperty("HPDS_PATH") String hpdsPath, @JsonProperty("derived_group_id") String derivedGroupId, | ||
@JsonProperty("columnmeta_hpds_path") String columnmetaHpdsPath, @JsonProperty("columnmeta_var_id") String columnmetaVarId, | ||
@JsonProperty("columnmeta_var_group_description") String columnmetaVarGroupDescription, | ||
@JsonProperty("derived_var_description") String derivedVarDescription, | ||
@JsonProperty("derived_variable_level_data") String derivedVariableLevelData, @JsonProperty("data_hierarchy") String dataHierarchy, | ||
@JsonProperty("derived_group_description") String derivedGroupDescription, @JsonProperty("columnmeta_max") String columnmetaMax, | ||
@JsonProperty("columnmeta_description") String columnmetaDescription, @JsonProperty("derived_study_id") String derivedStudyId, | ||
@JsonProperty("hashed_var_id") String hashedVarId, @JsonProperty("columnmeta_data_type") String columnmetaDataType, | ||
@JsonProperty("derived_var_id") String derivedVarId, @JsonProperty("columnmeta_study_id") String columnmetaStudyId, | ||
@JsonProperty("is_stigmatized") String isStigmatized, @JsonProperty("derived_var_name") String derivedVarName, | ||
@JsonProperty("derived_study_abv_name") String derivedStudyAbvName, | ||
@JsonProperty("derived_study_description") String derivedStudyDescription, | ||
@JsonProperty("columnmeta_var_group_id") String columnmetaVarGroupId, @JsonProperty("derived_group_name") String derivedGroupName, | ||
@JsonProperty("columnmeta_HPDS_PATH") String columnmetaHpdsPathAlternate | ||
) { | ||
public sealed interface Metadata permits ContinuousMetadata, CategoricalMetadata { | ||
} |