Search in sources :

Example 81 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException 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 82 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException 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 83 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException 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)

Example 84 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class GroupServiceImpl method findAll.

@Override
public List<GroupEntity> findAll() {
    try {
        logger.debug("Find all groups");
        Set<Group> all = groupRepository.findAll();
        logger.debug("Find all groups - DONE");
        return all.stream().map(this::map).collect(Collectors.toList());
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to find all groups", ex);
        throw new TechnicalManagementException("An error occurs while trying to find all groups", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 85 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class GroupServiceImpl method update.

@Override
public GroupEntity update(String groupId, UpdateGroupEntity group) {
    try {
        logger.debug("update {}", group);
        GroupEntity updatedGroupEntity = this.findById(groupId);
        Group previousGroup = this.map(updatedGroupEntity);
        updatedGroupEntity.setName(group.getName());
        updatedGroupEntity.setUpdatedAt(new Date());
        updatedGroupEntity.setEventRules(group.getEventRules());
        Group updatedGroup = this.map(updatedGroupEntity);
        GroupEntity grp = this.map(groupRepository.update(updatedGroup));
        logger.debug("update {} - DONE", grp);
        // Audit
        auditService.createPortalAuditLog(Collections.singletonMap(GROUP, groupId), GROUP_UPDATED, updatedGroupEntity.getUpdatedAt(), previousGroup, updatedGroup);
        return grp;
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to update a group", ex);
        throw new TechnicalManagementException("An error occurs while trying to update a group", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)102 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)80 Logger (org.slf4j.Logger)22 LoggerFactory (org.slf4j.LoggerFactory)22 Autowired (org.springframework.beans.factory.annotation.Autowired)22 Component (org.springframework.stereotype.Component)20 java.util (java.util)18 Collectors (java.util.stream.Collectors)18 io.gravitee.management.model (io.gravitee.management.model)16 AuditService (io.gravitee.management.service.AuditService)12 UUID (io.gravitee.common.utils.UUID)11 Date (java.util.Date)11 IdGenerator (io.gravitee.common.utils.IdGenerator)9 IOException (java.io.IOException)9 io.gravitee.management.service (io.gravitee.management.service)8 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7