← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 94: dhis-web-dataentry: fixed bug lp:344752 unable to select current quarterly period in dataentryscreen

 

------------------------------------------------------------
revno: 94
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-03-20 11:30:30 +0100
message:
  dhis-web-dataentry: fixed bug lp:344752 unable to select current quarterly period in dataentryscreen
modified:
  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/resources/META-INF/dhis/beans.xml

=== 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	2009-03-19 17:02:24 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java	2009-03-20 10:30:30 +0000
@@ -28,7 +28,6 @@
  */
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -44,7 +43,6 @@
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.period.CalendarPeriodType;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.UserAuthorityGroup;
@@ -61,7 +59,7 @@
 public class DefaultSelectedStateManager
     implements SelectedStateManager
 {
-    private static final Log LOG = LogFactory.getLog( DefaultSelectedStateManager.class );
+    private static final Log log = LogFactory.getLog( DefaultSelectedStateManager.class );
 
     public static final String SESSION_KEY_SELECTED_DATASET_ID = "data_entry_selected_dataset_id";
 
@@ -73,13 +71,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
     
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-
     private DataSetService dataSetService;
 
     public void setDataSetService( DataSetService dataSetService )
@@ -109,12 +100,6 @@
     }
 
     // -------------------------------------------------------------------------
-    // Cache
-    // -------------------------------------------------------------------------
-
-    private ThreadLocal<List<Period>> generatedPeriodsCache = new ThreadLocal<List<Period>>();
-
-    // -------------------------------------------------------------------------
     // SelectedStateManager implementation
     // -------------------------------------------------------------------------
 
@@ -131,7 +116,6 @@
     // DataSet
     // -------------------------------------------------------------------------
     
-    @SuppressWarnings( "unchecked" )
     public void setSelectedDataSet( DataSet dataSet )
     {
         getSession().put( SESSION_KEY_SELECTED_DATASET_ID, dataSet.getId() );
@@ -141,12 +125,7 @@
     {
         Integer id = (Integer) getSession().get( SESSION_KEY_SELECTED_DATASET_ID );
 
-        if ( id == null )
-        {
-            return null;
-        }
-
-        return dataSetService.getDataSet( id );
+        return id != null ? dataSetService.getDataSet( id ) : null;
     }
 
     public void clearSelectedDataSet()
@@ -158,6 +137,10 @@
     {
         List<DataSet> dataSets = new ArrayList<DataSet>( dataSetService.getDataSetsBySource( organisationUnit ) );
 
+        // ---------------------------------------------------------------------
+        // Retain only DataSets from current user's authority groups
+        // ---------------------------------------------------------------------
+
         if ( !currentUserService.currentUserIsSuper() )
         {
             UserCredentials userCredentials = userStore.getUserCredentials( currentUserService.getCurrentUser() );
@@ -195,7 +178,6 @@
     // Period
     // -------------------------------------------------------------------------
     
-    @SuppressWarnings( "unchecked" )
     public void setSelectedPeriodIndex( Integer index )
     {
         getSession().put( SESSION_KEY_SELECTED_PERIOD_INDEX, index );
@@ -232,41 +214,27 @@
 
     public List<Period> getPeriodList()
     {
-        List<Period> periods = generatedPeriodsCache.get();
         Period basePeriod = getBasePeriod();
-
-        if ( periods == null || periods.size() == 0
-            || !periods.get( 0 ).getPeriodType().equals( basePeriod.getPeriodType() ) || !periods.contains( basePeriod ) )
-        {
-            CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
-
-            LOG.debug( "Generated periods cache invalid, generating new periods based on " + basePeriod );
-
-            periods = periodType.generatePeriods( basePeriod );
-
-            generatedPeriodsCache.set( periods );
-        }
         
+        CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
+
+        List<Period> periods = periodType.generatePeriods( basePeriod );
+
         Date now = new Date();
 
         Iterator<Period> iterator = periods.iterator();
         
-        Collection<Period> persistedPeriods = periodService.getAllPeriods();
-
         while ( iterator.hasNext() )
         {
-            Period period = iterator.next();
-
-            if ( period.getStartDate().after( now ) || !persistedPeriods.contains( period ) )
+            if ( iterator.next().getStartDate().after( now ) )
             {
                 iterator.remove();
             }
         }
-
+        
         return periods;
     }
-
-    @SuppressWarnings( "unchecked" )
+    
     public void nextPeriodSpan()
     {
         List<Period> periods = getPeriodList();
@@ -278,12 +246,9 @@
         if ( newBasePeriod.getStartDate().before( new Date() ) ) // Future periods not allowed
         {
             getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
-
-            generatedPeriodsCache.remove();
         }
     }
 
-    @SuppressWarnings( "unchecked" )
     public void previousPeriodSpan()
     {
         List<Period> periods = getPeriodList();
@@ -293,8 +258,6 @@
         Period newBasePeriod = periodType.getPreviousPeriod( basePeriod );
 
         getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
-
-        generatedPeriodsCache.remove();
     }
 
     // -------------------------------------------------------------------------
@@ -313,22 +276,22 @@
         return dataSet.getPeriodType();
     }
 
-    @SuppressWarnings( "unchecked" )
     private Period getBasePeriod()
     {
         Period basePeriod = (Period) getSession().get( SESSION_KEY_BASE_PERIOD );
+        
         PeriodType periodType = getPeriodType();
 
         if ( basePeriod == null )
         {
-            LOG.debug( "getBasePeriod(): Base period is null, creating new." );
+            log.debug( "Base period is null, creating new" );
 
             basePeriod = periodType.createPeriod();
             getSession().put( SESSION_KEY_BASE_PERIOD, basePeriod );
         }
         else if ( !basePeriod.getPeriodType().equals( periodType ) )
         {
-            LOG.debug( "getBasePeriod(): Wrong type of base period, transforming." );
+            log.debug( "Wrong type of base period, transforming" );
 
             basePeriod = periodType.createPeriod( basePeriod.getStartDate() );
             getSession().put( SESSION_KEY_BASE_PERIOD, basePeriod );
@@ -338,7 +301,7 @@
     }
 
     @SuppressWarnings( "unchecked" )
-    private static final Map getSession()
+    private static final Map<Object, Object> getSession()
     {
         return ActionContext.getContext().getSession();
     }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2009-03-10 10:19:13 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2009-03-20 10:30:30 +0000
@@ -32,8 +32,6 @@
       ref="org.hisp.dhis.user.UserStore"/>
     <property name="currentUserService"
       ref="org.hisp.dhis.user.CurrentUserService"/>
-	<property name="periodService"
-      ref="org.hisp.dhis.period.PeriodService"/>
   </bean>
   
   <bean id="org.hisp.dhis.de.screen.DataEntryScreenManager"



--

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.



Follow ups