Search in sources :

Example 1 with ProfileImpl

use of org.eclipse.che.api.user.server.model.impl.ProfileImpl in project che by eclipse.

the class JpaProfileDao method doRemove.

@Transactional
protected void doRemove(String userId) {
    final EntityManager manager = managerProvider.get();
    final ProfileImpl profile = manager.find(ProfileImpl.class, userId);
    if (profile != null) {
        manager.remove(profile);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) Transactional(com.google.inject.persist.Transactional)

Example 2 with ProfileImpl

use of org.eclipse.che.api.user.server.model.impl.ProfileImpl in project che by eclipse.

the class JpaProfileDao method doUpdate.

@Transactional
protected void doUpdate(ProfileImpl profile) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    if (manager.find(ProfileImpl.class, profile.getUserId()) == null) {
        throw new NotFoundException(format("Couldn't update profile, because profile for user with id '%s' doesn't exist", profile.getUserId()));
    }
    manager.merge(profile);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 3 with ProfileImpl

use of org.eclipse.che.api.user.server.model.impl.ProfileImpl in project che by eclipse.

the class ProfileService method updateAttributesById.

@PUT
@Path("/{id}/attributes")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the profile attributes of the user with requested identifier", notes = "The replace strategy is used for the update, so all the existing profile " + "attributes will be override by the profile update")
@ApiResponses({ @ApiResponse(code = 200, message = "The profile successfully updated and the response contains " + "newly updated profile entity"), @ApiResponse(code = 404, message = "When profile for the user with requested identifier doesn't exist"), @ApiResponse(code = 500, message = "Couldn't retrieve profile due to internal server error") })
public ProfileDto updateAttributesById(@ApiParam("Id of the user") @PathParam("id") String userId, @ApiParam("New profile attributes") Map<String, String> updates) throws NotFoundException, ServerException, BadRequestException {
    checkAttributes(updates);
    final ProfileImpl profile = new ProfileImpl(profileManager.getById(userId));
    profile.setAttributes(updates);
    profileManager.update(profile);
    return linksInjector.injectLinks(asDto(profile, userManager.getById(userId)), getServiceContext());
}
Also used : ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with ProfileImpl

use of org.eclipse.che.api.user.server.model.impl.ProfileImpl 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 5 with ProfileImpl

use of org.eclipse.che.api.user.server.model.impl.ProfileImpl in project che by eclipse.

the class JpaTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(UserImpl.class, ProfileImpl.class, PreferenceEntity.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.getDataSource()));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).to(UserJpaTckRepository.class);
    bind(new TypeLiteral<TckRepository<ProfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(ProfileImpl.class));
    bind(new TypeLiteral<TckRepository<Pair<String, Map<String, String>>>>() {
    }).to(PreferenceJpaTckRepository.class);
    bind(UserDao.class).to(JpaUserDao.class);
    bind(ProfileDao.class).to(JpaProfileDao.class);
    bind(PreferenceDao.class).to(JpaPreferenceDao.class);
    // SHA-512 encryptor is faster than PBKDF2 so it is better for testing
    bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) PreferenceDao(org.eclipse.che.api.user.server.spi.PreferenceDao) SHA512PasswordEncryptor(org.eclipse.che.security.SHA512PasswordEncryptor) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) 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) ProfileDao(org.eclipse.che.api.user.server.spi.ProfileDao) TypeLiteral(com.google.inject.TypeLiteral) UserDao(org.eclipse.che.api.user.server.spi.UserDao) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Pair(org.eclipse.che.commons.lang.Pair)

Aggregations

ProfileImpl (org.eclipse.che.api.user.server.model.impl.ProfileImpl)24 Test (org.testng.annotations.Test)11 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)4 Transactional (com.google.inject.persist.Transactional)3 EntityManager (javax.persistence.EntityManager)3 TypeLiteral (com.google.inject.TypeLiteral)2 Response (com.jayway.restassured.response.Response)2 ApiOperation (io.swagger.annotations.ApiOperation)2 HashMap (java.util.HashMap)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AccountImpl (org.eclipse.che.account.spi.AccountImpl)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 Profile (org.eclipse.che.api.core.model.user.Profile)2 PreferenceDao (org.eclipse.che.api.user.server.spi.PreferenceDao)2 ProfileDao (org.eclipse.che.api.user.server.spi.ProfileDao)2 UserDao (org.eclipse.che.api.user.server.spi.UserDao)2