Package org.apache.rave.portal.model.util

Examples of org.apache.rave.portal.model.util.WidgetStatistics


        Widget widget = repository.get("3");
        List<WidgetRating> ratings = widget.getRatings();
        assertNotNull(ratings);
        assertEquals(0, ratings.size());

        WidgetStatistics widgetStatistics = repository.getWidgetStatistics(widget.getId(), "1");
        assertNotNull(widgetStatistics);
        assertEquals(0, widgetStatistics.getTotalDislike());
        assertEquals(0, widgetStatistics.getTotalLike());
        assertEquals(JpaWidgetRating.UNSET.intValue(), widgetStatistics.getUserRating());
    }
View Full Code Here


        return getSingleResult(resultList);
    }

    @Override
    public WidgetStatistics getWidgetStatistics(long widget_id, long user_id) {
        WidgetStatistics widgetStatistics = new WidgetStatistics();

        Query query = manager.createNamedQuery(WidgetRating.WIDGET_TOTAL_LIKES);
        query.setParameter(WidgetRating.PARAM_WIDGET_ID, widget_id);
        widgetStatistics.setTotalLike(((Number) query.getSingleResult()).intValue());

        query = manager.createNamedQuery(WidgetRating.WIDGET_TOTAL_DISLIKES);
        query.setParameter(WidgetRating.PARAM_WIDGET_ID, widget_id);
        widgetStatistics.setTotalDislike(((Number) query.getSingleResult()).intValue());

        query = manager.createNamedQuery(RegionWidget.REGION_WIDGET_GET_DISTINCT_USER_COUNT_SINGLE_WIDGET);
        query.setParameter(RegionWidget.PARAM_WIDGET_ID, widget_id);
        widgetStatistics.setTotalUserCount(((Number) query.getSingleResult()).intValue());

        try {
            query = manager.createNamedQuery(WidgetRating.WIDGET_USER_RATING);
            query.setParameter(WidgetRating.PARAM_WIDGET_ID, widget_id);
            query.setParameter(WidgetRating.PARAM_USER_ID, user_id);
            widgetStatistics.setUserRating(((Number) query.getSingleResult()).intValue());
        } catch (NoResultException e) {
            widgetStatistics.setUserRating(WidgetRating.UNSET);
        }

        return widgetStatistics;
    }
View Full Code Here

        //Generate the mapping of all likes done for the widgets
        Query query = manager.createNamedQuery(WidgetRating.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, widgetStatistics);
        }

        //Add the mapping of all dislikes done for the widgets
        query = manager.createNamedQuery(WidgetRating.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);
            if (widgetStatistics == null) {
                widgetStatistics = new WidgetStatistics();
                map.put(widgetId, widgetStatistics);
            }
            widgetStatistics.setTotalDislike(totalDislikes.intValue());
        }

        //get the total user count for widgets
        query = manager.createNamedQuery(RegionWidget.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);
            if (widgetStatistics == null) {
                widgetStatistics = new WidgetStatistics();
                map.put(widgetId, widgetStatistics);
            }
            widgetStatistics.setTotalUserCount(totalUserCount.intValue());
        }

        //Add the current user's current rating of the widget
        Map<Long, WidgetRating> userRatings = getUsersWidgetRatings(userId);
        for (Map.Entry<Long, WidgetStatistics> entry : map.entrySet()) {
View Full Code Here

    @Test
    public void getAllWidgetStatistics() {
        Map<Long, WidgetStatistics> widgetStatistics = repository.getAllWidgetStatistics(1L);

        WidgetStatistics gadgetOne = widgetStatistics.get(1L);
        assertEquals(0, gadgetOne.getTotalLike());
        assertEquals(1, gadgetOne.getTotalDislike());
        assertEquals(0, gadgetOne.getUserRating());
        assertEquals(10, gadgetOne.getTotalUserCount());

        WidgetStatistics gadgetTwo = widgetStatistics.get(2L);
        assertEquals(1, gadgetTwo.getTotalLike());
        assertEquals(0, gadgetTwo.getTotalDislike());
        assertEquals(10, gadgetTwo.getUserRating());
        assertEquals(10, gadgetOne.getTotalUserCount());
    }
View Full Code Here

        Widget widget = repository.get(1L);
        List<WidgetRating> ratings = widget.getRatings();
        assertNotNull(ratings);
        assertEquals(1, ratings.size());

        WidgetStatistics widgetStatistics = repository.getWidgetStatistics(widget.getEntityId(), 1L);
        widgetStatistics.toString();
        assertNotNull(widgetStatistics);
        assertEquals(0, widgetStatistics.getTotalLike());
        assertEquals(1, widgetStatistics.getTotalDislike());
        assertEquals(10, widgetStatistics.getTotalUserCount());
        assertEquals(WidgetRating.DISLIKE.intValue(), widgetStatistics.getUserRating());
    }
View Full Code Here

        Widget widget = repository.get(2L);
        List<WidgetRating> ratings = widget.getRatings();
        assertNotNull(ratings);
        assertEquals(1, ratings.size());

        WidgetStatistics widgetStatistics = repository.getWidgetStatistics(widget.getEntityId(), 1L);
        assertNotNull(widgetStatistics);
        assertEquals(1, widgetStatistics.getTotalLike());
        assertEquals(0, widgetStatistics.getTotalDislike());
        assertEquals(10, widgetStatistics.getTotalUserCount());
        assertEquals(WidgetRating.LIKE.intValue(), widgetStatistics.getUserRating());
    }
View Full Code Here

        Widget widget = repository.get(3L);
        List<WidgetRating> ratings = widget.getRatings();
        assertNotNull(ratings);
        assertEquals(0, ratings.size());

        WidgetStatistics widgetStatistics = repository.getWidgetStatistics(widget.getEntityId(), 1L);
        assertNotNull(widgetStatistics);
        assertEquals(0, widgetStatistics.getTotalDislike());
        assertEquals(0, widgetStatistics.getTotalLike());
        assertEquals(WidgetRating.UNSET.intValue(), widgetStatistics.getUserRating());
    }
View Full Code Here

        assertTrue("Save called", true);
    }

    @Test
    public void widgetStatistics() {
        expect(widgetRepository.getWidgetStatistics(1L, 1L)).andReturn(new WidgetStatistics());
        replay(widgetRepository);

        widgetService.getWidgetStatistics(1L, 1L);
        verify(widgetRepository);
    }
View Full Code Here

        return getSingleResult(resultList);
    }

    @Override
    public WidgetStatistics getWidgetStatistics(long widget_id, long user_id) {
        WidgetStatistics widgetStatistics = new WidgetStatistics();

        Query query = manager.createNamedQuery(WidgetRating.WIDGET_TOTAL_LIKES);
        query.setParameter(WidgetRating.PARAM_WIDGET_ID, widget_id);
        widgetStatistics.setTotalLike(((Number) query.getSingleResult()).intValue());

        query = manager.createNamedQuery(WidgetRating.WIDGET_TOTAL_DISLIKES);
        query.setParameter(WidgetRating.PARAM_WIDGET_ID, widget_id);
        widgetStatistics.setTotalDislike(((Number) query.getSingleResult()).intValue());

        query = manager.createNamedQuery(RegionWidget.REGION_WIDGET_GET_DISTINCT_USER_COUNT_SINGLE_WIDGET);
        query.setParameter(RegionWidget.PARAM_WIDGET_ID, widget_id);
        widgetStatistics.setTotalUserCount(((Number) query.getSingleResult()).intValue());

        try {
            query = manager.createNamedQuery(WidgetRating.WIDGET_USER_RATING);
            query.setParameter(WidgetRating.PARAM_WIDGET_ID, widget_id);
            query.setParameter(WidgetRating.PARAM_USER_ID, user_id);
            widgetStatistics.setUserRating(((Number) query.getSingleResult()).intValue());
        } catch (NoResultException e) {
            widgetStatistics.setUserRating(WidgetRating.UNSET);
        }

        return widgetStatistics;
    }
View Full Code Here

        //Generate the mapping of all likes done for the widgets
        Query query = manager.createNamedQuery(WidgetRating.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, widgetStatistics);
        }

        //Add the mapping of all dislikes done for the widgets
        query = manager.createNamedQuery(WidgetRating.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);
            if (widgetStatistics == null) {
                widgetStatistics = new WidgetStatistics();
                map.put(widgetId, widgetStatistics);
            }
            widgetStatistics.setTotalDislike(totalDislikes.intValue());
        }

        //get the total user count for widgets
        query = manager.createNamedQuery(RegionWidget.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);
            if (widgetStatistics == null) {
                widgetStatistics = new WidgetStatistics();
                map.put(widgetId, widgetStatistics);
            }
            widgetStatistics.setTotalUserCount(totalUserCount.intValue());
        }

        //Add the current user's current rating of the widget
        Map<Long, WidgetRating> userRatings = getUsersWidgetRatings(userId);
        for (Map.Entry<Long, WidgetStatistics> entry : map.entrySet()) {
View Full Code Here

TOP

Related Classes of org.apache.rave.portal.model.util.WidgetStatistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.