Search in sources :

Example 1 with NotificationTemplateNotFoundException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NotificationTemplateNotFoundException(io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException) NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with NotificationTemplateNotFoundException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NotificationTemplateNotFoundException(io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException) NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 NotificationTemplate (io.gravitee.repository.management.model.NotificationTemplate)2 NotificationTemplateNotFoundException (io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)1