use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationServiceImpl method create.
@Override
public void create(Hook hook, List<String> users, Object params) {
try {
// get notification template
String tpl = RELATIVE_TPL_PATH + hook.getScope().name() + "." + hook.name() + ".yml";
final Template template = freemarkerConfiguration.getTemplate(tpl);
final String yamlContent = processTemplateIntoString(template, params);
Yaml yaml = new Yaml();
Map<String, String> load = yaml.loadAs(yamlContent, HashMap.class);
List<NewPortalNotificationEntity> notifications = new ArrayList<>(users.size());
users.forEach(user -> {
NewPortalNotificationEntity notification = new NewPortalNotificationEntity();
notification.setUser(user);
notification.setTitle(load.get("title"));
notification.setMessage(load.get("message"));
notifications.add(notification);
});
create(notifications);
} catch (final Exception ex) {
LOGGER.error("Error while sending notification", ex);
throw new TechnicalManagementException("Error while sending notification", ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationServiceImpl method create.
private void create(List<NewPortalNotificationEntity> notificationEntities) {
final Date now = new Date();
List<PortalNotification> notifications = notificationEntities.stream().map(this::convert).collect(Collectors.toList());
notifications.forEach(n -> {
n.setId(UUID.toString(UUID.random()));
n.setCreatedAt(now);
});
try {
portalNotificationRepository.create(notifications);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create {}", notifications, ex);
throw new TechnicalManagementException("An error occurs while trying create " + notifications, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class RatingServiceImpl method findSummaryByApi.
@Override
public RatingSummaryEntity findSummaryByApi(final String api) {
if (!enabled) {
throw new ApiRatingUnavailableException();
}
try {
final List<Rating> ratings = ratingRepository.findByApi(api);
final RatingSummaryEntity ratingSummary = new RatingSummaryEntity();
ratingSummary.setApi(api);
ratingSummary.setNumberOfRatings(ratings.size());
final OptionalDouble optionalAvg = ratings.stream().mapToInt(Rating::getRate).average();
if (optionalAvg.isPresent()) {
ratingSummary.setAverageRate(optionalAvg.getAsDouble());
}
ratingSummary.setNumberOfRatingsByRate(ratings.stream().collect(groupingBy(Rating::getRate, counting())));
return ratingSummary;
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find summary rating for api {}", api, ex);
throw new TechnicalManagementException("An error occurred while trying to find summary rating 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 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.management.service.exceptions.TechnicalManagementException 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);
}
}
Aggregations