use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class TrackedEntityInstanceQueryParams method conform.
/**
* Performs a set of operations on this params.
* <p>
* <ul>
* <li>
* If a query item is specified as an attribute item as well as a filter
* item, the filter item will be removed. In that case, if the attribute
* item does not have any filters and the filter item has one or more filters,
* these will be applied to the attribute item.
* </li>
* </ul>
*/
public void conform() {
Iterator<QueryItem> filterIter = filters.iterator();
while (filterIter.hasNext()) {
QueryItem filter = filterIter.next();
// Filter present as attr
int index = attributes.indexOf(filter);
if (index >= 0) {
QueryItem attribute = attributes.get(index);
if (!attribute.hasFilter() && filter.hasFilter()) {
attribute.getFilters().addAll(filter.getFilters());
}
filterIter.remove();
}
}
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class EventQueryParamsTest method testGetDuplicateQueryItems.
@Test
public void testGetDuplicateQueryItems() {
QueryItem iA = new QueryItem(createDataElement('A', new DataElementCategoryCombo()));
QueryItem iB = new QueryItem(createDataElement('B', new DataElementCategoryCombo()));
QueryItem iC = new QueryItem(createDataElement('B', new DataElementCategoryCombo()));
QueryItem iD = new QueryItem(createDataElement('D', new DataElementCategoryCombo()));
EventQueryParams params = new EventQueryParams.Builder().addItem(iA).addItem(iB).addItem(iC).addItem(iD).build();
List<QueryItem> duplicates = params.getDuplicateQueryItems();
assertEquals(1, duplicates.size());
assertTrue(duplicates.contains(iC));
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class EventAnalyticsServiceMetadataTest method testGetQueryItemDimensionMetadata.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
@SuppressWarnings("unchecked")
public void testGetQueryItemDimensionMetadata() {
DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA));
DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA));
QueryItem itemLegendSet = new QueryItem(deA, lsA, deA.getValueType(), deA.getAggregationType(), null);
QueryItem itemLegendSetFilter = new QueryItem(deB, lsA, deB.getValueType(), deB.getAggregationType(), null);
itemLegendSetFilter.addFilter(new QueryFilter(QueryOperator.IN, leA.getUid() + OPTION_SEP + leB.getUid() + OPTION_SEP + leC.getUid()));
QueryItem item = new QueryItem(deC, null, deC.getValueType(), deC.getAggregationType(), null);
QueryItem itemFilter = new QueryItem(deD, null, deD.getValueType(), deD.getAggregationType(), null);
itemFilter.addFilter(new QueryFilter(QueryOperator.GT, "10"));
QueryItem itemOptionSet = new QueryItem(deE, null, deE.getValueType(), deE.getAggregationType(), osA);
QueryItem itemOptionSetFilter = new QueryItem(deF, null, deE.getValueType(), deE.getAggregationType(), osA);
itemOptionSetFilter.addFilter(new QueryFilter(QueryOperator.IN, opA.getCode() + OPTION_SEP + opB.getCode()));
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addDimension(periods).addDimension(orgUnits).addItem(itemLegendSet).addItem(itemLegendSetFilter).addItem(item).addItem(itemFilter).addItem(itemOptionSet).addItem(itemOptionSetFilter).withSkipData(true).withSkipMeta(false).withDisplayProperty(DisplayProperty.NAME).withApiVersion(DhisApiVersion.V26).build();
Grid grid = eventAnalyticsService.getAggregatedEventData(params);
Map<String, Object> metadata = grid.getMetaData();
assertNotNull(metadata);
Map<String, Object> dimensionItems = (Map<String, Object>) metadata.get(AnalyticsMetaDataKey.DIMENSIONS.getKey());
assertNotNull(dimensionItems);
List<String> itemsLegendSet = (List<String>) dimensionItems.get(itemLegendSet.getItemId());
List<String> itemsLegendSetFilter = (List<String>) dimensionItems.get(itemLegendSetFilter.getItemId());
List<String> items = (List<String>) dimensionItems.get(item.getItemId());
List<String> itemsFilter = (List<String>) dimensionItems.get(itemFilter.getItemId());
List<String> itemsOptionSet = (List<String>) dimensionItems.get(itemOptionSet.getItemId());
List<String> itemsOptionSetFilter = (List<String>) dimensionItems.get(itemOptionSetFilter.getItemId());
assertNotNull(itemsLegendSet);
assertNotNull(itemsLegendSetFilter);
assertNotNull(items);
assertNotNull(itemsFilter);
assertNotNull(itemsOptionSet);
assertNotNull(itemsOptionSetFilter);
assertEquals(4, itemsLegendSet.size());
assertEquals(itemsLegendSet, Lists.newArrayList(leA.getUid(), leB.getUid(), leC.getUid(), leD.getUid()));
assertEquals(3, itemsLegendSetFilter.size());
assertTrue(itemsLegendSetFilter.containsAll(IdentifiableObjectUtils.getUids(Sets.newHashSet(leA, leB, leC))));
assertTrue(items.isEmpty());
assertTrue(itemsFilter.isEmpty());
assertTrue(itemsOptionSet.isEmpty());
assertEquals(2, itemsOptionSetFilter.size());
assertTrue(itemsOptionSetFilter.containsAll(IdentifiableObjectUtils.getCodes(Sets.newHashSet(opA, opB))));
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class EventQueryPlannerTest method validateInvalidQueryItem.
@Test(expected = IllegalQueryException.class)
public void validateInvalidQueryItem() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withOrganisationUnits(Lists.newArrayList(ouB)).addItem(new QueryItem(deA, lsA, ValueType.TEXT, AggregationType.NONE, osA)).build();
queryPlanner.validate(params);
}
use of org.hisp.dhis.common.QueryItem in project dhis2-core by dhis2.
the class AbstractEventService method getQueryItem.
private QueryItem getQueryItem(String item) {
String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
if (split == null || split.length % 2 != 1) {
throw new IllegalQueryException("Query item or filter is invalid: " + item);
}
QueryItem queryItem = getItem(split[0]);
if (split.length > 1) {
for (int i = 1; i < split.length; i += 2) {
QueryOperator operator = QueryOperator.fromString(split[i]);
queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
}
}
return queryItem;
}
Aggregations