Package org.apache.rave.portal.model

Examples of org.apache.rave.portal.model.WidgetRating


    public void setWidgetRating(@PathVariable long widgetId,
                                    @RequestParam(value = "score") Integer score,
                                    HttpServletResponse response) {
        logger.debug("POST WidgetRating received for /api/rest/widgets/{} score: {}", widgetId, score);

        WidgetRating widgetRating = new WidgetRating();
        widgetRating.setScore(score);
        widgetRating.setUserId(userService.getAuthenticatedUser().getEntityId());
        widgetRating.setWidgetId(widgetId);
        widgetRatingService.saveWidgetRating(widgetRating);
       
        // send a 204 back for success since there is no content being returned
        response.setStatus(HttpStatus.NO_CONTENT.value());
    }
View Full Code Here


   
    @Test
    public void getUserWidgetRatings() {
        Map<Long, WidgetRating> widgetRatings = repository.getUsersWidgetRatings(1L);
       
        WidgetRating gadgetOne = widgetRatings.get(1L);
        assertEquals(WidgetRating.DISLIKE, gadgetOne.getScore());
        assertEquals(new Long(1), gadgetOne.getUserId());
        assertEquals(new Long(1), gadgetOne.getEntityId());
       
        WidgetRating gadgetTwo = widgetRatings.get(2L);
        assertEquals(WidgetRating.LIKE, gadgetTwo.getScore());
        assertEquals(new Long(1), gadgetTwo.getUserId());
        assertEquals(new Long(2), gadgetTwo.getEntityId());
    }
View Full Code Here

   
    @Test
    public void addWidgetRating() {
        Widget widget = repository.get(3L);
        assertNotNull(widget.getRatings());
        WidgetRating widgetRating = new WidgetRating();
        widgetRating.setScore(10);
        widgetRating.setUserId(1L);
        widgetRating.setWidgetId(widget.getEntityId());
        widget.getRatings().add(widgetRating);
       
        repository.save(widget);
       
        Widget reloadedWidget = repository.get(3L);
        List<WidgetRating> widgetRatings = reloadedWidget.getRatings();
        assertNotNull(widgetRatings);
        assertEquals(1, widgetRatings.size());
        WidgetRating reloadedWidgetRating = widgetRatings.get(0);
        assertNotNull(reloadedWidgetRating);
        assertEquals(widgetRating.getScore(), reloadedWidgetRating.getScore());
        assertEquals(widgetRating.getUserId(), reloadedWidgetRating.getUserId());
        assertEquals(widget.getEntityId(), reloadedWidgetRating.getWidgetId());
    }
View Full Code Here

    }
   
    @Test public void updateWidgetRating() {
        Widget widget = repository.get(4L);
        assertNotNull(widget.getRatings());
        WidgetRating widgetRating = new WidgetRating();
        widgetRating.setScore(10);
        widgetRating.setUserId(1L);
        widgetRating.setWidgetId(widget.getEntityId());
        widget.getRatings().add(widgetRating);
       
        repository.save(widget);
       
        Widget reloadedWidget = repository.get(4L);
        List<WidgetRating> widgetRatings = reloadedWidget.getRatings();
        assertNotNull(widgetRatings);
        assertEquals(1, widgetRatings.size());
        WidgetRating reloadedWidgetRating = widgetRatings.get(0);
        assertNotNull(reloadedWidgetRating);
        assertEquals(widgetRating.getScore(), reloadedWidgetRating.getScore());
        assertEquals(widgetRating.getUserId(), reloadedWidgetRating.getUserId());
        assertEquals(widget.getEntityId(), reloadedWidgetRating.getWidgetId());
       
        reloadedWidgetRating.setScore(0);
       
        repository.save(reloadedWidget);
        reloadedWidget = repository.get(4L);
        widgetRatings = reloadedWidget.getRatings();
        assertNotNull(widgetRatings);
        assertEquals(1, widgetRatings.size());
        reloadedWidgetRating = widgetRatings.get(0);
        assertNotNull(reloadedWidgetRating);
        assertEquals(widgetRating.getScore(), reloadedWidgetRating.getScore());
        assertEquals(widgetRating.getUserId(), reloadedWidgetRating.getUserId());
        assertEquals(widget.getEntityId(), reloadedWidgetRating.getWidgetId());
    }
View Full Code Here

    }

    // returns a trusted WidgetRating object, either from the WidgetRatingRepository, or the
    // cached container list
    private WidgetRating getTrustedWidgetRating(long widgetRatingId, List<WidgetRating> trustedWidgetRatingContainer) {
        WidgetRating widgetRating = null;
        if (trustedWidgetRatingContainer.isEmpty()) {
            widgetRating = widgetRatingRepository.get(widgetRatingId);
            trustedWidgetRatingContainer.add(widgetRating);
        } else {
            widgetRating = trustedWidgetRatingContainer.get(0);
View Full Code Here

    // checks to see if the Authentication object principal is the owner of the supplied widgetRating object
    // if trustedDomainObject is false, pull the entity from the database first to ensure
    // the model object is trusted and hasn't been modified
    private boolean isWidgetRatingOwner(Authentication authentication, WidgetRating widgetRating, List<WidgetRating> trustedWidgetRatingContainer, boolean trustedDomainObject) {
        WidgetRating trustedWidgetRating = null;
        if (trustedDomainObject) {
            trustedWidgetRating = widgetRating;
        } else {
            trustedWidgetRating = getTrustedWidgetRating(widgetRating.getId(), trustedWidgetRatingContainer);
        }
        return isWidgetRatingOwnerById(authentication, trustedWidgetRating.getUserId());
    }
View Full Code Here

    @Test
    @Transactional(readOnly=false)
    @Rollback(true)
    public void delete() {
        WidgetRating wr = repository.get(VALID_WIDGET_RATING_ID);
        assertThat(wr, is(notNullValue()));
        repository.delete(wr);
        wr = repository.get(VALID_WIDGET_RATING_ID);
        assertThat(wr, is(nullValue()));
    }
View Full Code Here

    @Transactional(readOnly=false)
    @Rollback(true)
    public void save_new() {
        final int EXPECTED_SCORE = 1;

        WidgetRating wr = new JpaWidgetRating();
        wr.setScore(EXPECTED_SCORE);
        wr.setUserId(VALID_USER_ID);
        wr.setWidgetId(VALID_WIDGET_ID);
        assertThat(wr.getId(), is(nullValue()));
        repository.save(wr);
        long newId = wr.getId();
        assertThat(newId > 0, is(true));
        WidgetRating newRating = repository.get(newId);
        assertThat(newRating.getScore(), is(EXPECTED_SCORE));
        assertThat(newRating.getUserId(), is(VALID_USER_ID));
        assertThat(newRating.getWidgetId(), is(VALID_WIDGET_ID));
    }
View Full Code Here

    @Test
    @Transactional(readOnly=false)
    @Rollback(true)
    public void save_existing() {
        int EXPECTED_SCORE = 99;
        WidgetRating wr = repository.get(VALID_WIDGET_RATING_ID);
        assertThat(wr.getScore(), is(not(EXPECTED_SCORE)));
        wr.setScore(99);
        repository.save(wr);
        WidgetRating updatedRating = repository.get(VALID_WIDGET_RATING_ID);
        assertThat(updatedRating.getScore(), is(EXPECTED_SCORE));
    }
View Full Code Here

        assertThat(converter.convert(template), is(sameInstance(template)));
    }

    @Test
    public void nullConversion() {
        WidgetRating template = null;
        assertThat(converter.convert(template), is(nullValue()));
    }
View Full Code Here

TOP

Related Classes of org.apache.rave.portal.model.WidgetRating

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.