← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13770: Impl GeneratedDataElementOperandController. Operands come in two fashions, one being persisted an...

 

------------------------------------------------------------
revno: 13770
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-01-18 15:41:38 +0100
message:
  Impl GeneratedDataElementOperandController. Operands come in two fashions, one being persisted and user for favorites, grey-fields etc, and another generated for all option combos for data elements.
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/GeneratedDataElementOperandController.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.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/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java	2014-01-07 19:29:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java	2014-01-18 14:41:38 +0000
@@ -175,6 +175,11 @@
     @Override
     public String getName()
     {
+        if ( name != null )
+        {
+            return name;
+        }
+        
         String name = null;
         
         if ( dataElement != null )
@@ -368,6 +373,9 @@
         this.frequencyOrder = dataElement.getFrequencyOrder();
         this.aggregationLevels = new ArrayList<Integer>( dataElement.getAggregationLevels() );
         this.valueType = dataElement.getType();
+
+        this.uid = dataElementId + SEPARATOR + optionComboId;
+        this.name = getPrettyName( dataElement, categoryOptionCombo );
     }
 
     /**
@@ -379,11 +387,14 @@
     {
         this.dataElementId = dataElement.getUid();
         this.operandId = String.valueOf( dataElementId );
-        this.operandName = dataElement.getDisplayName() + SPACE + NAME_TOTAL;
+        this.operandName = getPrettyName( dataElement, null );
         this.aggregationOperator = dataElement.getAggregationOperator();
         this.frequencyOrder = dataElement.getFrequencyOrder();
         this.aggregationLevels = new ArrayList<Integer>( dataElement.getAggregationLevels() );
         this.valueType = dataElement.getType();
+
+        this.uid = dataElementId;
+        this.name = getPrettyName( dataElement, null );
     }
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2014-01-07 19:29:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2014-01-18 14:41:38 +0000
@@ -603,9 +603,14 @@
         return operands;
     }
 
+    public Collection<DataElementOperand> getOperands( Collection<DataElement> dataElements )
+    {
+        return getOperands( dataElements, false );
+    }
+
     public Collection<DataElementOperand> getOperands( Collection<DataElement> dataElements, boolean includeTotals )
     {
-        Collection<DataElementOperand> operands = new ArrayList<DataElementOperand>();
+        List<DataElementOperand> operands = new ArrayList<DataElementOperand>();
 
         for ( DataElement dataElement : dataElements )
         {
@@ -630,11 +635,6 @@
         return operands;
     }
 
-    public Collection<DataElementOperand> getOperands( Collection<DataElement> dataElements )
-    {
-        return getOperands( dataElements, false );
-    }
-
     public Collection<DataElementOperand> getOperandsLikeName( String name )
     {
         Collection<DataElement> dataElements = dataElementService.getDataElementsLikeName( name );

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/GeneratedDataElementOperandController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/GeneratedDataElementOperandController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/GeneratedDataElementOperandController.java	2014-01-18 14:41:38 +0000
@@ -0,0 +1,151 @@
+package org.hisp.dhis.api.controller.dataelement;
+
+/*
+ * Copyright (c) 2004-2013, 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;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+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.common.comparator.IdentifiableObjectNameComparator;
+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.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;
+
+/**
+ * @author Lars Helge Overland
+ */
+@Controller
+@RequestMapping(value = GeneratedDataElementOperandController.RESOURCE_PATH)
+public class GeneratedDataElementOperandController
+    extends AbstractCrudController<DataElementOperand>
+{
+    public static final String RESOURCE_PATH = "/generatedDataElementOperands";
+
+    @Autowired
+    private DataElementCategoryService categoryService;
+
+    @Override
+    protected List<DataElementOperand> getEntityList( WebMetaData metaData, WebOptions options )
+    {
+        List<DataElement> dataElements = null;
+        
+        if ( options.getOptions().containsKey( "dataElementGroup" ) )
+        {
+            DataElementGroup group = manager.get( DataElementGroup.class, options.getOptions().get( "dataElementGroup" ) );
+
+            if ( group != null )
+            {
+                dataElements = new ArrayList<DataElement>( group.getMembers() );
+
+                Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE );
+            }
+        }
+        else
+        {
+            dataElements = new ArrayList<DataElement>( manager.getAllSorted( DataElement.class ) );
+        }
+        
+        List<DataElementOperand> entityList = new ArrayList<DataElementOperand>( categoryService.getOperands( dataElements ) );
+        
+        if ( options.hasPaging() )
+        {
+            Pager pager = new Pager( options.getPage(), entityList.size(), options.getPageSize() );
+            metaData.setPager( pager );
+            entityList = PagerUtils.pageCollection( entityList, pager );            
+        }
+
+        return entityList;
+    }
+
+    @Override
+    @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> allOperands = new ArrayList<DataElementOperand>( categoryService.getOperands( manager.getAllSorted( DataElement.class ) ) );
+        List<DataElementOperand> dataElementOperands = new ArrayList<DataElementOperand>();
+        
+        //TODO this will not scale well
+
+        for ( DataElementOperand operand : allOperands )
+        {
+            if ( operand.getDisplayName().toLowerCase().contains( query.toLowerCase() ) )
+            {
+                dataElementOperands.add( operand );
+            }
+        }
+
+        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";
+    }
+}