Search in sources :

Example 1 with Category

use of org.hisp.dhis.android.core.category.Category in project dhis2-android-sdk by dhis2.

the class CategoryCallFactory method create.

@NonNull
public static CategoryEndpointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter) {
    CategoryService categoryService = retrofit.create(CategoryService.class);
    ResponseValidator<Category> categoryResponseValidator = new ResponseValidator<>();
    CategoryHandler categoryHandler = HandlerFactory.createCategoryHandler(databaseAdapter);
    ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
    CategoryQuery categoryQuery = CategoryQuery.defaultQuery();
    CategoryEndpointCall categoryEndpointCall = new CategoryEndpointCall(categoryQuery, categoryService, categoryResponseValidator, categoryHandler, resourceHandler, databaseAdapter, new Date());
    return categoryEndpointCall;
}
Also used : Category(org.hisp.dhis.android.core.category.Category) ResponseValidator(org.hisp.dhis.android.core.category.ResponseValidator) CategoryQuery(org.hisp.dhis.android.core.category.CategoryQuery) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler) CategoryService(org.hisp.dhis.android.core.category.CategoryService) CategoryEndpointCall(org.hisp.dhis.android.core.category.CategoryEndpointCall) CategoryHandler(org.hisp.dhis.android.core.category.CategoryHandler) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Example 2 with Category

use of org.hisp.dhis.android.core.category.Category in project dhis2-android-sdk by dhis2.

the class CategoryShould method map_from_json_string.

@Test
public void map_from_json_string() throws IOException, ParseException {
    ObjectMapper objectMapper = Inject.objectMapper();
    Category category = objectMapper.readValue("{\"" + "lastUpdated\":\"2014-11-19T12:58:52.558\"," + "\"id\":\"KfdsGBcoiCa\"," + "\"href\":\"https://play.dhis2.org/demo/api/categories/KfdsGBcoiCa\"," + "\"created\":\"2011-12-24T12:24:25.155\"," + "\"name\":\"Births attended by\"," + "\"shortName\":\"Births attended by\"," + "\"dataDimensionType\":\"DISAGGREGATION\"," + "\"dimensionType\":\"CATEGORY\"," + "\"displayName\":\"Births attended by\"," + "\"publicAccess\":\"rw------\"," + "\"displayShortName\":\"Births attended by\"," + "\"externalAccess\":false," + "\"dimension\":\"KfdsGBcoiCa\"," + "\"allItems\":false," + "\"dataDimension\":false," + "\"user\":{\"id\":\"GOLswS44mh8\"}," + "\"translations\":[]," + "\"categoryCombos\":[{\"id\":\"m2jTvAj5kkm\"}]," + "\"categoryOptions\":[" + "{\"id\":\"TNYQzTHdoxL\"}," + "{\"id\":\"TXGfLxZlInA\"}," + "{\"id\":\"QgULqw9YDu2\"}," + "{\"id\":\"OjIOxG7vgna\"}," + "{\"id\":\"uZUnebiT5DI\"}," + "{\"id\":\"HTHvCohKoXt\"}]," + "\"userGroupAccesses\":[]" + "}", Category.class);
    assertThat(category.uid()).isEqualTo("KfdsGBcoiCa");
    assertThat(category.created()).isEqualTo(BaseIdentifiableObject.DATE_FORMAT.parse("2011-12-24T12:24:25.155"));
    assertThat(category.lastUpdated()).isEqualTo(BaseIdentifiableObject.DATE_FORMAT.parse("2014-11-19T12:58:52.558"));
    // names
    assertThat(category.name()).isEqualTo("Births attended by");
    assertThat(category.shortName()).isEqualTo("Births attended by");
    assertThat(category.displayName()).isEqualTo("Births attended by");
    assertThat(category.displayShortName()).isEqualTo("Births attended by");
    // checking options
    assertThat(category.categoryOptions().get(0).uid()).isEqualTo("TNYQzTHdoxL");
    assertThat(category.categoryOptions().get(1).uid()).isEqualTo("TXGfLxZlInA");
    assertThat(category.categoryOptions().get(2).uid()).isEqualTo("QgULqw9YDu2");
    assertThat(category.categoryOptions().get(3).uid()).isEqualTo("OjIOxG7vgna");
    assertThat(category.categoryOptions().get(4).uid()).isEqualTo("uZUnebiT5DI");
    assertThat(category.categoryOptions().get(5).uid()).isEqualTo("HTHvCohKoXt");
}
Also used : Category(org.hisp.dhis.android.core.category.Category) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Category (org.hisp.dhis.android.core.category.Category)2 NonNull (android.support.annotation.NonNull)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1 CategoryEndpointCall (org.hisp.dhis.android.core.category.CategoryEndpointCall)1 CategoryHandler (org.hisp.dhis.android.core.category.CategoryHandler)1 CategoryQuery (org.hisp.dhis.android.core.category.CategoryQuery)1 CategoryService (org.hisp.dhis.android.core.category.CategoryService)1 ResponseValidator (org.hisp.dhis.android.core.category.ResponseValidator)1 ResourceHandler (org.hisp.dhis.android.core.resource.ResourceHandler)1 Test (org.junit.Test)1