Search in sources :

Example 11 with RatingsException

use of org.xwiki.ratings.RatingsException 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)

Example 12 with RatingsException

use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.

the class SeparatePageRating method remove.

@Override
public boolean remove() throws RatingsException {
    try {
        XWikiDocument doc = getDocument();
        // remove the rating
        context.getWiki().deleteDocument(doc, context);
    } catch (XWikiException e) {
        throw new RatingsException(e);
    }
    return true;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) RatingsException(org.xwiki.ratings.RatingsException) XWikiException(com.xpn.xwiki.XWikiException)

Example 13 with RatingsException

use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.

the class AbstractRatingsManager method updateUserReputation.

@Override
public void updateUserReputation(DocumentReference author, AverageRating voterRating) throws RatingsException {
    try {
        // We should update the user rating
        AverageRating rating = getAverageRating(author, voterRating.getMethod(), true);
        rating.setAverageVote(voterRating.getAverageVote());
        rating.setMethod(voterRating.getMethod());
        rating.setNbVotes(voterRating.getNbVotes());
        rating.save();
    } catch (XWikiException e) {
        throw new RatingsException(e);
    }
}
Also used : AverageRating(org.xwiki.ratings.AverageRating) RatingsException(org.xwiki.ratings.RatingsException) XWikiException(com.xpn.xwiki.XWikiException)

Example 14 with RatingsException

use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.

the class AbstractRatingsManager method getAverageRatingFromQuery.

@Override
public AverageRating getAverageRatingFromQuery(String fromsql, String wheresql, String method) throws RatingsException {
    try {
        String fromsql2 = fromsql + ", BaseObject as avgobj, FloatProperty as avgvote, StringProperty as avgmethod ";
        String wheresql2 = (wheresql.equals("") ? "where " : wheresql + " and ") + "doc.fullName=avgobj.name and avgobj.className='" + getAverageRatingsClassName() + "' and avgobj.id=avgvote.id.id and avgvote.id.name='" + AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE + "' and avgobj.id=avgmethod.id.id and avgmethod.id.name='" + AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE_METHOD + "' and avgmethod.value='" + method + "'";
        String sql = "select sum(avgvote.value) as vote, count(avgvote.value) as nbvotes from XWikiDocument as doc " + fromsql2 + wheresql2;
        if (logger.isDebugEnabled()) {
            logger.debug("Running average rating with sql " + sql);
        }
        getXWikiContext().put("lastsql", sql);
        List result = getXWiki().getStore().search(sql, 0, 0, getXWikiContext());
        float vote = ((Number) ((Object[]) result.get(0))[0]).floatValue();
        int nbvotes = ((Number) ((Object[]) result.get(0))[1]).intValue();
        AverageRating avgr = new MemoryAverageRating(null, nbvotes, vote / nbvotes, method);
        return avgr;
    } catch (XWikiException e) {
        throw new RatingsException(e);
    }
}
Also used : AverageRating(org.xwiki.ratings.AverageRating) List(java.util.List) BaseObject(com.xpn.xwiki.objects.BaseObject) RatingsException(org.xwiki.ratings.RatingsException) XWikiException(com.xpn.xwiki.XWikiException)

Example 15 with RatingsException

use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.

the class DefaultRating method save.

@Override
public void save() throws RatingsException {
    try {
        // Force content dirty to false, so that the content update date is not changed when saving the document.
        // This should not be handled there, since it is not the responsibility of this plugin to decide if
        // the content has actually been changed or not since current revision, but the implementation of
        // this in XWiki core is wrong. See https://jira.xwiki.org/XWIKI-2800 for more details.
        // There is a draw-back to doing this, being that if the document content is being changed before
        // the document is rated, the contentUpdateDate will not be modified. Although possible, this is very
        // unlikely to happen, or to be a use case. The default rating application will use an asynchronous service
        // to
        // note a document, which service will only set the rating, so the behavior will be correct.
        getDocument().setContentDirty(false);
        context.getWiki().saveDocument(getDocument(), context);
    } catch (XWikiException e) {
        throw new RatingsException(e);
    }
}
Also used : RatingsException(org.xwiki.ratings.RatingsException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

RatingsException (org.xwiki.ratings.RatingsException)15 XWikiException (com.xpn.xwiki.XWikiException)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)7 BaseObject (com.xpn.xwiki.objects.BaseObject)6 DocumentReference (org.xwiki.model.reference.DocumentReference)5 AverageRating (org.xwiki.ratings.AverageRating)4 ArrayList (java.util.ArrayList)2 Rating (org.xwiki.ratings.Rating)2 ReputationException (org.xwiki.ratings.ReputationException)2 XWiki (com.xpn.xwiki.XWiki)1 Date (java.util.Date)1 List (java.util.List)1 ContextualLocalizationManager (org.xwiki.localization.ContextualLocalizationManager)1 UpdateRatingEvent (org.xwiki.ratings.UpdateRatingEvent)1 UpdatingRatingEvent (org.xwiki.ratings.UpdatingRatingEvent)1