Skip to content

Commit

Permalink
🚨 Update peristence module tests to pass within springboot framework
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed Sep 1, 2023
1 parent d60076f commit 5a150a6
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ List<ClinicalData> getSampleClinicalData(List<String> studyIds, List<String> sam
BaseMeta getMetaSampleClinicalData(List<String> studyIds, List<String> sampleIds, List<String> attributeIds);

List<ClinicalData> getPatientClinicalData(List<String> studyIds, List<String> patientIds, List<String> attributeIds,
String projection, Integer limit, Integer offset, String sortby,
String projection, Integer limit, Integer offset, String sortBy,
String direction);

List<ClinicalData> getSampleClinicalTable(List<String> studyIds, List<String> sampleIds, String projection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
INNER JOIN cancer_study ON cancer_study.CANCER_STUDY_ID = genetic_profile.CANCER_STUDY_ID
INNER JOIN reference_genome_gene ON reference_genome_gene.ENTREZ_GENE_ID = cna_event.ENTREZ_GENE_ID
INNER JOIN sample ON sample_cna_event.SAMPLE_ID = sample.INTERNAL_ID
AND reference_genome_gene.reference_genome_id = cancer_study.reference_genome_id
AND reference_genome_gene.REFERENCE_GENOME_ID = cancer_study.REFERENCE_GENOME_ID
<where>
<choose>
<when test="cnaTypes.hasNone()">NULL</when>
Expand Down Expand Up @@ -401,11 +401,11 @@
gene.HUGO_GENE_SYMBOL,
mutation_event.MUTATION_TYPE
FROM mutation
INNER JOIN mutation_event ON mutation_event.mutation_event_id = mutation.mutation_event_id
INNER JOIN gene ON mutation.entrez_gene_id = gene.entrez_gene_id
INNER JOIN genetic_profile ON mutation.genetic_profile_id = genetic_profile.genetic_profile_id
INNER JOIN sample ON sample.internal_id = mutation.sample_id
INNER JOIN patient ON sample.patient_id = patient.internal_id
INNER JOIN mutation_event ON mutation_event.MUTATION_EVENT_ID = mutation.MUTATION_EVENT_ID
INNER JOIN gene ON mutation.ENTREZ_GENE_ID = gene.ENTREZ_GENE_ID
INNER JOIN genetic_profile ON mutation.GENETIC_PROFILE_ID = genetic_profile.GENETIC_PROFILE_ID
INNER JOIN sample ON sample.INTERNAL_ID = mutation.SAMPLE_ID
INNER JOIN patient ON sample.PATIENT_ID = patient.INTERNAL_ID
<include refid="fromIncludeCustomAnnotationsMutation"/>
<where>
<choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@

<mapper namespace="org.cbioportal.persistence.mybatis.ClinicalDataMapper">

<!-- TODO duplicate of select in ClinicalAttributeMapper - remove-->
<!-- somehow the namespace mechanism does not work for this mapper xml-->
<sql id="selectClinicalAttribute">
clinical_attribute_meta.ATTR_ID AS "${prefix}attrId",
cancer_study.CANCER_STUDY_IDENTIFIER AS "${prefix}cancerStudyIdentifier",
clinical_attribute_meta.CANCER_STUDY_ID AS "${prefix}cancerStudyId",
clinical_attribute_meta.PATIENT_ATTRIBUTE AS "${prefix}patientAttribute",
clinical_attribute_meta.DISPLAY_NAME AS "${prefix}displayName"
<if test="projection == 'SUMMARY' || projection == 'DETAILED'">
,
clinical_attribute_meta.DESCRIPTION AS "${prefix}description",
clinical_attribute_meta.DATATYPE AS "${prefix}datatype",
clinical_attribute_meta.PRIORITY AS "${prefix}priority"
</if>
</sql>


<sql id="selectSample">
clinical_sample.INTERNAL_ID AS "${prefix}internalId",
sample.STABLE_ID AS "${prefix}sampleId",
Expand All @@ -32,7 +15,7 @@
</if>
<if test="projection == 'DETAILED'">
,
<include refid="selectClinicalAttribute">
<include refid="org.cbioportal.persistence.mybatis.ClinicalAttributeMapper.select">
<property name="prefix" value="${prefix}clinicalAttribute."/>
</include>
</if>
Expand All @@ -50,12 +33,12 @@
</if>
<if test="projection == 'DETAILED'">
,
<include refid="selectClinicalAttribute">
<include refid="org.cbioportal.persistence.mybatis.ClinicalAttributeMapper.select">
<property name="prefix" value="${prefix}clinicalAttribute."/>
</include>
</if>
</if>
</sql>
</sql>

<sql id="fromSample">
FROM clinical_sample
Expand Down Expand Up @@ -149,7 +132,7 @@
INNER JOIN type_of_cancer ON cancer_study.TYPE_OF_CANCER_ID = type_of_cancer.TYPE_OF_CANCER_ID
</if>
<include refid="whereSample"/>
<if test="_parameter.containsKey('sortBy') and sortBy != null and projection != 'ID'">
<if test="sortBy != null and projection != 'ID'">
ORDER BY "${sortBy}" ${direction}
</if>
<if test="projection == 'ID'">
Expand Down Expand Up @@ -179,7 +162,7 @@
INNER JOIN type_of_cancer ON cancer_study.TYPE_OF_CANCER_ID = type_of_cancer.TYPE_OF_CANCER_ID
</if>
<include refid="wherePatient"/>
<if test="_parameter.containsKey('sortBy') and sortBy != null and projection != 'ID'">
<if test="sortBy != null and projection != 'ID'">
ORDER BY ${sortBy} ${direction}
</if>
<if test="projection == 'ID'">
Expand Down Expand Up @@ -261,7 +244,7 @@
<sql id="whereSampleSearchAndPagination">
INNER JOIN (
SELECT DISTINCT clinical_sample.INTERNAL_ID
<if test="_parameter.containsKey('sortBy') and sortBy != null">
<if test="sortBy != null">
<if test="sortBy == 'sampleId'">
, sample.STABLE_ID AS SORT_BY
</if>
Expand All @@ -280,11 +263,11 @@
</if>
<include refid="fromSampleAndClinicalPatient"/>
<include refid="whereSample"/>
<if test="_parameter.containsKey('searchTerm') and searchTerm != null and not searchTerm.isBlank()">
<if test="searchTerm != null and not searchTerm.isBlank()">
AND
clinical_sample.ATTR_VALUE LIKE CONCAT('%', #{searchTerm}, '%')
</if>
<if test="_parameter.containsKey('sortBy') and sortBy != null">
<if test=" sortBy != null">
<!-- Put 'NULL samples' last: -->
<choose>
<when test="_databaseId == 'mysql'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
from sample
Inner Join patient on sample.PATIENT_ID = patient.INTERNAL_ID
Inner join clinical_event on clinical_event.PATIENT_ID = patient.INTERNAL_ID
Inner Join cancer_study on cancer_study.CANCER_STUDY_ID = patient.cancer_STUDY_ID
Inner Join cancer_study on cancer_study.CANCER_STUDY_ID = patient.CANCER_STUDY_ID
<where>
<if test="sampleIds == null and studyIds != null">
cancer_study.CANCER_STUDY_IDENTIFIER IN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@

<mapper namespace="org.cbioportal.persistence.mybatis.MolecularProfileMapper">

<!-- TODO duplicate of select in StudyMapper - remove-->
<!-- somehow the namespace import mechanism does not work for this mapper xml-->
<sql id="selectStudy">
cancer_study.CANCER_STUDY_ID AS "${prefix}cancerStudyId",
cancer_study.CANCER_STUDY_IDENTIFIER AS "${prefix}cancerStudyIdentifier"
<if test="projection == 'SUMMARY' || projection == 'DETAILED'">
,
cancer_study.TYPE_OF_CANCER_ID AS "${prefix}typeOfCancerId",
cancer_study.NAME AS "${prefix}name",
cancer_study.DESCRIPTION AS "${prefix}description",
cancer_study.PUBLIC AS "${prefix}publicStudy",
cancer_study.PMID AS "${prefix}pmid",
cancer_study.CITATION AS "${prefix}citation",
cancer_study.GROUPS AS "${prefix}groups",
cancer_study.STATUS AS "${prefix}status",
cancer_study.IMPORT_DATE AS "${prefix}importDate",
reference_genome.NAME AS "${prefix}referenceGenome"
</if>
</sql>

<sql id="select">
genetic_profile.GENETIC_PROFILE_ID AS "${prefix}molecularProfileId",
genetic_profile.STABLE_ID AS "${prefix}stableId",
Expand All @@ -42,7 +22,7 @@
</if>
<if test="projection == 'DETAILED'">
,
<include refid="selectStudy">
<include refid="org.cbioportal.persistence.mybatis.StudyMapper.select">
<property name="prefix" value="${prefix}cancerStudy."/>
</include>
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
reference_genome_gene.REFERENCE_GENOME_ID AS "${prefix}referenceGenomeId"
<if test="projection == 'SUMMARY' || projection == 'DETAILED'">
,
gene.hugo_gene_symbol AS "${prefix}hugoGeneSymbol",
gene.HUGO_GENE_SYMBOL AS "${prefix}hugoGeneSymbol",
reference_genome_gene.CHR AS "${prefix}chromosome",
reference_genome_gene.CYTOBAND AS "${prefix}cytoband",
reference_genome_gene.START AS "${prefix}start",
Expand All @@ -24,7 +24,7 @@
<property name="prefix" value=""/>
</include>
FROM reference_genome_gene
INNER JOIN gene on gene.entrez_gene_id = reference_genome_gene.entrez_gene_id
INNER JOIN gene on gene.ENTREZ_GENE_ID = reference_genome_gene.ENTREZ_GENE_ID
<if test="genomeName != null">
INNER JOIN reference_genome ON reference_genome.REFERENCE_GENOME_ID = reference_genome_gene.REFERENCE_GENOME_ID
WHERE reference_genome.NAME = #{genomeName}
Expand All @@ -38,7 +38,7 @@
</include>
FROM reference_genome_gene
INNER JOIN reference_genome ON reference_genome.REFERENCE_GENOME_ID = reference_genome_gene.REFERENCE_GENOME_ID
INNER JOIN gene ON gene.entrez_gene_id = reference_genome_gene.entrez_gene_id
INNER JOIN gene ON gene.ENTREZ_GENE_ID = reference_genome_gene.ENTREZ_GENE_ID
<where>
<if test="geneIds != null and !geneIds.isEmpty() and genomeName != null">
gene.HUGO_GENE_SYMBOL IN
Expand All @@ -60,7 +60,7 @@
</include>
FROM reference_genome_gene
INNER JOIN reference_genome ON reference_genome.REFERENCE_GENOME_ID = reference_genome_gene.REFERENCE_GENOME_ID
INNER JOIN gene ON gene.entrez_gene_id = reference_genome_gene.entrez_gene_id
INNER JOIN gene ON gene.ENTREZ_GENE_ID = reference_genome_gene.ENTREZ_GENE_ID
<where>
<if test="geneIds != null and !geneIds.isEmpty() and genomeName != null">
gene.ENTREZ_GENE_ID IN
Expand All @@ -82,7 +82,7 @@
</include>
FROM reference_genome_gene
INNER JOIN reference_genome ON reference_genome.REFERENCE_GENOME_ID = reference_genome_gene.REFERENCE_GENOME_ID
INNER JOIN gene ON gene.entrez_gene_id = reference_genome_gene.entrez_gene_id
INNER JOIN gene ON gene.ENTREZ_GENE_ID = reference_genome_gene.ENTREZ_GENE_ID
<where>
<if test="genomeName != null and geneId != null">
reference_genome.NAME = #{genomeName} AND gene.ENTREZ_GENE_ID = #{geneId}
Expand All @@ -95,11 +95,11 @@
<property name="prefix" value=""/>
</include>
FROM reference_genome_gene
INNER JOIN gene on gene.entrez_gene_id = reference_genome_gene.entrez_gene_id
INNER JOIN gene on gene.ENTREZ_GENE_ID = reference_genome_gene.ENTREZ_GENE_ID
INNER JOIN reference_genome ON reference_genome.REFERENCE_GENOME_ID = reference_genome_gene.REFERENCE_GENOME_ID
<where>
<if test="genomeName != null and geneticEntityId != null">
reference_genome.NAME = #{genomeName} AND gene.genetic_entity_id = #{geneticEntityId}
reference_genome.NAME = #{genomeName} AND gene.GENETIC_ENTITY_ID = #{geneticEntityId}
</if>
<if test="genomeName == null or geneticEntityId == null">
FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
sample.SAMPLE_TYPE AS "${prefix}sampleType",
sample.PATIENT_ID AS "${prefix}patientId"
</if>
<!--TODO: This causes an error while referencing another sql statement. Need to fix -->
<!-- <if test="projection == 'DETAILED'">-->
<!-- ,-->
<!-- <include refid="org.cbioportal.persistence.mybatis.PatientMapper.select">-->
<!-- <property name="prefix" value="${prefix}patient."/>-->
<!-- </include>-->
<!-- </if>-->
<if test="projection == 'DETAILED'">
,
<include refid="org.cbioportal.persistence.mybatis.PatientMapper.select">
<property name="prefix" value="${prefix}patient."/>
</include>
</if>
</sql>

<sql id="from">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@
</if>
</sql>

<!--TODO fix duplicate -->
<sql id="CancerTypeMapperSelect">
type_of_cancer.TYPE_OF_CANCER_ID AS "${prefix}typeOfCancerId"
<if test="projection == 'SUMMARY' || projection == 'DETAILED'">
,
type_of_cancer.NAME AS "${prefix}name",
type_of_cancer.DEDICATED_COLOR AS "${prefix}dedicatedColor",
type_of_cancer.SHORT_NAME AS "${prefix}shortName",
type_of_cancer.PARENT AS "${prefix}parent"
</if>
</sql>

<sql id="selectDetailed">
,
Expand All @@ -45,8 +34,8 @@
COUNT(CASE WHEN sample_list.STABLE_ID = CONCAT(cancer_study.CANCER_STUDY_IDENTIFIER,'_rppa') THEN 1 ELSE NULL END) AS rppaSampleCount,
COUNT(CASE WHEN sample_list.STABLE_ID = CONCAT(cancer_study.CANCER_STUDY_IDENTIFIER,'_protein_quantification') THEN 1 ELSE NULL END) AS massSpectrometrySampleCount,
COUNT(CASE WHEN sample_list.STABLE_ID = CONCAT(cancer_study.CANCER_STUDY_IDENTIFIER,'_3way_complete') THEN 1 ELSE NULL END) AS completeSampleCount,
IFNULL(treatment.count, 0 ) as treatmentCount,
<include refid="CancerTypeMapperSelect">
IFNULL(treatment.count, 0 ) as treatmentCount,
<include refid="org.cbioportal.persistence.mybatis.CancerTypeMapper.select">
<property name="prefix" value="typeOfCancer."/>
</include>
</sql>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cbioportal.persistence.mybatis;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -16,6 +17,7 @@
import org.cbioportal.model.QueryElement;
import org.cbioportal.model.util.Select;
import org.cbioportal.persistence.mybatis.config.TestConfig;
import org.h2.tools.Server;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ public void getAllClinicalDataOfSampleInStudyNullAttributeSummaryProjection() {
"TCGA-A1-A0SB-01", null, "SUMMARY", null, null, null, null);

Assert.assertEquals(4, result.size());
ClinicalData data = result.get(0);
Assert.assertEquals("DAYS_TO_COLLECTION", data.getAttrId());
Assert.assertEquals("276", data.getAttrValue());
Assert.assertEquals((Integer) 1, data.getInternalId());
Assert.assertNull(data.getClinicalAttribute());
Optional<ClinicalData> clinicalDataOptional =
result.stream().filter(r -> r.getAttrId().equals("DAYS_TO_COLLECTION")).findAny();
Assert.assertTrue(clinicalDataOptional.isPresent());
ClinicalData clinicalAttribute = clinicalDataOptional.get();

Assert.assertEquals("276", clinicalAttribute.getAttrValue());
Assert.assertEquals((Integer) 1, clinicalAttribute.getInternalId());
Assert.assertNull(clinicalAttribute.getClinicalAttribute());
}

@Test
Expand Down Expand Up @@ -230,7 +233,10 @@ public void getAllClinicalDataInStudyNullAttributeSummaryProjection() {
null, PersistenceConstants.SAMPLE_CLINICAL_DATA_TYPE, "SUMMARY", null, null, null, null);

Assert.assertEquals(8, result.size());
ClinicalData data = result.get(0);
Optional<ClinicalData> clinicalDataOptional =
result.stream().filter(r -> r.getAttrId().equals("DAYS_TO_COLLECTION")).findAny();
Assert.assertTrue(clinicalDataOptional.isPresent());
ClinicalData data = clinicalDataOptional.get();
Assert.assertEquals("DAYS_TO_COLLECTION", data.getAttrId());
Assert.assertEquals("276", data.getAttrValue());
Assert.assertEquals((Integer) 1, data.getInternalId());
Expand Down Expand Up @@ -325,14 +331,6 @@ public void fetchAllClinicalDataInStudy() {
PersistenceConstants.SAMPLE_CLINICAL_DATA_TYPE, "SUMMARY");

Assert.assertEquals(8, result.size());
ClinicalData data = result.get(0);
Assert.assertEquals("DAYS_TO_COLLECTION", data.getAttrId());
Assert.assertEquals("276", data.getAttrValue());
Assert.assertEquals((Integer) 1, data.getInternalId());
Assert.assertNull(data.getClinicalAttribute());
Assert.assertEquals(6, result.size());


Optional<ClinicalData> clinicalDataOptional =
result.stream().filter(r -> r.getAttrId().equals("DAYS_TO_COLLECTION")).findAny();
Assert.assertTrue(clinicalDataOptional.isPresent());
Expand All @@ -359,13 +357,6 @@ public void fetchClinicalDataNullAttributeSummaryProjection() {
PersistenceConstants.SAMPLE_CLINICAL_DATA_TYPE, "SUMMARY");

Assert.assertEquals(8, result.size());
ClinicalData data = result.get(0);
Assert.assertEquals("DAYS_TO_COLLECTION", data.getAttrId());
Assert.assertEquals("276", data.getAttrValue());
Assert.assertEquals((Integer) 1, data.getInternalId());
Assert.assertNull(data.getClinicalAttribute());
Assert.assertEquals(6, result.size());

Optional<ClinicalData> clinicalDataOptional =
result.stream().filter(r -> r.getAttrId().equals("DAYS_TO_COLLECTION")).findAny();
Assert.assertTrue(clinicalDataOptional.isPresent());
Expand Down
Loading

0 comments on commit 5a150a6

Please sign in to comment.