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

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


        expect(mongoOperations.findById(widget_id, WidgetRatingsMapReduceResult.class, WIDGET_RATINGS)).andReturn(null);
        expect(mongoOperations.findById(widget_id, WidgetUsersMapReduceResult.class, WIDGET_USERS)).andReturn(usersResult);
        replay(mongoOperations);

        WidgetStatistics result = aggregator.getWidgetStatistics(widget_id, "21L");

        assertThat(result.getTotalDislike(), is(equalTo(0)));
        assertThat(result.getTotalLike(), is(equalTo(0)));
        assertThat(result.getUserRating(), is(equalTo(-1)));
        assertThat(result.getTotalUserCount(), is(equalTo(2)));
    }
View Full Code Here


        expect(mongoOperations.findById(widget_id, WidgetRatingsMapReduceResult.class, WIDGET_RATINGS)).andReturn(ratingsResult);
        expect(mongoOperations.findById(widget_id, WidgetUsersMapReduceResult.class, WIDGET_USERS)).andReturn(null);
        replay(mongoOperations);

        WidgetStatistics result = aggregator.getWidgetStatistics(widget_id, "21L");

        assertThat(result.getTotalDislike(), is(equalTo(0)));
        assertThat(result.getTotalLike(), is(equalTo(20)));
        assertThat(result.getUserRating(), is(equalTo(10)));
        assertThat(result.getTotalUserCount(), is(equalTo(0)));
    }
View Full Code Here

    @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

        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

    @Before
    public void setup() {
        validUser = new User();
        validUser.setEntityId(1L);
        widgetStatistics = new WidgetStatistics();

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

        widgetService = createMock(WidgetService.class);
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());

        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());
        }

        //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

        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

    @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());
       
        WidgetStatistics gadgetTwo = widgetStatistics.get(2L);
        assertEquals(1, gadgetTwo.getTotalLike());
        assertEquals(0, gadgetTwo.getTotalDislike());
        assertEquals(10, gadgetTwo.getUserRating());
    }
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.