Search in sources :

Example 1 with DuplicateKeyException

use of org.eclipse.che.core.db.jpa.DuplicateKeyException in project che-server by eclipse-che.

the class JpaUserDevfileDao method create.

@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
    requireNonNull(userDevfile);
    try {
        Account account = accountDao.getByName(userDevfile.getNamespace());
        UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
        doCreate(userDevfileImpl);
        return userDevfileImpl;
    } catch (DuplicateKeyException ex) {
        throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
    } catch (IntegrityConstraintViolationException ex) {
        throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getMessage(), ex);
    } catch (NotFoundException e) {
        throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) DuplicateKeyException(org.eclipse.che.core.db.jpa.DuplicateKeyException)

Example 2 with DuplicateKeyException

use of org.eclipse.che.core.db.jpa.DuplicateKeyException in project devspaces-images by redhat-developer.

the class JpaUserDevfileDao method create.

@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
    requireNonNull(userDevfile);
    try {
        Account account = accountDao.getByName(userDevfile.getNamespace());
        UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
        doCreate(userDevfileImpl);
        return userDevfileImpl;
    } catch (DuplicateKeyException ex) {
        throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
    } catch (IntegrityConstraintViolationException ex) {
        throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getMessage(), ex);
    } catch (NotFoundException e) {
        throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) DuplicateKeyException(org.eclipse.che.core.db.jpa.DuplicateKeyException)

Aggregations

Account (org.eclipse.che.account.shared.model.Account)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)2 DuplicateKeyException (org.eclipse.che.core.db.jpa.DuplicateKeyException)2 IntegrityConstraintViolationException (org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException)2