← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2194: fixed bug:Excel report generator: can't use << and >> for period (earlier-later) references/gener...

 

------------------------------------------------------------
revno: 2194
committer: Tran Thanh Tri <Tran Thanh Tri@compaq>
branch nick: trunk
timestamp: Wed 2010-09-22 14:30:22 +0700
message:
  fixed bug:Excel report generator: can't use << and >> for period (earlier-later) references/generator
removed:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responsePeriods.vm
modified:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/SelectFormAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/DefaultPeriodGenericManager.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/action/GetPeriodsByPeriodTypeAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/export.js
  dhis-2/dhis-web/pom.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-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/SelectFormAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/SelectFormAction.java	2010-09-16 07:33:22 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/SelectFormAction.java	2010-09-22 07:30:22 +0000
@@ -123,7 +123,8 @@
 
         groups = new ArrayList<String>( reportService.getReportExcelGroups() );
 
-        periodGenericManager.setPeriodType( MonthlyPeriodType.NAME );
+        periodGenericManager.setPeriodType( MonthlyPeriodType.NAME );       
+        
 
         periods = periodGenericManager.getPeriodList();
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/DefaultPeriodGenericManager.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/DefaultPeriodGenericManager.java	2010-09-16 07:33:22 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/DefaultPeriodGenericManager.java	2010-09-22 07:30:22 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
@@ -37,9 +36,8 @@
 import org.apache.commons.logging.LogFactory;
 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.period.comparator.AscendingPeriodComparator;
-import org.hisp.dhis.period.comparator.PeriodComparator;
 
 import com.opensymphony.xwork2.ActionContext;
 
@@ -53,27 +51,41 @@
 
     private static final Log log = LogFactory.getLog( DefaultPeriodGenericManager.class );
 
-    public static final String SESSION_KEY_SELECTED_PERIOD_GENERIC_INDEX = "SESSION_KEY_SELECTED_PERIOD_GENERIC_INDEX";
-
-    public static final String SESSION_KEY_BASE_PERIOD_GENERIC = "SESSION_KEY_BASE_PERIOD_GENERIC";
-
-    public static final String SESSION_KEY_BASE_PERIOD_TYPE_GENERIC = "SESSION_KEY_BASE_PERIOD_TYPE_GENERIC";
-
+
+    public static final String SESSION_KEY_SELECTED_PERIOD_TYPE= "SESSION_KEY_SELECTED_PERIOD_TYPE";
+
+    public static final String SESSION_KEY_SELECTED_PERIOD_INDEX = "SESSION_KEY_SELECTED_PERIOD_INDEX";
+
+    public static final String SESSION_KEY_BASE_PERIOD = "SESSION_KEY_BASE_PERIOD";
+    
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+  
+
+    // -------------------------------------------------------------------------
+    // Period
+    // -------------------------------------------------------------------------
+    
     public void setSelectedPeriodIndex( Integer index )
     {
-
-        getSession().put( SESSION_KEY_SELECTED_PERIOD_GENERIC_INDEX, index );
+        getSession().put( SESSION_KEY_SELECTED_PERIOD_INDEX, index );
     }
 
     public Integer getSelectedPeriodIndex()
     {
-
-        return (Integer) getSession().get( SESSION_KEY_SELECTED_PERIOD_GENERIC_INDEX );
+        return (Integer) getSession().get( SESSION_KEY_SELECTED_PERIOD_INDEX );
     }
 
     public Period getSelectedPeriod()
     {
-
         Integer index = getSelectedPeriodIndex();
 
         if ( index == null )
@@ -93,14 +105,13 @@
 
     public void clearSelectedPeriod()
     {
-        getSession().remove( SESSION_KEY_SELECTED_PERIOD_GENERIC_INDEX );
+        getSession().remove( SESSION_KEY_SELECTED_PERIOD_INDEX );
     }
 
     public List<Period> getPeriodList()
     {
-
         Period basePeriod = getBasePeriod();
-
+        
         CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType();
 
         List<Period> periods = periodType.generatePeriods( basePeriod );
@@ -108,58 +119,41 @@
         Date now = new Date();
 
         Iterator<Period> iterator = periods.iterator();
-
+        
         while ( iterator.hasNext() )
         {
-
             if ( iterator.next().getStartDate().after( now ) )
             {
-
                 iterator.remove();
             }
         }
-
-        Collections.sort( periods, new PeriodComparator() );
-
+        
         return periods;
     }
     
-
-    @Override
-    public Period getSelectedPeriod( Integer index )
-    {        
-        return getPeriodList().get( index );
-    }
-
     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() ) )
+        if ( newBasePeriod.getStartDate().before( new Date() ) ) // Future periods not allowed
         {
-            getSession().put( SESSION_KEY_BASE_PERIOD_GENERIC, newBasePeriod );
+            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_GENERIC, newBasePeriod );
+        getSession().put( SESSION_KEY_BASE_PERIOD, newBasePeriod );
     }
 
     // -------------------------------------------------------------------------
@@ -168,22 +162,13 @@
 
     private PeriodType getPeriodType()
     {
-
-        String periodTypeName = (String) getSession().get( SESSION_KEY_BASE_PERIOD_TYPE_GENERIC );
-
-        if ( periodTypeName == null )
-        {
-            throw new IllegalStateException( "Cannot ask for Period Type when no Period Type Name is setted" );
-        }
-
-        return PeriodType.getPeriodTypeByName( periodTypeName );
+        return (PeriodType) getSession().get( SESSION_KEY_SELECTED_PERIOD_TYPE );
     }
 
     private Period getBasePeriod()
     {
-
-        Period basePeriod = (Period) getSession().get( SESSION_KEY_BASE_PERIOD_GENERIC );
-
+        Period basePeriod = (Period) getSession().get( SESSION_KEY_BASE_PERIOD );
+        
         PeriodType periodType = getPeriodType();
 
         if ( basePeriod == null )
@@ -191,18 +176,14 @@
             log.debug( "Base period is null, creating new" );
 
             basePeriod = periodType.createPeriod();
-
-            getSession().put( SESSION_KEY_BASE_PERIOD_GENERIC, basePeriod );
-
+            getSession().put( SESSION_KEY_BASE_PERIOD, basePeriod );
         }
         else if ( !basePeriod.getPeriodType().equals( periodType ) )
         {
-
             log.debug( "Wrong type of base period, transforming" );
 
             basePeriod = periodType.createPeriod( basePeriod.getStartDate() );
-
-            getSession().put( SESSION_KEY_BASE_PERIOD_GENERIC, basePeriod );
+            getSession().put( SESSION_KEY_BASE_PERIOD, basePeriod );
         }
 
         return basePeriod;
@@ -210,14 +191,20 @@
 
     private static final Map<String, Object> getSession()
     {
-
         return ActionContext.getContext().getSession();
     }
 
     @Override
-    public void setPeriodType( String periodTypeNam )
-    {
-        getSession().put( SESSION_KEY_BASE_PERIOD_TYPE_GENERIC, periodTypeNam );
+    public Period getSelectedPeriod( Integer index )
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setPeriodType( String periodType )
+    {
+        getSession().put( SESSION_KEY_SELECTED_PERIOD_TYPE, periodService.getPeriodTypeByName( periodType ) );
     }
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/action/GetPeriodsByPeriodTypeAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/action/GetPeriodsByPeriodTypeAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/period/generic/action/GetPeriodsByPeriodTypeAction.java	2010-09-22 07:30:22 +0000
@@ -79,9 +79,8 @@
     public String execute()
         throws Exception
     {
-        if ( periodTypeName == null || periodTypeName == "" )
+        if ( periodTypeName == null  )
         {
-
             periodGenericManager.setPeriodType( MonthlyPeriodType.NAME );
         }
         else

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2010-09-16 07:33:22 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2010-09-22 07:30:22 +0000
@@ -63,6 +63,7 @@
 	<bean id="org.hisp.dhis.reportexcel.period.generic.PeriodGenericManager"
 		class="org.hisp.dhis.reportexcel.period.generic.DefaultPeriodGenericManager"
 		scope="singleton">
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
 	</bean>
 
 	<bean

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2010-09-16 02:32:55 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2010-09-22 07:30:22 +0000
@@ -66,38 +66,38 @@
 
 		<action name="getPeriodsByPeriodTypeDB"
 			class="org.hisp.dhis.reportexcel.period.db.action.GetPeriodsByPeriodTypeAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-excel-reporting/responsePeriods.vm</result>
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonPeriods.vm</result>
 		</action>
 
 		<action name="nextPeriodsDB"
 			class="org.hisp.dhis.reportexcel.period.db.action.NextPeriodsAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-excel-reporting/responsePeriods.vm</result>
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonPeriods.vm</result>
 		</action>
 
 		<action name="previousPeriodsDB"
 			class="org.hisp.dhis.reportexcel.period.db.action.PreviousPeriodsAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-excel-reporting/responsePeriods.vm</result>
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonPeriods.vm</result>
 		</action>
 
 		<action name="getPeriodsByPeriodTypeGeneric"
 			class="org.hisp.dhis.reportexcel.period.generic.action.GetPeriodsByPeriodTypeAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-excel-reporting/responsePeriods.vm</result>
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonPeriods.vm</result>
 		</action>
 
 		<action name="nextPeriodsGeneric"
 			class="org.hisp.dhis.reportexcel.period.generic.action.NextPeriodsAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-excel-reporting/responsePeriods.vm</result>
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonPeriods.vm</result>
 		</action>
 
 		<action name="previousPeriodsGeneric"
 			class="org.hisp.dhis.reportexcel.period.generic.action.PreviousPeriodsAction">
-			<result name="success" type="velocity-xml">
-				/dhis-web-excel-reporting/responsePeriods.vm</result>
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonPeriods.vm</result>
 		</action>
 
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/export.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/export.js	2010-09-16 07:33:22 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/export.js	2010-09-22 07:30:22 +0000
@@ -54,34 +54,24 @@
 	byId("selectedOrganisationUnit").innerHTML = selectedOrganisationUnit; 
 }
 
-function getPreviousPeriod() {
-
-	var request = new Request();
-	request.setResponseTypeXML( 'xmlObject' );
-	request.setCallbackSuccess( responseListPeriodReceived );
-	request.send( 'previousPeriodsDB.action' ); 
-}
-
-function getNextPeriod() {
-
-	var request = new Request();
-	request.setResponseTypeXML( 'xmlObject' );
-	request.setCallbackSuccess( responseListPeriodReceived );
-	request.send( 'nextPeriodsDB.action' ); 
-}
-
-function responseListPeriodReceived( xmlObject ) {
-
+function getPreviousPeriod() 
+{
+	jQuery.postJSON('previousPeriodsGeneric.action', responseListPeriodReceived );	
+}
+
+function getNextPeriod() 
+{
+	jQuery.postJSON('nextPeriodsGeneric.action', responseListPeriodReceived );	
+}
+
+function responseListPeriodReceived( json ) 
+{	
 	clearListById('period');
-	var nodes = xmlObject.getElementsByTagName('period');
-	
-	for ( var i = 0; i < nodes.length; i++ )
-    {
-        node = nodes.item(i);  
-        var id = node.getElementsByTagName('id')[0].firstChild.nodeValue;
-        var name = node.getElementsByTagName('name')[0].firstChild.nodeValue;
-		addOption('period', name, id);
-    }
+	
+	jQuery.each( json.periods, function(i, item ){
+		addOption('period', item.name , i );
+	});
+	
 }
 
 function generateReportExcel() {

=== removed file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responsePeriods.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responsePeriods.vm	2009-09-14 03:19:36 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/responsePeriods.vm	1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<periods>
-	#foreach($period in $periods)
-		<period>
-			<id>$period.id</id>
-			<name>$format.formatPeriod( $period )</name>
-		</period>		
-	#end
-</periods>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/pom.xml'
--- dhis-2/dhis-web/pom.xml	2010-08-20 09:13:09 +0000
+++ dhis-2/dhis-web/pom.xml	2010-09-22 07:30:22 +0000
@@ -21,9 +21,9 @@
     <module>dhis-web-reporting</module>
     <module>dhis-web-mapping</module>
     <module>dhis-web-dashboard-integration</module>
-    <module>dhis-web-excel-reporting</module>
-    <module>dhis-web-caseentry</module>
-    <module>dhis-web-portal</module>	
+    <module>dhis-web-excel-reporting</module>   
+	<module>dhis-web-caseentry</module>
+    <module>dhis-web-portal</module>		
 </modules>
   
   <build>