Search in sources :

Example 26 with UserImpl

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));
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 27 with UserImpl

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);
}
Also used : EntityManager(javax.persistence.EntityManager) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 28 with UserImpl

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));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) SshDao(org.eclipse.che.api.ssh.server.spi.SshDao) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl)

Example 29 with UserImpl

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;
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl)

Example 30 with UserImpl

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));
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl)

Aggregations

UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)65 Test (org.testng.annotations.Test)45 User (org.eclipse.che.api.core.model.user.User)13 Response (com.jayway.restassured.response.Response)10 BeforeMethod (org.testng.annotations.BeforeMethod)9 ServerException (org.eclipse.che.api.core.ServerException)8 Transactional (com.google.inject.persist.Transactional)6 ConflictException (org.eclipse.che.api.core.ConflictException)5 BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)5 EntityManager (javax.persistence.EntityManager)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Page (org.eclipse.che.api.core.Page)4 PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)4 ProfileImpl (org.eclipse.che.api.user.server.model.impl.ProfileImpl)4 UserDao (org.eclipse.che.api.user.server.spi.UserDao)4 ArrayList (java.util.ArrayList)3 Inject (javax.inject.Inject)3 UserRemovedEvent (org.eclipse.che.api.user.server.event.UserRemovedEvent)3 UserDto (org.eclipse.che.api.user.shared.dto.UserDto)3 TckRepository (org.eclipse.che.commons.test.tck.repository.TckRepository)3