use of org.hisp.dhis.datastatistics.FavoriteStatistics in project dhis2-core by dhis2.
the class HibernateDataStatisticsEventStore method getFavoriteStatistics.
@Override
public FavoriteStatistics getFavoriteStatistics(String uid) {
String sql = "select count(dse.favoriteuid) " + "from datastatisticsevent dse " + "where dse.favoriteuid = ?;";
Object[] args = Lists.newArrayList(uid).toArray();
Integer views = jdbcTemplate.queryForObject(sql, args, Integer.class);
FavoriteStatistics stats = new FavoriteStatistics();
stats.setViews(views);
return stats;
}
use of org.hisp.dhis.datastatistics.FavoriteStatistics 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 ";
if (username != null) {
sql += "where username = ? ";
}
sql += "group by uid) as events " + "inner join " + eventType.getTable() + " c on c.uid = events.uid " + "order by events.views " + 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;
});
}
Aggregations