Package org.damour.base.client.objects

Examples of org.damour.base.client.objects.UserRating


      if (!SecurityHelper.doesUserHavePermission(session.get(), authUser, permissibleObject, PERM.READ)) {
        throw new SimpleMessageException("User is not authorized to set rating on this content.");
      }

      UserRating userRating = RatingHelper.getUserRating(session.get(), permissibleObject, authUser, getVoterGUID());
      // check if rating already exists
      if (userRating != null) {
        // TODO: consider changing the vote
        // simply subtract the previous amount and decrement the numRatingVotes and redivide
        throw new SimpleMessageException("Already voted.");
      }

      float totalRating = (float) permissibleObject.getNumRatingVotes() * permissibleObject.getAverageRating();
      totalRating += rating;
      permissibleObject.setNumRatingVotes(permissibleObject.getNumRatingVotes() + 1);
      float newAvg = totalRating / (float) permissibleObject.getNumRatingVotes();
      permissibleObject.setAverageRating(newAvg);
      session.get().save(permissibleObject);

      userRating = new UserRating();
      userRating.setPermissibleObject(permissibleObject);
      userRating.setRating(rating);
      userRating.setVoter(authUser);
      userRating.setVoterGUID(getVoterGUID());

      session.get().save(userRating);
      tx.commit();
      return userRating;
    } catch (Throwable t) {
View Full Code Here

TOP

Related Classes of org.damour.base.client.objects.UserRating

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.