Search in sources :

Example 6 with ApiRatingUnavailableException

use of io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException in project gravitee-management-rest-api by gravitee-io.

the class RatingServiceImpl method createAnswer.

@Override
public RatingEntity createAnswer(final NewRatingAnswerEntity answerEntity) {
    if (!isEnabled()) {
        throw new ApiRatingUnavailableException();
    }
    try {
        final Rating rating = findModelById(answerEntity.getRatingId());
        final RatingAnswer ratingAnswer = new RatingAnswer();
        ratingAnswer.setId(UuidString.generateRandom());
        ratingAnswer.setRating(answerEntity.getRatingId());
        ratingAnswer.setUser(getAuthenticatedUsername());
        ratingAnswer.setComment(answerEntity.getComment());
        ratingAnswer.setCreatedAt(new Date());
        ratingAnswerRepository.create(ratingAnswer);
        auditService.createApiAuditLog(rating.getReferenceId(), null, RatingAnswer.RatingAnswerEvent.RATING_ANSWER_CREATED, ratingAnswer.getCreatedAt(), null, ratingAnswer);
        notifierService.trigger(ApiHook.NEW_RATING_ANSWER, rating.getReferenceId(), new NotificationParamsBuilder().api(apiService.findById(rating.getReferenceId())).build());
        return convert(rating);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurred while trying to create a rating answer on rating {}", answerEntity.getRatingId(), ex);
        throw new TechnicalManagementException("An error occurred while trying to create a rating answer on rating" + answerEntity.getRatingId(), ex);
    }
}
Also used : RatingAnswer(io.gravitee.repository.management.model.RatingAnswer) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder)

Example 7 with ApiRatingUnavailableException

use of io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException in project gravitee-management-rest-api by gravitee-io.

the class RatingServiceImpl method findByApi.

@Override
public List<RatingEntity> findByApi(String api) {
    if (!isEnabled()) {
        throw new ApiRatingUnavailableException();
    }
    try {
        final List<Rating> ratings = ratingRepository.findByReferenceIdAndReferenceType(api, RatingReferenceType.API);
        final List<RatingEntity> ratingEntities = ratings.stream().map(this::convert).collect(toList());
        return ratingEntities;
    } 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) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 8 with ApiRatingUnavailableException

use of io.gravitee.rest.api.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 (!isEnabled()) {
        throw new ApiRatingUnavailableException();
    }
    try {
        Rating rating = findModelById(ratingId);
        ratingAnswerRepository.delete(answerId);
        auditService.createApiAuditLog(rating.getReferenceId(), 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.rest.api.service.exceptions.ApiRatingUnavailableException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

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