use of org.hisp.dhis.analytics.TimeField in project dhis2-core by dhis2.
the class EventTimeFieldSqlRenderer method getSqlConditionForPeriods.
@Override
protected String getSqlConditionForPeriods(EventQueryParams params) {
final List<DimensionalItemObject> periods = params.getDimensionOrFilterItems(PERIOD_DIM_ID);
Optional<TimeField> timeField = getTimeField(params);
StringBuilder sql = new StringBuilder();
if (timeField.isPresent()) {
sql.append(periods.stream().filter(dimensionalItemObject -> dimensionalItemObject instanceof Period).map(dimensionalItemObject -> (Period) dimensionalItemObject).map(period -> toSqlCondition(period, timeField.get())).collect(Collectors.joining(" or ", "(", ")")));
} else {
String alias = getPeriodAlias(params);
sql.append(quote(alias, params.getPeriodType().toLowerCase())).append(OPEN_IN).append(getQuotedCommaDelimitedString(getUids(periods))).append(") ");
}
return sql.toString();
}
Aggregations