dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41151
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20955: moved QueryService/QueryEngine classes to service-core, depends on hibernate-core / DateUtils (fr...
------------------------------------------------------------
revno: 20955
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-11-05 10:31:11 +0700
message:
moved QueryService/QueryEngine classes to service-core, depends on hibernate-core / DateUtils (from system) etc.
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Conjunction.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criteria.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criterion.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Disjunction.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Junction.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Order.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Query.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryEngine.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryException.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restriction.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/RestrictionException.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restrictions.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformer.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Typed.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/query/QueryTest.java
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Conjunction.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criteria.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criterion.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Disjunction.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Junction.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Operator.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryEngine.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryException.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restriction.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/RestrictionException.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/ResultTransformer.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Typed.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
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Conjunction.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Conjunction.java 2015-06-03 03:42:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Conjunction.java 1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.schema.Schema;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class Conjunction extends Junction
-{
- public Conjunction( Schema schema )
- {
- super( schema, Type.AND );
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criteria.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criteria.java 2015-06-04 09:25:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criteria.java 1970-01-01 00:00:00 +0000
@@ -1,90 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.schema.Schema;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public abstract class Criteria
-{
- protected List<Criterion> criterions = new ArrayList<>();
-
- protected final Schema schema;
-
- public Criteria( Schema schema )
- {
- this.schema = schema;
- }
-
- public List<Criterion> getCriterions()
- {
- return criterions;
- }
-
- public Criteria add( Criterion... criterions )
- {
- for ( Criterion criterion : criterions )
- {
- if ( !Restriction.class.isInstance( criterion ) )
- {
- this.criterions.add( criterion ); // if conjunction/disjunction just add it and move forward
- continue;
- }
-
- Restriction restriction = (Restriction) criterion;
-
- if ( !schema.haveProperty( restriction.getPath() ) )
- {
- continue;
- }
-
- if ( (restriction.getOperator().getMax() != null && restriction.getParameters().size() > restriction.getOperator().getMax())
- || (restriction.getOperator().getMin() != null && restriction.getParameters().size() < restriction.getOperator().getMin()) )
- {
- continue;
- }
-
- this.criterions.add( restriction );
- }
-
- return this;
- }
-
- public Criteria add( Collection<Criterion> criterions )
- {
- this.criterions.addAll( criterions );
- return this;
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criterion.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criterion.java 2015-06-02 04:25:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Criterion.java 1970-01-01 00:00:00 +0000
@@ -1,36 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 interface Criterion
-{
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Disjunction.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Disjunction.java 2015-06-03 03:42:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Disjunction.java 1970-01-01 00:00:00 +0000
@@ -1,42 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.schema.Schema;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class Disjunction extends Junction
-{
- public Disjunction( Schema schema )
- {
- super( schema, Type.OR );
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Junction.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Junction.java 2015-06-02 07:39:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Junction.java 1970-01-01 00:00:00 +0000
@@ -1,55 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.schema.Schema;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public abstract class Junction extends Criteria implements Criterion
-{
- protected enum Type
- {
- AND, OR
- }
-
- protected Type type;
-
- public Junction( Schema schema, Type type )
- {
- super( schema );
- this.type = type;
- }
-
- public Type getType()
- {
- return type;
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java 2015-06-04 09:25:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java 1970-01-01 00:00:00 +0000
@@ -1,117 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.schema.Klass;
-
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public enum Operator
-{
- EQ( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
- NE( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
- GT( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
- LT( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
- GE( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
- LE( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
- NULL( Typed.from( String.class, Boolean.class, Number.class, Date.class ) ),
- BETWEEN( Typed.from( String.class, Number.class, Date.class ), 2 ),
- LIKE( Typed.from( String.class ), 1 ),
- ILIKE( Typed.from( String.class ), 1 ),
- IN( 1, Integer.MAX_VALUE );
-
- Integer min;
-
- Integer max;
-
- // default is to allow all types
- Typed typed = Typed.from();
-
- Operator()
- {
- this.min = null;
- this.max = null;
- }
-
- Operator( Typed typed )
- {
- this.typed = typed;
- this.min = null;
- this.max = null;
- }
-
- Operator( int value )
- {
- this.min = value;
- this.max = value;
- }
-
- Operator( Typed typed, int value )
- {
- this.typed = typed;
- this.min = value;
- this.max = value;
- }
-
- Operator( int min, int max )
- {
- this.min = min;
- this.max = max;
- }
-
- Operator( Typed typed, int min, int max )
- {
- this.typed = typed;
- this.min = min;
- this.max = max;
- }
-
- public Integer getMin()
- {
- return min;
- }
-
- public Integer getMax()
- {
- return max;
- }
-
- public boolean isValid( Klass klass )
- {
- return typed.isValid( klass );
- }
-
- public boolean isValid( Class<?> klass )
- {
- return typed.isValid( klass );
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Order.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Order.java 2015-02-17 07:22:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Order.java 1970-01-01 00:00:00 +0000
@@ -1,119 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 com.google.common.base.MoreObjects;
-import org.hisp.dhis.schema.Property;
-
-import java.util.Objects;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class Order
-{
- private boolean ascending;
-
- private boolean ignoreCase;
-
- private Property property;
-
- public Order( Property property, boolean ascending )
- {
- this.property = property;
- this.ascending = ascending;
- }
-
- public Order ignoreCase()
- {
- this.ignoreCase = true;
- return this;
- }
-
- public boolean isAscending()
- {
- return ascending;
- }
-
- public boolean isIgnoreCase()
- {
- return ignoreCase;
- }
-
- public Property getProperty()
- {
- return property;
- }
-
- public static Order asc( Property property )
- {
- return new Order( property, true );
- }
-
- public static Order desc( Property property )
- {
- return new Order( property, false );
- }
-
- @Override
- public int hashCode()
- {
- return Objects.hash( ascending, ignoreCase, property );
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
-
- if ( obj == null || getClass() != obj.getClass() )
- {
- return false;
- }
-
- final Order other = (Order) obj;
-
- return Objects.equals( this.ascending, other.ascending )
- && Objects.equals( this.ignoreCase, other.ignoreCase )
- && Objects.equals( this.property, other.property );
- }
-
- @Override
- public String toString()
- {
- return MoreObjects.toStringHelper( this )
- .add( "ascending", ascending )
- .add( "ignoreCase", ignoreCase )
- .add( "property", property != null ? property.getName() : null )
- .toString();
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Query.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Query.java 2015-06-04 01:55:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Query.java 1970-01-01 00:00:00 +0000
@@ -1,176 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 com.google.common.base.MoreObjects;
-import com.google.common.base.Optional;
-import org.hisp.dhis.schema.Property;
-import org.hisp.dhis.schema.Schema;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class Query extends Criteria
-{
- private List<Order> orders = new ArrayList<>();
-
- private Integer firstResult;
-
- private Integer maxResults;
-
- public static Query from( Schema schema )
- {
- return new Query( schema );
- }
-
- private Query( Schema schema )
- {
- super( schema );
- }
-
- public Schema getSchema()
- {
- return schema;
- }
-
- public List<Order> getOrders()
- {
- return orders;
- }
-
- public Integer getFirstResult()
- {
- return firstResult;
- }
-
- public Query setFirstResult( Integer firstResult )
- {
- this.firstResult = firstResult;
- return this;
- }
-
- public Integer getMaxResults()
- {
- return maxResults;
- }
-
- public Query setMaxResults( Integer maxResults )
- {
- this.maxResults = maxResults;
- return this;
- }
-
- public Query addOrder( Order... orders )
- {
- for ( Order order : orders )
- {
- if ( order != null )
- {
- this.orders.add( order );
- }
- }
-
- return this;
- }
-
- public Query addOrders( Collection<Order> orders )
- {
- this.orders.addAll( orders );
- return this;
- }
-
- public Disjunction addDisjunction()
- {
- Disjunction disjunction = new Disjunction( schema );
- add( disjunction );
-
- return disjunction;
- }
-
- public Disjunction disjunction()
- {
- return new Disjunction( schema );
- }
-
- public Conjunction addConjunction()
- {
- Conjunction conjunction = new Conjunction( schema );
- add( conjunction );
-
- return conjunction;
- }
-
- public Conjunction conjunction()
- {
- return new Conjunction( schema );
- }
-
- public Query forceDefaultOrder()
- {
- orders.clear();
- return setDefaultOrder();
- }
-
- public Query setDefaultOrder()
- {
- if ( !orders.isEmpty() )
- {
- return this;
- }
-
- Optional<Property> name = Optional.fromNullable( schema.getPersistedProperty( "name" ) );
- Optional<Property> created = Optional.fromNullable( schema.getPersistedProperty( "created" ) );
-
- if ( name.isPresent() )
- {
- addOrder( Order.asc( name.get() ) );
- }
- else if ( created.isPresent() )
- {
- addOrder( Order.desc( created.get() ) );
- }
-
- return this;
- }
-
- @Override
- public String toString()
- {
- return MoreObjects.toStringHelper( this )
- .add( "firstResult", firstResult )
- .add( "maxResults", maxResults )
- .add( "orders", orders )
- .add( "criterions", criterions )
- .toString();
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryEngine.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryEngine.java 2015-11-04 03:03:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryEngine.java 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface QueryEngine<T>
-{
- /**
- * Return objects matching given query, T typed according to QueryEngine
- * implementation.
- *
- * @param query Query instance to use
- * @return Matching objects
- */
- List<T> query( Query query );
-
- /**
- * Returns how many objects matches the given query.
- *
- * @param query Query instance to use
- * @return N number of matching objects
- */
- int count( Query query );
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryException.java 2015-02-18 13:08:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryException.java 1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 class QueryException extends RuntimeException
-{
- public QueryException( String message )
- {
- super( message );
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryService.java 2015-11-04 03:03:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryService.java 1970-01-01 00:00:00 +0000
@@ -1,77 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.common.IdentifiableObject;
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface QueryService
-{
- /**
- * Return objects matching given query, T typed according to QueryEngine
- * implementation.
- *
- * @param query Query instance to use
- * @return Matching objects
- */
- List<? extends IdentifiableObject> query( Query query );
-
- /**
- * Return objects matching given query, T typed according to QueryEngine
- * implementation.
- *
- * @param query Query instance to use
- * @param transformer ResultTransformer to use for mutating the result
- * @return Matching objects
- */
- List<? extends IdentifiableObject> query( Query query, ResultTransformer transformer );
-
- /**
- * Returns how many objects matches the given query.
- *
- * @param query Query instance to use
- * @return N number of matching objects
- */
- int count( Query query );
-
- /**
- * Create a query instance from a given set of filters (property:operator:value), and
- * a list of orders.
- *
- * @param klass Type of object you want to query
- * @param filters List of filters to use as basis for query instance
- * @param orders List of orders to use for query
- * @return New query instance using provided filters/orders
- */
- Query getQueryFromUrl( Class<?> klass, List<String> filters, List<Order> orders );
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restriction.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restriction.java 2015-06-02 04:25:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restriction.java 1970-01-01 00:00:00 +0000
@@ -1,123 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 com.google.common.base.MoreObjects;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class Restriction implements Criterion
-{
- /**
- * Path to property you want to restrict only, one first-level properties are currently supported.
- */
- private String path;
-
- /**
- * Operator for restriction.
- */
- private Operator operator;
-
- /**
- * 0..* parameters as required by operator.
- */
- private List<Object> parameters = new ArrayList<>();
-
- public Restriction( String path, Operator operator, Object... parameters )
- {
- this.path = path;
- this.operator = operator;
-
- for ( Object object : parameters )
- {
- addParameter( object );
- }
- }
-
- public String getPath()
- {
- return path;
- }
-
- public void setPath( String path )
- {
- this.path = path;
- }
-
- public Operator getOperator()
- {
- return operator;
- }
-
- public void setOperator( Operator operator )
- {
- this.operator = operator;
- }
-
- public List<Object> getParameters()
- {
- return parameters;
- }
-
- public Object getParameter( int idx )
- {
- if ( parameters.size() < idx )
- {
- return null;
- }
-
- return parameters.get( idx );
- }
-
- public void setParameters( List<Object> parameters )
- {
- this.parameters = parameters;
- }
-
- // Builder
- public Restriction addParameter( Object parameter )
- {
- this.parameters.add( ( parameter ) );
- return this;
- }
-
- @Override
- public String toString()
- {
- return MoreObjects.toStringHelper( this )
- .add( "path", path )
- .add( "operator", operator )
- .add( "parameters", parameters )
- .toString();
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/RestrictionException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/RestrictionException.java 2015-02-18 13:08:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/RestrictionException.java 1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 class RestrictionException extends RuntimeException
-{
- public RestrictionException( String message )
- {
- super( message );
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restrictions.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restrictions.java 2015-06-04 09:25:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Restrictions.java 1970-01-01 00:00:00 +0000
@@ -1,102 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 java.util.Collection;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public final class Restrictions
-{
- public static Restriction eq( String path, Object value )
- {
- return new Restriction( path, Operator.EQ, value );
- }
-
- public static Restriction ne( String path, Object value )
- {
- return new Restriction( path, Operator.NE, value );
- }
-
- public static Restriction gt( String path, Object value )
- {
- return new Restriction( path, Operator.GT, value );
- }
-
- public static Restriction lt( String path, Object value )
- {
- return new Restriction( path, Operator.LT, value );
- }
-
- public static Restriction ge( String path, Object value )
- {
- return new Restriction( path, Operator.GE, value );
- }
-
- public static Restriction le( String path, Object value )
- {
- return new Restriction( path, Operator.LE, value );
- }
-
- public static Restriction between( String path, Object lside, Object rside )
- {
- return new Restriction( path, Operator.BETWEEN, 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 )
- {
- return new Restriction( path, Operator.ILIKE, value );
- }
-
- public static Restriction ilike( String path, Object value )
- {
- return new Restriction( path, Operator.ILIKE, value );
- }
-
- public static Restriction in( String path, Object... values )
- {
- return new Restriction( path, Operator.IN, values );
- }
-
- public static Restriction in( String path, Collection<?> values )
- {
- return new Restriction( path, Operator.IN, values );
- }
-
- public static Restriction isNull( String path )
- {
- return new Restriction( path, Operator.NULL );
- }
-
- private Restrictions()
- {
- }
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformer.java 2015-11-04 03:03:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformer.java 1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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 java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@FunctionalInterface
-public interface ResultTransformer<T>
-{
- List<T> transform( List<T> result );
-}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Typed.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Typed.java 2015-02-24 13:16:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Typed.java 1970-01-01 00:00:00 +0000
@@ -1,87 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.schema.Klass;
-
-import com.google.common.collect.Iterators;
-
-/**
- * Simple class for checking if an object is one of several allowed classes, mainly used in Operator where
- * a parameter can be type constrained.
- *
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class Typed
-{
- private final Class<?>[] klasses;
-
- public Typed( Class<?>[] klasses )
- {
- this.klasses = klasses;
- }
-
- public Class<?>[] getKlasses()
- {
- return klasses;
- }
-
- public boolean isValid( Klass klass )
- {
- return klass == null || isValid( klass.getKlass() );
- }
-
- public boolean isValid( Class<?> klass )
- {
- if ( klasses.length == 0 || klass == null )
- {
- return true;
- }
-
- for ( Class<?> k : klasses )
- {
- if ( k != null && k.isAssignableFrom( klass ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- public static Typed from( Class<?>... klasses )
- {
- return new Typed( klasses );
- }
-
- public static Typed from( Iterable<? extends Class<?>> iterable )
- {
- return new Typed( Iterators.toArray( iterable.iterator(), Class.class ) );
- }
-}
=== removed file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/query/QueryTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/query/QueryTest.java 2015-06-02 04:25:37 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/query/QueryTest.java 1970-01-01 00:00:00 +0000
@@ -1,120 +0,0 @@
-package org.hisp.dhis.query;
-
-/*
- * 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.dataelement.DataElement;
-import org.hisp.dhis.schema.Property;
-import org.hisp.dhis.schema.Schema;
-import org.junit.Test;
-
-import java.util.Date;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class QueryTest
-{
- private Property createProperty( Class<?> klazz, String name, boolean simple, boolean persisted )
- {
- Property property = new Property( klazz );
- property.setName( name );
- property.setFieldName( name );
- property.setSimple( simple );
- property.setPersisted( persisted );
-
- return property;
- }
-
- private Schema createSchema()
- {
- Schema schema = new Schema( DataElement.class, "dataElement", "dataElements" );
- schema.addProperty( createProperty( String.class, "id", true, true ) );
- schema.addProperty( createProperty( String.class, "name", true, true ) );
- schema.addProperty( createProperty( String.class, "code", true, true ) );
- schema.addProperty( createProperty( Date.class, "created", true, true ) );
- schema.addProperty( createProperty( Date.class, "lastUpdated", true, true ) );
-
- schema.addProperty( createProperty( Integer.class, "int", true, true ) );
- schema.addProperty( createProperty( Long.class, "long", true, true ) );
- schema.addProperty( createProperty( Float.class, "float", true, true ) );
- schema.addProperty( createProperty( Double.class, "double", true, true ) );
-
- return schema;
- }
-
- @Test
- public void validRestrictionParameters()
- {
- Query query = Query.from( createSchema() );
- query.add( Restrictions.eq( "id", "anc" ) );
- query.add( Restrictions.like( "name", "anc" ) );
- query.add( Restrictions.eq( "code", "anc" ) );
-
- assertEquals( 3, query.getCriterions().size() );
- }
-
- @Test
- public void invalidRestrictionParameters()
- {
- Query query = Query.from( createSchema() );
- query.add( new Restriction( "id", Operator.EQ ) );
- query.add( new Restriction( "id", Operator.EQ, 1, 2 ) );
- query.add( new Restriction( "name", Operator.EQ ) );
- query.add( new Restriction( "name", Operator.EQ, 1, 2 ) );
- query.add( new Restriction( "code", Operator.EQ ) );
- query.add( new Restriction( "code", Operator.EQ, 1, 2, 3, 4, 5 ) );
- query.add( new Restriction( "lastUpdated", Operator.BETWEEN, new Date() ) );
- query.add( new Restriction( "lastUpdated", Operator.BETWEEN, new Date(), 1, 2, 3, 4 ) );
-
- assertEquals( 0, query.getCriterions().size() );
- }
-
- @Test
- public void operatorValid()
- {
- Schema schema = createSchema();
-
- assertTrue( Operator.EQ.isValid( schema.getProperty( "id" ) ) );
- assertTrue( Operator.GE.isValid( schema.getProperty( "id" ) ) );
- assertTrue( Operator.LT.isValid( schema.getProperty( "id" ) ) );
- assertTrue( Operator.GE.isValid( schema.getProperty( "id" ) ) );
- assertTrue( Operator.LE.isValid( schema.getProperty( "id" ) ) );
- assertTrue( Operator.BETWEEN.isValid( schema.getProperty( "id" ) ) );
- assertTrue( Operator.LIKE.isValid( schema.getProperty( "id" ) ) );
-
- assertTrue( Operator.EQ.isValid( schema.getProperty( "int" ) ) );
- assertTrue( Operator.EQ.isValid( schema.getProperty( "long" ) ) );
- assertTrue( Operator.EQ.isValid( schema.getProperty( "float" ) ) );
- assertTrue( Operator.EQ.isValid( schema.getProperty( "double" ) ) );
-
- assertFalse( Operator.LIKE.isValid( schema.getProperty( "lastUpdated" ) ) );
- }
-}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Conjunction.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Conjunction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Conjunction.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,42 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.schema.Schema;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Conjunction extends Junction
+{
+ public Conjunction( Schema schema )
+ {
+ super( schema, Type.AND );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criteria.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criteria.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criteria.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,90 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.schema.Schema;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public abstract class Criteria
+{
+ protected List<Criterion> criterions = new ArrayList<>();
+
+ protected final Schema schema;
+
+ public Criteria( Schema schema )
+ {
+ this.schema = schema;
+ }
+
+ public List<Criterion> getCriterions()
+ {
+ return criterions;
+ }
+
+ public Criteria add( Criterion... criterions )
+ {
+ for ( Criterion criterion : criterions )
+ {
+ if ( !Restriction.class.isInstance( criterion ) )
+ {
+ this.criterions.add( criterion ); // if conjunction/disjunction just add it and move forward
+ continue;
+ }
+
+ Restriction restriction = (Restriction) criterion;
+
+ if ( !schema.haveProperty( restriction.getPath() ) )
+ {
+ continue;
+ }
+
+ if ( (restriction.getOperator().getMax() != null && restriction.getParameters().size() > restriction.getOperator().getMax())
+ || (restriction.getOperator().getMin() != null && restriction.getParameters().size() < restriction.getOperator().getMin()) )
+ {
+ continue;
+ }
+
+ this.criterions.add( restriction );
+ }
+
+ return this;
+ }
+
+ public Criteria add( Collection<Criterion> criterions )
+ {
+ this.criterions.addAll( criterions );
+ return this;
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criterion.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criterion.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Criterion.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,36 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 interface Criterion
+{
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Disjunction.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Disjunction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Disjunction.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,42 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.schema.Schema;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Disjunction extends Junction
+{
+ public Disjunction( Schema schema )
+ {
+ super( schema, Type.OR );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Junction.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Junction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Junction.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,55 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.schema.Schema;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public abstract class Junction extends Criteria implements Criterion
+{
+ protected enum Type
+ {
+ AND, OR
+ }
+
+ protected Type type;
+
+ public Junction( Schema schema, Type type )
+ {
+ super( schema );
+ this.type = type;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Operator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Operator.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Operator.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,117 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.schema.Klass;
+
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public enum Operator
+{
+ EQ( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
+ NE( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
+ GT( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
+ LT( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
+ GE( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
+ LE( Typed.from( String.class, Boolean.class, Number.class, Date.class ), 1 ),
+ NULL( Typed.from( String.class, Boolean.class, Number.class, Date.class ) ),
+ BETWEEN( Typed.from( String.class, Number.class, Date.class ), 2 ),
+ LIKE( Typed.from( String.class ), 1 ),
+ ILIKE( Typed.from( String.class ), 1 ),
+ IN( 1, Integer.MAX_VALUE );
+
+ Integer min;
+
+ Integer max;
+
+ // default is to allow all types
+ Typed typed = Typed.from();
+
+ Operator()
+ {
+ this.min = null;
+ this.max = null;
+ }
+
+ Operator( Typed typed )
+ {
+ this.typed = typed;
+ this.min = null;
+ this.max = null;
+ }
+
+ Operator( int value )
+ {
+ this.min = value;
+ this.max = value;
+ }
+
+ Operator( Typed typed, int value )
+ {
+ this.typed = typed;
+ this.min = value;
+ this.max = value;
+ }
+
+ Operator( int min, int max )
+ {
+ this.min = min;
+ this.max = max;
+ }
+
+ Operator( Typed typed, int min, int max )
+ {
+ this.typed = typed;
+ this.min = min;
+ this.max = max;
+ }
+
+ public Integer getMin()
+ {
+ return min;
+ }
+
+ public Integer getMax()
+ {
+ return max;
+ }
+
+ public boolean isValid( Klass klass )
+ {
+ return typed.isValid( klass );
+ }
+
+ public boolean isValid( Class<?> klass )
+ {
+ return typed.isValid( klass );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Order.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,119 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 com.google.common.base.MoreObjects;
+import org.hisp.dhis.schema.Property;
+
+import java.util.Objects;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Order
+{
+ private boolean ascending;
+
+ private boolean ignoreCase;
+
+ private Property property;
+
+ public Order( Property property, boolean ascending )
+ {
+ this.property = property;
+ this.ascending = ascending;
+ }
+
+ public Order ignoreCase()
+ {
+ this.ignoreCase = true;
+ return this;
+ }
+
+ public boolean isAscending()
+ {
+ return ascending;
+ }
+
+ public boolean isIgnoreCase()
+ {
+ return ignoreCase;
+ }
+
+ public Property getProperty()
+ {
+ return property;
+ }
+
+ public static Order asc( Property property )
+ {
+ return new Order( property, true );
+ }
+
+ public static Order desc( Property property )
+ {
+ return new Order( property, false );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash( ascending, ignoreCase, property );
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ {
+ return true;
+ }
+
+ if ( obj == null || getClass() != obj.getClass() )
+ {
+ return false;
+ }
+
+ final Order other = (Order) obj;
+
+ return Objects.equals( this.ascending, other.ascending )
+ && Objects.equals( this.ignoreCase, other.ignoreCase )
+ && Objects.equals( this.property, other.property );
+ }
+
+ @Override
+ public String toString()
+ {
+ return MoreObjects.toStringHelper( this )
+ .add( "ascending", ascending )
+ .add( "ignoreCase", ignoreCase )
+ .add( "property", property != null ? property.getName() : null )
+ .toString();
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Query.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,176 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 com.google.common.base.MoreObjects;
+import com.google.common.base.Optional;
+import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.Schema;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Query extends Criteria
+{
+ private List<Order> orders = new ArrayList<>();
+
+ private Integer firstResult;
+
+ private Integer maxResults;
+
+ public static Query from( Schema schema )
+ {
+ return new Query( schema );
+ }
+
+ private Query( Schema schema )
+ {
+ super( schema );
+ }
+
+ public Schema getSchema()
+ {
+ return schema;
+ }
+
+ public List<Order> getOrders()
+ {
+ return orders;
+ }
+
+ public Integer getFirstResult()
+ {
+ return firstResult;
+ }
+
+ public Query setFirstResult( Integer firstResult )
+ {
+ this.firstResult = firstResult;
+ return this;
+ }
+
+ public Integer getMaxResults()
+ {
+ return maxResults;
+ }
+
+ public Query setMaxResults( Integer maxResults )
+ {
+ this.maxResults = maxResults;
+ return this;
+ }
+
+ public Query addOrder( Order... orders )
+ {
+ for ( Order order : orders )
+ {
+ if ( order != null )
+ {
+ this.orders.add( order );
+ }
+ }
+
+ return this;
+ }
+
+ public Query addOrders( Collection<Order> orders )
+ {
+ this.orders.addAll( orders );
+ return this;
+ }
+
+ public Disjunction addDisjunction()
+ {
+ Disjunction disjunction = new Disjunction( schema );
+ add( disjunction );
+
+ return disjunction;
+ }
+
+ public Disjunction disjunction()
+ {
+ return new Disjunction( schema );
+ }
+
+ public Conjunction addConjunction()
+ {
+ Conjunction conjunction = new Conjunction( schema );
+ add( conjunction );
+
+ return conjunction;
+ }
+
+ public Conjunction conjunction()
+ {
+ return new Conjunction( schema );
+ }
+
+ public Query forceDefaultOrder()
+ {
+ orders.clear();
+ return setDefaultOrder();
+ }
+
+ public Query setDefaultOrder()
+ {
+ if ( !orders.isEmpty() )
+ {
+ return this;
+ }
+
+ Optional<Property> name = Optional.fromNullable( schema.getPersistedProperty( "name" ) );
+ Optional<Property> created = Optional.fromNullable( schema.getPersistedProperty( "created" ) );
+
+ if ( name.isPresent() )
+ {
+ addOrder( Order.asc( name.get() ) );
+ }
+ else if ( created.isPresent() )
+ {
+ addOrder( Order.desc( created.get() ) );
+ }
+
+ return this;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MoreObjects.toStringHelper( this )
+ .add( "firstResult", firstResult )
+ .add( "maxResults", maxResults )
+ .add( "orders", orders )
+ .add( "criterions", criterions )
+ .toString();
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryEngine.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryEngine.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,54 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface QueryEngine<T>
+{
+ /**
+ * Return objects matching given query, T typed according to QueryEngine
+ * implementation.
+ *
+ * @param query Query instance to use
+ * @return Matching objects
+ */
+ List<T> query( Query query );
+
+ /**
+ * Returns how many objects matches the given query.
+ *
+ * @param query Query instance to use
+ * @return N number of matching objects
+ */
+ int count( Query query );
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryException.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryException.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryException.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 class QueryException extends RuntimeException
+{
+ public QueryException( String message )
+ {
+ super( message );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/QueryService.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,77 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.common.IdentifiableObject;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface QueryService
+{
+ /**
+ * Return objects matching given query, T typed according to QueryEngine
+ * implementation.
+ *
+ * @param query Query instance to use
+ * @return Matching objects
+ */
+ List<? extends IdentifiableObject> query( Query query );
+
+ /**
+ * Return objects matching given query, T typed according to QueryEngine
+ * implementation.
+ *
+ * @param query Query instance to use
+ * @param transformer ResultTransformer to use for mutating the result
+ * @return Matching objects
+ */
+ List<? extends IdentifiableObject> query( Query query, ResultTransformer transformer );
+
+ /**
+ * Returns how many objects matches the given query.
+ *
+ * @param query Query instance to use
+ * @return N number of matching objects
+ */
+ int count( Query query );
+
+ /**
+ * Create a query instance from a given set of filters (property:operator:value), and
+ * a list of orders.
+ *
+ * @param klass Type of object you want to query
+ * @param filters List of filters to use as basis for query instance
+ * @param orders List of orders to use for query
+ * @return New query instance using provided filters/orders
+ */
+ Query getQueryFromUrl( Class<?> klass, List<String> filters, List<Order> orders );
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restriction.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restriction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restriction.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,123 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 com.google.common.base.MoreObjects;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Restriction implements Criterion
+{
+ /**
+ * Path to property you want to restrict only, one first-level properties are currently supported.
+ */
+ private String path;
+
+ /**
+ * Operator for restriction.
+ */
+ private Operator operator;
+
+ /**
+ * 0..* parameters as required by operator.
+ */
+ private List<Object> parameters = new ArrayList<>();
+
+ public Restriction( String path, Operator operator, Object... parameters )
+ {
+ this.path = path;
+ this.operator = operator;
+
+ for ( Object object : parameters )
+ {
+ addParameter( object );
+ }
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public void setPath( String path )
+ {
+ this.path = path;
+ }
+
+ public Operator getOperator()
+ {
+ return operator;
+ }
+
+ public void setOperator( Operator operator )
+ {
+ this.operator = operator;
+ }
+
+ public List<Object> getParameters()
+ {
+ return parameters;
+ }
+
+ public Object getParameter( int idx )
+ {
+ if ( parameters.size() < idx )
+ {
+ return null;
+ }
+
+ return parameters.get( idx );
+ }
+
+ public void setParameters( List<Object> parameters )
+ {
+ this.parameters = parameters;
+ }
+
+ // Builder
+ public Restriction addParameter( Object parameter )
+ {
+ this.parameters.add( ( parameter ) );
+ return this;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MoreObjects.toStringHelper( this )
+ .add( "path", path )
+ .add( "operator", operator )
+ .add( "parameters", parameters )
+ .toString();
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/RestrictionException.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/RestrictionException.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/RestrictionException.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 class RestrictionException extends RuntimeException
+{
+ public RestrictionException( String message )
+ {
+ super( message );
+ }
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Restrictions.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,102 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 java.util.Collection;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public final class Restrictions
+{
+ public static Restriction eq( String path, Object value )
+ {
+ return new Restriction( path, Operator.EQ, value );
+ }
+
+ public static Restriction ne( String path, Object value )
+ {
+ return new Restriction( path, Operator.NE, value );
+ }
+
+ public static Restriction gt( String path, Object value )
+ {
+ return new Restriction( path, Operator.GT, value );
+ }
+
+ public static Restriction lt( String path, Object value )
+ {
+ return new Restriction( path, Operator.LT, value );
+ }
+
+ public static Restriction ge( String path, Object value )
+ {
+ return new Restriction( path, Operator.GE, value );
+ }
+
+ public static Restriction le( String path, Object value )
+ {
+ return new Restriction( path, Operator.LE, value );
+ }
+
+ public static Restriction between( String path, Object lside, Object rside )
+ {
+ return new Restriction( path, Operator.BETWEEN, 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 )
+ {
+ return new Restriction( path, Operator.ILIKE, value );
+ }
+
+ public static Restriction ilike( String path, Object value )
+ {
+ return new Restriction( path, Operator.ILIKE, value );
+ }
+
+ public static Restriction in( String path, Object... values )
+ {
+ return new Restriction( path, Operator.IN, values );
+ }
+
+ public static Restriction in( String path, Collection<?> values )
+ {
+ return new Restriction( path, Operator.IN, values );
+ }
+
+ public static Restriction isNull( String path )
+ {
+ return new Restriction( path, Operator.NULL );
+ }
+
+ private Restrictions()
+ {
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/ResultTransformer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/ResultTransformer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/ResultTransformer.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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 java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@FunctionalInterface
+public interface ResultTransformer<T>
+{
+ List<T> transform( List<T> result );
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Typed.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Typed.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/Typed.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.schema.Klass;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * Simple class for checking if an object is one of several allowed classes, mainly used in Operator where
+ * a parameter can be type constrained.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Typed
+{
+ private final Class<?>[] klasses;
+
+ public Typed( Class<?>[] klasses )
+ {
+ this.klasses = klasses;
+ }
+
+ public Class<?>[] getKlasses()
+ {
+ return klasses;
+ }
+
+ public boolean isValid( Klass klass )
+ {
+ return klass == null || isValid( klass.getKlass() );
+ }
+
+ public boolean isValid( Class<?> klass )
+ {
+ if ( klasses.length == 0 || klass == null )
+ {
+ return true;
+ }
+
+ for ( Class<?> k : klasses )
+ {
+ if ( k != null && k.isAssignableFrom( klass ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static Typed from( Class<?>... klasses )
+ {
+ return new Typed( klasses );
+ }
+
+ public static Typed from( Iterable<? extends Class<?>> iterable )
+ {
+ return new Typed( Iterators.toArray( iterable.iterator(), Class.class ) );
+ }
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryTest.java 2015-11-05 03:31:11 +0000
@@ -0,0 +1,120 @@
+package org.hisp.dhis.query;
+
+/*
+ * 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.dataelement.DataElement;
+import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.Schema;
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class QueryTest
+{
+ private Property createProperty( Class<?> klazz, String name, boolean simple, boolean persisted )
+ {
+ Property property = new Property( klazz );
+ property.setName( name );
+ property.setFieldName( name );
+ property.setSimple( simple );
+ property.setPersisted( persisted );
+
+ return property;
+ }
+
+ private Schema createSchema()
+ {
+ Schema schema = new Schema( DataElement.class, "dataElement", "dataElements" );
+ schema.addProperty( createProperty( String.class, "id", true, true ) );
+ schema.addProperty( createProperty( String.class, "name", true, true ) );
+ schema.addProperty( createProperty( String.class, "code", true, true ) );
+ schema.addProperty( createProperty( Date.class, "created", true, true ) );
+ schema.addProperty( createProperty( Date.class, "lastUpdated", true, true ) );
+
+ schema.addProperty( createProperty( Integer.class, "int", true, true ) );
+ schema.addProperty( createProperty( Long.class, "long", true, true ) );
+ schema.addProperty( createProperty( Float.class, "float", true, true ) );
+ schema.addProperty( createProperty( Double.class, "double", true, true ) );
+
+ return schema;
+ }
+
+ @Test
+ public void validRestrictionParameters()
+ {
+ Query query = Query.from( createSchema() );
+ query.add( Restrictions.eq( "id", "anc" ) );
+ query.add( Restrictions.like( "name", "anc" ) );
+ query.add( Restrictions.eq( "code", "anc" ) );
+
+ assertEquals( 3, query.getCriterions().size() );
+ }
+
+ @Test
+ public void invalidRestrictionParameters()
+ {
+ Query query = Query.from( createSchema() );
+ query.add( new Restriction( "id", Operator.EQ ) );
+ query.add( new Restriction( "id", Operator.EQ, 1, 2 ) );
+ query.add( new Restriction( "name", Operator.EQ ) );
+ query.add( new Restriction( "name", Operator.EQ, 1, 2 ) );
+ query.add( new Restriction( "code", Operator.EQ ) );
+ query.add( new Restriction( "code", Operator.EQ, 1, 2, 3, 4, 5 ) );
+ query.add( new Restriction( "lastUpdated", Operator.BETWEEN, new Date() ) );
+ query.add( new Restriction( "lastUpdated", Operator.BETWEEN, new Date(), 1, 2, 3, 4 ) );
+
+ assertEquals( 0, query.getCriterions().size() );
+ }
+
+ @Test
+ public void operatorValid()
+ {
+ Schema schema = createSchema();
+
+ assertTrue( Operator.EQ.isValid( schema.getProperty( "id" ) ) );
+ assertTrue( Operator.GE.isValid( schema.getProperty( "id" ) ) );
+ assertTrue( Operator.LT.isValid( schema.getProperty( "id" ) ) );
+ assertTrue( Operator.GE.isValid( schema.getProperty( "id" ) ) );
+ assertTrue( Operator.LE.isValid( schema.getProperty( "id" ) ) );
+ assertTrue( Operator.BETWEEN.isValid( schema.getProperty( "id" ) ) );
+ assertTrue( Operator.LIKE.isValid( schema.getProperty( "id" ) ) );
+
+ assertTrue( Operator.EQ.isValid( schema.getProperty( "int" ) ) );
+ assertTrue( Operator.EQ.isValid( schema.getProperty( "long" ) ) );
+ assertTrue( Operator.EQ.isValid( schema.getProperty( "float" ) ) );
+ assertTrue( Operator.EQ.isValid( schema.getProperty( "double" ) ) );
+
+ assertFalse( Operator.LIKE.isValid( schema.getProperty( "lastUpdated" ) ) );
+ }
+}