Search in sources :

Example 21 with Category

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

the class DhisConvenienceTest method createCategoryCombo.

/**
 * @param categoryComboUniqueIdentifier A unique character to identify the
 *        category option combo.
 * @param categories the categories category options.
 * @return CategoryOptionCombo
 */
public static CategoryCombo createCategoryCombo(char categoryComboUniqueIdentifier, Category... categories) {
    CategoryCombo categoryCombo = new CategoryCombo("CategoryCombo" + categoryComboUniqueIdentifier, DataDimensionType.DISAGGREGATION);
    categoryCombo.setAutoFields();
    for (Category category : categories) {
        categoryCombo.getCategories().add(category);
    }
    return categoryCombo;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo)

Example 22 with Category

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

the class SharingControllerTest method systemDefaultMetadataNoAccess.

@Test
void systemDefaultMetadataNoAccess() {
    final Category category = new Category();
    category.setName(Category.DEFAULT_NAME + "x");
    doReturn(Category.class).when(aclService).classForType(eq("category"));
    when(aclService.isClassShareable(eq(Category.class))).thenReturn(true);
    when(manager.getNoAcl(eq(Category.class), eq("kkSjhdhks"))).thenReturn(category);
    assertThrows(AccessDeniedException.class, () -> sharingController.postSharing("category", "kkSjhdhks", request));
}
Also used : Category(org.hisp.dhis.category.Category) Test(org.junit.jupiter.api.Test)

Example 23 with Category

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

the class PreCheckDataRelationsValidationHookTest method categoryComboWithTwoCategories.

private CategoryCombo categoryComboWithTwoCategories() {
    char uniqueIdentifier = 'A';
    CategoryOption co1 = createCategoryOption(uniqueIdentifier);
    Category ca1 = createCategory(uniqueIdentifier, co1);
    CategoryOption co2 = createCategoryOption(uniqueIdentifier);
    Category ca2 = createCategory(uniqueIdentifier, co2);
    CategoryCombo cc = createCategoryCombo(uniqueIdentifier, ca1, ca2);
    cc.setDataDimensionType(DataDimensionType.ATTRIBUTE);
    CategoryOptionCombo aoc1 = createCategoryOptionCombo(cc, co1, co2);
    cc.setOptionCombos(Sets.newHashSet(aoc1));
    return cc;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 24 with Category

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

the class PreCheckDataRelationsValidationHookTest method categoryCombo.

private CategoryCombo categoryCombo(char uniqueIdentifier) {
    CategoryOption co1 = createCategoryOption(uniqueIdentifier);
    CategoryOption co2 = createCategoryOption(uniqueIdentifier);
    Category ca = createCategory(uniqueIdentifier, co1, co2);
    CategoryCombo cc = createCategoryCombo(uniqueIdentifier, ca);
    cc.setDataDimensionType(DataDimensionType.ATTRIBUTE);
    CategoryOptionCombo aoc1 = createCategoryOptionCombo(cc, co1);
    CategoryOptionCombo aoc2 = createCategoryOptionCombo(cc, co2);
    cc.setOptionCombos(Sets.newHashSet(aoc1, aoc2));
    return cc;
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 25 with Category

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

the class CsvImportServiceTest method testImportCategories.

@Test
void testImportCategories() throws IOException {
    InputStream in = new ClassPathResource("csv/categories.csv").getInputStream();
    Metadata metadata = csvImportService.fromCsv(in, new CsvImportOptions().setImportClass(CsvImportClass.CATEGORY).setFirstRowIsHeader(true));
    assertEquals(3, metadata.getCategories().size());
    Category gender = metadata.getCategories().get(0);
    Category ageGroup = metadata.getCategories().get(1);
    Category partner = metadata.getCategories().get(2);
    assertEquals("Gender", gender.getName());
    assertEquals(DataDimensionType.DISAGGREGATION, gender.getDataDimensionType());
    assertEquals("AGEGROUP", ageGroup.getCode());
    assertEquals(DataDimensionType.ATTRIBUTE, partner.getDataDimensionType());
}
Also used : Category(org.hisp.dhis.category.Category) InputStream(java.io.InputStream) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

Category (org.hisp.dhis.category.Category)61 CategoryOption (org.hisp.dhis.category.CategoryOption)25 CategoryCombo (org.hisp.dhis.category.CategoryCombo)22 Test (org.junit.jupiter.api.Test)21 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)13 CategoryOptionGroupSet (org.hisp.dhis.category.CategoryOptionGroupSet)13 ArrayList (java.util.ArrayList)12 User (org.hisp.dhis.user.User)12 DataElement (org.hisp.dhis.dataelement.DataElement)11 HashSet (java.util.HashSet)8 DataSet (org.hisp.dhis.dataset.DataSet)8 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)8 HashMap (java.util.HashMap)7 Date (java.util.Date)5 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)5 List (java.util.List)4 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 Attribute (org.hisp.dhis.attribute.Attribute)4