Skip to content

Commit

Permalink
Issue 43754: SampleTypeDomainKind.hasNullValues override to filter ou…
Browse files Browse the repository at this point in the history
…t aliquot rows in "can field be made required" check (#2583)

* Override hasNullValues in SampleTypeDomainKind to add where clause filtering out aliquot sample rows from total row count query
  • Loading branch information
cnathe committed Sep 1, 2021
1 parent 82e0414 commit 0291bc9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Expand Up @@ -185,7 +185,7 @@ public boolean hasNullValues(Domain domain, DomainProperty prop)
}
}

private boolean getTotalAndNonBlankSql(Domain domain, DomainProperty prop, SQLFragment allRowsSQL, SQLFragment nonBlankRowsSQL)
protected boolean getTotalAndNonBlankSql(Domain domain, DomainProperty prop, SQLFragment allRowsSQL, SQLFragment nonBlankRowsSQL)
{
if (getStorageSchemaName() == null)
{
Expand Down
26 changes: 26 additions & 0 deletions internal/src/org/labkey/experiment/api/SampleTypeDomainKind.java
Expand Up @@ -32,6 +32,7 @@
import org.labkey.api.data.PropertyStorageSpec;
import org.labkey.api.data.RuntimeSQLException;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.SqlSelector;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.UpdateableTableInfo;
import org.labkey.api.exp.ExperimentException;
Expand All @@ -44,6 +45,7 @@
import org.labkey.api.exp.api.SampleTypeService;
import org.labkey.api.exp.property.AbstractDomainKind;
import org.labkey.api.exp.property.Domain;
import org.labkey.api.exp.property.DomainProperty;
import org.labkey.api.exp.query.ExpSampleTypeTable;
import org.labkey.api.exp.query.SamplesSchema;
import org.labkey.api.gwt.client.DefaultValueType;
Expand Down Expand Up @@ -517,4 +519,28 @@ public SampleTypeDomainKindProperties getDomainKindProperties(GWTDomain domain,
ExpSampleType sampleType = domain != null ? SampleTypeService.get().getSampleType(domain.getDomainURI()) : null;
return new SampleTypeDomainKindProperties(sampleType);
}

@Override
public boolean hasNullValues(Domain domain, DomainProperty prop)
{
SQLFragment allRowsSQL = new SQLFragment();
SQLFragment nonBlankRowsSQL = new SQLFragment();

if (getTotalAndNonBlankSql(domain, prop, allRowsSQL, nonBlankRowsSQL))
{
// Issue 43754: Don't include aliquot rows in the null value check (see ExpMaterialTableImpl.createColumn for IsAliquot)
String table = domain.getStorageTableName();
SQLFragment nonAliquotRowsSQL = new SQLFragment("SELECT * FROM exp.material WHERE LSID IN (")
.append("SELECT LSID FROM " + getStorageSchemaName() + "." + table)
.append(") AND RootMaterialLSID IS NULL");

long totalRows = new SqlSelector(ExperimentService.get().getSchema(), nonAliquotRowsSQL).getRowCount();
long nonBlankRows = new SqlSelector(ExperimentService.get().getSchema(), nonBlankRowsSQL).getRowCount();
return totalRows != nonBlankRows;
}
else
{
return false;
}
}
}

0 comments on commit 0291bc9

Please sign in to comment.