dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41156
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20959: rename ContainsOperator => LikeOperator, adds MatchMode enum (start, end, anywhere, exact)
------------------------------------------------------------
revno: 20959
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-11-05 13:07:23 +0700
message:
rename ContainsOperator => LikeOperator, adds MatchMode enum (start, end, anywhere, exact)
removed:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ContainsOperator.java
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/MatchMode.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restrictions.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/OperatorTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java 2015-11-05 05:04:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java 2015-11-05 06:07:23 +0000
@@ -30,6 +30,7 @@
import com.google.common.collect.Lists;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.query.operators.MatchMode;
import org.hisp.dhis.schema.Property;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
@@ -210,11 +211,11 @@
}
case "like":
{
- return Restrictions.like( split[0], value );
+ return Restrictions.ilike( split[0], value, MatchMode.ANYWHERE );
}
case "ilike":
{
- return Restrictions.ilike( split[0], value );
+ return Restrictions.ilike( split[0], value, MatchMode.ANYWHERE );
}
case "in":
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restrictions.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restrictions.java 2015-11-05 05:04:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restrictions.java 2015-11-05 06:07:23 +0000
@@ -29,13 +29,14 @@
*/
import org.hisp.dhis.query.operators.BetweenOperator;
-import org.hisp.dhis.query.operators.ContainsOperator;
import org.hisp.dhis.query.operators.EqualOperator;
import org.hisp.dhis.query.operators.GreaterEqualOperator;
import org.hisp.dhis.query.operators.GreaterThanOperator;
import org.hisp.dhis.query.operators.InOperator;
import org.hisp.dhis.query.operators.LessEqualOperator;
import org.hisp.dhis.query.operators.LessThanOperator;
+import org.hisp.dhis.query.operators.LikeOperator;
+import org.hisp.dhis.query.operators.MatchMode;
import org.hisp.dhis.query.operators.NotEqualOperator;
import org.hisp.dhis.query.operators.NotNullOperator;
import org.hisp.dhis.query.operators.NullOperator;
@@ -82,15 +83,14 @@
return new Restriction( path, new BetweenOperator( lside, rside ) );
}
- // Map like to ilike for the moment, since like in the web-api is actually ilike..
- public static Restriction like( String path, Object value )
+ public static Restriction like( String path, String value, MatchMode matchMode )
{
- return new Restriction( path, new ContainsOperator( value, false ) );
+ return new Restriction( path, new LikeOperator( value, true, matchMode ) );
}
- public static Restriction ilike( String path, Object value )
+ public static Restriction ilike( String path, String value, MatchMode matchMode )
{
- return new Restriction( path, new ContainsOperator( value, false ) );
+ return new Restriction( path, new LikeOperator( value, false, matchMode ) );
}
public static Restriction in( String path, Collection<?> values )
=== removed file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ContainsOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ContainsOperator.java 2015-11-05 03:55:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ContainsOperator.java 1970-01-01 00:00:00 +0000
@@ -1,87 +0,0 @@
-package org.hisp.dhis.query.operators;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.MatchMode;
-import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.query.Typed;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class ContainsOperator extends Operator
-{
- private final boolean caseSensitive;
-
- public ContainsOperator( Object arg, boolean caseSensitive )
- {
- super( Typed.from( String.class ), arg );
- this.caseSensitive = caseSensitive;
- }
-
- @Override
- public Criterion getHibernateCriterion( String propertyName )
- {
- if ( caseSensitive )
- {
- return Restrictions.like( propertyName, String.valueOf( args.get( 0 ) ), MatchMode.ANYWHERE );
- }
- else
- {
- return Restrictions.ilike( propertyName, String.valueOf( args.get( 0 ) ), MatchMode.ANYWHERE );
- }
- }
-
- @Override
- public boolean test( Object value )
- {
- if ( args.isEmpty() || value == null )
- {
- return false;
- }
-
- if ( String.class.isInstance( value ) )
- {
- String s1 = getValue( String.class );
- String s2 = (String) value;
-
- if ( caseSensitive )
- {
- return s1 != null && s2.contains( s1 );
- }
- else
- {
- return s1 != null && s2.toLowerCase().contains( s1.toLowerCase() );
- }
- }
-
- return false;
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java 2015-11-05 05:04:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java 2015-11-05 06:07:23 +0000
@@ -40,9 +40,9 @@
*/
public class InOperator extends Operator
{
- public InOperator( Object arg )
+ public InOperator( Collection<?> arg )
{
- super( Typed.from( String.class, Boolean.class, Number.class, Date.class, Enum.class ), arg );
+ super( Typed.from( Collection.class ), arg );
}
@Override
@@ -55,14 +55,14 @@
@SuppressWarnings( "unchecked" )
public boolean test( Object value )
{
- Collection<String> items = getValue( Collection.class );
+ Collection<?> items = getValue( Collection.class );
if ( items == null || value == null )
{
return false;
}
- for ( String item : items )
+ for ( Object item : items )
{
if ( compare( item, value ) )
{
@@ -73,7 +73,7 @@
return false;
}
- private boolean compare( String item, Object object )
+ private boolean compare( Object item, Object object )
{
if ( String.class.isInstance( object ) )
{
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java 2015-11-05 06:07:23 +0000
@@ -0,0 +1,110 @@
+package org.hisp.dhis.query.operators;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.MatchMode;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.query.Typed;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class LikeOperator extends Operator
+{
+ private final boolean caseSensitive;
+
+ private final MatchMode matchMode;
+
+ public LikeOperator( String arg, boolean caseSensitive, org.hisp.dhis.query.operators.MatchMode matchMode )
+ {
+ super( Typed.from( String.class ), arg );
+ this.caseSensitive = caseSensitive;
+ this.matchMode = getMatchMode( matchMode );
+ }
+
+ @Override
+ public Criterion getHibernateCriterion( String propertyName )
+ {
+ if ( caseSensitive )
+ {
+ return Restrictions.like( propertyName, String.valueOf( args.get( 0 ) ), matchMode );
+ }
+ else
+ {
+ return Restrictions.ilike( propertyName, String.valueOf( args.get( 0 ) ), matchMode );
+ }
+ }
+
+ @Override
+ public boolean test( Object value )
+ {
+ if ( args.isEmpty() || value == null )
+ {
+ return false;
+ }
+
+ if ( String.class.isInstance( value ) )
+ {
+ String s1 = caseSensitive ? getValue( String.class ) : getValue( String.class ).toLowerCase();
+ String s2 = caseSensitive ? (String) value : ((String) value).toLowerCase();
+
+ switch ( matchMode )
+ {
+ case EXACT:
+ return s1.equals( s2 );
+ case START:
+ return s1.startsWith( s2 );
+ case END:
+ return s1.endsWith( s2 );
+ case ANYWHERE:
+ return s1.contains( s2 );
+ }
+ }
+
+ return false;
+ }
+
+ private MatchMode getMatchMode( org.hisp.dhis.query.operators.MatchMode matchMode )
+ {
+ switch ( matchMode )
+ {
+ case EXACT:
+ return MatchMode.EXACT;
+ case START:
+ return MatchMode.START;
+ case END:
+ return MatchMode.END;
+ case ANYWHERE:
+ return MatchMode.ANYWHERE;
+ }
+
+ return null;
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/MatchMode.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/MatchMode.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/MatchMode.java 2015-11-05 06:07:23 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.query.operators;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public enum MatchMode
+{
+ EXACT, START, END, ANYWHERE
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/OperatorTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/OperatorTest.java 2015-11-04 09:50:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/OperatorTest.java 2015-11-05 06:07:23 +0000
@@ -29,13 +29,14 @@
*/
import org.hisp.dhis.query.operators.BetweenOperator;
-import org.hisp.dhis.query.operators.ContainsOperator;
import org.hisp.dhis.query.operators.EqualOperator;
import org.hisp.dhis.query.operators.GreaterEqualOperator;
import org.hisp.dhis.query.operators.GreaterThanOperator;
import org.hisp.dhis.query.operators.InOperator;
import org.hisp.dhis.query.operators.LessEqualOperator;
import org.hisp.dhis.query.operators.LessThanOperator;
+import org.hisp.dhis.query.operators.LikeOperator;
+import org.hisp.dhis.query.operators.MatchMode;
import org.hisp.dhis.query.operators.NotEqualOperator;
import org.hisp.dhis.query.operators.NotNullOperator;
import org.hisp.dhis.query.operators.NullOperator;
@@ -207,31 +208,9 @@
}
@Test
- public void testILikeValidTypes()
- {
- ContainsOperator operator = new ContainsOperator( "operator", false );
-
- assertTrue( operator.isValid( String.class ) );
- assertFalse( operator.isValid( Number.class ) );
- assertFalse( operator.isValid( Date.class ) );
- assertFalse( operator.isValid( Boolean.class ) );
- assertFalse( operator.isValid( Collection.class ) );
- }
-
- @Test
- public void testILike()
- {
- ContainsOperator operator = new ContainsOperator( "operator", false );
-
- assertTrue( operator.test( "operator" ) );
- assertTrue( operator.test( "OPERATOR" ) );
- assertFalse( operator.test( "abc" ) );
- }
-
- @Test
public void testLikeValidTypes()
{
- ContainsOperator operator = new ContainsOperator( "operator", true );
+ LikeOperator operator = new LikeOperator( "operator", true, MatchMode.ANYWHERE );
assertTrue( operator.isValid( String.class ) );
assertFalse( operator.isValid( Number.class ) );
@@ -241,13 +220,63 @@
}
@Test
- public void testLike()
- {
- ContainsOperator operator = new ContainsOperator( "operator", true );
-
- assertTrue( operator.test( "operator" ) );
- assertFalse( operator.test( "OPERATOR" ) );
- assertFalse( operator.test( "abc" ) );
+ public void testLikeAnywhere()
+ {
+ LikeOperator operator = new LikeOperator( "operator", true, MatchMode.ANYWHERE );
+
+ assertTrue( operator.test( "pera" ) );
+ assertFalse( operator.test( "PERA" ) );
+ assertFalse( operator.test( "abc" ) );
+ }
+
+ @Test
+ public void testLikeStart()
+ {
+ LikeOperator operator = new LikeOperator( "operator", true, MatchMode.START );
+
+ assertTrue( operator.test( "ope" ) );
+ assertFalse( operator.test( "OPE" ) );
+ assertFalse( operator.test( "abc" ) );
+ }
+
+ @Test
+ public void testLikeEnd()
+ {
+ LikeOperator operator = new LikeOperator( "operator", true, MatchMode.END );
+
+ assertTrue( operator.test( "or" ) );
+ assertFalse( operator.test( "OPERA" ) );
+ assertFalse( operator.test( "opera" ) );
+ }
+
+ @Test
+ public void testILikeAnywhere()
+ {
+ LikeOperator operator = new LikeOperator( "operator", false, MatchMode.ANYWHERE );
+
+ assertTrue( operator.test( "pera" ) );
+ assertTrue( operator.test( "PERA" ) );
+ assertFalse( operator.test( "abc" ) );
+ }
+
+ @Test
+ public void testILikeStart()
+ {
+ LikeOperator operator = new LikeOperator( "operator", false, MatchMode.START );
+
+ assertTrue( operator.test( "ope" ) );
+ assertTrue( operator.test( "OPE" ) );
+ assertFalse( operator.test( "ator" ) );
+ }
+
+ @Test
+ public void testILikeEnd()
+ {
+ LikeOperator operator = new LikeOperator( "operator", false, MatchMode.END );
+
+ assertTrue( operator.test( "ator" ) );
+ assertTrue( operator.test( "ATOR" ) );
+ assertFalse( operator.test( "opera" ) );
}
@Test
@@ -349,19 +378,14 @@
@Test
public void testInValidTypes()
{
- InOperator operator = new InOperator( "[1,2,3]" );
-
- assertTrue( operator.isValid( String.class ) );
- assertTrue( operator.isValid( Number.class ) );
- assertTrue( operator.isValid( Date.class ) );
- assertTrue( operator.isValid( Boolean.class ) );
- assertTrue( operator.isValid( Enum.class ) );
+ InOperator operator = new InOperator( Arrays.asList( 1, 2, 3 ) );
+ assertTrue( operator.isValid( Collection.class ) );
}
@Test
public void testInInt()
{
- InOperator operator = new InOperator( "[1,2,3]" );
+ InOperator operator = new InOperator( Arrays.asList( 1, 2, 3 ) );
assertFalse( operator.test( 0 ) );
assertTrue( operator.test( 1 ) );
@@ -373,7 +397,7 @@
@Test
public void testInString()
{
- InOperator operator = new InOperator( "[b,c,d]" );
+ InOperator operator = new InOperator( Arrays.asList( "b", "c", "d" ) );
assertFalse( operator.test( "a" ) );
assertTrue( operator.test( "b" ) );
@@ -385,7 +409,7 @@
@Test
public void testInEnum()
{
- InOperator operator = new InOperator( "[A,B]" );
+ InOperator operator = new InOperator( Arrays.asList( "A", "B" ) );
assertTrue( operator.test( TestEnum.A ) );
assertTrue( operator.test( TestEnum.B ) );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java 2015-11-04 03:03:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java 2015-11-05 06:07:23 +0000
@@ -34,6 +34,7 @@
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.query.operators.MatchMode;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
import org.jfree.data.time.Year;
@@ -205,7 +206,7 @@
{
createDataElements();
Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
- query.add( Restrictions.like( "name", "%F" ) );
+ query.add( Restrictions.like( "name", "F", MatchMode.ANYWHERE ) );
List<? extends IdentifiableObject> objects = queryService.query( query );
assertEquals( 1, objects.size() );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryTest.java 2015-11-05 05:04:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryTest.java 2015-11-05 06:07:23 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.query.operators.MatchMode;
import org.hisp.dhis.schema.Property;
import org.hisp.dhis.schema.Schema;
import org.junit.Test;
@@ -75,7 +76,7 @@
{
Query query = Query.from( createSchema() );
query.add( Restrictions.eq( "id", "anc" ) );
- query.add( Restrictions.like( "name", "anc" ) );
+ query.add( Restrictions.like( "name", "anc", MatchMode.ANYWHERE ) );
query.add( Restrictions.eq( "code", "anc" ) );
assertEquals( 3, query.getCriterions().size() );