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();
}
}
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();
}
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());
}
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;
}
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);
}
Aggregations