Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for subqueries for the Criteria-based filtering service #715

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import org.hibernate.sql.JoinType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.PlatformTransactionManager;
import ubic.gemma.model.analysis.expression.diff.*;
import ubic.gemma.model.common.description.Characteristic;
import ubic.gemma.model.common.description.DatabaseEntry;
import ubic.gemma.model.common.measurement.Measurement;
import ubic.gemma.model.common.protocol.Protocol;
import ubic.gemma.model.expression.experiment.BioAssaySet;
import ubic.gemma.model.expression.experiment.ExpressionExperiment;
Expand All @@ -41,7 +39,10 @@
import ubic.gemma.persistence.util.*;

import javax.annotation.Nullable;
import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -221,13 +222,13 @@ protected void configureFilterableProperties( FilterablePropertiesConfigurer con
configurer.unregisterEntity( "analysis.protocol.", Protocol.class );

// use the characteristics instead
configurer.registerAlias( "analysis.subsetFactorValue.characteristics.", "sfvc", Characteristic.class, null, 1 );
configurer.registerAlias( "analysis.subsetFactorValue.characteristics.", "sfvc", Characteristic.class, null, 1, true );
configurer.unregisterProperty( "analysis.subsetFactorValue.characteristics.originalValue" );
configurer.unregisterProperty( "analysis.subsetFactorValue.value" );

// baseline is always baseline
configurer.unregisterProperty( "baselineGroup.isBaseline" );
configurer.registerAlias( "baselineGroup.characteristics.", "bc", Characteristic.class, null, 1 );
configurer.registerAlias( "baselineGroup.characteristics.", "bc", Characteristic.class, null, 1, true );
configurer.unregisterProperty( "baselineGroup.characteristics.originalValue" );
configurer.unregisterProperty( "baselineGroup.value" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import static java.util.Objects.requireNonNull;

/**
* Utilities for integrating {@link Filter} with Hibernate {@link Criteria} API.
Expand Down Expand Up @@ -75,7 +76,8 @@ private static Criterion formRestrictionClause( Filter filter ) {
return Restrictions.ne( property, filter.getRequiredValue() );
}
case like:
return Restrictions.like( property, escapeLike( ( String ) Objects.requireNonNull( filter.getRequiredValue(), "Required value cannot be null for the like operator." ) ), MatchMode.START );
return Restrictions.like( property, escapeLike( ( String ) requireNonNull( filter.getRequiredValue(),
"Required value cannot be null for the like operator." ) ), MatchMode.START );
case lessThan:
return Restrictions.lt( property, filter.getRequiredValue() );
case greaterThan:
Expand All @@ -85,8 +87,18 @@ private static Criterion formRestrictionClause( Filter filter ) {
case greaterOrEq:
return Restrictions.ge( property, filter.getRequiredValue() );
case in:
return Restrictions.in( property, ( Collection<?> ) Objects.requireNonNull( filter.getRequiredValue(),
return Restrictions.in( property, ( Collection<?> ) requireNonNull( filter.getRequiredValue(),
"Required value cannot be null for a collection." ) );
case inSubquery:
Subquery subquery = ( Subquery ) requireNonNull( filter.getRequiredValue(),
"Required value cannot be null for a subquery." );
DetachedCriteria dc = DetachedCriteria.forEntityName( subquery.getEntityName() )
.setProjection( Projections.id() );
for ( Subquery.Alias a : subquery.getAliases() ) {
dc.createAlias( a.getPropertyName(), a.getAlias() );
}
dc.add( formRestrictionClause( subquery.getFilter() ) );
return Subqueries.propertyIn( "id", dc );
default:
throw new IllegalStateException( "Unexpected operator for filter: " + filter.getOperator() );
}
Expand Down