Skip to content

Commit

Permalink
[ALS-7406] Bloat concept type
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina authored and Luke-Sikina committed Sep 25, 2024
1 parent 8cb5c32 commit 83058b9
Showing 11 changed files with 93 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ public List<Concept> getConcepts(Filter filter, Pageable pageable) {
SELECT
concept_node.*,
ds.REF as dataset,
ds.abbreviation AS studyAcronym,
continuous_min.VALUE as min, continuous_max.VALUE as max,
categorical_values.VALUE as values,
allow_filtering.allowFiltering AS allowFiltering,
@@ -95,6 +96,7 @@ public Optional<Concept> getConcept(String dataset, String conceptPath) {
SELECT
concept_node.*,
ds.REF as dataset,
ds.abbreviation AS studyAcronym,
continuous_min.VALUE as min, continuous_max.VALUE as max,
categorical_values.VALUE as values,
allow_filtering.allowFiltering AS allowFiltering,
@@ -215,6 +217,7 @@ WITH RECURSIVE nodes AS (
SELECT
concept_node.*,
ds.REF AS dataset,
ds.abbreviation AS studyAcronym,
continuous_min.VALUE AS min, continuous_max.VALUE AS max,
categorical_values.VALUE AS values,
meta_description.VALUE AS description,
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public CategoricalConcept mapCategorical(ResultSet rs) throws SQLException {
rs.getString("concept_path"), rs.getString("name"),
rs.getString("display"), rs.getString("dataset"), rs.getString("description"),
rs.getString("values") == null ? List.of() : parseValues(rs.getString("values")),
rs.getBoolean("allowFiltering"),
rs.getBoolean("allowFiltering"), rs.getString("studyAcronym"),
null,
null
);
@@ -32,6 +32,7 @@ public ContinuousConcept mapContinuous(ResultSet rs) throws SQLException {
rs.getString("display"), rs.getString("dataset"), rs.getString("description"),
rs.getBoolean("allowFiltering"),
parseMin(rs.getString("values")), parseMax(rs.getString("values")),
rs.getString("studyAcronym"),
null
);
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
public record CategoricalConcept(
String conceptPath, String name, String display, String dataset, String description,

List<String> values, boolean allowFiltering,
List<String> values, boolean allowFiltering, String studyAcronym,

@Nullable
List<Concept> children,
@@ -28,17 +28,20 @@ public record CategoricalConcept(

public CategoricalConcept(
String conceptPath, String name, String display, String dataset, String description, List<String> values,
boolean allowFiltering, @Nullable List<Concept> children, @Nullable Map<String, String> meta
boolean allowFiltering, String studyAcronym, @Nullable List<Concept> children, @Nullable Map<String, String> meta
) {
this(conceptPath, name, display, dataset, description, values, allowFiltering, children, meta, null, null);
this(conceptPath, name, display, dataset, description, values, allowFiltering, studyAcronym, children, meta, null, null);
}

public CategoricalConcept(CategoricalConcept core, Map<String, String> meta) {
this(core.conceptPath, core.name, core.display, core.dataset, core.description, core.values, core.allowFiltering, core.children, meta);
this(
core.conceptPath, core.name, core.display, core.dataset, core.description, core.values,
core.allowFiltering, core.studyAcronym, core.children, meta
);
}

public CategoricalConcept(String conceptPath, String dataset) {
this(conceptPath, "", "", dataset, "", List.of(), false, List.of(), null);
this(conceptPath, "", "", dataset, "", List.of(), false, "", List.of(), null);
}


@@ -50,20 +53,22 @@ public ConceptType type() {

@Override
public CategoricalConcept withChildren(List<Concept> children) {
return new CategoricalConcept(conceptPath, name, display, dataset, description, values, allowFiltering, children, meta);
return new CategoricalConcept(
conceptPath, name, display, dataset, description, values, allowFiltering, studyAcronym, children, meta
);
}

@Override
public Concept withTable(Concept table) {
return new CategoricalConcept(
conceptPath, name, display, dataset, description, values, allowFiltering, children, meta, table, study
conceptPath, name, display, dataset, description, values, allowFiltering, studyAcronym, children, meta, table, study
);
}

@Override
public Concept withStudy(Concept study) {
return new CategoricalConcept(
conceptPath, name, display, dataset, description, values, allowFiltering, children, meta, table, study
conceptPath, name, display, dataset, description, values, allowFiltering, studyAcronym, children, meta, table, study
);
}

Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ public sealed interface Concept
*/
String dataset();

String studyAcronym();

/**
* @return The type of this concept
*/
Original file line number Diff line number Diff line change
@@ -17,6 +17,11 @@ public String display() {
return "Shell. Not for external use.";
}

@Override
public String studyAcronym() {
return "Shell. Not for external use.";
}

@Override
public ConceptType type() {
return ConceptType.Continuous;
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
public record ContinuousConcept(
String conceptPath, String name, String display, String dataset, String description, boolean allowFiltering,

@Nullable Integer min, @Nullable Integer max,
@Nullable Integer min, @Nullable Integer max, String studyAcronym,
Map<String, String> meta,
@Nullable
List<Concept> children,
@@ -25,24 +25,30 @@ public record ContinuousConcept(

public ContinuousConcept(
String conceptPath, String name, String display, String dataset, String description, boolean allowFiltering,
@Nullable Integer min, @Nullable Integer max, Map<String, String> meta, @Nullable List<Concept> children
@Nullable Integer min, @Nullable Integer max, String studyAcronym, Map<String, String> meta, @Nullable List<Concept> children
) {
this(conceptPath, name, display, dataset, description, allowFiltering, min, max, meta, children, null, null);
this(
conceptPath, name, display, dataset, description, allowFiltering,
min, max, studyAcronym, meta, children, null, null
);
}

public ContinuousConcept(ContinuousConcept core, Map<String, String> meta) {
this(core.conceptPath, core.name, core.display, core.dataset, core.description, core.allowFiltering, core.min, core.max, meta, core.children);
this(
core.conceptPath, core.name, core.display, core.dataset, core.description, core.allowFiltering,
core.min, core.max, core.studyAcronym, meta, core.children
);
}

public ContinuousConcept(String conceptPath, String dataset) {
this(conceptPath, "", "", dataset, "", true, null, null, null, List.of());
this(conceptPath, "", "", dataset, "", true, null, null, "", null, List.of());
}

public ContinuousConcept(
String conceptPath, String name, String display, String dataset, String description, boolean allowFiltering,
@Nullable Integer min, @Nullable Integer max, Map<String, String> meta
@Nullable Integer min, @Nullable Integer max, String studyAcronym, Map<String, String> meta
) {
this(conceptPath, name, display, dataset, description, allowFiltering, min, max, meta, null);
this(conceptPath, name, display, dataset, description, allowFiltering, min, max, studyAcronym, meta, null);
}

@JsonProperty("type")
@@ -53,20 +59,24 @@ public ConceptType type() {

@Override
public ContinuousConcept withChildren(List<Concept> children) {
return new ContinuousConcept(conceptPath, name, display, dataset, description, allowFiltering, min, max, meta, children);
return new ContinuousConcept(
conceptPath, name, display, dataset, description, allowFiltering, min, max, studyAcronym, meta, children
);
}

@Override
public Concept withTable(Concept table) {
return new ContinuousConcept(
conceptPath, name, display, dataset, description, allowFiltering, min, max, meta, children, table, study
conceptPath, name, display, dataset, description, allowFiltering,
min, max, studyAcronym, meta, children, table, study
);
}

@Override
public Concept withStudy(Concept study) {
return new ContinuousConcept(
conceptPath, name, display, dataset, description, allowFiltering, min, max, meta, children, table, study
conceptPath, name, display, dataset, description, allowFiltering,
min, max, studyAcronym, meta, children, table, study
);
}

Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ class ConceptControllerTest {
@Test
void shouldListConcepts() {
List<Concept> expected = List.of(
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, null, Map.of()),
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(), Map.of()),
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, Map.of())
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, "", null, Map.of()),
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(), Map.of()),
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, "", Map.of())
);
Filter filter = new Filter(
List.of(new Facet("questionare", "Questionare", "?", "Questionare", 1, null, "category", null)),
@@ -55,7 +55,7 @@ void shouldListConcepts() {
@Test
void shouldGetConceptDetails() {
CategoricalConcept expected =
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(), Map.of());
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(), Map.of());
Mockito.when(conceptService.conceptDetail("my_dataset", "/foo//bar"))
.thenReturn(Optional.of(expected));

@@ -78,11 +78,11 @@ void shouldNotGetConceptDetails() {
@Test
void shouldGetConceptTree() {
Concept fooBar =
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(), Map.of());
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(), Map.of());
Concept fooBaz =
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, Map.of());
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, "", Map.of());
CategoricalConcept foo =
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, List.of(fooBar, fooBaz), Map.of());
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, "", List.of(fooBar, fooBaz), Map.of());

Mockito.when(conceptService.conceptTree("my_dataset", "/foo", 1))
.thenReturn(Optional.of(foo));
@@ -96,11 +96,11 @@ void shouldGetConceptTree() {
@Test
void shouldGetNotConceptTreeForLargeDepth() {
Concept fooBar =
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(), Map.of());
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(), Map.of());
Concept fooBaz =
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, Map.of());
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, "", Map.of());
CategoricalConcept foo =
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, List.of(fooBar, fooBaz), Map.of());
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, "", List.of(fooBar, fooBaz), Map.of());

Mockito.when(conceptService.conceptTree("my_dataset", "/foo", 1))
.thenReturn(Optional.of(foo));
@@ -114,11 +114,11 @@ void shouldGetNotConceptTreeForLargeDepth() {
@Test
void shouldGetNotConceptTreeForNegativeDepth() {
Concept fooBar =
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(), Map.of());
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(), Map.of());
Concept fooBaz =
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, Map.of());
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, "", Map.of());
CategoricalConcept foo =
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, List.of(fooBar, fooBaz), Map.of());
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, "", List.of(fooBar, fooBaz), Map.of());
Mockito.when(conceptService.conceptTree("my_dataset", "/foo", -1))
.thenReturn(Optional.of(foo));

@@ -131,11 +131,11 @@ void shouldGetNotConceptTreeForNegativeDepth() {
@Test
void shouldNotGetConceptTreeWhenConceptDNE() {
Concept fooBar =
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(), Map.of());
new CategoricalConcept("/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(), Map.of());
Concept fooBaz =
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, Map.of());
new ContinuousConcept("/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, "", Map.of());
CategoricalConcept foo =
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, List.of(fooBar, fooBaz), Map.of());
new CategoricalConcept("/foo", "foo", "Foo", "my_dataset", "foo!", List.of(), true, "", List.of(fooBar, fooBaz), Map.of());

Mockito.when(conceptService.conceptTree("my_dataset", "/foo", 1))
.thenReturn(Optional.of(foo));
@@ -148,11 +148,11 @@ void shouldNotGetConceptTreeWhenConceptDNE() {
@Test
void shouldDumpConcepts() {
Concept fooBar = new CategoricalConcept(
"/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, List.of(),
"/foo//bar", "bar", "Bar", "my_dataset", "foo!", List.of("a", "b"), true, "", List.of(),
Map.of("key", "value")
);
Concept fooBaz = new ContinuousConcept(
"/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100,
"/foo//baz", "baz", "Baz", "my_dataset", "foo!", true, 0, 100, "",
Map.of("key", "value")
);
List<Concept> concepts = List.of(fooBar, fooBaz);
Loading

0 comments on commit 83058b9

Please sign in to comment.