use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findByIds.
@Override
public Set<UserEntity> findByIds(List<String> ids) {
try {
LOGGER.debug("Find users by ID: {}", ids);
Set<User> users = userRepository.findByIds(ids);
if (!users.isEmpty()) {
return users.stream().map(u -> this.convert(u, false)).collect(Collectors.toSet());
}
Optional<String> idsAsString = ids.stream().reduce((a, b) -> a + '/' + b);
if (idsAsString.isPresent()) {
throw new UserNotFoundException(idsAsString.get());
} else {
throw new UserNotFoundException("?");
}
} catch (TechnicalException ex) {
Optional<String> idsAsString = ids.stream().reduce((a, b) -> a + '/' + b);
LOGGER.error("An error occurs while trying to find users using their ID {}", idsAsString, ex);
throw new TechnicalManagementException("An error occurs while trying to find users using their ID " + idsAsString, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findById.
@Override
public UserEntity findById(String id) {
try {
LOGGER.debug("Find user by ID: {}", id);
Optional<User> optionalUser = userRepository.findById(id);
if (optionalUser.isPresent()) {
return convert(optionalUser.get(), false);
}
// should never happen
throw new UserNotFoundException(id);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find user using its ID {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to find user using its ID " + id, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findByIdWithRoles.
@Override
public UserEntity findByIdWithRoles(String id) {
try {
LOGGER.debug("Find user by ID: {}", id);
Optional<User> optionalUser = userRepository.findById(id);
if (optionalUser.isPresent()) {
return convert(optionalUser.get(), true);
}
// should never happen
throw new UserNotFoundException(id);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find user using its ID {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to find user using its ID " + id, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method create.
/**
* Allows to pre-create a user.
* @param newExternalUserEntity
* @return
*/
@Override
public UserEntity create(NewExternalUserEntity newExternalUserEntity, boolean addDefaultRole) {
try {
LOGGER.debug("Create an external user {}", newExternalUserEntity);
Optional<User> checkUser = userRepository.findById(newExternalUserEntity.getUsername());
if (checkUser.isPresent()) {
throw new UsernameAlreadyExistsException(newExternalUserEntity.getUsername());
}
User user = convert(newExternalUserEntity);
user.setId(UUID.toString(UUID.random()));
// Set date fields
user.setCreatedAt(new Date());
user.setUpdatedAt(user.getCreatedAt());
User createdUser = userRepository.create(user);
auditService.createPortalAuditLog(Collections.singletonMap(USER, user.getUsername()), User.AuditEvent.USER_CREATED, user.getCreatedAt(), null, user);
if (addDefaultRole) {
addDefaultMembership(createdUser);
}
return convert(createdUser, true);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create an external user {}", newExternalUserEntity, ex);
throw new TechnicalManagementException("An error occurs while trying to create an external user" + newExternalUserEntity, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method update.
@Override
public List<ViewEntity> update(final List<UpdateViewEntity> viewEntities) {
final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
viewEntities.forEach(viewEntity -> {
try {
View view = convert(viewEntity);
Optional<View> viewOptional = viewRepository.findById(view.getId());
if (viewOptional.isPresent()) {
savedViews.add(convert(viewRepository.update(view)));
auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_UPDATED, new Date(), viewOptional.get(), view);
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update view {}", viewEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update view " + viewEntity.getName(), ex);
}
});
return savedViews;
}
Aggregations