Search in sources :

Example 1 with GenericNotificationConfig

use of io.gravitee.repository.management.model.GenericNotificationConfig in project gravitee-management-rest-api by gravitee-io.

the class GenericNotificationConfigServiceImpl method create.

@Override
public GenericNotificationConfigEntity create(GenericNotificationConfigEntity entity) {
    if (entity.getNotifier() == null || entity.getNotifier().isEmpty() || entity.getName() == null || entity.getName().isEmpty()) {
        throw new BadNotificationConfigException("Name or notifier is missing !");
    }
    try {
        GenericNotificationConfig notificationConfig = convert(entity);
        notificationConfig.setId(UUID.toString(UUID.random()));
        notificationConfig.setCreatedAt(new Date());
        notificationConfig.setUpdatedAt(notificationConfig.getCreatedAt());
        return convert(genericNotificationConfigRepository.create(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.management.service.exceptions.BadNotificationConfigException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 2 with GenericNotificationConfig

use of io.gravitee.repository.management.model.GenericNotificationConfig in project gravitee-management-rest-api by gravitee-io.

the class GenericNotificationConfigServiceImpl method convert.

private GenericNotificationConfig convert(GenericNotificationConfigEntity entity) {
    GenericNotificationConfig model = new GenericNotificationConfig();
    model.setId(entity.getId());
    model.setName(entity.getName());
    model.setReferenceType(NotificationReferenceType.valueOf(entity.getReferenceType()));
    model.setReferenceId(entity.getReferenceId());
    model.setNotifier(entity.getNotifier());
    model.setConfig(entity.getConfig());
    model.setHooks(entity.getHooks());
    return model;
}
Also used : GenericNotificationConfig(io.gravitee.repository.management.model.GenericNotificationConfig)

Example 3 with GenericNotificationConfig

use of io.gravitee.repository.management.model.GenericNotificationConfig 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("Name or notifier is missing !");
        }
        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.management.service.exceptions.BadNotificationConfigException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) NotificationConfigNotFoundException(io.gravitee.management.service.exceptions.NotificationConfigNotFoundException)

Aggregations

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