← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20950: adds getHibernateCriterion to Operator classes, will allow QueryEngine to get Hibernate Criterion...

 

------------------------------------------------------------
revno: 20950
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-11-04 16:45:59 +0700
message:
  adds getHibernateCriterion to Operator classes, will allow QueryEngine to get Hibernate Criterion directly from operator itself
removed:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILikeOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java
added:
  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/IContainsOperator.java
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.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/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/OperatorTest.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/operators/BetweenOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/BetweenOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.between( propertyName, args.get( 0 ), args.get( 1 ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         if ( args.isEmpty() || value == null )

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ContainsOperator.java	2015-11-04 09:45:59 +0000
@@ -0,0 +1,70 @@
+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
+{
+    public ContainsOperator( String arg )
+    {
+        super( Typed.from( String.class ), arg );
+    }
+
+    @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.like( propertyName, 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;
+
+            return s1 != null && s2.contains( s1 );
+        }
+
+        return false;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java	2015-11-04 09:24:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/EqualOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.eq( propertyName, args.get( 0 ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         if ( args.isEmpty() || value == null )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterEqualOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.ge( propertyName, args.get( 0 ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         if ( args.isEmpty() || value == null )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/GreaterThanOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.gt( propertyName, args.get( 0 ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         if ( args.isEmpty() || value == null )

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/IContainsOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/IContainsOperator.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/IContainsOperator.java	2015-11-04 09:45:59 +0000
@@ -0,0 +1,70 @@
+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 IContainsOperator extends Operator
+{
+    public IContainsOperator( String arg )
+    {
+        super( Typed.from( String.class ), arg );
+    }
+
+    @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.ilike( propertyName, 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;
+
+            return s1 != null && s2.toLowerCase().contains( s1.toLowerCase() );
+        }
+
+        return false;
+    }
+}

=== removed file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILikeOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILikeOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/ILikeOperator.java	1970-01-01 00:00:00 +0000
@@ -1,61 +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.hisp.dhis.query.Typed;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class ILikeOperator extends Operator
-{
-    public ILikeOperator( String arg )
-    {
-        super( Typed.from( String.class ), arg );
-    }
-
-    @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;
-
-            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-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/InOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.in( propertyName, getValue( Collection.class, args ) );
+    }
+
+    @Override
     @SuppressWarnings( "unchecked" )
     public boolean test( Object value )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessEqualOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.le( propertyName, args.get( 0 ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         if ( args.isEmpty() || value == null )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LessThanOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Collection;
@@ -44,6 +46,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.lt( propertyName, args.get( 0 ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         if ( args.isEmpty() || value == null )

=== removed 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	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/LikeOperator.java	1970-01-01 00:00:00 +0000
@@ -1,61 +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.hisp.dhis.query.Typed;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class LikeOperator extends Operator
-{
-    public LikeOperator( String arg )
-    {
-        super( Typed.from( String.class ), arg );
-    }
-
-    @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;
-
-            return s1 != null && s2.contains( s1 );
-        }
-
-        return false;
-    }
-}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -39,6 +42,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.not( super.getHibernateCriterion( propertyName ) );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         return !super.test( value );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotNullOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Date;
@@ -43,6 +45,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.isNotNull( propertyName );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         return value != null;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java	2015-11-04 08:43:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NullOperator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.query.Typed;
 
 import java.util.Date;
@@ -43,6 +45,12 @@
     }
 
     @Override
+    public Criterion getHibernateCriterion( String propertyName )
+    {
+        return Restrictions.isNull( propertyName );
+    }
+
+    @Override
     public boolean test( Object value )
     {
         return value == null;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java	2015-11-04 06:46:21 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/Operator.java	2015-11-04 09:45:59 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hibernate.criterion.Criterion;
 import org.hisp.dhis.query.QueryUtils;
 import org.hisp.dhis.query.Typed;
 
@@ -81,5 +82,7 @@
         return typed.isValid( klass );
     }
 
+    public abstract Criterion getHibernateCriterion( String propertyName );
+
     public abstract boolean test( Object value );
 }

=== 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:24:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/OperatorTest.java	2015-11-04 09:45:59 +0000
@@ -32,11 +32,11 @@
 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.ILikeOperator;
+import org.hisp.dhis.query.operators.IContainsOperator;
 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.ContainsOperator;
 import org.hisp.dhis.query.operators.NotEqualOperator;
 import org.hisp.dhis.query.operators.NotNullOperator;
 import org.hisp.dhis.query.operators.NullOperator;
@@ -210,7 +210,7 @@
     @Test
     public void testILikeValidTypes()
     {
-        ILikeOperator operator = new ILikeOperator( "operator" );
+        IContainsOperator operator = new IContainsOperator( "operator" );
 
         assertTrue( operator.isValid( String.class ) );
         assertFalse( operator.isValid( Number.class ) );
@@ -222,7 +222,7 @@
     @Test
     public void testILike()
     {
-        ILikeOperator operator = new ILikeOperator( "operator" );
+        IContainsOperator operator = new IContainsOperator( "operator" );
 
         assertTrue( operator.test( "operator" ) );
         assertTrue( operator.test( "OPERATOR" ) );
@@ -232,7 +232,7 @@
     @Test
     public void testLikeValidTypes()
     {
-        LikeOperator operator = new LikeOperator( "operator" );
+        ContainsOperator operator = new ContainsOperator( "operator" );
 
         assertTrue( operator.isValid( String.class ) );
         assertFalse( operator.isValid( Number.class ) );
@@ -244,7 +244,7 @@
     @Test
     public void testLike()
     {
-        LikeOperator operator = new LikeOperator( "operator" );
+        ContainsOperator operator = new ContainsOperator( "operator" );
 
         assertTrue( operator.test( "operator" ) );
         assertFalse( operator.test( "OPERATOR" ) );