Skip to content

Commit

Permalink
Add support for subqueries for the Criteria-based filtering service
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Jun 5, 2023
1 parent de3e4fb commit c6ad099
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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

0 comments on commit c6ad099

Please sign in to comment.