Search in sources :

Example 31 with OptionSet

use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testOptionSetMerge.

@Test
void testOptionSetMerge() throws IOException {
    // Import 1 OptionSet with 3 Options
    ImportReport importReport = runImport("metadata/optionSet_add.csv", CsvImportClass.OPTION_SET);
    assertEquals(4, importReport.getStats().getCreated());
    // Send payload with 2 new Options
    importReport = runImport("metadata/optionSet_update.csv", CsvImportClass.OPTION_SET, null, params -> params.setMergeMode(MergeMode.MERGE));
    assertEquals(2, importReport.getStats().getCreated());
    OptionSet optionSet = optionService.getOptionSetByCode("COLOR");
    // Total 5 options added
    assertEquals(5, optionSet.getOptions().size());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) DataElementService(org.hisp.dhis.dataelement.DataElementService) PreheatIdentifier(org.hisp.dhis.preheat.PreheatIdentifier) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ArrayList(java.util.ArrayList) OptionGroup(org.hisp.dhis.option.OptionGroup) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CsvImportService(org.hisp.dhis.dxf2.csv.CsvImportService) OptionService(org.hisp.dhis.option.OptionService) UserService(org.hisp.dhis.user.UserService) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) IOException(java.io.IOException) SchemaService(org.hisp.dhis.schema.SchemaService) MergeMode(org.hisp.dhis.common.MergeMode) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) Option(org.hisp.dhis.option.Option) CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) OptionSet(org.hisp.dhis.option.OptionSet) DhisSpringTest(org.hisp.dhis.DhisSpringTest) InputStream(java.io.InputStream) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 32 with OptionSet

use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testOptionSetImport.

@Test
void testOptionSetImport() throws Exception {
    ImportReport importReport = runImport("metadata/optionSets.csv", CsvImportClass.OPTION_SET, metadata -> {
        assertEquals(4, metadata.getOptionSets().size());
        assertEquals(3, metadata.getOptionSets().get(0).getOptions().size());
        assertEquals(3, metadata.getOptionSets().get(1).getOptions().size());
        assertEquals(3, metadata.getOptionSets().get(2).getOptions().size());
        assertEquals(3, metadata.getOptionSets().get(3).getOptions().size());
    });
    assertEquals(16, importReport.getStats().getCreated());
    List<OptionSet> optionSets = new ArrayList<>(optionService.getAllOptionSets());
    assertEquals(4, optionSets.size());
    assertEquals(3, optionSets.get(0).getOptions().size());
    assertEquals(3, optionSets.get(1).getOptions().size());
    assertEquals(3, optionSets.get(2).getOptions().size());
    assertEquals(3, optionSets.get(3).getOptions().size());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) ArrayList(java.util.ArrayList) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 33 with OptionSet

use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.

the class BaseAnalyticalObjectTest method testPopulateAnalyticalProperties.

@Test
void testPopulateAnalyticalProperties() {
    TrackedEntityAttribute tea = new TrackedEntityAttribute();
    tea.setAutoFields();
    tea.setValueType(ValueType.TEXT);
    tea.setOptionSet(new OptionSet("name", ValueType.BOOLEAN));
    TrackedEntityAttributeDimension tead = new TrackedEntityAttributeDimension(tea, null, "EQ:10");
    EventChart eventChart = new EventChart();
    eventChart.setAutoFields();
    eventChart.getColumnDimensions().add(tea.getUid());
    eventChart.getAttributeDimensions().add(tead);
    eventChart.populateAnalyticalProperties();
    assertEquals(1, eventChart.getColumns().size());
    DimensionalObject dim = eventChart.getColumns().get(0);
    assertNotNull(dim);
    assertEquals(DimensionType.PROGRAM_ATTRIBUTE, dim.getDimensionType());
    assertEquals(AnalyticsType.EVENT, dim.getAnalyticsType());
    assertEquals(tead.getFilter(), dim.getFilter());
    assertEquals(tead.getAttribute().getValueType(), dim.getValueType());
    assertEquals(tead.getAttribute().getOptionSet(), dim.getOptionSet());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) EventChart(org.hisp.dhis.eventchart.EventChart) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test)

Example 34 with OptionSet

use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.

the class QueryItemHelperTest method setUp.

@BeforeEach
void setUp() {
    DataElement deA = createDataElement('A');
    Option opA = createOption('A');
    Option opB = createOption('B');
    opA.setUid(UID_A);
    opB.setUid(UID_B);
    OptionSet os = createOptionSet('A', opA, opB);
    Legend lpA = createLegend('A', 0.0, 1.0);
    lpA.setCode(LEGEND_CODE_A);
    Legend lpB = createLegend('B', 0.0, 1.0);
    lpB.setCode(LEGEND_CODE_B);
    lpA.setUid(UID_A);
    lpB.setUid(UID_B);
    LegendSet ls = createLegendSet('A', lpA, lpB);
    queryItem = new QueryItem(deA, ls, deA.getValueType(), deA.getAggregationType(), os);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) QueryItem(org.hisp.dhis.common.QueryItem) Legend(org.hisp.dhis.legend.Legend) Option(org.hisp.dhis.option.Option) LegendSet(org.hisp.dhis.legend.LegendSet) OptionSet(org.hisp.dhis.option.OptionSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with OptionSet

use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.

the class EventQueryValidatorTest method setUpTest.

@Override
public void setUpTest() {
    queryValidator = new DefaultEventQueryValidator(aggregateQueryValidator, systemSettingManager);
    prA = createProgram('A');
    prB = createProgram('B');
    idObjectManager.save(prA);
    idObjectManager.save(prB);
    deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
    deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
    deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
    deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
    deE = createDataElement('E', ValueType.COORDINATE, AggregationType.NONE, DataElementDomain.TRACKER);
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    idObjectManager.save(deC);
    idObjectManager.save(deD);
    idObjectManager.save(deE);
    atA = createTrackedEntityAttribute('A');
    atB = createTrackedEntityAttribute('B');
    idObjectManager.save(atA);
    idObjectManager.save(atB);
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B', ouA);
    ouC = createOrganisationUnit('C', ouA);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    lsA = createLegendSet('A');
    idObjectManager.save(lsA);
    osA = new OptionSet("OptionSetA", ValueType.TEXT);
    idObjectManager.save(osA);
}
Also used : OptionSet(org.hisp.dhis.option.OptionSet)

Aggregations

OptionSet (org.hisp.dhis.option.OptionSet)40 Option (org.hisp.dhis.option.Option)24 Test (org.junit.jupiter.api.Test)20 DataElement (org.hisp.dhis.dataelement.DataElement)12 List (java.util.List)10 ArrayList (java.util.ArrayList)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 OptionGroup (org.hisp.dhis.option.OptionGroup)6 OptionGroupSet (org.hisp.dhis.option.OptionGroupSet)6 HashSet (java.util.HashSet)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Map (java.util.Map)4 CategoryOption (org.hisp.dhis.category.CategoryOption)4