← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18376: minor fixes, adds type to QueryEngine and adds ResultTransformers for running multiple transforme...

 

------------------------------------------------------------
revno: 18376
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-02-23 18:17:55 +0700
message:
  minor fixes, adds type to QueryEngine and adds ResultTransformers for running multiple transformes on a result
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformers.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryEngine.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java	2015-02-20 08:28:01 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/Operator.java	2015-02-23 11:17:55 +0000
@@ -28,7 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.apache.commons.lang3.time.DateUtils;
 import org.hisp.dhis.schema.Klass;
 
 import java.util.Date;

=== modified 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-02-18 13:08:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/QueryEngine.java	2015-02-23 11:17:55 +0000
@@ -35,7 +35,7 @@
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-public interface QueryEngine
+public interface QueryEngine<T>
 {
-    List<? extends IdentifiableObject> query( Query query );
+    List<T> query( Query query );
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformers.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformers.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/query/ResultTransformers.java	2015-02-23 11:17:55 +0000
@@ -0,0 +1,75 @@
+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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ResultTransformers implements ResultTransformer
+{
+    private List<ResultTransformer> resultTransformers = new ArrayList<>();
+
+    public ResultTransformers( ResultTransformer... resultTransformers )
+    {
+        Collections.addAll( this.resultTransformers, resultTransformers );
+    }
+
+    public ResultTransformers( List<ResultTransformer> resultTransformers )
+    {
+        this.resultTransformers = resultTransformers;
+    }
+
+    @Override
+    public Result transform( MutableResult mutableResult )
+    {
+        Result result = mutableResult;
+
+        for ( ResultTransformer resultTransformer : resultTransformers )
+        {
+            result = resultTransformer.transform( new MutableResult( result.getItems() ) );
+        }
+
+        return result;
+    }
+
+    public ResultTransformer add( ResultTransformer... resultTransformers )
+    {
+        Collections.addAll( this.resultTransformers, resultTransformers );
+        return this;
+    }
+
+    public static ResultTransformer from( ResultTransformer... resultTransformers )
+    {
+        return new ResultTransformers( resultTransformers );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java	2015-02-20 08:28:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/CriteriaQueryEngine.java	2015-02-23 11:17:55 +0000
@@ -30,7 +30,6 @@
 
 import org.apache.commons.lang3.time.DateUtils;
 import org.hibernate.Criteria;
-import org.hibernate.criterion.Conjunction;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Disjunction;
 import org.hibernate.criterion.Restrictions;
@@ -49,7 +48,7 @@
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-public class CriteriaQueryEngine implements QueryEngine
+public class CriteriaQueryEngine<T extends IdentifiableObject> implements QueryEngine<T>
 {
     @Autowired
     private final List<HibernateGenericStore<? extends IdentifiableObject>> hibernateGenericStores = new ArrayList<>();
@@ -58,7 +57,7 @@
 
     @Override
     @SuppressWarnings( "unchecked" )
-    public List<? extends IdentifiableObject> query( Query query )
+    public List<T> query( Query query )
     {
         Schema schema = query.getSchema();
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java	2015-02-20 09:14:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/DefaultQueryService.java	2015-02-23 11:17:55 +0000
@@ -39,12 +39,14 @@
 import java.util.List;
 
 /**
+ * Default implementation of QueryService which works with IdObjects.
+ *
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-public class DefaultQueryService implements QueryService
+public class DefaultQueryService<T extends IdentifiableObject> implements QueryService
 {
     @Autowired
-    private QueryEngine queryEngine;
+    private QueryEngine<T> queryEngine;
 
     @Autowired
     private SchemaService schemaService;
@@ -52,14 +54,14 @@
     @Override
     public Result query( Query query )
     {
-        List<? extends IdentifiableObject> objects = queryEngine.query( query );
+        List<T> objects = queryEngine.query( query );
         return new Result( objects );
     }
 
     @Override
     public Result query( Query query, ResultTransformer transformer )
     {
-        List<? extends IdentifiableObject> objects = queryEngine.query( query );
+        List<T> objects = queryEngine.query( query );
 
         if ( transformer != null )
         {