=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java' --- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java 1970-01-01 00:00:00 +0000 +++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java 2010-08-26 19:55:46 +0000 @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.mobile.db; + +import java.util.Enumeration; +import java.util.Vector; + +import javax.microedition.rms.RecordStoreException; + +import org.hisp.dhis.mobile.model.AbstractModel; +import org.hisp.dhis.mobile.model.Activity; +import org.hisp.dhis.mobile.model.OrgUnit; +import org.hisp.dhis.mobile.model.ProgramStageForm; + +public class Storage +{ + + // Get all Form from RMS + public static Vector getAllForm() + { + ModelRecordStore modelRecordStore = null; + Vector downloadedFormVector = null; + try + { + modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); + downloadedFormVector = modelRecordStore.getAllRecord(); + } + catch ( RecordStoreException rse ) + { + + } + return downloadedFormVector; + } + + + public static ProgramStageForm fetchForm( int formId ) + { + ModelRecordStore modelRecordStore = null; + ProgramStageForm frm = null; + + try + { + modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); + byte rec[] = modelRecordStore.getRecord( formId ); + if ( rec != null ) + frm = ProgramStageForm.recordToProgramStageForm( rec ); + } + catch ( RecordStoreException rse ) + { + } + + return frm; + } + + + public static AbstractModel getForm(int index) { + return (AbstractModel) getAllForm().elementAt( index ); + } + + + public static void storeActivities( Vector activitiesVector ) + { + ModelRecordStore modelRecordStore = new ModelRecordStore( ModelRecordStore.ACTIVITY_DB ); + Enumeration activities = activitiesVector.elements(); + Activity activity = null; + int i = 0; + while ( activities.hasMoreElements() ) + { + try + { + activity = (Activity) activities.nextElement(); + modelRecordStore.addRecord( Activity.activityToRecord( activity ) ); + i += 1; + } + catch ( RecordStoreException rse ) + { + } + } + } + + + public static void storeForm( ProgramStageForm programStageForm ) + { + ModelRecordStore modelRecordStore; + try + { + modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); + modelRecordStore.addRecord( ProgramStageForm.programStageFormToRecord( programStageForm ) ); + } + catch ( RecordStoreException rse ) + { + } + + try + { + modelRecordStore = new ModelRecordStore( ModelRecordStore.DATAELEMENT_DB ); + modelRecordStore.AddDataElementRecords( programStageForm.getDataElements() ); + } + catch ( RecordStoreException rse ) + { + } + } + + + public static void saveOrgUnit( OrgUnit orgUnit ) + { + ModelRecordStore modelRecordStore; + try + { + modelRecordStore = new ModelRecordStore( ModelRecordStore.ORGUNIT_DB ); + modelRecordStore.addRecord( OrgUnit.orgUnitToRecord( orgUnit ) ); + } + catch ( RecordStoreException rse ) + { + } + } +} === 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-26 19:12:57 +0000 +++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java 2010-08-26 19:55:46 +0000 @@ -1,6 +1,5 @@ package org.hisp.dhis.mobile.ui; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; @@ -20,8 +19,8 @@ import javax.microedition.rms.RecordStoreException; import org.hisp.dhis.mobile.connection.DownloadManager; -import org.hisp.dhis.mobile.db.ModelRecordStore; import org.hisp.dhis.mobile.db.SettingsRectordStore; +import org.hisp.dhis.mobile.db.Storage; import org.hisp.dhis.mobile.model.AbstractModel; import org.hisp.dhis.mobile.model.Activity; import org.hisp.dhis.mobile.model.DataElement; @@ -297,11 +296,8 @@ } /** - * Returns an initiliazed instance of mainMenuList component. - * - * @return the initialized component instance + * Method to initialize the downloaded forms screen. */ - // Method to initialize the downloaded forms screen. public List getDownloadedFormsList() { if ( downloadedFormsList == null ) @@ -317,11 +313,15 @@ // Action when user select a downloaded form private void downloadedFormsSelectAction() { - AbstractModel downloadedProgramStage = (AbstractModel) getAllForm().elementAt( - ((List) getDownloadedFormsList()).getSelectedIndex() ); + int index = ((List) getDownloadedFormsList()).getSelectedIndex(); + + AbstractModel downloadedProgramStage = Storage.getForm( index ) ; + System.out.println( "Selected ID: " + downloadedProgramStage.getId() ); - System.out.println( "Name: " + fetchForm( downloadedProgramStage.getId() ).getName() ); - this.getForm( fetchForm( downloadedProgramStage.getId() ) ); + + ProgramStageForm form = Storage.fetchForm( downloadedProgramStage.getId() ); + System.out.println( "Name: " + form.getName() ); + this.getForm( form ); } // the "Back" command of the downloaded forms list @@ -334,22 +334,6 @@ return downloadedBckCmd; } - // Get all Form from RMS - public Vector getAllForm() - { - ModelRecordStore modelRecordStore = null; - Vector downloadedFormVector = null; - try - { - modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); - downloadedFormVector = modelRecordStore.getAllRecord(); - } - catch ( RecordStoreException rse ) - { - - } - return downloadedFormVector; - } public void displayDownloadedForms( Vector downloadedForms ) { @@ -413,7 +397,7 @@ } else if ( __selectedString.equals( "Record Data" ) ) { - this.displayDownloadedForms( this.getAllForm() ); + this.displayDownloadedForms( Storage.getAllForm() ); } else if ( __selectedString.equals( "Settings" ) ) { @@ -670,7 +654,7 @@ form.setCommandListener( this ); // This is just for test ..... - ProgramStageForm frm = fetchForm( 1 ); + ProgramStageForm frm = Storage.fetchForm( 1 ); renderForm( frm, form ); } return form; @@ -951,44 +935,11 @@ downloadManager.start(); } - public ProgramStageForm fetchForm( int formId ) - { - ModelRecordStore modelRecordStore = null; - ProgramStageForm frm = null; - - try - { - modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); - byte rec[] = modelRecordStore.getRecord( formId ); - if ( rec != null ) - frm = ProgramStageForm.recordToProgramStageForm( rec ); - } - catch ( RecordStoreException rse ) - { - } - - return frm; - } public void saveActivities( Vector activitiesVector ) { this.activitiesVector = activitiesVector; - ModelRecordStore modelRecordStore = new ModelRecordStore( ModelRecordStore.ACTIVITY_DB ); - Enumeration activities = activitiesVector.elements(); - Activity activity = null; - int i = 0; - while ( activities.hasMoreElements() ) - { - try - { - activity = (Activity) activities.nextElement(); - modelRecordStore.addRecord( Activity.activityToRecord( activity ) ); - i += 1; - } - catch ( RecordStoreException rse ) - { - } - } + Storage.storeActivities(activitiesVector); } public void displayCurActivities() @@ -1025,25 +976,7 @@ public void saveForm( ProgramStageForm programStageForm ) { - ModelRecordStore modelRecordStore; - try - { - modelRecordStore = new ModelRecordStore( ModelRecordStore.FORM_DB ); - modelRecordStore.addRecord( ProgramStageForm.programStageFormToRecord( programStageForm ) ); - } - catch ( RecordStoreException rse ) - { - } - - try - { - modelRecordStore = new ModelRecordStore( ModelRecordStore.DATAELEMENT_DB ); - modelRecordStore.AddDataElementRecords( programStageForm.getDataElements() ); - } - catch ( RecordStoreException rse ) - { - } - + Storage.storeForm(programStageForm); } public void renderForm( ProgramStageForm prStgFrm, Form form ) @@ -1092,15 +1025,7 @@ public void saveOrgUnit( OrgUnit orgunit ) { this.orgUnit = orgunit; - ModelRecordStore modelRecordStore; - try - { - modelRecordStore = new ModelRecordStore( ModelRecordStore.ORGUNIT_DB ); - modelRecordStore.addRecord( OrgUnit.orgUnitToRecord( orgunit ) ); - } - catch ( RecordStoreException rse ) - { - } + Storage.saveOrgUnit(orgUnit); } public void sendRecordedData() === modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/StringUtil.java' --- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/StringUtil.java 2010-08-26 14:59:39 +0000 +++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/StringUtil.java 2010-08-26 19:55:46 +0000 @@ -50,7 +50,6 @@ int month = Integer.parseInt( strDate.substring( 5, 7 ) ); int year = Integer.parseInt( strDate.substring( 0, 4 ) ); - System.err.println(strDate + ": " + day +" " + month + " " +year );; cal.set( Calendar.DATE, day ); cal.set( Calendar.MONTH, month-1 ); cal.set( Calendar.YEAR, year );