Search in sources :

Example 11 with ResourceHandler

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

the class CategoryEndpointCallShould method provideCategoryEndpointCall.

private CategoryEndpointCall provideCategoryEndpointCall() {
    CategoryQuery query = CategoryQuery.builder().paging(true).pageSize(CategoryQuery.DEFAULT_PAGE_SIZE).page(1).build();
    ResponseValidator<Category> validator = new ResponseValidator<>();
    CategoryStore store = new CategoryStoreImpl(databaseAdapter());
    CategoryOptionStore categoryOptionStore = new CategoryOptionStoreImpl(databaseAdapter());
    CategoryOptionHandler categoryOptionHandler = new CategoryOptionHandler(categoryOptionStore);
    CategoryCategoryOptionLinkStore categoryCategoryOptionLinkStore = new CategoryCategoryOptionLinkStoreImpl(databaseAdapter());
    CategoryHandler handler = new CategoryHandler(store, categoryOptionHandler, categoryCategoryOptionLinkStore);
    ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter());
    ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
    Date serverDate = new Date();
    return new CategoryEndpointCall(query, categoryService, validator, handler, resourceHandler, databaseAdapter(), serverDate);
}
Also used : ResourceStore(org.hisp.dhis.android.core.resource.ResourceStore) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl) Date(java.util.Date)

Example 12 with ResourceHandler

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

the class TrackedEntityInstanceCallFactory method create.

public static TrackedEntityInstanceEndPointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter, String trackedEntityInstanceUid) {
    TrackedEntityInstanceService trackedEntityInstanceService = retrofit.create(TrackedEntityInstanceService.class);
    TrackedEntityInstanceHandler trackedEntityInstanceHandler = HandlerFactory.createTrackedEntityInstanceHandler(databaseAdapter);
    ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
    TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = new TrackedEntityInstanceEndPointCall(trackedEntityInstanceService, databaseAdapter, trackedEntityInstanceHandler, resourceHandler, new Date(), trackedEntityInstanceUid);
    return trackedEntityInstanceEndPointCall;
}
Also used : ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) TrackedEntityInstanceEndPointCall(org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEndPointCall) TrackedEntityInstanceHandler(org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceHandler) TrackedEntityInstanceService(org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceService) Date(java.util.Date)

Example 13 with ResourceHandler

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

the class MetadataCall method call.

@SuppressWarnings("PMD.NPathComplexity")
@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;
        }
        GenericCallData data = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit);
        Response<User> userResponse = new UserCall(userService, databaseAdapter, userStore, userCredentialsStore, userRoleStore, resourceStore, data.serverDate()).call();
        response = userResponse;
        if (!response.isSuccessful()) {
            return response;
        }
        response = downloadCategories(data.serverDate());
        if (!response.isSuccessful()) {
            return response;
        }
        response = downloadCategoryCombos(data.serverDate());
        if (!response.isSuccessful()) {
            return response;
        }
        Response<Payload<Program>> programAccessResponse = ProgramAccessEndpointCall.FACTORY.create(data, programService).call();
        response = programAccessResponse;
        if (!response.isSuccessful()) {
            return response;
        }
        Set<String> programUids = getProgramUidsWithDataReadAccess(programAccessResponse.body().items());
        response = new ProgramCall(programService, databaseAdapter, resourceStore, programUids, programStore, data.serverDate(), trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, relationshipStore, styleHandler, renderTypeHandler).call();
        if (!response.isSuccessful()) {
            return response;
        }
        List<Program> programs = ((Response<Payload<Program>>) response).body().items();
        Set<String> assignedProgramStageUids = getAssignedProgramStageUids(programs);
        Response programStageResponse = programStageCallFactory.create(data, assignedProgramStageUids).call();
        if (!programStageResponse.isSuccessful()) {
            return programStageResponse;
        }
        Set<String> trackedEntityUids = getAssignedTrackedEntityUids(programs);
        response = new TrackedEntityCall(trackedEntityUids, databaseAdapter, trackedEntityStore, resourceStore, trackedEntityService, data.serverDate()).call();
        if (!response.isSuccessful()) {
            return response;
        }
        User user = userResponse.body();
        Response<Payload<OrganisationUnit>> organisationUnitResponse = organisationUnitCallFactory.create(data, user, programUids).call();
        if (!organisationUnitResponse.isSuccessful()) {
            return organisationUnitResponse;
        }
        List<ProgramStage> programStages = ((Response<Payload<ProgramStage>>) programStageResponse).body().items();
        Set<String> optionSetUids = getAssignedOptionSetUids(programs, programStages);
        response = new OptionSetCall(data, optionSetService, optionSetHandler, optionSetUids).call();
        if (!response.isSuccessful()) {
            return response;
        }
        List<OrganisationUnit> organisationUnits = organisationUnitResponse.body().items();
        response = dataSetParentCallFactory.create(user, data, organisationUnits).call();
        if (!response.isSuccessful()) {
            return response;
        }
        transaction.setSuccessful();
        return response;
    } finally {
        transaction.end();
    }
}
Also used : OrganisationUnit(org.hisp.dhis.android.core.organisationunit.OrganisationUnit) User(org.hisp.dhis.android.core.user.User) Program(org.hisp.dhis.android.core.program.Program) TrackedEntityCall(org.hisp.dhis.android.core.trackedentity.TrackedEntityCall) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) GenericCallData(org.hisp.dhis.android.core.common.GenericCallData) Response(retrofit2.Response) Transaction(org.hisp.dhis.android.core.data.database.Transaction) SystemInfoCall(org.hisp.dhis.android.core.systeminfo.SystemInfoCall) UserCall(org.hisp.dhis.android.core.user.UserCall) Payload(org.hisp.dhis.android.core.common.Payload) ProgramStage(org.hisp.dhis.android.core.program.ProgramStage) OptionSetCall(org.hisp.dhis.android.core.option.OptionSetCall) ProgramCall(org.hisp.dhis.android.core.program.ProgramCall)

Example 14 with ResourceHandler

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

the class SystemInfoCall method insertOrUpdateSystemInfo.

private void insertOrUpdateSystemInfo(Response<SystemInfo> response) {
    SystemInfoHandler systemInfoHandler = new SystemInfoHandler(systemInfoStore);
    ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
    Transaction transaction = databaseAdapter.beginNewTransaction();
    try {
        if (response.body() != null) {
            SystemInfo systemInfo = response.body();
            systemInfoHandler.handleSystemInfo(systemInfo);
            resourceHandler.handleResource(ResourceModel.Type.SYSTEM_INFO, systemInfo.serverDate());
        }
        transaction.setSuccessful();
    } finally {
        transaction.end();
    }
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler)

Example 15 with ResourceHandler

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

the class UserCall method call.

@Override
public Response<User> call() throws Exception {
    synchronized (this) {
        if (isExecuted) {
            throw new IllegalStateException("Already executed");
        }
        isExecuted = true;
    }
    Response<User> response = getUser();
    if (response.isSuccessful()) {
        UserHandler userHandler = new UserHandler(userStore);
        UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore);
        UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore);
        ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
        Transaction transaction = databaseAdapter.beginNewTransaction();
        try {
            User user = response.body();
            // TODO: check that this is user is authenticated and is persisted in db
            userHandler.handleUser(user);
            UserCredentials userCredentials = user.userCredentials();
            userCredentialsHandler.handleUserCredentials(userCredentials, user);
            List<UserRole> userRoles = userCredentials.userRoles();
            userRoleHandler.handleUserRoles(userRoles);
            resourceHandler.handleResource(ResourceModel.Type.USER, serverDate);
            transaction.setSuccessful();
        } catch (SQLiteConstraintException constraintException) {
            // constraintException.printStackTrace();
            Log.d("CAll", "call: constraintException");
        } finally {
            transaction.end();
        }
    }
    return response;
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler)

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