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) {