← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2221: Fix bug: Cannot save Calculated dataelements into Dataentry module.

 

------------------------------------------------------------
revno: 2221
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-09-24 13:12:10 +0700
message:
  Fix bug: Cannot save Calculated dataelements into Dataentry module.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java
  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/SelectedStateManager.java
  dhis-2/dhis-web/dhis-web-dataentry/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/period/PeriodService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java	2010-09-04 06:30:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java	2010-09-24 06:12:10 +0000
@@ -252,6 +252,8 @@
      */
     Collection<Period> namePeriods( Collection<Period> periods, I18nFormat format );
     
+    Period reloadPeriod( Period period );
+    
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2010-09-18 10:34:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2010-09-24 06:12:10 +0000
@@ -414,11 +414,11 @@
     public String generateExpression( String expression, Period period, Source source, boolean nullIfNoValues, boolean aggregated )
     {
         StringBuffer buffer = null;
-
+        
         if ( expression != null )
         {
             final Matcher matcher = FORMULA_PATTERN.matcher( expression );
-
+            
             buffer = new StringBuffer();
 
             while ( matcher.find() )
@@ -428,11 +428,11 @@
                 final DataElementOperand operand = getOperand( replaceString );
                 
                 String value = null;
-                
+              
                 if ( aggregated )
                 {
                     Double aggregatedValue = aggregatedDataValueService.getAggregatedDataValue( operand.getDataElementId(), operand.getOptionComboId(), period.getId(), source.getId() );
-                    
+
                     value = aggregatedValue != null ? String.valueOf( aggregatedValue ) : null;
                 }
                 else

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2010-09-04 06:30:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2010-09-24 06:12:10 +0000
@@ -93,33 +93,33 @@
     public Collection<Period> getPeriods( final Collection<Integer> identifiers )
     {
         Collection<Period> periods = getAllPeriods();
-        
+
         return identifiers == null ? periods : FilterUtils.filter( periods, new Filter<Period>()
+        {
+            public boolean retain( Period object )
             {
-                public boolean retain( Period object )
-                {
-                    return identifiers.contains( object.getId() );
-                }
-            } );
+                return identifiers.contains( object.getId() );
+            }
+        } );
     }
 
     public Period getPeriodByExternalId( String externalId )
     {
         return periodStore.reloadForceAddPeriod( new Period( externalId ) );
     }
-    
+
     public Collection<Period> getPeriodsByExternalIds( Collection<String> externalIds )
     {
         Collection<Period> periods = new ArrayList<Period>();
-        
+
         for ( String id : externalIds )
         {
             periods.add( getPeriodByExternalId( id ) );
         }
-        
+
         return periods;
     }
-    
+
     public Collection<Period> getPeriodsByPeriodType( PeriodType periodType )
     {
         return periodStore.getPeriodsByPeriodType( periodType );
@@ -129,7 +129,7 @@
     {
         return periodStore.getPeriodsBetweenDates( startDate, endDate );
     }
-    
+
     public Collection<Period> getPeriodsBetweenDates( PeriodType periodType, Date startDate, Date endDate )
     {
         return periodStore.getPeriodsBetweenDates( periodType, startDate, endDate );
@@ -195,19 +195,19 @@
     {
         return periodStore.getPeriods( period, dataElements, sources );
     }
-    
+
     public List<Period> reloadPeriods( List<Period> periods )
     {
         List<Period> reloaded = new ArrayList<Period>();
-        
+
         for ( Period period : periods )
         {
             reloaded.add( periodStore.reloadForceAddPeriod( period ) );
         }
-        
+
         return reloaded;
     }
-    
+
     public List<Period> getPeriods( Period lastPeriod, int historyLength )
     {
         List<Period> periods = new ArrayList<Period>( historyLength );
@@ -215,15 +215,15 @@
         CalendarPeriodType periodType = (CalendarPeriodType) lastPeriod.getPeriodType();
 
         Period period = lastPeriod;
-        
+
         Period p = new Period();
 
         for ( int i = 0; i < historyLength; ++i )
         {
             p = getPeriodFromDates( period.getStartDate(), period.getEndDate(), periodType );
-            
+
             periods.add( p != null ? p : period );
-            
+
             period = periodType.getPreviousPeriod( period );
         }
 
@@ -231,17 +231,17 @@
 
         return periods;
     }
-    
+
     public Collection<Period> namePeriods( Collection<Period> periods, I18nFormat format )
     {
         for ( Period period : periods )
         {
             period.setName( format.formatPeriod( period ) );
         }
-        
+
         return periods;
     }
-    
+
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------
@@ -260,14 +260,19 @@
     {
         return PeriodType.getPeriodTypeByName( name );
     }
-    
+
     public PeriodType getPeriodTypeByClass( Class<? extends PeriodType> periodType )
     {
         return periodStore.getPeriodType( periodType );
     }
-    
+
     public Period getPeriodFromDates( Date startDate, Date endDate, PeriodType periodType )
     {
         return periodStore.getPeriodFromDates( startDate, endDate, periodType );
     }
+
+    public Period reloadPeriod( Period period )
+    {
+        return periodStore.reloadPeriod( period );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java	2010-08-31 08:14:32 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/CalculateCDEsAction.java	2010-09-24 06:12:10 +0000
@@ -76,7 +76,7 @@
     {
         this.statefulDataValueSaver = statefulDataValueSaver;
     }
-    
+
     private ExpressionService expressionService;
 
     public void setExpressionService( ExpressionService expressionService )
@@ -85,7 +85,7 @@
     }
 
     private DataElementCategoryService categoryService;
-    
+
     public void setCategoryService( DataElementCategoryService categoryService )
     {
         this.categoryService = categoryService;
@@ -110,56 +110,58 @@
         throws Exception
     {
         OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
-        
-        Period period = selectedStateManager.getSelectedPeriod();
-        
+
+        Period period = selectedStateManager.reloadPeriod();
+
         Collection<DataElement> dataElements = selectedStateManager.getSelectedDataSet().getDataElements();
-        
+
         if ( dataElements.size() > 0 )
-        {           	
+        {
             Collection<CalculatedDataElement> cdes = dataElementService
-            	.getCalculatedDataElementsByDataElements( dataElements );
-        	
-            //Look for the existence of CDEs in the form itself
-            Iterator<DataElement> iterator = dataElements.iterator();            
+                .getCalculatedDataElementsByDataElements( dataElements );
+
+            // Look for the existence of CDEs in the form itself
+            Iterator<DataElement> iterator = dataElements.iterator();
 
             while ( iterator.hasNext() )
             {
                 DataElement dataElement = iterator.next();
 
                 if ( dataElement instanceof CalculatedDataElement )
-                {                	
-                    cdes.add( (CalculatedDataElement) dataElement );  
+                {
+                    cdes.add( (CalculatedDataElement) dataElement );
                 }
-            }            
-        	
+            }
+
             cdeValueMap = new HashMap<Integer, String>();
 
             String value = null;
 
             for ( CalculatedDataElement cde : cdes )
-            {        		
-    		value = expressionService.getExpressionValue( cde.getExpression(), period, organisationUnit, false, false ).toString();        			
-    		
-    		if ( value == null )
-    		{
-    		    continue;
-    		}
-
-    		// Should the value be updated in Data Entry?
-    		if ( dataElements.contains( cde ) )
-    		{        		
-    		    cdeValueMap.put( cde.getId(), value );        			
-    		}
-
-    		// Should the value be saved to the database?
-    		if ( cde.isSaved() )
-    		{
-                    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
-    		    statefulDataValueSaver.saveValue( cde.getId(), optionCombo.getId(), "" + value );
-    		}
-
-    		value = null;
+            {
+                value = expressionService.getExpressionValue( cde.getExpression(), period, organisationUnit, false,
+                    false ).toString();
+                
+                if ( value == null )
+                {
+                    continue;
+                }
+
+                // Should the value be updated in Data Entry?
+                if ( dataElements.contains( cde ) )
+                {
+                    cdeValueMap.put( cde.getId(), value );
+                }
+
+                // Should the value be saved to the database?
+                if ( cde.isSaved() )
+                {
+                    DataElementCategoryOptionCombo optionCombo = categoryService
+                        .getDefaultDataElementCategoryOptionCombo();
+                    statefulDataValueSaver.saveValue( cde.getId(), optionCombo.getId(), "" + value );
+                }
+
+                value = null;
             }
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java	2010-08-20 08:34:39 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SaveValueAction.java	2010-09-24 06:12:10 +0000
@@ -168,7 +168,7 @@
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
 
         Period period = selectedStateManager.getSelectedPeriod();
-
+System.out.println("\n\n\n ++++  selected period : " + period + " +++++ \n" );
         DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
         storedBy = currentUserService.getCurrentUsername();

=== 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	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java	2010-09-24 06:12:10 +0000
@@ -43,6 +43,7 @@
 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;
@@ -99,6 +100,13 @@
         this.currentUserService = currentUserService;
     }
 
+    public PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+    
     // -------------------------------------------------------------------------
     // SelectedStateManager implementation
     // -------------------------------------------------------------------------
@@ -107,6 +115,7 @@
     // OrganisationUnit
     // -------------------------------------------------------------------------
     
+
     public OrganisationUnit getSelectedOrganisationUnit()
     {
         return selectionManager.getSelectedOrganisationUnit();
@@ -260,6 +269,13 @@
         getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
     }
 
+    public Period reloadPeriod(){
+        
+        Period period = getSelectedPeriod();
+
+        return periodService.reloadPeriod( period );
+    }
+    
     // -------------------------------------------------------------------------
     // Support methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java	2010-09-24 06:12:10 +0000
@@ -74,4 +74,6 @@
     void nextPeriodSpan();
 
     void previousPeriodSpan();
+    
+    Period reloadPeriod();
 }

=== 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	2010-08-31 14:34:31 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2010-09-24 06:12:10 +0000
@@ -26,6 +26,7 @@
 			ref="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
 		<property name="userStore" 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" class="org.hisp.dhis.de.screen.DefaultDataEntryScreenManager">