Search in sources :

Example 6 with DuplicateKeyException

use of org.springframework.dao.DuplicateKeyException in project perun by CESNET.

the class GroupsManagerImpl method addMember.

public Member addMember(PerunSession sess, Group group, Member member, MembershipType type, int sourceGroupId) throws InternalErrorException, AlreadyMemberException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    member.setMembershipType(type);
    member.setSourceGroupId(sourceGroupId);
    try {
        jdbc.update("insert into groups_members (group_id, member_id, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid, membership_type, source_group_id) " + "values (?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?,?,?)", group.getId(), member.getId(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId(), type.getCode(), sourceGroupId);
    } catch (DuplicateKeyException ex) {
        throw new AlreadyMemberException(member);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
    return member;
}
Also used : AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Aggregations

DuplicateKeyException (org.springframework.dao.DuplicateKeyException)6 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)3 ApplicationMail (cz.metacentrum.perun.registrar.model.ApplicationMail)3 Member (cz.metacentrum.perun.core.api.Member)1 AlreadyMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 CannotAcquireLockException (org.springframework.dao.CannotAcquireLockException)1 CannotSerializeTransactionException (org.springframework.dao.CannotSerializeTransactionException)1 DataAccessException (org.springframework.dao.DataAccessException)1 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 DeadlockLoserDataAccessException (org.springframework.dao.DeadlockLoserDataAccessException)1 PermissionDeniedDataAccessException (org.springframework.dao.PermissionDeniedDataAccessException)1 TransientDataAccessResourceException (org.springframework.dao.TransientDataAccessResourceException)1 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)1 InvalidResultSetAccessException (org.springframework.jdbc.InvalidResultSetAccessException)1