← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1914: Add ImportDataValueAction.java for server and DataValueUploadManager.java for client.

 

------------------------------------------------------------
revno: 1914
committer: Long <thanhlongngo1988>
branch nick: cbhis-mobile
timestamp: Mon 2010-09-13 10:48:16 +0700
message:
  Add ImportDataValueAction.java for server and DataValueUploadManager.java for client.
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java
  dhis-2/dhis-web/dhis-web-api/src/main/resources/exception.vm
  dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/dhis-web-case-api/main.vm
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DataValueUploadManager.java
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.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
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java	2010-09-13 03:48:16 +0000
@@ -0,0 +1,189 @@
+package org.hisp.dhis.web.api.action;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.interceptor.ServletRequestAware;
+import org.apache.struts2.interceptor.ServletResponseAware;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.patientdatavalue.PatientDataValueService;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import com.opensymphony.xwork2.ActionSupport;
+
+public class ImportDataValueAction
+    extends ActionSupport
+    implements ServletRequestAware, ServletResponseAware
+{
+    // Dependencies
+    private ProgramStageInstanceService programStageInstanceService;
+
+    private PatientDataValueService patientDataValueService;
+
+    private DataElementService dataElementService;
+
+    private HttpServletRequest request;
+
+    private HttpServletResponse response;
+
+    private OrganisationUnitService orgUnitService;
+
+    private DataElementCategoryService dataElementCategoryService;
+
+    // Setter and Getter
+    @Override
+    public void setServletResponse( HttpServletResponse response )
+    {
+        this.response = response;
+
+    }
+
+    @Override
+    public void setServletRequest( HttpServletRequest request )
+    {
+        this.request = request;
+
+    }
+
+    public HttpServletRequest getServletRequest()
+    {
+        return request;
+    }
+
+    public HttpServletResponse getServletResponse()
+    {
+        return response;
+    }
+
+    public ProgramStageInstanceService getProgramStageInstanceService()
+    {
+        return programStageInstanceService;
+    }
+
+    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
+    {
+        this.programStageInstanceService = programStageInstanceService;
+    }
+
+    public PatientDataValueService getPatientDataValueService()
+    {
+        return patientDataValueService;
+    }
+
+    public void setPatientDataValueService( PatientDataValueService patientDataValueService )
+    {
+        this.patientDataValueService = patientDataValueService;
+    }
+
+    public DataElementService getDataElementService()
+    {
+        return dataElementService;
+    }
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+    public OrganisationUnitService getOrgUnitService()
+    {
+        return orgUnitService;
+    }
+
+    public void setOrgUnitService( OrganisationUnitService orgUnitService )
+    {
+        this.orgUnitService = orgUnitService;
+    }
+
+    public DataElementCategoryService getDataElementCategoryService()
+    {
+        return dataElementCategoryService;
+    }
+
+    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+    {
+        this.dataElementCategoryService = dataElementCategoryService;
+    }
+
+    // Output
+    private InputStream inputStream;
+
+    public InputStream getInputStream()
+    {
+        return inputStream;
+    }
+
+    public void setInputStream( InputStream inputStream )
+    {
+        this.inputStream = inputStream;
+    }
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        String message = "Upload Successfully!";
+        request = ServletActionContext.getRequest();
+        response = ServletActionContext.getResponse();
+        this.setInputStream( new ByteArrayInputStream( message.getBytes() ) );
+        
+        InputStream clientInput = request.getInputStream();
+        DataInputStream dis = new DataInputStream( clientInput );
+        
+        if ( clientInput.available() > -1 )
+        {
+            int numOfDataValue = dis.readInt();
+            OrganisationUnit orgUnit = orgUnitService.getOrganisationUnit( dis.readInt() );
+            this.setInputStream( new ByteArrayInputStream( message.getBytes() ) );
+            try
+            {
+                for ( int i = 0; i < numOfDataValue; i++ )
+                {
+                    this.saveDataValue( dis, orgUnit );
+                }
+            }
+            catch ( Exception ex )
+            {
+                message = "Upload fail!";
+                this.setInputStream( new ByteArrayInputStream( message.getBytes() ) );
+            }
+        }
+        return SUCCESS;
+    }
+
+    private void saveDataValue( DataInputStream dis, OrganisationUnit orgUnit ) throws IOException
+
+    {
+            DataElement dataElement = dataElementService.getDataElement( dis.readInt() );
+            ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( dis
+                .readInt() );
+            DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
+                .getDataElementCategoryOptionCombo( 1 );
+
+            PatientDataValue patientDataValue = new PatientDataValue();
+            patientDataValue.setDataElement( dataElement );
+            patientDataValue.setOptionCombo( optionCombo );
+            patientDataValue.setOrganisationUnit( orgUnit );
+            patientDataValue.setProgramStageInstance( programStageInstance );
+            patientDataValue.setTimestamp( new Date() );
+            patientDataValue.setProvidedByAnotherFacility( false );
+            patientDataValue.setValue( dis.readUTF() );
+
+            patientDataValueService.savePatientDataValue( patientDataValue );
+        }
+
+
+    }
+
+

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml	2010-08-25 17:40:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml	2010-09-13 03:48:16 +0000
@@ -1,28 +1,49 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans";
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-  xsi:schemaLocation="
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+	xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd";>
-
-  <!-- Resources -->
-
-  <bean id="org.hisp.dhis.web.api.resources.UserResource" 
-    class="org.hisp.dhis.web.api.resources.UserResource" scope="prototype" />
-
-  <bean id="org.hisp.dhis.web.api.resources.OrgUnitResource" 
-    class="org.hisp.dhis.web.api.resources.OrgUnitResource" scope="prototype" />
-
-  <bean id="org.hisp.dhis.web.api.resources.FormsResource"
-    class="org.hisp.dhis.web.api.resources.FormsResource" scope="prototype" />
-
-  <!-- Web service layer -->
-
-  <bean id="org.hisp.dhis.web.api.service.ActivityPlanModelService"
-      class="org.hisp.dhis.web.api.service.ActivityPlanModelService" />
-
-  <bean id="org.hisp.dhis.web.api.service.ProgramStageService"
-      class="org.hisp.dhis.web.api.service.ProgramStageService" />
-
-  <!-- Response writers -->
-
+	
+	<!-- Resources -->
+	
+	<bean id="org.hisp.dhis.web.api.resources.UserResource"
+		class="org.hisp.dhis.web.api.resources.UserResource" scope="prototype"/>
+	
+	<bean id="org.hisp.dhis.web.api.resources.OrgUnitResource"
+		class="org.hisp.dhis.web.api.resources.OrgUnitResource"
+		scope="prototype"/>
+	
+	<bean id="org.hisp.dhis.web.api.resources.FormsResource"
+		class="org.hisp.dhis.web.api.resources.FormsResource" scope="prototype"/>
+	
+	<!-- Web service layer -->
+	
+	<bean id="org.hisp.dhis.web.api.service.ActivityPlanModelService"
+		class="org.hisp.dhis.web.api.service.ActivityPlanModelService"/>
+	
+	<bean id="org.hisp.dhis.web.api.service.ProgramStageService"
+		class="org.hisp.dhis.web.api.service.ProgramStageService"/>
+	
+	<!-- Response writers -->
+	
+	<!-- ImportDataValue beans -->
+	<bean id="org.hisp.dhis.web.api.action.ImportDataValueAction"
+		class="org.hisp.dhis.web.api.action.ImportDataValueAction">
+		<property name="programStageInstanceService">
+			<ref bean="org.hisp.dhis.program.ProgramStageInstanceService"/>
+		</property>
+		<property name="patientDataValueService">
+			<ref bean="org.hisp.dhis.patientdatavalue.PatientDataValueService"/>
+		</property>
+		<property name="dataElementService">
+			<ref bean="org.hisp.dhis.dataelement.DataElementService"/>
+		</property>
+		<property name="orgUnitService">
+			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+		</property>
+		<property name="dataElementCategoryService">
+			<ref bean="org.hisp.dhis.dataelement.DataElementCategoryService"/>
+		</property>
+	</bean>
+	
 </beans>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/exception.vm'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/exception.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/exception.vm	2010-09-13 03:48:16 +0000
@@ -0,0 +1,102 @@
+#set( $idCount = 0 )
+
+#macro( printException $exception $preText )
+  <h5>
+    #if( $showStackTrace )
+      <span id="toggle$idCount" class="toggle"><a href="javascript:toggle( $idCount )">[+]</a></span>
+    #end
+    $preText (${exception.class.name}):
+    #if( !$exception.message )
+      null
+    #else
+      $encoder.htmlEncode( $exception.message )
+    #end
+  </h5>
+  #if( $showStackTrace )
+    <div id="stackTrace$idCount" style="display:none">
+      #set( $idCount = $idCount + 1 )
+      <ul>
+        #foreach( $element in $exception.stackTrace )
+          #if( $element.fileName )
+            <li>${element.className}.${element.methodName}(${element.fileName}:${element.lineNumber})</li>
+          #else
+            <li>${element.className}.${element.methodName}($i18n.getString( "unknown_source" ))</li>
+          #end
+        #end
+      </ul>
+    </div>
+  #end
+  #if( $exception.cause )
+    #printException( $exception.cause $i18n.getString( "caused_by" ) )
+  #end
+#end
+
+## -------------------------------------------------------------------------- ##
+
+<html>
+<head>
+  <title>DHIS 2</title>
+  <style>
+  *
+  {
+    font-family: tahoma, sans-serif;
+  }
+
+  .toggle a
+  {
+    font-family: courier, monospace;
+    text-decoration: none;
+  }
+
+  ul
+  {
+    font-size: 10pt;
+    margin-top: 0em;
+  }
+
+  h5
+  {
+    margin-bottom: 0em;
+  }
+  </style>
+  <script type="text/javascript">
+
+  function toggle( idCount )
+  {
+    var stackTraceId = 'stackTrace' + idCount;
+    var toggleId = 'toggle' + idCount;
+    
+    var stackTraceElement = document.getElementById( stackTraceId ); // div
+    var toggleElement = document.getElementById( toggleId );         // span
+    toggleElement = toggleElement.firstChild;                        // a
+    
+    if ( stackTraceElement.style.display == 'none' )
+    {
+      stackTraceElement.style.display = 'block';
+      
+      toggleElement.replaceChild( document.createTextNode( '[-]' ), toggleElement.firstChild );
+    }
+    else
+    {
+      stackTraceElement.style.display = 'none';
+      
+      toggleElement.replaceChild( document.createTextNode( '[+]' ), toggleElement.firstChild );
+    }
+  }
+  </script>
+</head>
+<body>
+
+## -------------------------------------------------------------------------- ##
+
+<h2>$i18n.getString( "an_exception_occured" )</h2>
+
+<p>$encoder.htmlEncode( $i18n.getString( "exception_explanation_text" ))</p>
+<p><input type="button" value="$encoder.htmlEncode( $i18n.getString( "go_back" ))" onclick="history.go( -1 )"></p>
+
+#printException( $exception $i18n.getString( "exception" ) )
+
+## -------------------------------------------------------------------------- ##
+
+</body>
+</html>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml	2010-09-13 03:48:16 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE struts PUBLIC
+"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+"http://struts.apache.org/dtds/struts-2.0.dtd";>
+<struts>
+
+  <include file="dhis-web-commons.xml"/>
+	<package name="dhis-web-api" extends="dhis-web-commons"
+		namespace="/dhis-web-api">
+		
+		<action name="importDataValue" class="org.hisp.dhis.web.api.action.ImportDataValueAction">
+			<result name="success" type="stream">
+				<param name="contentType">text/plain</param>
+				<param name="inputName">inputStream</param>
+				<param name="contentDisposition">inline</param>
+				<param name="bufferSize">1024</param>
+			</result>
+		</action>		
+		
+	</package>
+	
+</struts>

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml	2010-08-25 09:59:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml	2010-09-13 03:48:16 +0000
@@ -1,77 +1,95 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-  "http://java.sun.com/dtd/web-app_2_3.dtd";>
+	"http://java.sun.com/dtd/web-app_2_3.dtd";>
 <web-app>
-  <display-name>DHIS Case Entry</display-name>
-  
-  <context-param>
-    <param-name>contextConfigLocation</param-name>
-    <param-value>classpath*:/META-INF/dhis/beans.xml</param-value>
-  </context-param>
-  <context-param>
-    <param-name>automaticAccessType</param-name>
-    <param-value>ghostAdmin</param-value>
-  </context-param>
-  
-  <filter>
-    <filter-name>RedirectFilter</filter-name>
-    <filter-class>org.hisp.dhis.servlet.filter.HttpRedirectFilter</filter-class>
-    <init-param>
-      <param-name>redirectPath</param-name>
-      <param-value>api/</param-value>
-    </init-param>
-  </filter>
-  <filter>
-    <filter-name>OpenSessionInViewFilter</filter-name>
-    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
-  </filter>
-  
+	<display-name>DHIS Case Entry</display-name>
+	
+	<context-param>
+		<param-name>contextConfigLocation</param-name>
+		<param-value>classpath*:/META-INF/dhis/beans.xml</param-value>
+	</context-param>
+	<context-param>
+		<param-name>automaticAccessType</param-name>
+		<param-value>ghostAdmin</param-value>
+	</context-param>
+	
+	<filter>
+		<filter-name>RedirectFilter</filter-name>
+		<filter-class>
+			org.hisp.dhis.servlet.filter.HttpRedirectFilter</filter-class>
+		<init-param>
+			<param-name>redirectPath</param-name>
+			<param-value>api/</param-value>
+		</init-param>
+	</filter>
+	<filter>
+		<filter-name>OpenSessionInViewFilter</filter-name>
+		<filter-class>
+			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
+	</filter>
 	<filter>
 		<filter-name>filterChainProxy</filter-name>
 		<filter-class>
 			org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 	</filter>
-  
-  <filter-mapping>
-    <filter-name>RedirectFilter</filter-name>
-    <url-pattern>/</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-    <filter-name>OpenSessionInViewFilter</filter-name>
-    <url-pattern>*.action</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-    <filter-name>OpenSessionInViewFilter</filter-name>
-    <url-pattern>/api/*</url-pattern>
-  </filter-mapping>
-  <filter-mapping>
-    <filter-name>filterChainProxy</filter-name>
-    <url-pattern>/*</url-pattern>
-  </filter-mapping>
-  
-  <listener>
-    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-  </listener>
-  <listener>
-    <listener-class>org.hisp.dhis.system.startup.StartupListener</listener-class>
-  </listener>
-
-  <servlet>
-    <servlet-name>web-api</servlet-name>
-    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
-    <init-param>
-      <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
-      <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
-    </init-param>
-    <init-param>
-      <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
-      <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
-    </init-param>
-    <load-on-startup>1</load-on-startup>
-  </servlet>
-  <servlet-mapping>
-    <servlet-name>web-api</servlet-name>
-    <url-pattern>/api/*</url-pattern>
-  </servlet-mapping>
-
-</web-app>
+	
+	<filter>
+		<filter-name>Struts</filter-name>
+		<filter-class>
+			org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
+	</filter>
+	
+	<filter-mapping>
+		<filter-name>RedirectFilter</filter-name>
+		<url-pattern>/</url-pattern>
+	</filter-mapping>
+	<filter-mapping>
+		<filter-name>OpenSessionInViewFilter</filter-name>
+		<url-pattern>*.action</url-pattern>
+	</filter-mapping>
+	<filter-mapping>
+		<filter-name>OpenSessionInViewFilter</filter-name>
+		<url-pattern>/api/*</url-pattern>
+	</filter-mapping>
+	<filter-mapping>
+		<filter-name>filterChainProxy</filter-name>
+		<url-pattern>/*</url-pattern>
+	</filter-mapping>
+	<filter-mapping>
+		<filter-name>Struts</filter-name>
+		<url-pattern>*.action</url-pattern>
+	</filter-mapping>
+	
+	<listener>
+		<listener-class>
+			org.springframework.web.context.ContextLoaderListener</listener-class>
+	</listener>
+	<listener>
+		<listener-class>
+			org.hisp.dhis.system.startup.StartupListener</listener-class>
+	</listener>
+	
+	<servlet>
+		<servlet-name>web-api</servlet-name>
+		<servlet-class>
+			com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
+		<init-param>
+			<param-name>
+				com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
+			<param-value>
+				com.sun.jersey.api.container.filter.LoggingFilter</param-value>
+		</init-param>
+		<init-param>
+			<param-name>
+				com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
+			<param-value>
+				com.sun.jersey.api.container.filter.LoggingFilter</param-value>
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>web-api</servlet-name>
+		<url-pattern>/api/*</url-pattern>
+	</servlet-mapping>
+	
+</web-app>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/dhis-web-case-api/main.vm'
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DataValueUploadManager.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DataValueUploadManager.java	2010-09-08 09:52:06 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DataValueUploadManager.java	2010-09-13 03:48:16 +0000
@@ -2,20 +2,25 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
 import javax.microedition.io.Connector;
 import javax.microedition.io.HttpConnection;
+import javax.microedition.midlet.MIDlet;
 
 import org.hisp.dhis.mobile.model.DataValue;
 import org.hisp.dhis.mobile.model.OrgUnit;
 import org.hisp.dhis.mobile.model.User;
+import org.hisp.dhis.mobile.ui.DHISMIDlet;
+import org.hisp.dhis.mobile.util.AlertUtil;
 
 public class DataValueUploadManager
     extends Thread
 {
+    private DHISMIDlet dhisMidlet;
 
     private Hashtable dataValueTable;
 
@@ -25,12 +30,14 @@
 
     private User user;
 
-    public DataValueUploadManager( Hashtable dataValueTable, String url, OrgUnit orgUnit, User user )
+    public DataValueUploadManager( DHISMIDlet dhisMidlet, Hashtable dataValueTable, String url, OrgUnit orgUnit,
+        User user )
     {
         this.dataValueTable = dataValueTable;
         this.url = url;
         this.orgUnit = orgUnit;
         this.user = user;
+        this.dhisMidlet = dhisMidlet;
     }
 
     public void run()
@@ -42,42 +49,74 @@
         Enumeration en = null;
         try
         {
-            for ( int redirectTimes = 0; redirectTimes < 5; redirectTimes++ )
-            {
-                connection = (HttpConnection) Connector.open( url );
-                configureConnection( connection );
-                int status = connection.getResponseCode();
-                switch ( status )
-                {
-                case HttpConnection.HTTP_SEE_OTHER:
-                case HttpConnection.HTTP_TEMP_REDIRECT:
-                case HttpConnection.HTTP_MOVED_TEMP:
-                case HttpConnection.HTTP_MOVED_PERM:
-                    url = connection.getHeaderField( "location" );
-                default:
-                    break;
-                }
-                System.out.println("Status: " + connection.getResponseCode());
-            }
-
-             int numOfDataValue = dataValueTable.size();
-             opt = connection.openOutputStream();
-             dos = new DataOutputStream( opt );
-            
-             dos.writeInt( numOfDataValue );
-             dos.writeInt( orgUnit.getId() );
-             en = dataValueTable.elements();
-             while ( en.hasMoreElements() )
-             {
-             DataValue dataValue = (DataValue) en.nextElement();
-             dos.writeInt( dataValue.getDataElementId() );
-             dos.writeInt( dataValue.getProgramInstanceId() );
-             dos.writeUTF( dataValue.getValue() );
-             }
+            // for ( int redirectTimes = 0; redirectTimes < 5; redirectTimes++ )
+            // {
+            connection = (HttpConnection) Connector.open( url );
+            configureConnection( connection );
+            opt = connection.openOutputStream();
+            // int status = connection.getResponseCode();
+            // switch ( status )
+            // {
+            // case HttpConnection.HTTP_SEE_OTHER:
+            // case HttpConnection.HTTP_TEMP_REDIRECT:
+            // case HttpConnection.HTTP_MOVED_TEMP:
+            // case HttpConnection.HTTP_MOVED_PERM:
+            // url = connection.getHeaderField( "location" );
+            //
+            // if ( connection != null )
+            // try
+            // {
+            // connection.close();
+            // }
+            // catch ( IOException ioe )
+            // {
+            // }
+            // if ( opt != null )
+            // try
+            // {
+            // opt.close();
+            // }
+            // catch ( IOException ioe )
+            // {
+            // }
+            // connection = null;
+            // break;
+            // default:
+            // }
+            // System.out.println( "Status: " + connection.getResponseCode() );
+            // }
+
+            int numOfDataValue = dataValueTable.size();
+            System.out.println( "No of DataValues: " + numOfDataValue );
+            dos = new DataOutputStream( opt );
+
+            dos.writeInt( numOfDataValue );
+            dos.writeInt( orgUnit.getId() );
+            en = dataValueTable.elements();
+            while ( en.hasMoreElements() )
+            {
+                DataValue dataValue = (DataValue) en.nextElement();
+                dos.writeInt( dataValue.getDataElementId() );
+                dos.writeInt( dataValue.getProgramInstanceId() );
+                dos.writeUTF( dataValue.getValue() );
+            }
+            dos.flush();
+
+            InputStream input = connection.openInputStream();
+            StringBuffer buffer = new StringBuffer();
+            int ch = -1;
+            while ( (ch = input.read()) != -1 )
+            {
+                buffer.append( (char) ch );
+            }
+            System.out.println( buffer.toString() );
+            dhisMidlet.switchDisplayable( AlertUtil.getInfoAlert( "Result", buffer.toString() ),
+                dhisMidlet.getActivitiesList() );
         }
         catch ( Exception e )
         {
-            System.out.println( e.getMessage() );
+            System.out.println( "Error in DOS: " + e.getMessage() );
+            e.printStackTrace();
         }
         finally
         {
@@ -87,7 +126,7 @@
                 opt.close();
                 connection.close();
             }
-            catch ( IOException e )
+            catch ( Exception e )
             {
                 System.out.println( e.getMessage() );
             }

=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java	2010-09-08 09:52:06 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java	2010-09-13 03:48:16 +0000
@@ -192,7 +192,7 @@
                 DataValue dataValue = DataValue.recordToDataValue( re.nextRecord() );
                 if ( dataValue.getProgramInstanceId() == activity.getTask().getProgStageInstId() )
                 {
-                    dataValuesTable.put( String.valueOf( dataValue.getDataElementId() ), dataValue.getValue() );
+                    dataValuesTable.put( String.valueOf( dataValue.getDataElementId() ), dataValue );
                 }
             }
             re = null;

=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java	2010-09-08 09:52:06 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java	2010-09-13 03:48:16 +0000
@@ -1392,7 +1392,8 @@
                     if ( dataValueTable.get( String.valueOf( de.getId() ) ) != null )
                     {
                         Date date = new Date();
-                        date.setTime( Long.parseLong( (String) dataValueTable.get( String.valueOf( de.getId() ) ) ) );
+                        date.setTime( Long.parseLong( ((DataValue) dataValueTable.get( String.valueOf( de.getId() ) ))
+                            .getValue() ) );
                         dateField.setDate( date );
                         System.out.println( "Date in db is: " + date.toString() );
                     }
@@ -1404,7 +1405,8 @@
                     TextField intField = new TextField( de.getName(), "", 32, TextField.NUMERIC );
                     if ( dataValueTable.get( String.valueOf( de.getId() ) ) != null )
                     {
-                        intField.setString( (String) dataValueTable.get( String.valueOf( de.getId() ) ) );
+                        intField
+                            .setString( ((DataValue) dataValueTable.get( String.valueOf( de.getId() ) )).getValue() );
                     }
                     form.append( intField );
                     formElements.put( de, intField );
@@ -1414,7 +1416,8 @@
                     TextField txtField = new TextField( de.getName(), "", 32, TextField.ANY );
                     if ( dataValueTable.get( String.valueOf( de.getId() ) ) != null )
                     {
-                        txtField.setString( (String) dataValueTable.get( String.valueOf( de.getId() ) ) );
+                        txtField
+                            .setString( ((DataValue) dataValueTable.get( String.valueOf( de.getId() ) )).getValue() );
                     }
                     form.append( txtField );
                     formElements.put( de, txtField );
@@ -1439,20 +1442,21 @@
     public void sendRecordedData()
     {
         // Need more test
-        
-        // try
-        // {
-        // this.saveDataValueToRMS();
-        // }
-        // catch ( Exception e )
-        // {
-        // System.out.println(e.getMessage());
-        // }
-        // DataValueUploadManager uploadManager = new DataValueUploadManager(
-        // dataValueTable,
-        // "http://localhost:8080/dhis-web-api/importDataValue.action";, orgUnit,
-        // user );
-        // uploadManager.start();
+        try
+        {
+            this.saveDataValueToRMS();
+        }
+        catch ( Exception e )
+        {
+            System.out.println( e.getMessage() );
+        }
+        // If you are running Apache Tomcat, use the URL
+        // http://localhost:8080/dhis-web-api/dhis-web-api/importDataValue.action
+        // Otherwise, use http://localhost:8080/dhis-web-api/importDataValue.action for Jetty
+        DataValueUploadManager uploadManager = new DataValueUploadManager( this, dataValueTable,
+            "http://localhost:8080/dhis-web-api/importDataValue.action";, orgUnit, user );
+        this.switchDisplayable( null, this.getWaitForm( "Please wait", "Uploading..." ) );
+        uploadManager.start();
 
     }