← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2233: All Holidays are indicated with different color in DataStatus for India

 

------------------------------------------------------------
revno: 2233
committer: Neeraj <neeraj.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2010-11-30 11:18:19 +0530
message:
  All Holidays are indicated with different color in DataStatus for India
modified:
  local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dashboard/ds/mobile/action/GenerateMobileDataStatusResultAction.java
  local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/mobileDataStatusResult.vm


--
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 'local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dashboard/ds/mobile/action/GenerateMobileDataStatusResultAction.java'
--- local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dashboard/ds/mobile/action/GenerateMobileDataStatusResultAction.java	2010-11-26 12:48:06 +0000
+++ local/in/dhis-web-dashboard/src/main/java/org/hisp/dhis/dashboard/ds/mobile/action/GenerateMobileDataStatusResultAction.java	2010-11-30 05:48:19 +0000
@@ -26,6 +26,8 @@
  */
 package org.hisp.dhis.dashboard.ds.mobile.action;
 
+import java.io.File;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -38,6 +40,9 @@
 import java.util.Set;
 import java.util.UUID;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.hibernate.SessionFactory;
 import org.hisp.dhis.dashboard.util.DashBoardService;
 import org.hisp.dhis.dataelement.DataElement;
@@ -52,11 +57,19 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.reports.ReportService;
+import org.hisp.dhis.reports.Report_inDesign;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserStore;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.support.rowset.SqlRowSet;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 import com.opensymphony.xwork2.Action;
 
@@ -146,6 +159,14 @@
     {
         this.userStore = userStore;
     }
+    
+    private ReportService reportService;
+
+    public void setReportService( ReportService reportService )
+    {
+        this.reportService = reportService;
+    }
+    
     // ---------------------------------------------------------------
     // Output Parameters
     // ---------------------------------------------------------------
@@ -163,6 +184,13 @@
     {
         return ouMapUserPhoneNo;
     }
+    
+    private Map<OrganisationUnit, List<String>> ouMapDataStatusColorList;
+    
+    public Map<OrganisationUnit, List<String>> getOuMapDataStatusColorList()
+    {
+        return ouMapDataStatusColorList;
+    }
 
     private Collection<Period> periodList;
 
@@ -372,6 +400,8 @@
     int orgUnitCount;
 
     private String dataViewName;
+    
+    private String raFolderName;
 
     // ---------------------------------------------------------------
     // Action Implementation
@@ -383,10 +413,12 @@
         System.out.println("Inside Mobile DataStatus Result Action");
         orgUnitCount = 0;
         dataViewName = "";
-
+        raFolderName = reportService.getRAFolderName();
+        
         // Intialization
         periodNameList = new ArrayList<String>();
         ouMapDataStatusResult = new HashMap<OrganisationUnit, List<Integer>>();
+        ouMapDataStatusColorList = new HashMap<OrganisationUnit, List<String>>();
         ouMapUserPhoneNo = new HashMap<OrganisationUnit,String>();//for User PhoneNo Map
         
         results = new ArrayList<Integer>();
@@ -493,10 +525,13 @@
                 orgUnitInfo += "," + ou.getId();
             }
         }
+        
+        List<String> holidayList = getHolidayList();
        
         // Period Related Info
         Period startPeriod = periodService.getPeriod( sDateLB );
         Period endPeriod = periodService.getPeriod( eDateLB );
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
         PeriodType dataSetPeriodType = selDataSet.getPeriodType();        
         periodList = periodService.getPeriodsBetweenDates( dataSetPeriodType, startPeriod.getStartDate(),
@@ -547,8 +582,6 @@
             
             ouMapUserPhoneNo.put( o, userPhoneNo );            
             
-            
-            
             orgUnitInfo = "" + o.getId();
 
             if ( maxOULevel < organisationUnitService.getLevelOfOrganisationUnit( o ) )
@@ -563,6 +596,7 @@
 
             double dataStatusPercentatge;
             List<Integer> dsResults = new ArrayList<Integer>();
+            List<String> colorList = new ArrayList<String>();
             while ( periodIterator.hasNext() )
             {
                 p = (Period) periodIterator.next();
@@ -652,9 +686,36 @@
                 dataStatusPercentatge = Math.round( dataStatusPercentatge * Math.pow( 10, 0 ) ) / Math.pow( 10, 0 );
 
                 dsResults.add( (int) dataStatusPercentatge );
+                
+                if( holidayList.contains( simpleDateFormat.format( p.getStartDate() ) ) )
+                {
+                    colorList.add( "#463e41" );
+                }
+                else
+                {
+                    if ( dataStatusPercentatge == 0 )
+                    {
+                        colorList.add( "#ff0000" );
+                    }
+                    else if ( dataStatusPercentatge > 75)
+                    {
+                        colorList.add( "#a0c0a0" );
+                    }
+                    else if ( dataStatusPercentatge > 40 && dataStatusPercentatge <= 75 )
+                    {
+                        colorList.add( "#a0a0ff" );
+                    }
+                    else
+                    {
+                        colorList.add( "#905090" );
+                    }
+                }
+                
             }
 
+            ouMapDataStatusColorList.put( o, colorList );
             ouMapDataStatusResult.put( o, dsResults );
+            
         }
 
         // For Level Names
@@ -848,5 +909,68 @@
         }
         return deInfo.toString();
     }
+    
+    public List<String> getHolidayList()
+    {
+        String fileName = "holidays.xml";
+        String path = System.getProperty( "user.home" ) + File.separator + "dhis" + File.separator + raFolderName
+            + File.separator + fileName;
+
+        List<String> holidayList = new ArrayList<String>();
+        try
+        {
+            String newpath = System.getenv( "DHIS2_HOME" );
+            if ( newpath != null )
+            {
+                path = newpath + File.separator + raFolderName + File.separator + fileName;
+            }
+        }
+        catch ( NullPointerException npe )
+        {
+            System.out.println( "DHIS2 HOME is not set" );
+            // do nothing, but we might be using this somewhere without
+            // USER_HOME set, which will throw a NPE
+        }
+
+        try
+        {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            Document doc = docBuilder.parse( new File( path ) );
+            if ( doc == null )
+            {
+                System.out.println( "XML File Not Found at user home" );
+                return null;
+            }
+
+            NodeList listOfholidays = doc.getElementsByTagName( "holiday" );
+            int totalholidays = listOfholidays.getLength();
+            for ( int s = 0; s < totalholidays; s++ )
+            {
+                    Element deCodeElement = (Element) listOfholidays.item( s );
+                    NodeList textDECodeList = deCodeElement.getChildNodes();
+                    String holidayDate = ((Node) textDECodeList.item( 0 )).getNodeValue().trim();
+                    holidayList.add( holidayDate );
+                                    
+            }
+            
+        }// try block end
+        catch ( SAXParseException err )
+        {
+            System.out.println( "** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() );
+            System.out.println( " " + err.getMessage() );
+        }
+        catch ( SAXException e )
+        {
+            Exception x = e.getException();
+            ((x == null) ? e : x).printStackTrace();
+        }
+        catch ( Throwable t )
+        {
+            t.printStackTrace();
+        }
+
+        return holidayList;
+    }
 
 }// class end

=== modified file 'local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml	2010-11-29 06:47:55 +0000
+++ local/in/dhis-web-dashboard/src/main/resources/META-INF/dhis/beans.xml	2010-11-30 05:48:19 +0000
@@ -497,6 +497,9 @@
         <property name="organisationUnitService">
             <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
         </property>
+		<property name="reportService">
+            <ref bean="org.hisp.dhis.reports.ReportService"/>
+        </property>
         <property name="sessionFactory" ref="sessionFactory"/>
         <property name="jdbcTemplate" ref="jdbcTemplate"/>
 		<property name="userStore" ref="org.hisp.dhis.user.UserStore">
@@ -518,6 +521,7 @@
         <property name="organisationUnitService">
             <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
         </property>
+		
         <property name="sessionFactory" ref="sessionFactory"/>
         <property name="jdbcTemplate" ref="jdbcTemplate"/>
 		<property name="userStore" ref="org.hisp.dhis.user.UserStore">

=== modified file 'local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/mobileDataStatusResult.vm'
--- local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/mobileDataStatusResult.vm	2010-11-25 07:50:13 +0000
+++ local/in/dhis-web-dashboard/src/main/webapp/dhis-web-dashboard/mobileDataStatusResult.vm	2010-11-30 05:48:19 +0000
@@ -64,6 +64,10 @@
                 <td bgcolor="#ff0000">&nbsp;</td>
                 <td align="left">&nbsp;Not Entered ( 0 )</td>
             </tr>
+            <tr class="TableHeadingCellStyles">
+                <td bgcolor="#463e41">&nbsp;</td>
+                <td align="left">&nbsp;Holidays</td>
+            </tr>
         </table>
     </div>
     #set($count2 = 0)
@@ -102,19 +106,11 @@
                  <td class="TableHeadingCellStyles">$dsValidationPhoneNo</td>
                                
                 #set($dsresultList = $ouMapDataStatusResult.get($chiildorgUnit))
-                    #foreach($result in $dsresultList)
-	                   #set($count2 = $count2 + 1)
-	                    #if($result < 0)
-	                        <td  bgcolor="white">&nbsp;</td>
-		                      #elseif($result == 0)
-		                          <td align="center" bgcolor="#ff0000"><font color="#ffffff">$result</font></td>
-		                      #elseif($result > 75)
-		                          <td align="center" bgcolor="#a0c0a0"><font color="#ffffff">$result</font></td>
-		                      #elseif($result > 40 && $result <= 75 )
-		                           <td align="center" bgcolor="#a0a0ff"><font color="#ffffff">$result</font></td>
-		                      #else
-		                           <td align="center" bgcolor="#905090"><font color="#ffffff">$result</font></td>
-	                  #end
+                #set($dsColorList = $ouMapDataStatusColorList.get($chiildorgUnit))
+                #set($count2 = 0)
+                    #foreach($result in $dsresultList)	                   
+                       <td align="center" bgcolor="$dsColorList.get($count2)"><font color="#ffffff">$result</font></td>
+                       #set($count2 = $count2 + 1)
 	              #end
             </tr>
           #end