Search in sources :

Example 1 with SortOrder

use of org.hisp.dhis.analytics.SortOrder in project dhis2-core by dhis2.

the class HibernateDataStatisticsEventStore method getFavoritesData.

@Override
public List<FavoriteStatistics> getFavoritesData(DataStatisticsEventType eventType, int pageSize, SortOrder sortOrder, String username) {
    Assert.notNull(eventType, "Data statistics event type cannot be null");
    Assert.notNull(sortOrder, "Sort order cannot be null");
    String sql = "select c.uid, views, c.name, c.created from ( " + "select favoriteuid as uid, count(favoriteuid) as views " + "from datastatisticsevent where eventtype = '" + eventType.name() + "' ";
    if (username != null) {
        sql += "and username = ? ";
    }
    sql += "group by uid) as events " + "inner join " + escapeSql(eventType.getTable()) + " c on c.uid = events.uid " + "order by events.views " + escapeSql(sortOrder.getValue()) + " " + "limit ?;";
    PreparedStatementSetter pss = (ps) -> {
        int i = 1;
        if (username != null) {
            ps.setString(i++, username);
        }
        ps.setInt(i++, pageSize);
    };
    return jdbcTemplate.query(sql, pss, (rs, i) -> {
        FavoriteStatistics stats = new FavoriteStatistics();
        stats.setPosition(i + 1);
        stats.setId(rs.getString("uid"));
        stats.setName(rs.getString("name"));
        stats.setCreated(rs.getDate("created"));
        stats.setViews(rs.getInt("views"));
        return stats;
    });
}
Also used : SortOrder(org.hisp.dhis.analytics.SortOrder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) DataStatisticsEventStore(org.hisp.dhis.datastatistics.DataStatisticsEventStore) Date(java.util.Date) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SessionFactory(org.hibernate.SessionFactory) HashMap(java.util.HashMap) DataStatisticsEventType(org.hisp.dhis.datastatistics.DataStatisticsEventType) COUNT_PASSIVE_DASHBOARD_VIEWS_IN_USAGE_ANALYTICS(org.hisp.dhis.setting.SettingKey.COUNT_PASSIVE_DASHBOARD_VIEWS_IN_USAGE_ANALYTICS) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) List(java.util.List) Lists(com.google.common.collect.Lists) DateUtils.asSqlDate(org.hisp.dhis.util.DateUtils.asSqlDate) Map(java.util.Map) SqlUtils.escapeSql(org.hisp.dhis.system.util.SqlUtils.escapeSql) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Repository(org.springframework.stereotype.Repository) FavoriteStatistics(org.hisp.dhis.datastatistics.FavoriteStatistics) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) DataStatisticsEvent(org.hisp.dhis.datastatistics.DataStatisticsEvent) Assert(org.springframework.util.Assert) FavoriteStatistics(org.hisp.dhis.datastatistics.FavoriteStatistics) PreparedStatementSetter(org.springframework.jdbc.core.PreparedStatementSetter)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SessionFactory (org.hibernate.SessionFactory)1 SortOrder (org.hisp.dhis.analytics.SortOrder)1 DataStatisticsEvent (org.hisp.dhis.datastatistics.DataStatisticsEvent)1 DataStatisticsEventStore (org.hisp.dhis.datastatistics.DataStatisticsEventStore)1 DataStatisticsEventType (org.hisp.dhis.datastatistics.DataStatisticsEventType)1 FavoriteStatistics (org.hisp.dhis.datastatistics.FavoriteStatistics)1 HibernateGenericStore (org.hisp.dhis.hibernate.HibernateGenericStore)1 COUNT_PASSIVE_DASHBOARD_VIEWS_IN_USAGE_ANALYTICS (org.hisp.dhis.setting.SettingKey.COUNT_PASSIVE_DASHBOARD_VIEWS_IN_USAGE_ANALYTICS)1 SystemSettingManager (org.hisp.dhis.setting.SystemSettingManager)1 SqlUtils.escapeSql (org.hisp.dhis.system.util.SqlUtils.escapeSql)1 DateUtils.asSqlDate (org.hisp.dhis.util.DateUtils.asSqlDate)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)1