Search in sources :

Example 1 with EventNotFoundException

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

the class InstanceServiceImpl method findByEvent.

@Override
public InstanceEntity findByEvent(String eventId) {
    try {
        LOGGER.debug("Find instance by event ID: {}", eventId);
        EventEntity event = eventService.findById(eventId);
        List<String> environments = Stream.of(event.getProperties().get(ENVIRONMENTS_HRIDS_PROPERTY).split(", ")).filter(env -> !StringUtils.isEmpty(env)).collect(Collectors.toList());
        List<String> organizations = Stream.of(event.getProperties().get(ORGANIZATIONS_HRIDS_PROPERTY).split(", ")).filter(org -> !StringUtils.isEmpty(org)).collect(Collectors.toList());
        return convert(event, environments, organizations);
    } catch (EventNotFoundException enfe) {
        throw new InstanceNotFoundException(eventId);
    }
}
Also used : InstanceService(io.gravitee.rest.api.service.InstanceService) java.util(java.util) InstanceNotFoundException(io.gravitee.rest.api.service.exceptions.InstanceNotFoundException) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Page(io.gravitee.common.data.domain.Page) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Instant(java.time.Instant) EventNotFoundException(io.gravitee.rest.api.service.exceptions.EventNotFoundException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) EventService(io.gravitee.rest.api.service.EventService) Value(org.springframework.beans.factory.annotation.Value) Component(org.springframework.stereotype.Component) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) Duration(java.time.Duration) io.gravitee.rest.api.model(io.gravitee.rest.api.model) StringUtils(org.springframework.util.StringUtils) InstanceNotFoundException(io.gravitee.rest.api.service.exceptions.InstanceNotFoundException) EventNotFoundException(io.gravitee.rest.api.service.exceptions.EventNotFoundException)

Example 2 with EventNotFoundException

use of io.gravitee.rest.api.service.exceptions.EventNotFoundException 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.rest.api.service.exceptions.EventNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

EventNotFoundException (io.gravitee.rest.api.service.exceptions.EventNotFoundException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Page (io.gravitee.common.data.domain.Page)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Event (io.gravitee.repository.management.model.Event)1 io.gravitee.rest.api.model (io.gravitee.rest.api.model)1 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)1 EventService (io.gravitee.rest.api.service.EventService)1 InstanceService (io.gravitee.rest.api.service.InstanceService)1 InstanceNotFoundException (io.gravitee.rest.api.service.exceptions.InstanceNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 java.util (java.util)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1