dhis-mobile-devs team mailing list archive
-
dhis-mobile-devs team
-
Mailing list archive
-
Message #00282
[Branch ~dhis-mobile-devs/dhis-mobile/lwuit-tracking] Rev 143: support register and enroll in one form
------------------------------------------------------------
revno: 143
committer: Long <Long@Long-Laptop>
branch nick: lwuit-tracking
timestamp: Tue 2013-09-10 16:08:58 +0700
message:
support register and enroll in one form
modified:
src/org/hisp/dhis/mobile/connection/task/AbstractTask.java
src/org/hisp/dhis/mobile/connection/task/PersonRegistrationTask.java
--
lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking
https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking
Your team DHIS mobile developers is subscribed to branch lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking/+edit-subscription
=== modified file 'src/org/hisp/dhis/mobile/connection/task/AbstractTask.java'
--- src/org/hisp/dhis/mobile/connection/task/AbstractTask.java 2013-04-05 06:35:29 +0000
+++ src/org/hisp/dhis/mobile/connection/task/AbstractTask.java 2013-09-10 09:08:58 +0000
@@ -178,6 +178,81 @@
}
+ protected DataInputStream upload( byte[] request_body, String additionalProperty, String additionalPropertyName )
+ throws IOException
+ {
+ HttpConnection hcon = null;
+ DataOutputStream dos = null;
+ try
+ {
+ int redirectTimes = 0;
+ boolean redirect;
+ do
+ {
+ redirect = false;
+ hcon = ConnectionManager.createConnection();
+ hcon.setRequestMethod( HttpConnection.POST );
+ hcon.setRequestProperty( "Content-Length", "" + request_body.toString().length() );
+ hcon.setRequestProperty( additionalPropertyName, additionalProperty );
+ dos = hcon.openDataOutputStream();
+
+ for ( int i = 0; i < request_body.length; i++ )
+ {
+ dos.writeByte( request_body[i] );
+ }
+ dos.flush();
+
+ int status = hcon.getResponseCode();
+ DHISMIDlet.debug( "Response Satus: " + status );
+ switch ( status )
+ {
+ case HttpConnection.HTTP_OK:
+ return new DataInputStream( hcon.openInputStream() );
+ case HttpConnection.HTTP_NO_CONTENT:
+ // Went fine!
+ return null;
+ case HttpConnection.HTTP_TEMP_REDIRECT:
+ case HttpConnection.HTTP_MOVED_TEMP:
+ case HttpConnection.HTTP_MOVED_PERM:
+ ConnectionManager.setUrl( hcon.getHeaderField( "location" ) );
+ if ( hcon != null )
+ hcon.close();
+ redirectTimes++;
+ redirect = true;
+ break;
+ case HttpConnection.HTTP_CONFLICT:
+ handleError( Text.SENT_DATA_PROBLEM(), hcon );
+ case HttpConnection.HTTP_INTERNAL_ERROR:
+ handleError( Text.SERVER_ERROR(), hcon );
+ default:
+ hcon.close();
+ handleError( Text.SERVER_NOT_FOUND(), hcon );
+ }
+ }
+ while ( redirect == true && redirectTimes < 5 );
+
+ if ( redirectTimes == 5 )
+ {
+ throw new IOException( Text.TOO_MUCH_REDIRECT() );
+ }
+ }
+ finally
+ {
+ try
+ {
+ if ( hcon != null )
+ hcon.close();
+ if ( dos != null )
+ dos.close();
+ }
+ catch ( IOException ioe )
+ {
+ ioe.printStackTrace();
+ }
+ }
+ return null;
+ }
+
protected DataInputStream upload( byte[] request_body )
throws IOException
{
=== modified file 'src/org/hisp/dhis/mobile/connection/task/PersonRegistrationTask.java'
--- src/org/hisp/dhis/mobile/connection/task/PersonRegistrationTask.java 2013-09-10 08:17:24 +0000
+++ src/org/hisp/dhis/mobile/connection/task/PersonRegistrationTask.java 2013-09-10 09:08:58 +0000
@@ -33,7 +33,8 @@
try
{
- DataInputStream messageStream = this.upload( SerializationUtil.serialize( this.patient ) );
+ DataInputStream messageStream = this.upload( SerializationUtil.serialize( this.patient ), enrollProgramId,
+ "programid" );
String message = this.readMessage( messageStream );
if ( message.equalsIgnoreCase( PATIENT_REGISTERED ) )
{