use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByMinMaxDate.
/**
* Groups queries by their minDate/MaxDate query modifiers.
*
* @param params the {@link DataQueryParams}.
* @return a list of {@link DataQueryParams}.
*/
private List<DataQueryParams> groupByMinMaxDate(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (!params.getDataElements().isEmpty()) {
ListMap<QueryModifiers, DimensionalItemObject> minMaxDateDateElementMap = QueryPlannerUtils.getMinMaxDateDateElementMap(params.getDataElements());
for (QueryModifiers queryMods : minMaxDateDateElementMap.keySet()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(minMaxDateDateElementMap.get(queryMods)).withStartDate(getLatest(params.getStartDate(), queryMods.getMinDate())).withEndDate(getEarliest(params.getEndDate(), queryMods.getMaxDate())).build();
queries.add(query);
}
} else {
queries.add(params);
}
logQuerySplit(queries, "minDate/maxDate query modifiers");
return queries;
}
use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.
the class QueryPlannerTest method assertQueryMods.
private void assertQueryMods(List<DataQueryParams> group, QueryModifiers mods, DataElement... elements) {
List<DataElement> modElements = Arrays.asList(elements);
for (DataQueryParams params : group) {
List<DimensionalItemObject> groupElements = params.getDataElements();
assertNotEquals(0, groupElements.size());
QueryModifiers groupMods = groupElements.get(0).getQueryMods();
if (Objects.equals(mods, groupMods)) {
assertTrue(Objects.equals(params.getStartDate(), mods == null ? null : mods.getMinDate()));
assertTrue(Objects.equals(params.getEndDate(), mods == null ? null : mods.getMaxDate()));
assertEquals(modElements.size(), groupElements.size());
assertTrue(groupElements.containsAll(modElements));
groupElements.forEach(e -> {
assertEquals(mods, e.getQueryMods());
});
return;
}
}
throw new RuntimeException("No group found for queryMods " + mods);
}
use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.
the class FunctionMaxDate method evaluate.
@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
Date maxDate = parseExpressionDate(ctx.maxDate.getText());
QueryModifiers queryMods = visitor.getState().getQueryModsBuilder().maxDate(maxDate).build();
return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.
the class PeriodOffset method evaluate.
@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
ExpressionState state = visitor.getState();
int existingPeriodOffset = (state.getQueryMods() == null) ? 0 : state.getQueryMods().getPeriodOffset();
int parsedPeriodOffset = (ctx.period == null) ? 0 : firstNonNull(parseInt(ctx.period.getText()), 0);
int periodOffset = existingPeriodOffset + parsedPeriodOffset;
QueryModifiers queryMods = state.getQueryModsBuilder().periodOffset(periodOffset).build();
return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
use of org.hisp.dhis.common.QueryModifiers in project dhis2-core by dhis2.
the class FunctionMinDate method evaluate.
@Override
public Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
Date minDate = parseExpressionDate(ctx.minDate.getText());
QueryModifiers queryMods = visitor.getState().getQueryModsBuilder().minDate(minDate).build();
return visitor.visitWithQueryMods(ctx.expr(0), queryMods);
}
Aggregations