Skip to content

Instantly share code, notes, and snippets.

@danishjamal104
Last active August 31, 2021 07:06
Show Gist options
  • Save danishjamal104/ddb099d5f7985dc08537db658c178a81 to your computer and use it in GitHub Desktop.
Save danishjamal104/ddb099d5f7985dc08537db658c178a81 to your computer and use it in GitHub Desktop.
GSoC '21 Report | The Apache Software Foundation | The Mifos Initiative | Mifos Android SDK

GSoC 2021 @ The Mifos Initiative | The Apache Software Foundation

This gist contains the details about My GSoC '21 Project with The Mifos Initiative as an umbrella under The Apache Software Foundation. During summer, I will be working on architecting and developing the Mifos Android SDK, releasing the Fineract Client API Library using the open api generator in the Apache Fineract project and finally integrate it with the Mifos Android SDK project. The generated SDK project will further be used in MIFOS Android Client project.

In all the Android Applications of Mifos, android-client, mifos-mobile, mobile-wallet there is a lot of repeated code defining all the services file separately for all the apps which deals with interacting with the Fineract APIs. Considering this idea last year the library was generated for older version of fineract, this year I will be generating the library for Fineract v1.5.0 and adding an android specific abstraction layer over it and releasing Mifos Android SDK, which will replace all the boiler plate code in MIFOS Android Client project..

Goals of the Project

  1. To release Fineract-Client new version based on Fineract 1.5.0 latest release.
  2. To automate the SDK generation by optimising the gradle task in Fineract project.
  3. To build an android specific abstract layer over generated sdk and release it as an android library.
  4. To integrate the mifos-android-sdk-architecture in android-client.

Features

  1. Alpha version of Fineract Client Library is released and can be added in the gradle dependency for Mifos Android SDK.
  2. The Mifos Android SDK will be containing all the abstraction code and serve as an entry point to the SDK.
  3. All the API call implementations are abstracted from the developer. So the only concern of the developer is to request the data from SDK and update UI for the user.
  4. Testing coverage will be provided in the SDK itself.
  5. Base class for User management/preferences will be provided by Mifos Android SDK.

Phase 1 - Project Development

Initially the Fineract Client Library was generated manually but later it was defined as a buildJavaSdk gradle task but still there are many scopes of optimisation. So my 1st Coding Period started with working on Apache Fineract project followed by Fineract Client Library, Mifos Android SDK & Mifos Android Client. Following are the details of each project:

1. Apache Fineract | Java

I worked on Fineract Client Module. Since the services and util classes are defined separately hence each time a the SDK is generated we have to copy and paste those file in the generated library, so this task has to be automated apart from that there are some missing dependency which need to be fixed using mustache template. Below are the work done.

2. Fineract Client | Java

Here I worked on Fineract Client Library, where the major goal was to generate the library for Apache Fineract v1.5.0. So I created a new branch named development-1.5.0 where the new library will be pushed and once the library is pretty stable then I will be creating the release. Initially the 2.1.0-alpha is released for testing purpose. Below are the implementation and work done so far.

  • 2.0.0-alpha released.
    • This is the first upgraded release whith proper documentation and sample codes.
  • 2.1.0-alpha released.
    • In previous release the library was using newer version of rxjava which is reactivex, but in Android Client the older version is used hence to support the legacy support the rxjava version was downgraded to 1.3.0 from 2.1.1.
  • Debugged and tested the generated SDK, found some major bug checkout issues in below references.
  • References

3. Mifos Android Architecture | Kotlin

Here I worked on Mifos Android SDK. The main goal of this project is to add abstraction layer over the generated Fineract Client SDK. Defining the abstract class and interface which will be used in Android Client project, making the code short and reusable. Below are the main things I have worked on.

  • Initial implementation of shared preference abstract base class, named BasePreferenceManager
    • SharedPreference has different methods for accessing the preferences, this class provides single point of access for all type of data. for example for putting string with custom key use put(Key.Custom("demo_key"), "example data") and for accessing use get(Key.Custom("demo_key"), default = "I am default data, can be nullable").
  • Implemented UserPreferences abstract class.
    • This class will be act as a base for PrefManager in android-client project.
    • This class has the implementation of basic user settings like tokens, instant urls, user status etc.
  • Added EntityMapper interface and AbstractMapper.
    • Since the services return the response as custom models which is generated along with the services files and hence in order to convert them to domain specific models the client application has to define the custom mapper for each conversion implementing these interface or abstract class.
    • AbstractMapper internally defines the function body for mapFromEntityList and mapToEntityList, so for most of the cases client can extend this class but in case client has to define some custom logic for these two methods then it must implement EntityMapper.
  • Added BaseApiManager interface and its implementation concrete class BaseApiManagerImpl
    • This will be the entry point to the sdk.
    • The BaseApiManager interface declares all the necessary functions which are required to access the APIs currently required by Android Client project, refer client's BaseApiManager for the supported services.
    • Client app has to get instant using the companion's object getInstance() method.
    • createService(username: String, password: String, baseUrl: String, tenant: String) has to be called to initiate the services, currently the api manager does not allow client to intervene in the service creation and hence not able to add a custom interceptor or add custom ok http client.
    • Below is the code snippet for making a basic http auth request using the sdk.
      val base_url = "https://10.0.2.2:8443/fineract-provider/api/v1/"
      val tenant = "default"
      
      val baseApiManager = BaseApiManager.getInstance();
      baseApiManager.createService("mifos", "password", base_url, tenant)
      
      baseApiManager.getAuthApi().authenticate(true, "")
              .observeOn(AndroidSchedulers.mainThread())
              .subscribeOn(Schedulers.io())
              .subscribe(object : Subscriber<PostAuthenticationResponse>() {
                  override fun onCompleted() {
                      Log.i("subscriber", "completed")
                  }
      
                  override fun onError(e: Throwable?) {
                      Log.i("subscriber", "error: ${e?.localizedMessage}")
                  }
      
                  override fun onNext(t: PostAuthenticationResponse?) {
                      Log.i("subscriber", "next: ${t.toString()}")
                  }
      
              })
      }
  • References

3. Fineract Android Client | Android(Kotlin + Java)

Here I worked on Mifos Android Client application. In this project the major change this year would be to remove the existing api services and make use of Mifos Android SDK library. This application is dependent on many legacy libraries which are now deprecated, so it is a bit challenging migrating the API code to sdk. Hence the SDK will be having support for most of the older libraries. Below are the implementation and work done so far.

  • Added Mifos Android SDK dependency, fixed some major depenedncy clash and minor issues. Until this point all the three projects are lined up.
  • Migrated the PrefManager to extend the UserPreferences.
  • References

Phase 2

In phase 2 the main work was done in the integration/migration part. The Android-Client consumes fineract api and was diffining all the services and retrofit client on the domain level, but now it needs to be migrated to make use of generated SDK in the phase 1. Since the migration was majorly related to apis this task can be achieved by only changing the api calls in DataManager to make use of sdk client for making api request and use abstract/entity mapper for casting data from entity to domain model. Apart from integration this phase also include major improvements in the sdk and the swagger documentation resources in fineract project.

1. Android Client | Android(Kotlin + Java)

Integrated the sdk and removed the old api calls. As mentioned in my proposal I migrated all the basic endpoints like clients/centers/groups/savingsAccounts etc, rest of the endpoint will be migrated post GSoC. The migration include getting the appropriate api and deffining the mapper depending on the enity. All the changes made are mostly consoncentrated over datamanagers without making the much changes in the rest of the code. Below are the list of PRs related to integration.

Type PR
Client Integration #1825
Groups Integration #1827
Centers Integration #1828
Staff and Search Integration #1829
Survey Integration #1831
Sdk version update #1832

2. Apache Fineract | Java

Throughout the migration of SDK many issues with the swagger doc and generated SDK was encountered which had to be fixed in order for the SDK to work as expected. Below is the list of JIRA ticket and respected PRs.

JIRA Ticket PR
FINERACT-1363 #1817
FINERACT-1364 #1810
FINERACT-1365 #1813
FINERACT-1366 #1812
FINERACT-1369 #1814
FINERACT-1370 #1815
FINERACT-1372 #1828
FINERACT-1373 #1827
FINERACT-1376 #1826
FINERACT-1377 #1825
FINERACT-1378 #1824
FINERACT-1380 #1815
FINERACT-1381 #1821
FINERACT-1382 #1820
FINERACT-1383 #1819

3. Fineract Client | Java


Made a stable release of the client library, please do checkout the release changelog for getting more info about the changes. Apart from the release their has been some of the major improvements and fixes after the initial release. Refer below link for all the PRs that are merged. Merged pull request

4. Fineract Android SDK | Android(Kotlin + Java)


Release version one of the SDK. The main changes here include updation of fineract client version to resolve the issues mentioned earlier in this post also added project build check using github actions. Refer below link for all the PRs that are merged. Merged pull request

Contact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment