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);
}
}
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);
}
}
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);
}
}
Aggregations