Search in sources :

Example 1 with AverageRatingApi

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

the class AbstractExtensionRESTResource method getExtensionRating.

protected ExtensionRating getExtensionRating(DocumentReference extensionDocumentReference) {
    ExtensionRating extensionRating = this.extensionObjectFactory.createExtensionRating();
    try {
        AverageRatingApi averageRating = new AverageRatingApi(ratingsManager.getAverageRating(extensionDocumentReference));
        extensionRating.setTotalVotes(averageRating.getNbVotes());
        extensionRating.setAverageVote(averageRating.getAverageVote());
    } catch (XWikiException e) {
        extensionRating.setTotalVotes(0);
        extensionRating.setAverageVote(0);
    }
    return extensionRating;
}
Also used : ExtensionRating(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating) AverageRatingApi(org.xwiki.ratings.AverageRatingApi) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)1 ExtensionRating (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating)1 AverageRatingApi (org.xwiki.ratings.AverageRatingApi)1