← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13682: bugfix for operand/query

 

------------------------------------------------------------
revno: 13682
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-09 17:58:06 +0100
message:
  bugfix for operand/query
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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/api/controller/dataelement/DataElementOperandController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementOperandController.java	2013-12-23 09:13:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementOperandController.java	2014-01-09 16:58:06 +0000
@@ -28,25 +28,34 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
 import org.hisp.dhis.api.controller.AbstractCrudController;
 import org.hisp.dhis.api.controller.WebMetaData;
 import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.common.Pager;
+import org.hisp.dhis.common.PagerUtils;
 import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementOperandService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping( value = DataElementOperandController.RESOURCE_PATH )
+@RequestMapping(value = DataElementOperandController.RESOURCE_PATH)
 public class DataElementOperandController extends AbstractCrudController<DataElementOperand>
 {
     public static final String RESOURCE_PATH = "/dataElementOperands";
@@ -93,4 +102,49 @@
 
         return entityList;
     }
+
+    @RequestMapping( value = "/query/{query}", method = RequestMethod.GET )
+    public String query( @PathVariable String query, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws Exception
+    {
+        WebOptions options = new WebOptions( parameters );
+        WebMetaData metaData = new WebMetaData();
+
+        List<DataElementOperand> dataElementOperands = Lists.newArrayList();
+
+        for ( DataElementOperand dataElementOperand : dataElementOperandService.getAllDataElementOperands() )
+        {
+            if ( dataElementOperand.getDisplayName().toLowerCase().contains( query.toLowerCase() ) )
+            {
+                dataElementOperands.add( dataElementOperand );
+            }
+        }
+
+        if ( options.hasPaging() )
+        {
+            Pager pager = new Pager( options.getPage(), dataElementOperands.size(), options.getPageSize() );
+            metaData.setPager( pager );
+            dataElementOperands = PagerUtils.pageCollection( dataElementOperands, pager );
+        }
+
+        metaData.setDataElementOperands( dataElementOperands );
+
+        String viewClass = options.getViewClass( "basic" );
+
+        if ( viewClass.equals( "basic" ) || viewClass.equals( "sharingBasic" ) )
+        {
+            handleLinksAndAccess( options, metaData, dataElementOperands, false );
+        }
+        else
+        {
+            handleLinksAndAccess( options, metaData, dataElementOperands, true );
+        }
+
+        postProcessEntities( dataElementOperands );
+        postProcessEntities( dataElementOperands, options, parameters );
+
+        model.addAttribute( "model", metaData );
+        model.addAttribute( "viewClass", viewClass );
+
+        return StringUtils.uncapitalize( getEntitySimpleName() ) + "List";
+    }
 }