use of io.gravitee.management.service.exceptions.ApiRatingUnavailableException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method findByApi.
@Override
public Page<RatingEntity> findByApi(final String api, final Pageable pageable) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Page<Rating> pageRating = ratingRepository.findByApiPageable(api, new PageableBuilder().pageNumber(pageable.pageNumber() - 1).pageSize(pageable.pageSize()).build());
final List<RatingEntity> ratingEntities = pageRating.getContent().stream().map(this::convert).collect(toList());
return new Page<>(ratingEntities, pageRating.getPageNumber(), (int) pageRating.getPageElements(), pageRating.getTotalElements());
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find ratings for api {}", api, ex);
throw new TechnicalManagementException("An error occurred while trying to find ratings for api " + api, ex);
}
}
use of io.gravitee.management.service.exceptions.ApiRatingUnavailableException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method deleteAnswer.
@Override
public void deleteAnswer(final String ratingId, final String answerId) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
Rating rating = findById(ratingId);
ratingAnswerRepository.delete(answerId);
auditService.createApiAuditLog(rating.getApi(), null, RatingAnswer.RatingAnswerEvent.RATING_ANSWER_DELETED, new Date(), rating, null);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete rating answer {}", answerId, ex);
throw new TechnicalManagementException("An error occurs while trying to delete rating answer " + answerId, ex);
}
}
Aggregations