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

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


    @Before
    public void setup() {
        validUser = new UserImpl();
        validUser.setId("1");
        widgetStatistics = new WidgetStatistics();

        allWidgetStatisticsMap = new HashMap<String, WidgetStatistics>();
        allWidgetStatisticsMap.put(WIDGET_ID, widgetStatistics);

        widgetService = createMock(WidgetService.class);
View Full Code Here


        assertTrue("Save called", true);
    }

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

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

    @Test
    public void getWidgetStatistics(){
        String widget_id = "1111L";
        String user_id = "2222L";

        WidgetStatistics ws = new WidgetStatistics();

        expect(statsAggregator.getWidgetStatistics(widget_id, user_id)).andReturn(ws);
        replay(statsAggregator);

        ws = repo.getWidgetStatistics(widget_id, user_id);
View Full Code Here

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

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

        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

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

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

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

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

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

        return getSingleResult(resultList);
    }

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

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

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

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

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

        return widgetStatistics;
    }
View Full Code Here

        //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()) {
View Full Code Here

        return getSingleResult(resultList);
    }

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

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

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

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

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

        return widgetStatistics;
    }
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.