use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PolicyServiceImpl method findAll.
@Override
public Set<PolicyEntity> findAll() {
try {
LOGGER.debug("List all policies");
final Collection<PolicyPlugin> policyDefinitions = policyManager.findAll();
return policyDefinitions.stream().map(policyDefinition -> convert(policyDefinition, false)).collect(Collectors.toSet());
} catch (Exception ex) {
LOGGER.error("An error occurs while trying to list all policies", ex);
throw new TechnicalManagementException("An error occurs while trying to list all policies", ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigServiceImpl method save.
@Override
public PortalNotificationConfigEntity save(PortalNotificationConfigEntity notificationEntity) {
try {
if (notificationEntity.getHooks() == null || notificationEntity.getHooks().isEmpty()) {
portalNotificationConfigRepository.delete(convert(notificationEntity));
return getDefaultEmpty(notificationEntity.getUser(), NotificationReferenceType.valueOf(notificationEntity.getReferenceType()), notificationEntity.getReferenceId());
} else {
Optional<PortalNotificationConfig> optionalConfig = portalNotificationConfigRepository.findById(notificationEntity.getUser(), NotificationReferenceType.valueOf(notificationEntity.getReferenceType()), notificationEntity.getReferenceId());
PortalNotificationConfig notificationConfig = convert(notificationEntity);
if (optionalConfig.isPresent()) {
notificationConfig.setCreatedAt(optionalConfig.get().getCreatedAt());
notificationConfig.setUpdatedAt(new Date());
return convert(portalNotificationConfigRepository.update(notificationConfig));
} else {
notificationConfig.setCreatedAt(new Date());
notificationConfig.setUpdatedAt(notificationConfig.getCreatedAt());
return convert(portalNotificationConfigRepository.create(notificationConfig));
}
}
} catch (TechnicalException te) {
LOGGER.error("An error occurs while trying to save the notification settings {}", notificationEntity, te);
throw new TechnicalManagementException("An error occurs while trying to save the notification settings " + notificationEntity, te);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException 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.TechnicalManagementException 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);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method convert.
private RatingEntity convert(final Rating rating) {
final RatingEntity ratingEntity = new RatingEntity();
final UserEntity user = userService.findById(rating.getUser());
ratingEntity.setUser(user.getId());
if (user.getFirstname() != null && user.getLastname() != null) {
ratingEntity.setUserDisplayName(user.getFirstname() + ' ' + user.getLastname());
} else {
ratingEntity.setUserDisplayName(user.getUsername());
}
ratingEntity.setId(rating.getId());
ratingEntity.setApi(rating.getApi());
ratingEntity.setTitle(rating.getTitle());
ratingEntity.setComment(rating.getComment());
ratingEntity.setRate(rating.getRate());
ratingEntity.setCreatedAt(rating.getCreatedAt());
ratingEntity.setUpdatedAt(rating.getUpdatedAt());
try {
final List<RatingAnswer> ratingAnswers = ratingAnswerRepository.findByRating(rating.getId());
if (ratingAnswers != null) {
ratingEntity.setAnswers(ratingAnswers.stream().map(ratingAnswer -> {
final RatingAnswerEntity ratingAnswerEntity = new RatingAnswerEntity();
ratingAnswerEntity.setId(ratingAnswer.getId());
final UserEntity userAnswer = userService.findById(ratingAnswer.getUser());
ratingAnswerEntity.setUser(userAnswer.getId());
if (userAnswer.getFirstname() != null && userAnswer.getLastname() != null) {
ratingAnswerEntity.setUserDisplayName(userAnswer.getFirstname() + ' ' + userAnswer.getLastname());
} else {
ratingAnswerEntity.setUserDisplayName(userAnswer.getUsername());
}
ratingAnswerEntity.setComment(ratingAnswer.getComment());
ratingAnswerEntity.setCreatedAt(ratingAnswer.getCreatedAt());
return ratingAnswerEntity;
}).sorted(comparing(RatingAnswerEntity::getCreatedAt, reverseOrder())).collect(toList()));
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find rating answers by rating id {}", rating.getId(), ex);
throw new TechnicalManagementException("An error occurred while trying to find rating answers by rating id " + rating.getId(), ex);
}
return ratingEntity;
}
Aggregations