-
Notifications
You must be signed in to change notification settings - Fork 3
Integrating new dhis sdk
To work in the integration of the new SDK is necessary move your branch to:
malariapp: feature-new_sdk sdk: 2.25-EyeSeeTea_temp_changes
SDK important changes.
The sdk use dagger2.
The sdk use JXjava.
The sdk wiki code not work at this momment, example of login and organisationUnits pull by code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
D2.init(this);
Configuration configuration = new Configuration("SERVER");
ConfigurationPreferencesImpl pref= new ConfigurationPreferencesImpl(this);
pref.save(configuration);
D2.configuration();
D2.configure(configuration);
new TestAsync().execute();
context=this;
}
class TestAsync extends AsyncTask<Void, Integer, String>
{
protected void onPreExecute (){
}
protected String doInBackground(Void...arg0) {
Observable<UserAccount> observable = D2.me().signIn("USER", "PASSWORD");
observable.subscribe(new Action1<UserAccount>() {
@Override
public void call(UserAccount userAccount) {
Log.d("TAG", "userAccount+" + userAccount.toString());
userAccount.getOrganisationUnits();
Log.d("TAG", "programs+" + userAccount.getPrograms().toString());
Log.d("TAG", "orgunits" + userAccount.getOrganisationUnits().toString());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
// do something
Log.d("TAG", "Error");
Log.d("TAG", throwable.toString());
throwable.printStackTrace();
}
});
Set<ProgramType> programType = null;
List<Program> pr= (List<Program>) D2.me().programs().pull(SyncStrategy.DEFAULT, ProgramFields.ALL,programType);
Log.d("TAG",
D2.programs().toString());
Log.d("TAG", D2.me().organisationUnits().toString());
return "You are at PostExecute";
}
protected void onPostExecute(String result) {
Intent intent2 = new Intent(context, LoginActivity.class);
startActivity(intent2);
}
}
The sdk is now more abstract and modular.
The db models are sepparated than the sdk models.
The sdk new modules are these:
core
core-android -> contains the dbflow models, and android core
core-rules
models -> contains the sdk models
ui
ui-bindings -> contains the final android ui components
We need import core-rules and ui-bindings(and ui-binbdings imports ui and core-android, core-android imports core, and core-rules imports models).
Clone git dhis sdk repository on workspace root folder(../malariapp).
git clone https://github.com/dhis2/dhis2-android-sdk.git
Move the branch to development
Remove DBflow folders and SDk from malariapp
In malariapp/build.gradle:
Add this line to include dbflow librarie
maven {url "https://jitpack.io"}
bellow this line:
maven { url "https://raw.github.com/Raizlabs/maven-releases/master/releases"}
Add the sdk config extesions inside of ext:
configuration = [
package : "org.hisp.dhis.android.skeleton",
buildToolsVersion: "23.0.2",
minSdkVersion : 15,
compileSdkVersion: 23,
targetSdkVersion : 23,
versionCode : 21,
versionName : "0.5.0.2"
]
libraries = [
// dhis libs
dhisCommonsVersion : "1.1",
// android libs
supportVersion : "23.4.0",
rxAndroidVersion : "1.1.0",
dbFlowVersion : "3.0.1",
progressBarVersion : "1.2.0",
smoothProgressBarVersion: "1.1.0",
crashlyticsVersion : "2.5.5",
stethoVersion : "1.3.1",
multidex : "1.0.1",
// java libs
timberVersion : "4.1.0",
okhttpVersion : "3.2.0",
retrofitVersion : "2.0.0",
jacksonVersion : "2.7.4",
jodaTimeVersion : "2.9.2",
jexlVersion : "2.1.1",
commonsLang3Version : "3.3.2",
commonsMath3Version : "3.6",
dagger : "2.2",
// testing libs
jUnitVersion : "4.12",
mockitoVersion : "1.10.19",
powerMockVersion : "1.6.3",
]
And set the buildToolsVersion supportVersion compileSdkVersion and targetSdkVersion with the sdk versions.
Replace the settings.gradle content with:
include ':app', ':core', ':core-android', ':core-rules', ':models', ':ui', ':ui-bindings', ':utils'
project(':core').projectDir = new File(settingsDir, '../dhis2-android-sdk/core')
project(':core-android').projectDir = new File(settingsDir, '../dhis2-android-sdk/core-android')
project(':core-rules').projectDir = new File(settingsDir, '../dhis2-android-sdk/core-rules')
project(':models').projectDir = new File(settingsDir, '../dhis2-android-sdk/models')
project(':ui').projectDir = new File(settingsDir, '../dhis2-android-sdk/ui')
project(':ui-bindings').projectDir = new File(settingsDir, '../dhis2-android-sdk/ui-bindings')
project(':utils').projectDir = new File(settingsDir, '../dhis2-android-sdk/utils')
malariapp/app/build.gradle remove:
compile project(':sdk:app')
apt project(':DBFlowORM:DBFlow-Compiler')
compile project(':DBFlowORM:DBFlow-Core')
compile project(':DBFlowORM:DBFlow')
and add:
compile project(":core-rules")
compile project(":ui-bindings")
We need add:
// Dagger dependencies
provided "com.google.dagger:dagger-compiler:${rootProject.ext.libraries.dagger}"
apt "com.google.dagger:dagger-compiler:${rootProject.ext.libraries.dagger}"
compile "com.google.dagger:dagger:${rootProject.ext.libraries.dagger}"
To use dagger like in the sdk. It's necesary by the userComponent().
-
Fix queries
-
Use one dbflow instance to work with sdk database and our database.
-
Create and pull some entities.
-
Create missing queries: getMinimizedEvents getEventsFromDate getEventsBetweenDate getOrganisationUnitLevels().
-
Fix activities.
-
Its needed pull all the necessary from the server.
-
Its needed convert from DB to sdk model to our DB.
-
Its needed change the push methods to use the new push.
-
Its needed change the convertToSdkVisitor in some steps.
The sdk is using the last dbflow version(3.0.1).
New sdk scheme
List of entities:
Sql query:
- Its need fix queries
The com.raizlabs.android.dbflow.sql.language.ColumnAlias not exist and is used in so many queries.
And its needed modify all the sdk imports and models in our queries.
- its need use one dbflow instance to work with sdk database and our database:
The FlowManager is initialized in:
core-android/src/main/java/org/hisp/dhis/client/sdk/android/api/persistence/PersistenceModuleImpl
Look how create two modules with one dbflow here:
https://github.com/Raizlabs/DBFlow/issues/266
https://github.com/Raizlabs/DBFlow/blob/master/usage2/MultipleModules.md
Difference between dbflow models and sdk models:
The dhis models are in:
org.hisp.dhis.client.sdk.models.*
and the database POJOS are in :
org.hisp.dhis.client.sdk.android.api.persistence.*
Example: Event controllers
The sdk-dbflow(in core-android) uses XXXFlow.class models and the sdk uses XXX.class, the application entities are abstracted from the db POJOS, the sdk uses XXXStoreImpl to transform it, for example event to stored eventflow.
To create new sdk model we need create the follow structure:
XXXApiClientImpl contains the server querys
XXXApiClientRetrofit(Interfaz)
XXXInteractor(interfaz)
XXXInteractorImpl contains the observable calls
XXXStoreImpl contains the dbflow queries and the dbflow mapper.
- Create and pull the follow entities:
Attribute
DataelementAttributeValue
OptionAttributeValue
OrganisationUnitAttribute
OrganisationUnitDataSet
OrganisationUnitGroup
OrganisationUnitLevel
ProgramAttributeValue
DataValue is now called TrackedEntityDataValue
Note: The sdk is using a new table called ModelLinkFlow to create relations between entities.
- Create missing queries: getMinimizedEvents getEventsFromDate getEventsBetweenDate getOrganisationUnitLevels()
Create Events queries in: To create queries in EventApiClientImpl/EventApiClient(Interface) Tp create or modify pull in EventControllerImpl.
- EyeSeeTeaApplication -> EventCaptureApp in EventCapture App The sdk needs a Inject class that need be initialise here with Inject.init method, and it needs dagger.
We need build a DraggerAppComponent from the dagger library for that. (It should compile with the project not have compilation errors).
- LoginActivity -> HomeActivity in EventCapture App
LoginActivity should extends from DefaultLoginActivity.
The sdk uses a LoginPresenter that calls validateCredentials, that calls onSuccess(). We can overwrite the method navigateToHome or OnSuccess.
- ProgressActivity -> Progressactivity not exists in the sdk or in EventCapture App
The EventCapture App use showProgressBar() method. This fragment use a SwipeRefreshLayout to show the progress wheel.
Note: The dhis2Api class is only used by the sdk with the method "getDashboards", for example the events queries are in the events package(EventControllerImpl to call requests to the server and XXXStoreImpl to use local db).
- Its need pull all the necessary from the server.
The EventCapture App is downloading only:
"OrganisationUnitFlow" "ModelLinkFlow" "ProgramFlow" "ProgramStageFlow" "ProgramStageSectionFlow" "ProgramStageDataElementFlow" "DataElementFlow" "OptionFlow" "OptionSetFlow"
- Its need include all the missing Pojos and download:
Attribute not exists
Dataelement is pulled as DataelementFlow
DataElementAttributeValue not exists
DataValue is not pulled and is TrackedEntityDataValue
Event is not pulled and is EventFlow
Option is pulled as OptionFlow
OptionAttributeValue not exists
OptionSet is pulled as OptionSetFlow
OrganisationUnit is pulled as OrganisationUnitFlow
OrganisationUnitAttributeValue not exists
OrganisationUnitDataSet not exists
OrganisationUnitGroup not exists
OrganisationUnitLevel not exists
OrganisationUnitProgamRelationship
Program is pulled as ProgramFlow
ProgramAttributeValue not exists
ProgramStage is pulled as ProgramStageFlow
ProgramStageDataElement is pulled as ProgramStageDataElementFlow
ProgramStageSection is pulled as ProgramStageSectionFlow
UserAccount is pulled as UserAccountFlow
We need copy the SyncWrapper class from Eventcapture App.
This class is used to pull the programs and the organisationunits. Special attention to the methods syncMetaData() and syncData()
- Its need convert from DB to sdk model to our DB.
- Its need change the convertToSdkVisitor in some steps.
For example: The events not have LocalEventId, and not have setFromServer, the date format is datatime.
To create a event we need take a look at:
createEvent in SelectorPresenterImpl in the eventcapture App.
- Its need change the push methods to use the new push.
We can look a example of the event push in syncData() called by sync() in the eventCapture