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

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


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

    @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

        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

    public WidgetStatistics getWidgetStatistics(String widget_id, String user_id) {
        WidgetUsersMapReduceResult userResult = mongoOperations.findById(widget_id, WidgetUsersMapReduceResult.class, WIDGET_USERS);
        WidgetRatingsMapReduceResult ratingResult = mongoOperations.findById(widget_id, WidgetRatingsMapReduceResult.class, WIDGET_RATINGS);

        int userCount = userResult == null ? 0 : userResult.getValue().size();
        WidgetStatistics stats;
        if(ratingResult == null) {
            stats = new WidgetStatistics();
            stats.setUserRating(-1);
        } else {
            stats = createWidgetStatisticsFromResults(user_id, ratingResult);
        }
        stats.setTotalUserCount(userCount);
        return stats;
    }
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.