//Generate the mapping of all likes done for the widgets
Query query = manager.createNamedQuery(JpaWidgetRating.WIDGET_ALL_TOTAL_LIKES);
for (Object[] result : (List<Object[]>) query.getResultList()) {
Long totalLikes = (Long) result[0];
Long widgetId = (Long) result[1];
WidgetStatistics widgetStatistics = new WidgetStatistics();
widgetStatistics.setTotalLike(totalLikes.intValue());
map.put(widgetId.toString(), widgetStatistics);
}
//Add the mapping of all dislikes done for the widgets
query = manager.createNamedQuery(JpaWidgetRating.WIDGET_ALL_TOTAL_DISLIKES);
for (Object[] result : (List<Object[]>) query.getResultList()) {
Long totalDislikes = (Long) result[0];
Long widgetId = (Long) result[1];
WidgetStatistics widgetStatistics = map.get(widgetId.toString());
if (widgetStatistics == null) {
widgetStatistics = new WidgetStatistics();
map.put(widgetId.toString(), widgetStatistics);
}
widgetStatistics.setTotalDislike(totalDislikes.intValue());
}
//get the total user count for widgets
query = manager.createNamedQuery(JpaRegionWidget.REGION_WIDGET_GET_DISTINCT_USER_COUNT_ALL_WIDGETS);
for (Object[] result : (List<Object[]>) query.getResultList()) {
Long widgetId = (Long) result[0];
Long totalUserCount = (Long) result[1];
WidgetStatistics widgetStatistics = map.get(widgetId.toString());
if (widgetStatistics == null) {
widgetStatistics = new WidgetStatistics();
map.put(widgetId.toString(), widgetStatistics);
}
widgetStatistics.setTotalUserCount(totalUserCount.intValue());
}
//Add the current user's current rating of the widget
Map<String, WidgetRating> userRatings = getUsersWidgetRatings(userId);
for (Map.Entry<String, WidgetStatistics> entry : map.entrySet()) {