=== 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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
=== 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 )
+
+ #if( $showStackTrace )
+ [+]
+ #end
+ $preText (${exception.class.name}):
+ #if( !$exception.message )
+ null
+ #else
+ $encoder.htmlEncode( $exception.message )
+ #end
+
+ #if( $showStackTrace )
+
+ #set( $idCount = $idCount + 1 )
+
+ #foreach( $element in $exception.stackTrace )
+ #if( $element.fileName )
+ - ${element.className}.${element.methodName}(${element.fileName}:${element.lineNumber})
+ #else
+ - ${element.className}.${element.methodName}($i18n.getString( "unknown_source" ))
+ #end
+ #end
+
+
+ #end
+ #if( $exception.cause )
+ #printException( $exception.cause $i18n.getString( "caused_by" ) )
+ #end
+#end
+
+## -------------------------------------------------------------------------- ##
+
+
+
+ DHIS 2
+
+
+
+
+
+## -------------------------------------------------------------------------- ##
+
+$i18n.getString( "an_exception_occured" )
+
+$encoder.htmlEncode( $i18n.getString( "exception_explanation_text" ))
+
+
+#printException( $exception $i18n.getString( "exception" ) )
+
+## -------------------------------------------------------------------------- ##
+
+
+
=== 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 @@
+
+
+
+
+
+
+
+
+
+ text/plain
+ inputStream
+ inline
+ 1024
+
+
+
+
+
+
=== 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 @@
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
- DHIS Case Entry
-
-
- contextConfigLocation
- classpath*:/META-INF/dhis/beans.xml
-
-
- automaticAccessType
- ghostAdmin
-
-
-
- RedirectFilter
- org.hisp.dhis.servlet.filter.HttpRedirectFilter
-
- redirectPath
- api/
-
-
-
- OpenSessionInViewFilter
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
-
-
+ DHIS Case Entry
+
+
+ contextConfigLocation
+ classpath*:/META-INF/dhis/beans.xml
+
+
+ automaticAccessType
+ ghostAdmin
+
+
+
+ RedirectFilter
+
+ org.hisp.dhis.servlet.filter.HttpRedirectFilter
+
+ redirectPath
+ api/
+
+
+
+ OpenSessionInViewFilter
+
+ org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
+
filterChainProxy
org.springframework.web.filter.DelegatingFilterProxy
-
-
- RedirectFilter
- /
-
-
- OpenSessionInViewFilter
- *.action
-
-
- OpenSessionInViewFilter
- /api/*
-
-
- filterChainProxy
- /*
-
-
-
- org.springframework.web.context.ContextLoaderListener
-
-
- org.hisp.dhis.system.startup.StartupListener
-
-
-
- web-api
- com.sun.jersey.spi.spring.container.servlet.SpringServlet
-
- com.sun.jersey.spi.container.ContainerRequestFilters
- com.sun.jersey.api.container.filter.LoggingFilter
-
-
- com.sun.jersey.spi.container.ContainerResponseFilters
- com.sun.jersey.api.container.filter.LoggingFilter
-
- 1
-
-
- web-api
- /api/*
-
-
-
+
+
+ Struts
+
+ org.apache.struts2.dispatcher.FilterDispatcher
+
+
+
+ RedirectFilter
+ /
+
+
+ OpenSessionInViewFilter
+ *.action
+
+
+ OpenSessionInViewFilter
+ /api/*
+
+
+ filterChainProxy
+ /*
+
+
+ Struts
+ *.action
+
+
+
+
+ org.springframework.web.context.ContextLoaderListener
+
+
+
+ org.hisp.dhis.system.startup.StartupListener
+
+
+
+ web-api
+
+ com.sun.jersey.spi.spring.container.servlet.SpringServlet
+
+
+ com.sun.jersey.spi.container.ContainerRequestFilters
+
+ com.sun.jersey.api.container.filter.LoggingFilter
+
+
+
+ com.sun.jersey.spi.container.ContainerResponseFilters
+
+ com.sun.jersey.api.container.filter.LoggingFilter
+
+ 1
+
+
+ web-api
+ /api/*
+
+
+
\ 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();
}