use of org.xwiki.ratings.ReputationException in project xwiki-platform by xwiki.
the class SimpleReputationAlgorithm method getUserReputation.
/**
* Gets or calculates the user reputation.
*
* @param documentRef the document which the ratings are for
* @param username Person to calculate the reputation for
* @return AverageRating of the voter
*/
public AverageRating getUserReputation(DocumentReference documentRef, DocumentReference username) throws ReputationException {
try {
AverageRating aveRating = getRatingsManager(documentRef).getAverageRating(username, RatingsManager.RATING_REPUTATION_METHOD_AVERAGE);
float oldRep = aveRating.getAverageVote();
aveRating.setAverageVote(aveRating.getAverageVote() * 100 / getTotalReputation());
totalReputation += aveRating.getAverageVote() - oldRep;
return aveRating;
} catch (RatingsException e) {
throw new ReputationException(e);
}
}
use of org.xwiki.ratings.ReputationException in project xwiki-platform by xwiki.
the class DefaultReputationAlgorithm method updateReputation.
@Override
public void updateReputation(DocumentReference documentRef, Rating rating, int oldVote) {
// we only update if we are in stored mode and if the vote changed
if (oldVote != rating.getVote()) {
// voter reputation. This will give points to the voter
try {
AverageRating voterRating = calcNewVoterReputation(rating.getAuthor(), documentRef, rating, oldVote);
// we need to save this reputation if it has changed
try {
getRatingsManager(documentRef).updateUserReputation(rating.getAuthor(), voterRating);
} catch (RatingsException re) {
if (logger.isErrorEnabled()) {
logger.error("Error while storing reputation for user " + rating.getAuthor(), re);
}
}
} catch (ReputationException e) {
if (e.getCode() != ReputationException.ERROR_REPUTATION_NOT_IMPLEMENTED) {
// we should log this error
if (logger.isErrorEnabled()) {
logger.error("Error while calculating voter reputation " + rating.getAuthor() + " for document " + documentRef, e);
}
}
}
// author reputation. This will be giving points to the creator of a document or comment
try {
XWikiDocument doc = getXWiki().getDocument(documentRef, getXWikiContext());
AverageRating authorRating = calcNewContributorReputation(doc.getCreatorReference(), documentRef, rating, oldVote);
// we need to save the author reputation
try {
getRatingsManager(documentRef).updateUserReputation(doc.getCreatorReference(), authorRating);
} catch (RatingsException re) {
if (logger.isErrorEnabled()) {
logger.error("Error while storing reputation for user " + doc.getCreatorReference().getName(), re);
}
}
} catch (ReputationException e) {
if (e.getCode() != ReputationException.ERROR_REPUTATION_NOT_IMPLEMENTED) {
// we should log this error
if (logger.isErrorEnabled()) {
logger.error("Error while calculating author reputation for document " + documentRef, e);
}
}
} catch (XWikiException e) {
if (logger.isErrorEnabled()) {
logger.error("Error while calculating author reputation for document " + documentRef, e);
}
}
// all authors reputation. This will be used to give points to all participants to a document
try {
Map<String, AverageRating> authorsRatings = calcNewAuthorsReputation(documentRef, rating, oldVote);
// TODO this is not implemented yet
} catch (ReputationException e) {
if (e.getCode() != ReputationException.ERROR_REPUTATION_NOT_IMPLEMENTED) {
// we should log this error
if (logger.isErrorEnabled()) {
logger.error("Error while calculating authors reputation for document " + documentRef, e);
}
}
}
}
}
Aggregations