use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class SshDaoTest method setUp.
@BeforeMethod
public void setUp() throws TckRepositoryException {
UserImpl[] users = new UserImpl[COUNT_OF_USERS];
for (int i = 0; i < COUNT_OF_USERS; i++) {
users[i] = new UserImpl("owner" + i, "owner" + i + "@eclipse.org", "owner" + i, "password", emptyList());
}
pairs = new SshPairImpl[COUNT_OF_PAIRS];
for (int i = 0; i < COUNT_OF_PAIRS; i++) {
pairs[i] = new // 3 each pairs share the same owner
SshPairImpl(// 3 each pairs share the same owner
"owner" + i / 3, // each 2 pairs share the same service
"service" + i / 2, "name" + i, NameGenerator.generate("publicKey-", 20), NameGenerator.generate("privateKey-", 20));
}
userRepository.createAll(Arrays.asList(users));
sshRepository.createAll(Arrays.asList(pairs));
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class JpaUserDao method doRemove.
@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected Optional<UserImpl> doRemove(String id) throws ServerException {
final EntityManager manager = managerProvider.get();
final UserImpl user = manager.find(UserImpl.class, id);
if (user == null) {
return Optional.empty();
}
eventService.publish(new BeforeUserRemovedEvent(user)).propagateException();
manager.remove(user);
manager.flush();
return Optional.of(user);
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class SshTckModule method configure.
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(SshPairImpl.class, UserImpl.class, AccountImpl.class).setExceptionHandler(H2ExceptionHandler.class).build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
bind(SshDao.class).to(JpaSshDao.class);
bind(new TypeLiteral<TckRepository<SshPairImpl>>() {
}).toInstance(new JpaTckRepository<>(SshPairImpl.class));
bind(new TypeLiteral<TckRepository<UserImpl>>() {
}).toInstance(new JpaTckRepository<>(UserImpl.class));
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class UserManager method create.
/**
* Creates new user and his profile.
*
* @param newUser
* created user
* @throws NullPointerException
* when {@code newUser} is null
* @throws ConflictException
* when user with such name/email/alias already exists
* @throws ServerException
* when any other error occurs
*/
public User create(User newUser, boolean isTemporary) throws ConflictException, ServerException {
requireNonNull(newUser, "Required non-null user");
if (reservedNames.contains(newUser.getName().toLowerCase())) {
throw new ConflictException(String.format("Username '%s' is reserved", newUser.getName()));
}
final String userId = newUser.getId() != null ? newUser.getId() : generate("user", ID_LENGTH);
final UserImpl user = new UserImpl(userId, newUser.getEmail(), newUser.getName(), firstNonNull(newUser.getPassword(), generate("", PASSWORD_LENGTH)), newUser.getAliases());
try {
userDao.create(user);
profileDao.create(new ProfileImpl(user.getId()));
preferencesDao.setPreferences(user.getId(), ImmutableMap.of("temporary", Boolean.toString(isTemporary), "codenvy:created", Long.toString(currentTimeMillis())));
} catch (ConflictException | ServerException x) {
// NOTE: this logic must be replaced with transaction management
try {
userDao.remove(user.getId());
profileDao.remove(user.getId());
preferencesDao.remove(user.getId());
} catch (ServerException rollbackEx) {
LOG.error(format("An attempt to clean up resources due to user creation failure was unsuccessful." + "Now the system may be in inconsistent state. " + "User with id '%s' must not exist", user.getId()), rollbackEx);
}
throw x;
}
return user;
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class UserManager method update.
/**
* Updates user by replacing an existing user entity with a new one.
*
* @param user
* user update
* @throws NullPointerException
* when {@code user} is null
* @throws NotFoundException
* when user with id {@code user.getId()} is not found
* @throws ConflictException
* when user's new alias/email/name is not unique
* @throws ServerException
* when any other error occurs
*/
public void update(User user) throws NotFoundException, ServerException, ConflictException {
requireNonNull(user, "Required non-null user");
userDao.update(new UserImpl(user));
}
Aggregations