public int rateMetadata(final int metadataId, final String ipAddress, final int rating) throws Exception {
MetadataRatingByIp ratingEntity = new MetadataRatingByIp();
ratingEntity.setRating(rating);
ratingEntity.setId(new MetadataRatingByIpId(metadataId, ipAddress));
final MetadataRatingByIpRepository ratingByIpRepository = _applicationContext.getBean(MetadataRatingByIpRepository.class);
ratingByIpRepository.save(ratingEntity);
//
// calculate new rating
//
final int newRating = ratingByIpRepository.averageRating(metadataId);
if(Log.isDebugEnabled(Geonet.DATA_MANAGER))
Log.debug(Geonet.DATA_MANAGER, "Setting rating for id:"+ metadataId +" --> rating is:"+newRating);