← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2734: Omitting action rather than throwing runtime exception in dataentry

 

------------------------------------------------------------
revno: 2734
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-01-24 21:34:45 +0100
message:
  Omitting action rather than throwing runtime exception in dataentry
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.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-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java	2011-01-24 19:40:35 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java	2011-01-24 20:34:45 +0000
@@ -230,6 +230,11 @@
 
     public List<Period> getPeriodList()
     {
+        if ( getSelectedDataSet() == null )
+        {
+            return new ArrayList<Period>();
+        }
+        
         Period basePeriod = getBasePeriod();
         
         CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
@@ -253,29 +258,35 @@
     
     public void nextPeriodSpan()
     {
-        List<Period> periods = getPeriodList();
-        CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
-
-        Period basePeriod = periods.get( periods.size() - 1 );
-        Period newBasePeriod = periodType.getNextPeriod( basePeriod );
-
-        if ( newBasePeriod.getStartDate().before( new Date() ) ) // Future periods not allowed
-        {
+        if ( getSelectedDataSet() != null )
+        {
+            List<Period> periods = getPeriodList();
+            CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
+    
+            Period basePeriod = periods.get( periods.size() - 1 );
+            Period newBasePeriod = periodType.getNextPeriod( basePeriod );
+    
+            if ( newBasePeriod.getStartDate().before( new Date() ) ) // Future periods not allowed
+            {
+                getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
+            }
+        }
+    }
+
+    public void previousPeriodSpan()
+    {
+        if ( getSelectedDataSet() != null )
+        {
+            List<Period> periods = getPeriodList();
+            CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
+    
+            Period basePeriod = periods.get( 0 );
+            Period newBasePeriod = periodType.getPreviousPeriod( basePeriod );
+    
             getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
         }
     }
 
-    public void previousPeriodSpan()
-    {
-        List<Period> periods = getPeriodList();
-        CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
-
-        Period basePeriod = periods.get( 0 );
-        Period newBasePeriod = periodType.getPreviousPeriod( basePeriod );
-
-        getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
-    }
-
     public Period reloadPeriod(){
         
         Period period = getSelectedPeriod();
@@ -338,12 +349,7 @@
     {
         DataSet dataSet = getSelectedDataSet();
 
-        if ( dataSet == null )
-        {
-            throw new IllegalStateException( "Cannot ask for PeriodType when no DataSet is selected" );
-        }
-
-        return dataSet.getPeriodType();
+        return dataSet != null ? dataSet.getPeriodType() : null;
     }
 
     private Period getBasePeriod()