Search in sources :

Example 1 with ResourceHandler

use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.

the class TrackedEntityCall method call.

@Override
public Response<Payload<TrackedEntity>> call() throws Exception {
    synchronized (this) {
        if (isExecuted) {
            throw new IllegalStateException("Already executed");
        }
        isExecuted = true;
    }
    if (uidSet.size() > MAX_UIDS) {
        throw new IllegalArgumentException("Can't handle the amount of tracked entities: " + uidSet.size() + ". " + "Max size is: " + MAX_UIDS);
    }
    ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
    String lastUpdated = resourceHandler.getLastUpdated(resourceType);
    Response<Payload<TrackedEntity>> response = getTrackedEntities(lastUpdated);
    TrackedEntityHandler trackedEntityHandler = new TrackedEntityHandler(trackedEntityStore);
    Transaction transaction = databaseAdapter.beginNewTransaction();
    try {
        if (response != null && response.isSuccessful()) {
            List<TrackedEntity> trackedEntities = response.body().items();
            int size = trackedEntities.size();
            for (int i = 0; i < size; i++) {
                TrackedEntity trackedEntity = trackedEntities.get(i);
                trackedEntityHandler.handleTrackedEntity(trackedEntity);
            }
            resourceHandler.handleResource(resourceType, serverDate);
            transaction.setSuccessful();
        }
    } finally {
        transaction.end();
    }
    return response;
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) Payload(org.hisp.dhis.android.core.common.Payload)

Example 2 with ResourceHandler

use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.

the class ProgramCall method call.

@Override
public Response<Payload<Program>> call() throws Exception {
    synchronized (this) {
        if (isExecuted) {
            throw new IllegalStateException("Already executed");
        }
        isExecuted = true;
    }
    if (uids.size() > MAX_UIDS) {
        throw new IllegalArgumentException("Can't handle the amount of programs: " + uids.size() + ". " + "Max size is: " + MAX_UIDS);
    }
    ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
    String lastSyncedPrograms = resourceHandler.getLastUpdated(ResourceModel.Type.PROGRAM);
    Response<Payload<Program>> programsByLastUpdated = programService.getPrograms(getFields(), Program.lastUpdated.gt(lastSyncedPrograms), Program.uid.in(uids), Boolean.FALSE).execute();
    if (programsByLastUpdated.isSuccessful()) {
        Transaction transaction = databaseAdapter.beginNewTransaction();
        try {
            List<Program> programs = programsByLastUpdated.body().items();
            int size = programs.size();
            for (int i = 0; i < size; i++) {
                Program program = programs.get(i);
                programHandler.handleProgram(program);
            }
            resourceHandler.handleResource(ResourceModel.Type.PROGRAM, serverDate);
            transaction.setSuccessful();
        } finally {
            transaction.end();
        }
    }
    return programsByLastUpdated;
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) Payload(org.hisp.dhis.android.core.common.Payload)

Example 3 with ResourceHandler

use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.

the class DataElementEndpointCallRealIntegrationShould method createCall.

private DataElementEndpointCall createCall() {
    ResourceHandler resourceHandler = new ResourceHandler(new ResourceStoreImpl(databaseAdapter()));
    GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit());
    Set<String> uids = new HashSet<>();
    uids.add("FTRrcoaog83");
    uids.add("P3jJH5Tu5VC");
    uids.add("FQ2o8UBlcrS");
    return DataElementEndpointCall.FACTORY.create(data, uids);
}
Also used : ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) GenericCallData(org.hisp.dhis.android.core.common.GenericCallData) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl) HashSet(java.util.HashSet)

Example 4 with ResourceHandler

use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.

the class DataSetAccessEndpointCallRealIntegrationShould method createCall.

private DataSetAccessEndpointCall createCall() {
    ResourceHandler resourceHandler = new ResourceHandler(new ResourceStoreImpl(databaseAdapter()));
    GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit());
    return DataSetAccessEndpointCall.FACTORY.create(data);
}
Also used : ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) GenericCallData(org.hisp.dhis.android.core.common.GenericCallData) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl)

Example 5 with ResourceHandler

use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.

the class DataSetEndpointCallRealIntegrationShould method createCall.

private DataSetEndpointCall createCall() {
    ResourceHandler resourceHandler = new ResourceHandler(new ResourceStoreImpl(databaseAdapter()));
    GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit());
    Set<String> uids = new HashSet<>();
    uids.add("BfMAe6Itzgt");
    uids.add("Lpw6GcnTrmS");
    uids.add("TuL8IOPzpHh");
    return DataSetEndpointCall.FACTORY.create(data, uids);
}
Also used : ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) GenericCallData(org.hisp.dhis.android.core.common.GenericCallData) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl) HashSet(java.util.HashSet)

Aggregations

ResourceHandler (org.hisp.dhis.android.core.resource.ResourceHandler)17 ResourceStoreImpl (org.hisp.dhis.android.core.resource.ResourceStoreImpl)8 GenericCallData (org.hisp.dhis.android.core.common.GenericCallData)7 Date (java.util.Date)5 Transaction (org.hisp.dhis.android.core.data.database.Transaction)5 HashSet (java.util.HashSet)3 Payload (org.hisp.dhis.android.core.common.Payload)3 ResourceStore (org.hisp.dhis.android.core.resource.ResourceStore)3 NonNull (android.support.annotation.NonNull)2 CategoryCombo (org.hisp.dhis.android.core.category.CategoryCombo)2 ResponseValidator (org.hisp.dhis.android.core.category.ResponseValidator)2 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 MockWebServer (okhttp3.mockwebserver.MockWebServer)1 Category (org.hisp.dhis.android.core.category.Category)1 CategoryComboEndpointCall (org.hisp.dhis.android.core.category.CategoryComboEndpointCall)1 CategoryComboHandler (org.hisp.dhis.android.core.category.CategoryComboHandler)1 CategoryComboQuery (org.hisp.dhis.android.core.category.CategoryComboQuery)1 CategoryComboService (org.hisp.dhis.android.core.category.CategoryComboService)1