'Rate an item. Return type is <item_class>RatingAssociation.'

def rate_item(self, db_session, user, item, rating, webapp_model=None):

    if (webapp_model is None):
        webapp_model = galaxy.model
    item_rating = self.get_user_item_rating(db_session, user, item, webapp_model=webapp_model)
    if (not item_rating):
        item_rating_assoc_class = self._get_item_rating_assoc_class(item, webapp_model=webapp_model)
        item_rating = item_rating_assoc_class()
        item_rating.user = user
        item_rating.set_item(item)
        item_rating.rating = rating
        db_session.add(item_rating)
        db_session.flush()
    elif (item_rating.rating != rating):
        item_rating.rating = rating
        db_session.flush()
    return item_rating
