Search in sources :

Example 66 with TechnicalManagementException

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

the class EventServiceImpl method findById.

@Override
public EventEntity findById(String id) {
    try {
        LOGGER.debug("Find event by ID: {}", id);
        Optional<Event> event = eventRepository.findById(id);
        if (event.isPresent()) {
            return convert(event.get());
        }
        throw new EventNotFoundException(id);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find an event using its ID {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to find an event using its ID " + id, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Event(io.gravitee.repository.management.model.Event) EventNotFoundException(io.gravitee.management.service.exceptions.EventNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 67 with TechnicalManagementException

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

the class EventServiceImpl method create.

@Override
public EventEntity create(NewEventEntity newEventEntity) {
    String hostAddress = "";
    try {
        hostAddress = InetAddress.getLocalHost().getHostAddress();
        LOGGER.debug("Create {} for server {}", newEventEntity, hostAddress);
        Event event = convert(newEventEntity);
        event.setId(io.gravitee.common.utils.UUID.random().toString());
        // Set origin
        event.getProperties().put(Event.EventProperties.ORIGIN.getValue(), hostAddress);
        // Set date fields
        event.setCreatedAt(new Date());
        event.setUpdatedAt(event.getCreatedAt());
        Event createdEvent = eventRepository.create(event);
        return convert(createdEvent);
    } catch (UnknownHostException e) {
        LOGGER.error("An error occurs while getting the server IP address", e);
        throw new TechnicalManagementException("An error occurs while getting the server IP address", e);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create {} for server {}", newEventEntity, hostAddress, ex);
        throw new TechnicalManagementException("An error occurs while trying create " + newEventEntity + " for server " + hostAddress, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UnknownHostException(java.net.UnknownHostException) Event(io.gravitee.repository.management.model.Event) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 68 with TechnicalManagementException

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

the class FetcherServiceImpl method findAll.

@Override
public Set<FetcherEntity> findAll() {
    try {
        LOGGER.debug("List all fetchers");
        final Collection<FetcherPlugin> fetcherDefinitions = fetcherPluginManager.findAll();
        return fetcherDefinitions.stream().map(fetcherDefinition -> convert(fetcherDefinition, false)).collect(Collectors.toSet());
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to list all fetchers", ex);
        throw new TechnicalManagementException("An error occurs while trying to list all fetchers", ex);
    }
}
Also used : Logger(org.slf4j.Logger) PluginEntity(io.gravitee.management.model.PluginEntity) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) IOException(java.io.IOException) FetcherService(io.gravitee.management.service.FetcherService) FetcherPluginManager(io.gravitee.plugin.fetcher.FetcherPluginManager) Collectors(java.util.stream.Collectors) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) Component(org.springframework.stereotype.Component) Plugin(io.gravitee.plugin.core.api.Plugin) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException) FetcherEntity(io.gravitee.management.model.FetcherEntity) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 69 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException 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)

Example 70 with TechnicalManagementException

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

the class GroupServiceImpl method findByEvent.

@Override
public Set<GroupEntity> findByEvent(GroupEvent event) {
    try {
        logger.debug("findByEvent : {}", event);
        Set<GroupEntity> set = groupRepository.findAll().stream().filter(g -> g.getEventRules() != null && g.getEventRules().stream().map(GroupEventRule::getEvent).collect(Collectors.toList()).contains(event)).map(this::map).collect(Collectors.toSet());
        logger.debug("findByEvent : {} - DONE", set);
        return set;
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to find groups by event", ex);
        throw new TechnicalManagementException("An error occurs while trying to find groups by event", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)90 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)83 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Component (org.springframework.stereotype.Component)17 Collectors (java.util.stream.Collectors)13 java.util (java.util)11 Date (java.util.Date)11 AuditService (io.gravitee.management.service.AuditService)10 IdGenerator (io.gravitee.common.utils.IdGenerator)9 io.gravitee.management.model (io.gravitee.management.model)9 User (io.gravitee.repository.management.model.User)9 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 DuplicateMetadataNameException (io.gravitee.management.service.exceptions.DuplicateMetadataNameException)7 ApiService (io.gravitee.management.service.ApiService)6 MetadataService (io.gravitee.management.service.MetadataService)6