Skip to content

Conversation

@cjmamo
Copy link
Collaborator

@cjmamo cjmamo commented Apr 29, 2022

The DHIS2 Java SDK aims to provide the nuts and bolts for integrating with a DHIS2 server. Specifically, it provides a fluent-like interface for creating, fetching, modifying, and deleting DHIS2 resources. Its value proposition is that client developers:

  1. Have a type-safe API model, where possible, thanks to the POJOs generated at build-time: a developer doesn't need to worry whether a POJO isn't compatible with the DHIS2 API as long he's using the right version of the model (e.g., org.hisp.dhis.api.v2_37_4.model.OrganisationUnit)
  2. Can focus on the business logic and not the low-level details of API communication like authentication, retries, pagination, etc...
  3. Are free to choose to whichever JSON (de)serializer they want. Though the SDK does provide suitable defaults, an Android developer may choose to read/write JSON with Moshi while an integration developer may choose Jackson.

Usage example:

Dhis2Client dhis2Client = Dhis2ClientBuilder.newClient( "http://localhost:8081/api", "admin", "district" )
            .build();

org.hisp.dhis.api.v2_37_4.model.OrganisationUnit newOrgUnit = new org.hisp.dhis.api.v2_37_4.model.OrganisationUnit().withName(
        "Acme" )
    .withShortName( "Acme" )
    .withOpeningDate( new Date() );

String orgUnitId = dhis2Client.post( "organisationUnits" ).withResource( newOrgUnit )
    .transfer().returnAs( WebMessage.class )
    .getResponse().get().get( "uid" );

for ( OrganisationUnit orgUnit : dhis2Client.get( "organisationUnits" ).withPaging().transfer()
    .returnAs( OrganisationUnit.class, "organisationUnits" ) )
{
    if ( orgUnit.getCode().isPresent() )
    {
        System.out.println( orgUnit.getCode().get() );
    }
}

This SDK is meant to be an alternative to https://github.com/dhis2/dhis2-java-client. The latter brings with it too many dependencies so it's hard to leverage in a constrained environment like Android. In fact, a design principle of this SDK is to keep it lightweight so it can be easily called from within other applications. Besides the dependencies, dhis2-java-client is tightly bound with a specific version of the DHIS2 API model: it's not easy to switch over to a different version of the API model without having to downgrade/upgrade the client. In the Android team context, this presents a problem because they need the ability to support different API versions side-by-side.

@cjmamo cjmamo requested a review from a team April 29, 2022 15:10
@cjmamo cjmamo self-assigned this Apr 29, 2022
@cjmamo cjmamo marked this pull request as ready for review May 2, 2022 07:56
@mortenoh mortenoh merged commit bf57501 into main May 3, 2022
@cjmamo cjmamo deleted the dhis2-java-sdk branch May 3, 2022 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants