=== modified file 'mobile/dhis-mobile/.mtj' --- mobile/dhis-mobile/.mtj 2010-08-30 08:09:07 +0000 +++ mobile/dhis-mobile/.mtj 2010-08-30 09:47:01 +0000 @@ -8,8 +8,8 @@ + - === modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DownloadManager.java' --- mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DownloadManager.java 2010-08-28 10:25:49 +0000 +++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DownloadManager.java 2010-08-30 09:47:01 +0000 @@ -65,8 +65,29 @@ if ( task.equals( DOWNLOAD_FORMS ) ) { + // Vector programStagesVector = (Vector) download( url, new + // FormsParser() ); + // dhisMIDlet.displayFormsForDownload( programStagesVector ); + + // Get the ProgramStageForm vector (without dataelements) Vector programStagesVector = (Vector) download( url, new FormsParser() ); - dhisMIDlet.displayFormsForDownload( programStagesVector ); + + ProgramStageForm form = null; + ProgramStageForm completeForm = null; + + // for each form on the vector, set dataelement vector for it + for ( int i = 0; i < programStagesVector.size(); i++ ) + { + form = (ProgramStageForm) programStagesVector.elementAt( i ); + completeForm = (ProgramStageForm) download( url + form.getId(), new FormParser() ); + form.setDataElements( completeForm.getDataElements() ); + } + form = null; + completeForm = null; + + // now we have a completed form vector (each form has id, name + // and dataelement vector). Then call the save method + dhisMIDlet.saveForms( programStagesVector ); } else if ( task.equals( DOWNLOAD_FORM ) ) { @@ -86,7 +107,7 @@ Vector activitiesVector = (Vector) download( url, new ActivityPlanParser() ); dhisMIDlet.saveActivities( activitiesVector ); dhisMIDlet.switchDisplayable( null, dhisMIDlet.getMainMenuList() ); - //dhisMIDlet.displayCurActivities(); + // dhisMIDlet.displayCurActivities(); } else if ( task.equals( DOWNLOAD_ALL ) ) { @@ -164,7 +185,7 @@ throw new AuthenticationException(); case HttpConnection.HTTP_NOT_FOUND: connection.close(); - throw new IOException("Server not found"); + throw new IOException( "Server not found" ); default: // Error: throw exception connection.close(); === 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-08-28 10:25:49 +0000 +++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java 2010-08-30 09:47:01 +0000 @@ -81,17 +81,18 @@ public static void storeActivities( Vector activityVector ) { - clear(ModelRecordStore.ACTIVITY_DB); + clear( ModelRecordStore.ACTIVITY_DB ); ActivityRecordStore activityRecordStore = new ActivityRecordStore(); activityRecordStore.setActivityVector( activityVector ); activityRecordStore.save(); activityRecordStore = null; } - - public static Vector loadActivities(){ + + public static Vector loadActivities() + { ActivityRecordStore activityRecordStore = new ActivityRecordStore(); return activityRecordStore.loadAll(); - + } public static void storeForm( ProgramStageForm programStageForm ) @@ -116,9 +117,58 @@ } } + public static void storeForms( Vector programStageFormVector ) + { + clear( ModelRecordStore.FORM_DB ); + clear( ModelRecordStore.DATAELEMENT_DB ); + ModelRecordStore modelRecordStore; + for ( int i = 0; i < programStageFormVector.size(); i++ ) + { + try + { + modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); + modelRecordStore.addRecord( ProgramStageForm + .programStageFormToRecord( (ProgramStageForm) programStageFormVector.elementAt( i ) ) ); + modelRecordStore = new ModelRecordStore( ModelRecordStore.DATAELEMENT_DB ); + modelRecordStore.AddDataElementRecords( ((ProgramStageForm) programStageFormVector.elementAt( i )) + .getDataElements() ); + } + catch ( RecordStoreException rse ) + { + System.out.println( rse.getMessage() ); + } + + } + + } + + public static Vector loadForms() + { + RecordStore rs = null; + RecordEnumeration re = null; + Vector formsVector = new Vector(); + try + { + rs = RecordStore.openRecordStore( ModelRecordStore.FORM_DB, true ); + re = rs.enumerateRecords( null, null, false ); + while ( re.hasNextElement() ) + { + formsVector.addElement( ProgramStageForm.recordToProgramStageForm( re.nextRecord() ) ); + } + re = null; + rs = null; + return formsVector; + } + catch ( RecordStoreException rse ) + { + rse.printStackTrace(); + return null; + } + } + public static void saveOrgUnit( OrgUnit orgUnit ) { - clear(ModelRecordStore.ORGUNIT_DB); + clear( ModelRecordStore.ORGUNIT_DB ); ModelRecordStore modelRecordStore; try { @@ -129,7 +179,7 @@ { } } - + public static OrgUnit loadOrgUnit() { RecordStore rs = null; @@ -139,8 +189,9 @@ { rs = RecordStore.openRecordStore( ModelRecordStore.ORGUNIT_DB, true ); re = rs.enumerateRecords( null, null, false ); - while(re.hasNextElement()){ - orgUnit = OrgUnit.recordToOrgUnit( re.nextRecord()); + while ( re.hasNextElement() ) + { + orgUnit = OrgUnit.recordToOrgUnit( re.nextRecord() ); } return orgUnit; } @@ -152,9 +203,9 @@ } public static void saveUser( User user ) - + { - clear(ModelRecordStore.USER_DB); + clear( ModelRecordStore.USER_DB ); ModelRecordStore modelRecordStore; try { @@ -165,7 +216,7 @@ { } } - + public static User loadUser() { RecordStore rs = null; @@ -175,8 +226,9 @@ { rs = RecordStore.openRecordStore( ModelRecordStore.USER_DB, true ); re = rs.enumerateRecords( null, null, false ); - while(re.hasNextElement()){ - user = User.recordToUser(re.nextRecord()); + while ( re.hasNextElement() ) + { + user = User.recordToUser( re.nextRecord() ); } return user; } @@ -186,7 +238,7 @@ return null; } } - + public static void clear( String dbName ) { RecordStore rs = null; @@ -204,7 +256,7 @@ } catch ( Exception e ) { - System.out.println(e.getMessage()); + System.out.println( e.getMessage() ); } finally { === 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-08-30 08:09:07 +0000 +++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java 2010-08-30 09:47:01 +0000 @@ -19,6 +19,7 @@ import javax.microedition.rms.RecordStoreException; import org.hisp.dhis.mobile.connection.DownloadManager; +import org.hisp.dhis.mobile.db.ActivityRecordStore; import org.hisp.dhis.mobile.db.SettingsRectordStore; import org.hisp.dhis.mobile.db.Storage; import org.hisp.dhis.mobile.model.AbstractModel; @@ -35,8 +36,7 @@ extends MIDlet implements CommandListener { - - private String serverUrl = "http://localhost:8080/dhis-web-api/api/"; + private String serverUrl = "http://localhost:8080/api/"; private boolean midletPaused = false; @@ -108,6 +108,8 @@ private Command deFrmSavCmd; private Command screenCommand; + + private Command saveCommand; private Command backCommand; @@ -216,10 +218,13 @@ { if ( command == backCommand ) { - switchDisplayable( null, getDownloadedFormsList() ); + switchDisplayable( null, getActivitiesList() ); } else if ( command == screenCommand ) { + sendRecordedData(); + } else if (command == saveCommand){ + } } else if ( displayable == formDownloadList ) @@ -257,11 +262,12 @@ else if ( command == getMnuListDnldCmd() ) { // clear DataValue - + this.getDisplay().setCurrent( AlertUtil.getConfirmAlert( "Warning", - "All data which are not sent to the server will be clear, do you want to continue ?", new DnlActivitiesConfirmAlertListener(), this, - getMainMenuList(), getWaitForm("Redownloading Activities", "Downloading.....Please wait") ) ); + "All data which are not sent to the server will be clear, do you want to continue ?", + new DnlActivitiesConfirmAlertListener(), this, getMainMenuList(), + getWaitForm( "Redownloading Activities", "Downloading.....Please wait" ) ) ); } else if ( command == mnuListExtCmd ) { @@ -276,7 +282,7 @@ } else if ( command == stngsOkCmd ) { - //save new settings + // save new settings switchDisplayable( null, getMainMenuList() ); } } @@ -285,6 +291,8 @@ if ( command == actvyPlnListBakCmd ) { switchDisplayable( null, getMainMenuList() ); + } else if (command == List.SELECT_COMMAND){ + this.displaySelectedActivity(); } } else if ( displayable == downloadedFormsList ) @@ -323,8 +331,9 @@ // Load Activities switchDisplayable( null, this.getWaitForm( "Load Activities", "Loading.....please wait" ) ); + this.loadForms(); this.loadActivities(); - // Load Forms + } else { @@ -347,6 +356,7 @@ // Clear, Download and Save activities switchDisplayable( null, this.getWaitForm( "Download Activities", "Downloading.....please wait" ) ); + downloadForms(); downloadActivities(); // Download and Save Forms @@ -367,7 +377,8 @@ else if ( command == pinFormReinitCmd ) { this.getDisplay().setCurrent( - AlertUtil.getConfirmAlert( "Confirmation", "Are you sure ?",new DefaultAlertConfirmListener( ), this, getPinForm(), getLoginForm() ) ); + AlertUtil.getConfirmAlert( "Confirmation", "Are you sure ?", new DefaultAlertConfirmListener(), + this, getPinForm(), getLoginForm() ) ); } else if ( command == pinFormExitCmd ) { @@ -376,6 +387,13 @@ } } + private void displaySelectedActivity() + { + Activity selectedActivity = (Activity) activitiesVector.elementAt( getActivitiesList().getSelectedIndex() ); + ProgramStageForm formOfActivity = Storage.fetchForm( selectedActivity.getTask().getProgStageId() ); + this.renderForm( formOfActivity, getForm() ); + } + /** * Returns an vector of activities loaded from RMS */ @@ -393,6 +411,26 @@ }.start(); } + private void loadForms() + { + new Thread() + { + public void run() + { + programStagesVector = Storage.loadForms(); + } + }.start(); + + } + + private void downloadForms() + { + DownloadManager manager = new DownloadManager( this, this.url.getString() + "forms/", user, + DownloadManager.DOWNLOAD_FORMS ); + manager.start(); + + } + /** * Returns an initiliazed instance of exitCommand component. * @@ -669,13 +707,14 @@ { if ( settingsForm == null ) { - //settingsForm = new Form( "Configurable Parameters", new Item[] { getUrl(), getAdminPass() } ); - //settingsForm = new Form( "Configurable Parameters", new Item[] { getUrl() } ); - System.out.println(getUrl().getString()); - settingsForm = new Form("Configurable Parameters"); - - - //settingsForm.append( getUrlInSetting() ); + // settingsForm = new Form( "Configurable Parameters", new Item[] { + // getUrl(), getAdminPass() } ); + // settingsForm = new Form( "Configurable Parameters", new Item[] { + // getUrl() } ); + System.out.println( getUrl().getString() ); + settingsForm = new Form( "Configurable Parameters" ); + + // settingsForm.append( getUrlInSetting() ); settingsForm.addCommand( getSetngsBakCmd() ); settingsForm.addCommand( getStngsOkCmd() ); settingsForm.setCommandListener( this ); @@ -810,6 +849,7 @@ form = new Form( "form" ); form.addCommand( getBackCommand() ); form.addCommand( getScreenCommand() ); + form.addCommand(getSaveCommand()); form.setCommandListener( this ); // This is just for test ..... @@ -819,6 +859,14 @@ return form; } + private Command getSaveCommand() + { + if (saveCommand == null){ + saveCommand = new Command( "Save", Command.SCREEN, 0 ); + } + return saveCommand; + } + public Form getPinForm() { if ( pinForm == null ) @@ -904,7 +952,7 @@ { if ( screenCommand == null ) { - screenCommand = new Command( "Save", Command.SCREEN, 0 ); + screenCommand = new Command( "Send", Command.SCREEN, 0 ); } return screenCommand; } @@ -1072,13 +1120,13 @@ { settingsRecord = new SettingsRectordStore( "SETTINGS" ); settingsRecord.put( "url", url.getString() ); - //settingsRecord.put( "adminPass", adminPass.getString() ); + // settingsRecord.put( "adminPass", adminPass.getString() ); settingsRecord.save(); } catch ( RecordStoreException rse ) { } - + settingsRecord = null; } @@ -1263,4 +1311,10 @@ { switchDisplayable( AlertUtil.getInfoAlert( "Login failed", "Username/password was wrong" ), getLoginForm() ); } + + public void saveForms( Vector downloadedProgramStagesVector ) + { + this.programStagesVector = downloadedProgramStagesVector; + Storage.storeForms( this.programStagesVector ); + } }