Search in sources :

Example 6 with ApiRatingUnavailableException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) Page(io.gravitee.common.data.domain.Page) ApiRatingUnavailableException(io.gravitee.management.service.exceptions.ApiRatingUnavailableException) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 7 with ApiRatingUnavailableException

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

Aggregations

ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)7 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)7 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)7 Rating (io.gravitee.repository.management.model.Rating)7 Date (java.util.Date)4 Page (io.gravitee.common.data.domain.Page)1 RatingAlreadyExistsException (io.gravitee.management.service.exceptions.RatingAlreadyExistsException)1 RatingNotFoundException (io.gravitee.management.service.exceptions.RatingNotFoundException)1 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)1 RatingAnswer (io.gravitee.repository.management.model.RatingAnswer)1 OptionalDouble (java.util.OptionalDouble)1