Search in sources :

Example 1 with TimeField

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();
}
Also used : DATE_PERIOD_STRUCT_ALIAS(org.hisp.dhis.analytics.util.AnalyticsSqlUtils.DATE_PERIOD_STRUCT_ALIAS) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Getter(lombok.Getter) TimeField(org.hisp.dhis.analytics.TimeField) AnalyticsSqlUtils.quote(org.hisp.dhis.analytics.util.AnalyticsSqlUtils.quote) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Collections.singleton(java.util.Collections.singleton) EVENT_DATE(org.hisp.dhis.analytics.TimeField.EVENT_DATE) ANALYTICS_TBL_ALIAS(org.hisp.dhis.analytics.util.AnalyticsSqlUtils.ANALYTICS_TBL_ALIAS) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) Period(org.hisp.dhis.period.Period) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) PERIOD_DIM_ID(org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID) Collection(java.util.Collection) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) OPEN_IN(org.hisp.dhis.analytics.event.data.JdbcEventAnalyticsManager.OPEN_IN) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) IdentifiableObjectUtils.getUids(org.hisp.dhis.common.IdentifiableObjectUtils.getUids) ENROLLMENT(org.hisp.dhis.analytics.EventOutputType.ENROLLMENT) AnalyticsSqlUtils.quoteAlias(org.hisp.dhis.analytics.util.AnalyticsSqlUtils.quoteAlias) Optional(java.util.Optional) DateUtils.plusOneDay(org.hisp.dhis.util.DateUtils.plusOneDay) EventOutputType(org.hisp.dhis.analytics.EventOutputType) TimeField(org.hisp.dhis.analytics.TimeField) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Period(org.hisp.dhis.period.Period) TextUtils.getQuotedCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString)

Aggregations

Collection (java.util.Collection)1 Collections.singleton (java.util.Collections.singleton)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Getter (lombok.Getter)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 EventOutputType (org.hisp.dhis.analytics.EventOutputType)1 ENROLLMENT (org.hisp.dhis.analytics.EventOutputType.ENROLLMENT)1 TimeField (org.hisp.dhis.analytics.TimeField)1 EVENT_DATE (org.hisp.dhis.analytics.TimeField.EVENT_DATE)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 OPEN_IN (org.hisp.dhis.analytics.event.data.JdbcEventAnalyticsManager.OPEN_IN)1 ANALYTICS_TBL_ALIAS (org.hisp.dhis.analytics.util.AnalyticsSqlUtils.ANALYTICS_TBL_ALIAS)1 DATE_PERIOD_STRUCT_ALIAS (org.hisp.dhis.analytics.util.AnalyticsSqlUtils.DATE_PERIOD_STRUCT_ALIAS)1 AnalyticsSqlUtils.quote (org.hisp.dhis.analytics.util.AnalyticsSqlUtils.quote)1 AnalyticsSqlUtils.quoteAlias (org.hisp.dhis.analytics.util.AnalyticsSqlUtils.quoteAlias)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 PERIOD_DIM_ID (org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID)1 IdentifiableObjectUtils.getUids (org.hisp.dhis.common.IdentifiableObjectUtils.getUids)1