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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations