Search in sources :

Example 1 with ProgramStage

use of org.hisp.dhis.android.core.program.ProgramStage in project dhis2-android-sdk by dhis2.

the class MetadataCall method getOptionSetUidsForDataElements.

private void getOptionSetUidsForDataElements(Set<String> uids, List<ProgramStage> programStages) {
    int programStagesSize = programStages.size();
    for (int j = 0; j < programStagesSize; j++) {
        ProgramStage programStage = programStages.get(j);
        List<ProgramStageDataElement> programStageDataElements = programStage.programStageDataElements();
        int programStageDataElementSize = programStageDataElements.size();
        for (int k = 0; k < programStageDataElementSize; k++) {
            ProgramStageDataElement programStageDataElement = programStageDataElements.get(k);
            if (programStageDataElement.dataElement() != null && programStageDataElement.dataElement().optionSet() != null) {
                uids.add(programStageDataElement.dataElement().optionSet().uid());
            }
        }
    }
}
Also used : ProgramStageDataElement(org.hisp.dhis.android.core.program.ProgramStageDataElement) ProgramStage(org.hisp.dhis.android.core.program.ProgramStage)

Example 2 with ProgramStage

use of org.hisp.dhis.android.core.program.ProgramStage 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)

Aggregations

ProgramStage (org.hisp.dhis.android.core.program.ProgramStage)2 GenericCallData (org.hisp.dhis.android.core.common.GenericCallData)1 Payload (org.hisp.dhis.android.core.common.Payload)1 Transaction (org.hisp.dhis.android.core.data.database.Transaction)1 OptionSetCall (org.hisp.dhis.android.core.option.OptionSetCall)1 OrganisationUnit (org.hisp.dhis.android.core.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.android.core.program.Program)1 ProgramCall (org.hisp.dhis.android.core.program.ProgramCall)1 ProgramStageDataElement (org.hisp.dhis.android.core.program.ProgramStageDataElement)1 ResourceHandler (org.hisp.dhis.android.core.resource.ResourceHandler)1 SystemInfoCall (org.hisp.dhis.android.core.systeminfo.SystemInfoCall)1 TrackedEntityCall (org.hisp.dhis.android.core.trackedentity.TrackedEntityCall)1 User (org.hisp.dhis.android.core.user.User)1 UserCall (org.hisp.dhis.android.core.user.UserCall)1 Response (retrofit2.Response)1