use of io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceImpl method update.
@Override
public NotificationTemplateEntity update(NotificationTemplateEntity updatingNotificationTemplate) {
try {
LOGGER.debug("Update notificationTemplate {}", updatingNotificationTemplate);
if (updatingNotificationTemplate.getUpdatedAt() == null) {
updatingNotificationTemplate.setUpdatedAt(new Date());
}
Optional<NotificationTemplate> optNotificationTemplate = notificationTemplateRepository.findById(updatingNotificationTemplate.getId());
NotificationTemplate notificationTemplateToUpdate = optNotificationTemplate.orElseThrow(() -> new NotificationTemplateNotFoundException(updatingNotificationTemplate.getId()));
notificationTemplateToUpdate.setTitle(updatingNotificationTemplate.getTitle());
notificationTemplateToUpdate.setContent(updatingNotificationTemplate.getContent());
notificationTemplateToUpdate.setEnabled(updatingNotificationTemplate.isEnabled());
NotificationTemplate updatedNotificationTemplate = notificationTemplateRepository.update(notificationTemplateToUpdate);
createAuditLog(NotificationTemplate.AuditEvent.NOTIFICATION_TEMPLATE_UPDATED, updatingNotificationTemplate.getUpdatedAt(), optNotificationTemplate.get(), updatedNotificationTemplate);
final NotificationTemplateEntity updatedNotificationTemplateEntity = convert(updatedNotificationTemplate);
// Update template in loader cache
updateFreemarkerCache(updatedNotificationTemplateEntity);
return updatedNotificationTemplateEntity;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create or update notificationTemplate {}", updatingNotificationTemplate, ex);
throw new TechnicalManagementException("An error occurs while trying to create or update " + updatingNotificationTemplate, ex);
}
}
use of io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceImpl method findById.
@Override
public NotificationTemplateEntity findById(String id) {
try {
LOGGER.debug("Find notificationTemplate by ID: {}", id);
Optional<NotificationTemplate> notificationTemplate = notificationTemplateRepository.findById(id);
if (notificationTemplate.isPresent()) {
return convert(notificationTemplate.get());
}
throw new NotificationTemplateNotFoundException(id);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete a notificationTemplate using its ID {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to delete a notificationTemplate using its ID " + id, ex);
}
}
Aggregations