use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class SshManager method generatePair.
/**
* Generates and stores ssh pair for specified user.
*
* @param owner
* the id of the user who will be the owner of the ssh pair
* @param service
* service name pf ssh pair
* @param name
* name of pair
* @return instance of generated ssh pair
* @throws ConflictException
* when given ssh pair cannot be generated or created
* @throws ServerException
* when any other error occurs during ssh pair generating or creating
*/
public SshPairImpl generatePair(String owner, String service, String name) throws ServerException, ConflictException {
KeyPair keyPair;
try {
keyPair = KeyPair.genKeyPair(genJSch, 2, 2048);
} catch (JSchException e) {
throw new ServerException("Failed to generate ssh pair.", e);
}
ByteArrayOutputStream privateBuff = new ByteArrayOutputStream();
keyPair.writePrivateKey(privateBuff);
ByteArrayOutputStream publicBuff = new ByteArrayOutputStream();
keyPair.writePublicKey(publicBuff, null);
final SshPairImpl generatedSshPair = new SshPairImpl(owner, service, name, publicBuff.toString(), privateBuff.toString());
sshDao.create(generatedSshPair);
return generatedSshPair;
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class JpaSshDao method remove.
@Override
public void remove(String owner, String service, String name) throws ServerException, NotFoundException {
requireNonNull(owner);
requireNonNull(service);
requireNonNull(name);
try {
doRemove(owner, service, name);
} catch (RuntimeException e) {
throw new ServerException(e);
}
}
use of org.eclipse.che.api.core.ServerException 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.core.ServerException in project che by eclipse.
the class JpaPreferenceDao method setPreferences.
@Override
public void setPreferences(String userId, Map<String, String> preferences) throws ServerException {
requireNonNull(userId);
requireNonNull(preferences);
final PreferenceEntity prefs = new PreferenceEntity(userId, preferences);
if (preferences.isEmpty()) {
remove(userId);
} else {
try {
doSetPreference(prefs);
} catch (RuntimeException ex) {
throw new ServerException(ex.getLocalizedMessage(), ex);
}
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class RecipeDaoTest method shouldNotRemoveRecipeWhenSubscriberThrowsExceptionOnRecipeRemoving.
@Test(dependsOnMethods = "shouldGetRecipeById")
public void shouldNotRemoveRecipeWhenSubscriberThrowsExceptionOnRecipeRemoving() throws Exception {
final RecipeImpl recipe = recipes.get(0);
CascadeEventSubscriber<BeforeRecipeRemovedEvent> subscriber = mockCascadeEventSubscriber();
doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
eventService.subscribe(subscriber, BeforeRecipeRemovedEvent.class);
try {
recipeDao.remove(recipe.getId());
fail("RecipeDao#remove had to throw server exception");
} catch (ServerException ignored) {
}
assertEquals(recipeDao.getById(recipe.getId()), recipe);
eventService.unsubscribe(subscriber, BeforeRecipeRemovedEvent.class);
}
Aggregations