Search in sources :

Example 1 with BanAlreadyExistsException

use of cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException in project perun by CESNET.

the class ResourcesManagerBlImpl method setBan.

@Override
public BanOnResource setBan(PerunSession sess, BanOnResource banOnResource) throws BanAlreadyExistsException {
    if (this.banExists(sess, banOnResource.getMemberId(), banOnResource.getResourceId()))
        throw new BanAlreadyExistsException(banOnResource);
    banOnResource = getResourcesManagerImpl().setBan(sess, banOnResource);
    getPerunBl().getAuditer().log(sess, new BanSetForResource(banOnResource, banOnResource.getMemberId(), banOnResource.getResourceId()));
    return banOnResource;
}
Also used : BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource)

Example 2 with BanAlreadyExistsException

use of cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException in project perun by CESNET.

the class MembersManagerBlImpl method moveMembersBans.

/**
 * Moves bans on resources and ban on VO from source member to target member.
 *
 * @param sess
 * @param sourceMember member to move bans from
 * @param targetMember member to move bans to
 */
private void moveMembersBans(PerunSession sess, Member sourceMember, Member targetMember) {
    // move members bans on resources
    List<BanOnResource> bansOnResources = getPerunBl().getResourcesManagerBl().getBansForMember(sess, sourceMember.getId());
    for (BanOnResource banOnResource : bansOnResources) {
        try {
            banOnResource.setMemberId(targetMember.getId());
            getPerunBl().getResourcesManagerBl().setBan(sess, banOnResource);
        } catch (BanAlreadyExistsException e) {
            log.warn("Moving ban on resource {} from source member {} to target member {}, but the target member" + " already has ban on the resource.", banOnResource, sourceMember, targetMember);
        }
    }
    // move members ban on VO
    Optional<BanOnVo> banOnVo = getPerunBl().getVosManagerBl().getBanForMember(sess, sourceMember.getId());
    if (banOnVo.isPresent()) {
        banOnVo.get().setMemberId(targetMember.getId());
        try {
            getPerunBl().getVosManagerBl().setBan(sess, banOnVo.get());
        } catch (MemberNotExistsException e) {
            throw new InternalErrorException(e);
        }
    }
}
Also used : BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource)

Example 3 with BanAlreadyExistsException

use of cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException in project perun by CESNET.

the class FacilitiesManagerBlImpl method setBan.

@Override
public BanOnFacility setBan(PerunSession sess, BanOnFacility banOnFacility) throws BanAlreadyExistsException {
    if (this.banExists(sess, banOnFacility.getUserId(), banOnFacility.getFacilityId()))
        throw new BanAlreadyExistsException(banOnFacility);
    banOnFacility = getFacilitiesManagerImpl().setBan(sess, banOnFacility);
    getPerunBl().getAuditer().log(sess, new BanSetForFacility(banOnFacility, banOnFacility.getUserId(), banOnFacility.getFacilityId()));
    return banOnFacility;
}
Also used : BanAlreadyExistsException(cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException) BanSetForFacility(cz.metacentrum.perun.audit.events.FacilityManagerEvents.BanSetForFacility)

Aggregations

BanAlreadyExistsException (cz.metacentrum.perun.core.api.exceptions.BanAlreadyExistsException)3 BanSetForFacility (cz.metacentrum.perun.audit.events.FacilityManagerEvents.BanSetForFacility)1 BanSetForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)1