class SoapDocumentService extends AbstractService implements DocumentService {

	@Override
	public WSRating rateDocument(String sid, long docId, int vote) throws Exception {
		User user = validateSession(sid);
		WSDocument document = getDocument(sid, docId);
		if (document == null)
			throw new Exception("Document with ID " + docId + " not found or not accessible");

		DocumentHistory transaction = new DocumentHistory();
		transaction.setSessionId(sid);
		transaction.setUser(user);

		RatingDAO ratingDao = (RatingDAO) Context.get().getBean(RatingDAO.class);

		Rating rating = ratingDao.findByDocIdAndUserId(docId, user.getId());
		if (rating == null) {
			rating = new Rating();
			rating.setDocId(docId);
			rating.setUserId(user.getId());
			rating.setUsername(user.getFullName());
		}
		rating.setVote(vote);

		ratingDao.store(rating, transaction);
		return WSRating.fromRating(rating);
	}

}