use of io.gravitee.management.service.exceptions.RatingAlreadyExistsException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method create.
@Override
public RatingEntity create(final NewRatingEntity ratingEntity) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Optional<Rating> ratingOptional = ratingRepository.findByApiAndUser(ratingEntity.getApi(), getAuthenticatedUsername());
if (ratingOptional.isPresent()) {
throw new RatingAlreadyExistsException(ratingEntity.getApi(), getAuthenticatedUsername());
}
Rating rating = ratingRepository.create(convert(ratingEntity));
auditService.createApiAuditLog(rating.getApi(), null, Rating.RatingEvent.RATING_CREATED, rating.getCreatedAt(), null, rating);
return convert(rating);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to create rating on api {}", ratingEntity.getApi(), ex);
throw new TechnicalManagementException("An error occurred while trying to create rating on api " + ratingEntity.getApi(), ex);
}
}
Aggregations