use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.
the class SeparatePageRatingsManager method getRating.
@Override
public Rating getRating(String ratingId) throws RatingsException {
try {
int i1 = ratingId.indexOf(".");
if (i1 == -1) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, RatingsException.ERROR_RATINGS_INVALID_RATING_ID, "Invalid rating ID, cannot parse rating id");
}
XWikiDocument doc = getXWiki().getDocument(ratingId, getXWikiContext());
if (doc.isNew()) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, RatingsException.ERROR_RATINGS_INVALID_RATING_ID, "Invalid rating ID, rating does not exist");
}
BaseObject object = doc.getObject(getRatingsClassName());
if (object == null) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, RatingsException.ERROR_RATINGS_INVALID_RATING_ID, "Invalid rating ID, rating does not exist");
}
String parentDocName = object.getStringValue(RATING_CLASS_FIELDNAME_PARENT);
XWikiDocument parentDoc = getXWikiContext().getWiki().getDocument(parentDocName, getXWikiContext());
return new SeparatePageRating(parentDoc.getDocumentReference(), doc, getXWikiContext(), this);
} catch (XWikiException e) {
throw new RatingsException(e);
}
}
use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.
the class SeparatePageRatingsManager method getRating.
@Override
public Rating getRating(DocumentReference documentRef, int id) throws RatingsException {
String sql = ", BaseObject as obj, StringProperty as parentprop where doc.fullName=obj.name and obj.className=?" + " and obj.id=parentprop.id.id and parentprop.id.name=?" + " and parentprop.value=?" + " and obj.name not in (select obj2.name from BaseObject as obj2, StringProperty as statusprop where obj2.className=?" + " and obj2.id=statusprop.id.id and statusprop.id.name=? and (statusprop.value=? or statusprop.value=?) and obj.id=obj2.id) order by doc.date desc";
List<?> params = new ArrayList<String>(Arrays.asList(getRatingsClassName(), RATING_CLASS_FIELDNAME_PARENT, entityReferenceSerializer.serialize(documentRef), getRatingsClassName(), "status", "moderated", "refused"));
try {
List<DocumentReference> ratingPageReferenceList = getXWikiContext().getWiki().getStore().searchDocumentReferences(sql, 1, id, params, getXWikiContext());
if ((ratingPageReferenceList == null) || (ratingPageReferenceList.size() == 0)) {
return null;
} else {
return new SeparatePageRatingsManager().getRatingFromDocument(documentRef, getXWiki().getDocument(ratingPageReferenceList.get(0), getXWikiContext()));
}
} catch (XWikiException e) {
throw new RatingsException(e);
}
}
use of org.xwiki.ratings.RatingsException 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.RatingsException in project xwiki-platform by xwiki.
the class AbstractRatingsManager method getAverageRating.
@Override
public AverageRating getAverageRating(DocumentReference documentRef, String method, boolean create) throws RatingsException {
try {
if (isAverageRatingStored(documentRef)) {
String className = getAverageRatingsClassName();
XWikiDocument doc = getXWikiContext().getWiki().getDocument(documentRef, getXWikiContext());
BaseObject averageRatingObject = doc.getObject(className, RatingsManager.AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE_METHOD, method, false);
if (averageRatingObject == null) {
if (!create) {
return calcAverageRating(documentRef, method);
}
// initiate a new average rating object
averageRatingObject = doc.newObject(className, getXWikiContext());
averageRatingObject.setStringValue(RatingsManager.AVERAGERATING_CLASS_FIELDNAME_AVERAGEVOTE_METHOD, method);
}
return new StoredAverageRating(doc, averageRatingObject, getXWikiContext());
} else {
return calcAverageRating(documentRef, method);
}
} catch (XWikiException e) {
throw new RatingsException(e);
}
}
use of org.xwiki.ratings.RatingsException in project xwiki-platform by xwiki.
the class DefaultRatingsManager method getRating.
@Override
public Rating getRating(String ratingId) throws RatingsException {
try {
int i1 = ratingId.indexOf(":");
if (i1 == -1) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, RatingsException.ERROR_RATINGS_INVALID_RATING_ID, "Invalid rating ID, cannot parse rating id");
}
String docName = ratingId.substring(0, i1);
String sObjectNb = ratingId.substring(i1 + 1);
int objectNb = Integer.parseInt(sObjectNb);
XWikiDocument doc = getXWiki().getDocument(docName, getXWikiContext());
DocumentReference docRef = doc.getDocumentReference();
if (doc.isNew()) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, RatingsException.ERROR_RATINGS_INVALID_RATING_ID, "Invalid rating ID, document does not exist");
}
BaseObject object = doc.getObject(getRatingsClassName(), objectNb);
if (object == null) {
throw new RatingsException(RatingsException.MODULE_PLUGIN_RATINGS, RatingsException.ERROR_RATINGS_INVALID_RATING_ID, "Invalid rating ID, could not find rating");
}
return new DefaultRating(docRef, object, getXWikiContext(), this);
} catch (XWikiException e) {
throw new RatingsException(e);
}
}
Aggregations