Search in sources :

Example 1 with RatingAlreadyExistsException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) RatingAlreadyExistsException(io.gravitee.management.service.exceptions.RatingAlreadyExistsException) ApiRatingUnavailableException(io.gravitee.management.service.exceptions.ApiRatingUnavailableException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)1 RatingAlreadyExistsException (io.gravitee.management.service.exceptions.RatingAlreadyExistsException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Rating (io.gravitee.repository.management.model.Rating)1