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

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


        return mongoOperations.mapReduce(WIDGET_COLLECTION, RATINGS_MAP, RATINGS_REDUCE, getOptions(WIDGET_RATINGS), WidgetRatingsMapReduceResult.class);
    }

    private void addUserCount(Map<String, Integer> users, Map<String, WidgetStatistics> stats) {
        for (Map.Entry<String, Integer> result : users.entrySet()) {
            WidgetStatistics widgetStatistics = getTotalUserOnlyWidgetStatistics(result.getValue());
            stats.put(result.getKey(), widgetStatistics);
        }
    }
View Full Code Here


        for(Map.Entry<String, Integer> id : usersMap.entrySet()) {
            Integer value = id.getValue();
            if(stats.containsKey(id.getKey())) {
                stats.get(id.getKey()).setTotalUserCount(value);
            } else {
                WidgetStatistics stat = getTotalUserOnlyWidgetStatistics(value);
                stats.put(id.getKey(), stat);
            }
        }
    }
View Full Code Here

            }
        }
    }

    private WidgetStatistics getTotalUserOnlyWidgetStatistics(Integer value) {
        WidgetStatistics stat = new WidgetStatistics();
        stat.setTotalUserCount(value);
        stat.setUserRating(-1);
        return stat;
    }
View Full Code Here

        stat.setUserRating(-1);
        return stat;
    }

    private WidgetStatistics createWidgetStatisticsFromResults(String user_id, WidgetRatingsMapReduceResult statsResult) {
        WidgetStatistics statistics = new WidgetStatistics();
        WidgetRatingsMapReduceResult.WidgetStatisticsMapReduceResult result = statsResult.getValue();
        if (result != null) {
            statistics.setTotalDislike(result.getDislike().intValue());
            statistics.setTotalLike(result.getLike().intValue());
            statistics.setUserRating(result.getUserRatings().containsKey(user_id) ? result.getUserRatings().get(user_id).intValue() : -1);
        } else {
            statistics.setUserRating(-1);
        }
        return statistics;
    }
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

        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

        expect(mongoOperations.findById(widget_id, WidgetRatingsMapReduceResult.class, WIDGET_RATINGS)).andReturn(ratingsResult);
        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(20)));
        assertThat(result.getUserRating(), is(equalTo(10)));
        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(usersResult);
        replay(mongoOperations);

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

        assertThat(result.getTotalDislike(), is(equalTo(0)));
        assertThat(result.getTotalLike(), is(equalTo(20)));
        assertThat(result.getUserRating(), is(equalTo(-1)));
        assertThat(result.getTotalUserCount(), is(equalTo(2)));
    }
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.