Search in sources :

Example 16 with ResourceHandler

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

the class OptionSetCallShould method setUp.

@Override
@Before
public void setUp() throws IOException {
    super.setUp();
    mockWebServer = new MockWebServer();
    mockWebServer.start();
    MockResponse mockResponse = new MockResponse();
    mockResponse.setBody("{\n" + "\n" + "    \"pager\": {\n" + "        \"page\": 1,\n" + "        \"pageCount\": 1,\n" + "        \"total\": 1,\n" + "        \"pageSize\": 50\n" + "    },\n" + "    \"optionSets\": [\n" + "        {\n" + "            \"lastUpdated\": \"2012-09-20T16:05:17.555\",\n" + "            \"created\": \"2012-09-20T16:05:17.555\",\n" + "            \"name\": \"MNCH PMTCT code\",\n" + "            \"id\": \"POc7DkGU3QU\",\n" + "            \"displayName\": \"MNCH PMTCT code\",\n" + "            \"valueType\": \"TEXT\",\n" + "            \"version\": 1,\n" + "            \"options\": [\n" + "                {\n" + "                    \"code\": \"C\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"C\",\n" + "                    \"id\": \"s2gIL3CEyKL\",\n" + "                    \"displayName\": \"C\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 1,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                },\n" + "                {\n" + "                    \"code\": \"TR\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"TR\",\n" + "                    \"id\": \"poM80hUlVi9\",\n" + "                    \"displayName\": \"TR\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 2,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                },\n" + "                {\n" + "                    \"code\": \"TRR\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"TRR\",\n" + "                    \"id\": \"hcvPpAy3kb2\",\n" + "                    \"displayName\": \"TRR\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 3,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                },\n" + "                {\n" + "                    \"code\": \"TRRDm\",\n" + "                    \"created\": \"2014-08-18T12:39:16.000\",\n" + "                    \"lastUpdated\": \"2014-08-18T12:39:16.000\",\n" + "                    \"name\": \"TRRDm\",\n" + "                    \"id\": \"u4wsy7OPQIg\",\n" + "                    \"displayName\": \"TRRDm\",\n" + "                    \"externalAccess\": false,\n" + "                    \"sortOrder\": 4,\n" + "                    \"optionSet\": {\n" + "                        \"id\": \"POc7DkGU3QU\"\n" + "                    },\n" + "                    \"userGroupAccesses\": [ ],\n" + "                    \"attributeValues\": [ ],\n" + "                    \"translations\": [ ],\n" + "                    \"userAccesses\": [ ]\n" + "                }\n" + "            ]\n" + "        }\n" + "    ]\n" + "\n" + "}");
    mockWebServer.enqueue(mockResponse);
    // ToDo: consider moving this out
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setDateFormat(BaseIdentifiableObject.DATE_FORMAT.raw());
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    Retrofit retrofit = new Retrofit.Builder().baseUrl(mockWebServer.url("/")).addConverterFactory(JacksonConverterFactory.create(objectMapper)).addConverterFactory(FieldsConverterFactory.create()).build();
    OptionSetService optionSetService = retrofit.create(OptionSetService.class);
    ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter());
    Set<String> uids = new HashSet<>();
    uids.add("POc7DkGU3QU");
    // TODO fix
    GenericCallData data = GenericCallData.create(databaseAdapter(), new ResourceHandler(resourceStore), retrofit);
    GenericHandler<OptionSet, OptionSetModel> optionSetHandler = OptionSetHandler.create(databaseAdapter());
    optionSetCall = new OptionSetCall(data, optionSetService, optionSetHandler, uids);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ResourceStore(org.hisp.dhis.android.core.resource.ResourceStore) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) GenericCallData(org.hisp.dhis.android.core.common.GenericCallData) ResourceStoreImpl(org.hisp.dhis.android.core.resource.ResourceStoreImpl) Retrofit(retrofit2.Retrofit) MockWebServer(okhttp3.mockwebserver.MockWebServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 17 with ResourceHandler

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

the class DataValueEndpointCallRealIntegrationShould method createCall.

private DataValueEndpointCall createCall() {
    ResourceHandler resourceHandler = new ResourceHandler(new ResourceStoreImpl(databaseAdapter()));
    GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit());
    return DataValueEndpointCall.FACTORY.create(data, getDataSetUids(), getPeriodIds(), getOrgUnitUids());
}
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)

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