11package org .labkey .mgap .query ;
22
3+ import org .apache .logging .log4j .Logger ;
34import org .jetbrains .annotations .NotNull ;
45import org .jetbrains .annotations .Nullable ;
6+ import org .labkey .api .data .AbstractTableInfo ;
57import org .labkey .api .data .Container ;
68import org .labkey .api .data .ContainerFilter ;
79import org .labkey .api .data .DbSchema ;
810import org .labkey .api .data .DbSchemaType ;
11+ import org .labkey .api .data .JdbcType ;
12+ import org .labkey .api .data .SQLFragment ;
913import org .labkey .api .data .TableInfo ;
14+ import org .labkey .api .gwt .client .FacetingBehaviorType ;
1015import org .labkey .api .ldk .table .ContainerScopedTable ;
1116import org .labkey .api .module .Module ;
1217import org .labkey .api .query .DefaultSchema ;
18+ import org .labkey .api .query .DetailsURL ;
19+ import org .labkey .api .query .ExprColumn ;
1320import org .labkey .api .query .QuerySchema ;
1421import org .labkey .api .query .SimpleUserSchema ;
1522import org .labkey .api .security .User ;
23+ import org .labkey .api .util .logging .LogHelper ;
1624import org .labkey .mgap .mGAPSchema ;
1725
1826/**
1927 * Created by bimber on 3/28/2017.
2028 */
2129public class mGAPUserSchema extends SimpleUserSchema
2230{
31+ private static final Logger _log = LogHelper .getLogger (mGAPUserSchema .class , "mGAP User Schema" );
32+
2333 private mGAPUserSchema (User user , Container container , DbSchema schema )
2434 {
2535 super (mGAPSchema .NAME , null , user , container , schema );
@@ -56,6 +66,10 @@ else if (mGAPSchema.TABLE_VARIANT_CATALOG_RELEASES.equalsIgnoreCase(name))
5666 {
5767 return createWrappedVariantTable (name , sourceTable , cf );
5868 }
69+ else if (mGAPSchema .TABLE_RELEASE_TRACKS .equalsIgnoreCase (name ))
70+ {
71+ return (customizeReleaseTracks (name , sourceTable , cf ));
72+ }
5973
6074 return super .createWrappedTable (name , sourceTable , cf );
6175 }
@@ -64,4 +78,30 @@ private TableInfo createWrappedVariantTable(String name, TableInfo sourceTable,
6478 {
6579 return super .createWrappedTable (name , sourceTable , cf );
6680 }
81+
82+ private TableInfo customizeReleaseTracks (String name , TableInfo sourceTable , ContainerFilter cf )
83+ {
84+ if (sourceTable instanceof AbstractTableInfo ati )
85+ {
86+ String fieldName = "totalSamples" ;
87+ if (ati .getColumn (fieldName ) == null )
88+ {
89+ SQLFragment sql = new SQLFragment ("(SELECT count(distinct t.subjectId) as total FROM " + mGAPSchema .NAME + "." + mGAPSchema .TABLE_RELEASE_TRACK_SUBSETS + " t WHERE t.trackName = " + ExprColumn .STR_TABLE_ALIAS + ".trackName)" );
90+ ExprColumn col = new ExprColumn (ati , name , sql , JdbcType .INTEGER , ati .getColumn ("trackName" ));
91+ col .setLabel ("# Samples" );
92+ col .setFacetingBehaviorType (FacetingBehaviorType .ALWAYS_OFF );
93+ col .setDescription ("This column shows the total number of registered subject IDs for this track" );
94+ col .setURL (DetailsURL .fromString ("/query/executeQuery.view?schemaName=mgap&query.queryName=releaseTrackSubsets&query.trackName~eq=${trackName}" , getContainer ()));
95+ ati .addColumn (col );
96+ }
97+
98+ return createWrappedTable (name , ati , cf );
99+ }
100+ else
101+ {
102+ _log .error ("mGapUserSchema.customizeReleaseTracks was passed a TableInfo that wasnt a AbstractTableInfo. Was: " + sourceTable .getClass ().getName ());
103+ }
104+
105+ return createWrappedTable (name , sourceTable , cf );
106+ }
67107}
0 commit comments