use of io.gravitee.repository.management.model.User in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method connect.
@Override
public UserEntity connect(String userId) {
try {
LOGGER.debug("Connection of {}", userId);
Optional<User> checkUser = userRepository.findById(userId);
if (!checkUser.isPresent()) {
throw new UserNotFoundException(userId);
}
User user = checkUser.get();
User previousUser = new User(user);
// First connection: create default application for user
if (defaultApplicationForFirstConnection && user.getLastConnectionAt() == null) {
LOGGER.debug("Create a default application for {}", userId);
NewApplicationEntity defaultApp = new NewApplicationEntity();
defaultApp.setName("Default application");
defaultApp.setDescription("My default application");
applicationService.create(defaultApp, userId);
}
// Set date fields
user.setLastConnectionAt(new Date());
user.setUpdatedAt(user.getLastConnectionAt());
User updatedUser = userRepository.update(user);
auditService.createPortalAuditLog(Collections.singletonMap(USER, userId), User.AuditEvent.USER_CONNECTED, user.getUpdatedAt(), previousUser, user);
return convert(updatedUser, true);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to connect {}", userId, ex);
throw new TechnicalManagementException("An error occurs while trying to connect " + userId, ex);
}
}
use of io.gravitee.repository.management.model.User in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method convert.
private static User convert(NewExternalUserEntity newExternalUserEntity) {
if (newExternalUserEntity == null) {
return null;
}
User user = new User();
user.setUsername(newExternalUserEntity.getUsername());
user.setEmail(newExternalUserEntity.getEmail());
user.setFirstname(newExternalUserEntity.getFirstname());
user.setLastname(newExternalUserEntity.getLastname());
user.setSource(newExternalUserEntity.getSource());
user.setSourceId(newExternalUserEntity.getSourceId());
return user;
}
use of io.gravitee.repository.management.model.User 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.repository.management.model.User 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.repository.management.model.User 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);
}
}
Aggregations