dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33116
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16873: optimize dataElementOperandController dataElement.dataElementGroup.id path, get group directly an...
------------------------------------------------------------
revno: 16873
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-30 11:38:03 +0700
message:
optimize dataElementOperandController dataElement.dataElementGroup.id path, get group directly and use members
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.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/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-09-29 04:34:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-09-30 04:38:03 +0000
@@ -127,7 +127,7 @@
// GET
//--------------------------------------------------------------------------
- @RequestMapping(method = RequestMethod.GET)
+ @RequestMapping( method = RequestMethod.GET )
public @ResponseBody RootNode getObjectList(
@RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request )
{
@@ -148,7 +148,7 @@
if ( filters.isEmpty() || DataElementOperand.class.isAssignableFrom( getEntityClass() ) )
{
- entityList = getEntityList( metaData, options );
+ entityList = getEntityList( metaData, options, filters );
}
else
{
@@ -328,7 +328,7 @@
// POST
//--------------------------------------------------------------------------
- @RequestMapping(method = RequestMethod.POST, consumes = { "application/xml", "text/xml" })
+ @RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } )
public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
{
if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) )
@@ -353,7 +353,7 @@
renderService.toXml( response.getOutputStream(), summary );
}
- @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
+ @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
{
if ( !aclService.canCreate( currentUserService.getCurrentUser(), getEntityClass() ) )
@@ -382,9 +382,9 @@
// PUT
//--------------------------------------------------------------------------
- @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
- @ResponseStatus(value = HttpStatus.NO_CONTENT)
- public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream
+ @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
input ) throws Exception
{
List<T> objects = getEntity( uid );
@@ -413,9 +413,9 @@
renderService.toXml( response.getOutputStream(), summary );
}
- @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseStatus(value = HttpStatus.NO_CONTENT)
- public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream
+ @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
input ) throws Exception
{
List<T> objects = getEntity( uid );
@@ -448,9 +448,9 @@
// DELETE
//--------------------------------------------------------------------------
- @RequestMapping(value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
- @ResponseStatus(value = HttpStatus.NO_CONTENT)
- public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid )
+ @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid )
throws Exception
{
List<T> objects = getEntity( uid );
@@ -525,6 +525,11 @@
protected List<T> getEntityList( WebMetaData metaData, WebOptions options )
{
+ return getEntityList( metaData, options, null );
+ }
+
+ protected List<T> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters )
+ {
List<T> entityList;
if ( options.getOptions().containsKey( "query" ) )
@@ -602,7 +607,7 @@
private String entitySimpleName;
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
protected Class<T> getEntityClass()
{
if ( entityClass == null )
@@ -634,7 +639,7 @@
return entitySimpleName;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
protected T getEntityInstance()
{
try
=== 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 2014-08-08 08:54:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java 2014-09-30 04:38:03 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.common.PagerUtils;
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.schema.descriptors.DataElementOperandSchemaDescriptor;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
@@ -43,6 +44,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
/**
@@ -55,7 +57,8 @@
@Autowired
private DataElementCategoryService categoryService;
- protected List<DataElementOperand> getEntityList( WebMetaData metaData, WebOptions options )
+ @Override
+ protected List<DataElementOperand> getEntityList( WebMetaData metaData, WebOptions options, List<String> filters )
{
List<DataElementOperand> dataElementOperands;
@@ -65,8 +68,31 @@
}
else
{
- List<DataElement> dataElements = new ArrayList<>( manager.getAllSorted( DataElement.class ) );
- dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElements ) );
+ Iterator<String> iterator = filters.iterator();
+ String deGroup = null;
+
+ while ( iterator.hasNext() )
+ {
+ String filter = iterator.next();
+
+ if ( filter.startsWith( "dataElement.dataElementGroup.id:eq:" ) )
+ {
+ deGroup = filter.substring( "dataElement.dataElementGroup.id:eq:".length() );
+ iterator.remove();
+ break;
+ }
+ }
+
+ if ( deGroup != null )
+ {
+ DataElementGroup dataElementGroup = manager.get( DataElementGroup.class, deGroup );
+ dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElementGroup.getMembers() ) );
+ }
+ else
+ {
+ List<DataElement> dataElements = new ArrayList<>( manager.getAllSorted( DataElement.class ) );
+ dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElements ) );
+ }
}
if ( options.hasPaging() )