Search in sources :

Example 31 with Option

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

the class DefaultMetadataExportServiceTest method getParamsFromMapIncludedSecondary.

@Test
void getParamsFromMapIncludedSecondary() {
    Mockito.when(schemaService.getSchemaByPluralName(Mockito.eq("jobConfigurations"))).thenReturn(new Schema(JobConfiguration.class, "jobConfiguration", "jobConfigurations"));
    Mockito.when(schemaService.getSchemaByPluralName(Mockito.eq("options"))).thenReturn(new Schema(Option.class, "option", "options"));
    final Map<String, List<String>> params = new HashMap<>();
    params.put("jobConfigurations", Collections.singletonList("true"));
    params.put("options", Collections.singletonList("true"));
    MetadataExportParams exportParams = service.getParamsFromMap(params);
    Assertions.assertTrue(exportParams.getClasses().contains(JobConfiguration.class));
    Assertions.assertTrue(exportParams.getClasses().contains(Option.class));
}
Also used : HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Option(org.hisp.dhis.option.Option) List(java.util.List) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 32 with Option

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

the class AbstractAnalyticsService method getItemOptions.

/**
 * Returns a map of metadata item options and {@link Option}.
 *
 * @param grid the Grid instance.
 * @return a list of options.
 */
protected List<Option> getItemOptions(Grid grid) {
    List<Option> options = new ArrayList<>();
    for (int i = 0; i < grid.getHeaders().size(); ++i) {
        GridHeader gridHeader = grid.getHeaders().get(i);
        if (gridHeader.hasOptionSet()) {
            final int columnIndex = i;
            options.addAll(gridHeader.getOptionSetObject().getOptions().stream().filter(opt -> opt != null && grid.getRows().stream().anyMatch(r -> {
                Object o = r.get(columnIndex);
                if (o instanceof String) {
                    return ((String) o).equalsIgnoreCase(opt.getCode());
                }
                return false;
            })).collect(Collectors.toList()));
        }
    }
    return options.stream().distinct().collect(Collectors.toList());
}
Also used : ArrayList(java.util.ArrayList) Option(org.hisp.dhis.option.Option) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GridHeader(org.hisp.dhis.common.GridHeader)

Example 33 with Option

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

the class AbstractAnalyticsService method addMetadata.

/**
 * Adds meta data values to the given grid based on the given data query
 * parameters.
 *
 * @param params the data query parameters.
 * @param grid the grid.
 */
protected void addMetadata(EventQueryParams params, List<DimensionItemKeywords.Keyword> periodKeywords, Grid grid) {
    if (!params.isSkipMeta()) {
        final Map<String, Object> metadata = new HashMap<>();
        List<Option> options = getItemOptions(grid);
        metadata.put(ITEMS.getKey(), getMetadataItems(params, periodKeywords, options));
        metadata.put(DIMENSIONS.getKey(), getDimensionItems(params, options));
        if (params.isHierarchyMeta() || params.isShowHierarchy()) {
            User user = securityManager.getCurrentUser(params);
            List<OrganisationUnit> organisationUnits = asTypedList(params.getDimensionOrFilterItems(ORGUNIT_DIM_ID));
            Collection<OrganisationUnit> roots = user != null ? user.getOrganisationUnits() : null;
            if (params.isHierarchyMeta()) {
                metadata.put(ORG_UNIT_HIERARCHY.getKey(), getParentGraphMap(organisationUnits, roots));
            }
            if (params.isShowHierarchy()) {
                metadata.put(ORG_UNIT_NAME_HIERARCHY.getKey(), getParentNameGraphMap(organisationUnits, roots, true));
            }
        }
        grid.setMetaData(metadata);
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Option(org.hisp.dhis.option.Option)

Example 34 with Option

use of org.hisp.dhis.option.Option 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 Option

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

the class EventQueryParamsTest method testGetItemOptions.

@Test
void testGetItemOptions() {
    QueryItem qiA = new QueryItem(deA, null, deA.getValueType(), deA.getAggregationType(), osA);
    QueryItem qiB = new QueryItem(deB, null, deB.getValueType(), deB.getAggregationType(), osB);
    EventQueryParams params = new EventQueryParams.Builder().addItem(qiA).addItem(qiB).build();
    Set<Option> expected = Sets.newHashSet(opA, opB, opC, opD);
    assertEquals(expected, params.getItemOptions());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) Option(org.hisp.dhis.option.Option) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

Option (org.hisp.dhis.option.Option)40 OptionSet (org.hisp.dhis.option.OptionSet)23 Test (org.junit.jupiter.api.Test)16 List (java.util.List)11 DataElement (org.hisp.dhis.dataelement.DataElement)10 HashMap (java.util.HashMap)8 Legend (org.hisp.dhis.legend.Legend)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)6 CategoryOption (org.hisp.dhis.category.CategoryOption)6 HashSet (java.util.HashSet)5 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 VersionedObject (org.hisp.dhis.common.VersionedObject)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)3 OptionGroup (org.hisp.dhis.option.OptionGroup)3 OptionGroupSet (org.hisp.dhis.option.OptionGroupSet)3