Search in sources :

Example 1 with NotificationConfigNotFoundException

use of io.gravitee.rest.api.service.exceptions.NotificationConfigNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class GenericNotificationConfigServiceImpl method update.

@Override
public GenericNotificationConfigEntity update(GenericNotificationConfigEntity entity) {
    try {
        if (entity.getNotifier() == null || entity.getNotifier().isEmpty() || entity.getName() == null || entity.getName().isEmpty()) {
            throw new BadNotificationConfigException();
        }
        if (entity.getId() == null || entity.getId().isEmpty()) {
            throw new NotificationConfigNotFoundException();
        }
        Optional<GenericNotificationConfig> optionalConfig = genericNotificationConfigRepository.findById(entity.getId());
        if (!optionalConfig.isPresent()) {
            throw new NotificationConfigNotFoundException();
        }
        GenericNotificationConfig notificationConfig = convert(entity);
        notificationConfig.setCreatedAt(optionalConfig.get().getCreatedAt());
        notificationConfig.setUpdatedAt(new Date());
        return convert(genericNotificationConfigRepository.update(notificationConfig));
    } catch (TechnicalException te) {
        LOGGER.error("An error occurs while trying to save the generic notification settings {}", entity, te);
        throw new TechnicalManagementException("An error occurs while trying to save the generic notification settings " + entity, te);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) GenericNotificationConfig(io.gravitee.repository.management.model.GenericNotificationConfig) BadNotificationConfigException(io.gravitee.rest.api.service.exceptions.BadNotificationConfigException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) NotificationConfigNotFoundException(io.gravitee.rest.api.service.exceptions.NotificationConfigNotFoundException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 GenericNotificationConfig (io.gravitee.repository.management.model.GenericNotificationConfig)1 BadNotificationConfigException (io.gravitee.rest.api.service.exceptions.BadNotificationConfigException)1 NotificationConfigNotFoundException (io.gravitee.rest.api.service.exceptions.NotificationConfigNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1