use of io.gravitee.management.service.exceptions.RatingNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method update.
@Override
public RatingEntity update(final UpdateRatingEntity ratingEntity) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Rating rating = findById(ratingEntity.getId());
final Rating oldRating = new Rating(rating);
if (!rating.getApi().equals(ratingEntity.getApi())) {
throw new RatingNotFoundException(ratingEntity.getId(), ratingEntity.getApi());
}
final Date now = new Date();
rating.setUpdatedAt(now);
rating.setRate(ratingEntity.getRate());
// we can save a title/comment only once
if (isBlank(rating.getTitle())) {
rating.setTitle(ratingEntity.getTitle());
}
if (isBlank(rating.getComment())) {
rating.setComment(ratingEntity.getComment());
}
Rating updatedRating = ratingRepository.update(rating);
auditService.createApiAuditLog(rating.getApi(), null, Rating.RatingEvent.RATING_UPDATED, updatedRating.getUpdatedAt(), oldRating, updatedRating);
return convert(updatedRating);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to update rating {}", ratingEntity.getId(), ex);
throw new TechnicalManagementException("An error occurred while trying to update rating " + ratingEntity.getId(), ex);
}
}
Aggregations