← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1338: Added method DataElementService.getDataElementsByPeriodType(PeriodType) and added it to common aj...

 

------------------------------------------------------------
revno: 1338
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-01-25 16:21:02 +0100
message:
  Added method DataElementService.getDataElementsByPeriodType(PeriodType) and added it to common ajax request getDataElements.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml


--
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/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2010-01-25 07:24:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java	2010-01-25 15:21:02 +0000
@@ -33,6 +33,7 @@
 import java.util.Set;
 
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
+import org.hisp.dhis.period.PeriodType;
 
 /**
  * Defines service functionality for DataElements and DataElementGroups.
@@ -212,6 +213,14 @@
     Collection<DataElement> getDataElementsByType( String type );
 
     /**
+     * Returns the DataElements with the given PeriodType.
+     * 
+     * @param periodType the PeriodType.
+     * @return a Collection of DataElements.
+     */
+    Collection<DataElement> getDataElementsByPeriodType( PeriodType periodType );
+    
+    /**
      * Returns all DataElements with the given category combo.
      * 
      * @param categoryCombo the DataElementCategoryCombo.
@@ -220,12 +229,23 @@
     Collection<DataElement> getDataElementByCategoryCombo( DataElementCategoryCombo categoryCombo );
 
     /**
-     * @param dataElements
-     * @return grouped dataElements based on their categoryCombo
+     * Returns a Map with DataElementCategoryCombo as key and a Collection of
+     * the DataElements belonging to the DataElementCategoryCombo from the given
+     * argument List of DataElements as value.
+     * 
+     * @param dataElements the DataElements to include.
+     * @return grouped DataElements based on their DataElementCategoryCombo.
      */
     Map<DataElementCategoryCombo, Collection<DataElement>> getGroupedDataElementsByCategoryCombo(
         List<DataElement> dataElements );
 
+    /**
+     * Returns the DataElementCategoryCombos associated with the given argument
+     * list of DataElements.
+     * 
+     * @param dataElements the DataElements.
+     * @return a list of DataElements.
+     */
     List<DataElementCategoryCombo> getDataElementCategoryCombos( List<DataElement> dataElements );
 
     /**

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2010-01-25 14:08:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2010-01-25 15:21:02 +0000
@@ -45,6 +45,7 @@
 import org.hisp.dhis.common.comparator.CategoryComboSizeComparator;
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
 import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.UUIdUtils;
@@ -246,6 +247,19 @@
     {
         return i18n( i18nService, dataElementStore.getDataElementsByType( type ) );
     }
+    
+    public Collection<DataElement> getDataElementsByPeriodType( final PeriodType periodType )
+    {
+        Collection<DataElement> dataElements = getAllDataElements();
+
+        return FilterUtils.filter( dataElements, new Filter<DataElement>()
+        {
+            public boolean retain( DataElement dataElement )
+            {
+                return dataElement.getPeriodType() != null && dataElement.getPeriodType().equals( periodType );
+            }
+        } );
+    }
 
     public Collection<DataElement> getDataElementsByDomainType( String domainType )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java	2009-11-21 16:44:08 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java	2010-01-25 15:21:02 +0000
@@ -40,6 +40,8 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.filter.AggregatableDataElementFilter;
 import org.hisp.dhis.system.util.FilterUtils;
 
@@ -78,6 +80,13 @@
     {
         this.dataSetService = dataSetService;
     }
+    
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }    
 
     // -------------------------------------------------------------------------
     // Comparator
@@ -125,6 +134,13 @@
     {
         this.dataSetId = dataSetId;
     }
+    
+    private String periodTypeName;
+
+    public void setPeriodTypeName( String periodTypeName )
+    {
+        this.periodTypeName = periodTypeName;
+    }
 
     private boolean aggregate = false;
 
@@ -154,10 +170,6 @@
             {
                 dataElements = new ArrayList<DataElement>( dataElementGroup.getMembers() );
             }
-            else
-            {
-                dataElements = new ArrayList<DataElement>();
-            }
         }
         else if ( categoryComboId != null && categoryComboId != ALL )
         {
@@ -167,10 +179,6 @@
             {
                 dataElements = new ArrayList<DataElement>( dataElementService.getDataElementByCategoryCombo( categoryCombo ) );
             }
-            else
-            {
-                dataElements = new ArrayList<DataElement>();
-            }
         }
         else if ( dataSetId != null )
         {
@@ -180,9 +188,14 @@
             {
                 dataElements = new ArrayList<DataElement>( dataset.getDataElements() );
             }
-            else
+        }
+        else if ( periodTypeName != null )
+        {
+            PeriodType periodType = periodService.getPeriodTypeByName( periodTypeName );
+            
+            if ( periodType != null )
             {
-                dataElements = new ArrayList<DataElement>();
+                dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsByPeriodType( periodType ) );
             }
         }
         else
@@ -190,6 +203,11 @@
             dataElements = new ArrayList<DataElement>( dataElementService.getAllDataElements() );
         }
         
+        if ( dataElements == null )
+        {
+            dataElements = new ArrayList<DataElement>();
+        }
+        
         Collections.sort( dataElements, dataElementComparator );
         
         displayPropertyHandler.handle( dataElements );

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2010-01-25 11:54:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2010-01-25 15:21:02 +0000
@@ -536,9 +536,9 @@
 	<bean id="org.hisp.dhis.commons.action.GetDataElementsAction"
 		class="org.hisp.dhis.commons.action.GetDataElementsAction" scope="prototype">
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-		<property name="categoryService"
-			ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+		<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
 		<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.commons.action.GetDataSetAction"