use of org.xwiki.ratings.UpdateRatingEvent in project xwiki-platform by xwiki.
the class DefaultRatingsManager method setRating.
@Override
public Rating setRating(DocumentReference documentRef, DocumentReference author, int vote) throws RatingsException {
Rating rating = getRating(documentRef, author);
int oldVote;
if (rating == null) {
oldVote = 0;
try {
rating = new DefaultRating(documentRef, author, vote, getXWikiContext(), this);
} catch (XWikiException e) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, e.getCode(), "Failed to create new rating object", e);
}
} else {
oldVote = rating.getVote();
rating.setVote(vote);
rating.setDate(new Date());
}
// Indicate that we start modifying the rating
this.observationManager.notify(new UpdatingRatingEvent(documentRef, rating, oldVote), null);
boolean updateFailed = true;
try {
// update rating
rating.save();
// update average rating count
updateAverageRatings(documentRef, rating, oldVote);
updateFailed = false;
} finally {
if (updateFailed) {
// Indicate that the we start modifying the rating
this.observationManager.notify(new UpdatingRatingEvent(documentRef, rating, oldVote), null);
} else {
// Indicate that we finished updating the rating
this.observationManager.notify(new UpdateRatingEvent(documentRef, rating, oldVote), null);
}
}
return rating;
}
use of org.xwiki.ratings.UpdateRatingEvent in project xwiki-platform by xwiki.
the class SeparatePageRatingsManager method setRating.
@Override
public Rating setRating(DocumentReference documentRef, DocumentReference author, int vote) throws RatingsException {
Rating rating = getRating(documentRef, author);
int oldVote;
if (rating == null) {
oldVote = 0;
rating = new SeparatePageRating(documentRef, author, vote, getXWikiContext(), this);
} else {
oldVote = rating.getVote();
rating.setVote(vote);
rating.setDate(new Date());
}
// Indicate that we start modifying the rating
this.observationManager.notify(new UpdatingRatingEvent(documentRef, rating, oldVote), null);
boolean updateFailed = true;
try {
// saving rating
rating.save();
// update the average rating
updateAverageRatings(documentRef, rating, oldVote);
updateFailed = false;
} finally {
if (updateFailed) {
// Indicate that the we start modifying the rating
this.observationManager.notify(new UpdatingRatingEvent(documentRef, rating, oldVote), null);
} else {
// Indicate that we finished updating the rating
this.observationManager.notify(new UpdateRatingEvent(documentRef, rating, oldVote), null);
}
}
return rating;
}
use of org.xwiki.ratings.UpdateRatingEvent in project xwiki-platform by xwiki.
the class UpdateReputationListener method onEvent.
@Override
public void onEvent(Event event, Object arg1, Object arg2) {
UpdateRatingEvent ratingEvent = (UpdateRatingEvent) event;
DocumentReference documentRef = ratingEvent.getDocumentReference();
reputationAlgorithm.get(documentRef).updateReputation(documentRef, ratingEvent.getNewRating(), ratingEvent.getOldRating());
}
Aggregations