Search in sources :

Example 1 with ReputationException

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);
    }
}
Also used : AverageRating(org.xwiki.ratings.AverageRating) RatingsException(org.xwiki.ratings.RatingsException) ReputationException(org.xwiki.ratings.ReputationException)

Example 2 with ReputationException

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);
                }
            }
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) AverageRating(org.xwiki.ratings.AverageRating) RatingsException(org.xwiki.ratings.RatingsException) ReputationException(org.xwiki.ratings.ReputationException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

AverageRating (org.xwiki.ratings.AverageRating)2 RatingsException (org.xwiki.ratings.RatingsException)2 ReputationException (org.xwiki.ratings.ReputationException)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1