Search in sources :

Example 1 with SystemInfo

use of org.hisp.dhis.android.core.systeminfo.SystemInfo in project dhis2-android-sdk by dhis2.

the class SingleDataCall method call.

@Override
public Response call() throws Exception {
    synchronized (this) {
        if (isExecuted) {
            throw new IllegalStateException("Already executed");
        }
        isExecuted = true;
    }
    Response response = null;
    Transaction transaction = databaseAdapter.beginNewTransaction();
    try {
        response = new SystemInfoCall(databaseAdapter, systemInfoStore, systemInfoService, resourceStore).call();
        if (!response.isSuccessful()) {
            return response;
        }
        SystemInfo systemInfo = (SystemInfo) response.body();
        Date serverDate = systemInfo.serverDate();
        response = eventCall(serverDate);
        if (response == null || !response.isSuccessful()) {
            return response;
        }
        transaction.setSuccessful();
        return response;
    } finally {
        transaction.end();
    }
}
Also used : Response(retrofit2.Response) SystemInfo(org.hisp.dhis.android.core.systeminfo.SystemInfo) Transaction(org.hisp.dhis.android.core.data.database.Transaction) SystemInfoCall(org.hisp.dhis.android.core.systeminfo.SystemInfoCall) Date(java.util.Date)

Example 2 with SystemInfo

use of org.hisp.dhis.android.core.systeminfo.SystemInfo in project dhis2-android-sdk by dhis2.

the class TrackerDataCall method call.

@Override
public Response call() throws Exception {
    synchronized (this) {
        if (isExecuted) {
            throw new IllegalStateException("Already executed");
        }
        isExecuted = true;
    }
    Response response = null;
    Map<String, TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceStore.querySynced();
    if (!trackedEntityInstances.isEmpty()) {
        Transaction transaction = databaseAdapter.beginNewTransaction();
        try {
            response = new SystemInfoCall(databaseAdapter, systemInfoStore, systemInfoService, resourceStore).call();
            if (!response.isSuccessful()) {
                return response;
            }
            SystemInfo systemInfo = (SystemInfo) response.body();
            Date serverDate = systemInfo.serverDate();
            response = trackedEntityInstanceCall(serverDate, trackedEntityInstances);
            transaction.setSuccessful();
        } finally {
            transaction.end();
        }
    }
    return response;
}
Also used : Response(retrofit2.Response) SystemInfo(org.hisp.dhis.android.core.systeminfo.SystemInfo) Transaction(org.hisp.dhis.android.core.data.database.Transaction) SystemInfoCall(org.hisp.dhis.android.core.systeminfo.SystemInfoCall) TrackedEntityInstance(org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance) Date(java.util.Date)

Example 3 with SystemInfo

use of org.hisp.dhis.android.core.systeminfo.SystemInfo in project dhis2-android-sdk by dhis2.

the class TrackerEntitiesDataCall method call.

@Override
public Response call() throws Exception {
    synchronized (this) {
        if (isExecuted) {
            throw new IllegalStateException("Already executed");
        }
        isExecuted = true;
    }
    Response response = null;
    Transaction transaction = databaseAdapter.beginNewTransaction();
    try {
        response = new SystemInfoCall(databaseAdapter, systemInfoStore, systemInfoService, resourceStore).call();
        if (!response.isSuccessful()) {
            return response;
        }
        SystemInfo systemInfo = (SystemInfo) response.body();
        Date serverDate = systemInfo.serverDate();
        response = trackerCall(serverDate);
        if (response == null || !response.isSuccessful()) {
            return response;
        }
        transaction.setSuccessful();
        return response;
    } finally {
        transaction.end();
    }
}
Also used : Response(retrofit2.Response) SystemInfo(org.hisp.dhis.android.core.systeminfo.SystemInfo) Transaction(org.hisp.dhis.android.core.data.database.Transaction) SystemInfoCall(org.hisp.dhis.android.core.systeminfo.SystemInfoCall) Date(java.util.Date)

Aggregations

Date (java.util.Date)3 Transaction (org.hisp.dhis.android.core.data.database.Transaction)3 SystemInfo (org.hisp.dhis.android.core.systeminfo.SystemInfo)3 SystemInfoCall (org.hisp.dhis.android.core.systeminfo.SystemInfoCall)3 Response (retrofit2.Response)3 TrackedEntityInstance (org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance)1