dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41996
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21454: support filtering in DataElementOperandController
------------------------------------------------------------
revno: 21454
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-15 09:08:01 +0100
message:
support filtering in DataElementOperandController
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2015-12-15 07:58:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2015-12-15 08:08:01 +0000
@@ -90,21 +90,13 @@
@SuppressWarnings( "unchecked" )
protected List<DimensionalObject> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters, List<Order> orders ) throws QueryParserException
{
- List<DimensionalObject> entityList;
+ List<DimensionalObject> dimensionalObjects;
Query query = queryService.getQueryFromUrl( DimensionalObject.class, filters, orders );
query.setDefaultOrder();
query.setObjects( dimensionService.getAllDimensions() );
-
- if ( options.getOptions().containsKey( "query" ) )
- {
- entityList = Lists.newArrayList( manager.filter( getEntityClass(), options.getOptions().get( "query" ) ) );
- }
- else
- {
- entityList = (List<DimensionalObject>) queryService.query( query );
- }
-
- return entityList;
+ dimensionalObjects = (List<DimensionalObject>) queryService.query( query );
+
+ return dimensionalObjects;
}
@Override
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2015-11-22 12:26:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2015-12-15 08:08:01 +0000
@@ -28,15 +28,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.common.collect.Lists;
import org.hisp.dhis.commons.collection.CollectionUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.query.Order;
+import org.hisp.dhis.query.Query;
+import org.hisp.dhis.query.QueryParserException;
import org.hisp.dhis.schema.descriptors.DataElementOperandSchemaDescriptor;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
@@ -45,24 +45,26 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
@RequestMapping( value = DataElementOperandSchemaDescriptor.API_ENDPOINT )
-public class DataElementOperandController
+public class DataElementOperandController
extends AbstractCrudController<DataElementOperand>
{
@Autowired
private DataElementCategoryService dataElementCategoryService;
@Override
- protected List<DataElementOperand> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters, List<Order> orders )
+ @SuppressWarnings( "unchecked" )
+ protected List<DataElementOperand> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters, List<Order> orders ) throws QueryParserException
{
- List<DataElementOperand> dataElementOperands = Lists.newArrayList();
-
+ List<DataElementOperand> dataElementOperands = new ArrayList<>();
+
if ( options.isTrue( "persisted" ) )
{
dataElementOperands = Lists.newArrayList( manager.getAll( DataElementOperand.class ) );
@@ -70,7 +72,7 @@
else
{
boolean totals = options.isTrue( "totals" );
-
+
String deGroup = CollectionUtils.popStartsWith( filters, "dataElement.dataElementGroups.id:eq:" );
deGroup = deGroup != null ? deGroup.substring( "dataElement.dataElementGroups.id:eq:".length() ) : null;
@@ -86,6 +88,12 @@
}
}
+ Query query = queryService.getQueryFromUrl( getEntityClass(), filters, orders );
+ query.setDefaultOrder();
+ query.setObjects( dataElementOperands );
+
+ dataElementOperands = (List<DataElementOperand>) queryService.query( query );
+
return dataElementOperands;
}
}