use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method createAnswer.
@Override
public RatingEntity createAnswer(final NewRatingAnswerEntity answerEntity) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Rating rating = findById(answerEntity.getRatingId());
final RatingAnswer ratingAnswer = new RatingAnswer();
ratingAnswer.setId(UUID.toString(UUID.random()));
ratingAnswer.setRating(answerEntity.getRatingId());
ratingAnswer.setUser(getAuthenticatedUsername());
ratingAnswer.setComment(answerEntity.getComment());
ratingAnswer.setCreatedAt(new Date());
ratingAnswerRepository.create(ratingAnswer);
auditService.createApiAuditLog(rating.getApi(), null, RatingAnswer.RatingAnswerEvent.RATING_ANSWER_CREATED, ratingAnswer.getCreatedAt(), null, ratingAnswer);
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.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method delete.
@Override
public void delete(final String id) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
Rating rating = findById(id);
ratingRepository.delete(id);
auditService.createApiAuditLog(rating.getApi(), null, Rating.RatingEvent.RATING_DELETED, new Date(), rating, null);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete rating {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to delete rating " + id, ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException 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);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method update.
@Override
public RatingEntity update(final UpdateRatingEntity ratingEntity) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final Rating rating = findById(ratingEntity.getId());
final Rating oldRating = new Rating(rating);
if (!rating.getApi().equals(ratingEntity.getApi())) {
throw new RatingNotFoundException(ratingEntity.getId(), ratingEntity.getApi());
}
final Date now = new Date();
rating.setUpdatedAt(now);
rating.setRate(ratingEntity.getRate());
// we can save a title/comment only once
if (isBlank(rating.getTitle())) {
rating.setTitle(ratingEntity.getTitle());
}
if (isBlank(rating.getComment())) {
rating.setComment(ratingEntity.getComment());
}
Rating updatedRating = ratingRepository.update(rating);
auditService.createApiAuditLog(rating.getApi(), null, Rating.RatingEvent.RATING_UPDATED, updatedRating.getUpdatedAt(), oldRating, updatedRating);
return convert(updatedRating);
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to update rating {}", ratingEntity.getId(), ex);
throw new TechnicalManagementException("An error occurred while trying to update rating " + ratingEntity.getId(), ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method delete.
@Override
public void delete(final RoleScope scope, final String name) {
if (isReserved(name)) {
throw new RoleReservedNameException(SystemRole.ADMIN.name());
}
try {
Optional<Role> optRole = roleRepository.findById(scope, name);
if (!optRole.isPresent()) {
throw new RoleNotFoundException(scope, name);
}
Role role = optRole.get();
roleRepository.delete(scope, name);
auditService.createPortalAuditLog(Collections.singletonMap(ROLE, role.getScope() + ":" + role.getName()), ROLE_DELETED, role.getUpdatedAt(), role, null);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete role {}/{}", scope, name, ex);
throw new TechnicalManagementException("An error occurs while trying to delete role " + scope + "/" + name, ex);
}
}
Aggregations