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));
}
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());
}
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);
}
}
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);
}
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());
}
Aggregations