Search in sources :

Example 1 with MemberNotExistsException

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

the class VosManagerBlImpl method findCandidates.

public List<Candidate> findCandidates(PerunSession sess, Vo vo, String searchString, int maxNumOfResults) throws InternalErrorException {
    List<Candidate> candidates = new ArrayList<Candidate>();
    int numOfResults = 0;
    try {
        // Iterate through all registered extSources
        for (ExtSource source : getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, vo)) {
            // Info if this is only simple ext source, change behavior if not
            boolean simpleExtSource = true;
            // Get potential subjects from the extSource
            List<Map<String, String>> subjects;
            try {
                if (source instanceof ExtSourceApi) {
                    // find subjects with all their properties
                    subjects = ((ExtSourceApi) source).findSubjects(searchString, maxNumOfResults);
                    simpleExtSource = false;
                } else {
                    // find subjects only with logins - they then must be retrieved by login
                    subjects = ((ExtSourceSimpleApi) source).findSubjectsLogins(searchString, maxNumOfResults);
                }
            } catch (ExtSourceUnsupportedOperationException e1) {
                log.warn("ExtSource {} doesn't support findSubjects", source.getName());
                continue;
            } catch (InternalErrorException e) {
                log.error("Error occurred on ExtSource {},  Exception {}.", source.getName(), e);
                continue;
            } finally {
                try {
                    ((ExtSourceSimpleApi) source).close();
                } catch (ExtSourceUnsupportedOperationException e) {
                // ExtSource doesn't support that functionality, so silently skip it.
                } catch (InternalErrorException e) {
                    log.error("Can't close extSource connection. Cause: {}", e);
                }
            }
            Set<String> uniqueLogins = new HashSet<>();
            for (Map<String, String> s : subjects) {
                // Check if the user has unique identifier within extSource
                if ((s.get("login") == null) || (s.get("login") != null && ((String) s.get("login")).isEmpty())) {
                    log.error("User '{}' cannot be added, because he/she doesn't have a unique identifier (login)", s);
                    // Skip to another user
                    continue;
                }
                String extLogin = (String) s.get("login");
                // check uniqueness of every login in extSource
                if (uniqueLogins.contains(extLogin)) {
                    throw new InternalErrorException("There are more than 1 login '" + extLogin + "' getting from extSource '" + source + "'");
                } else {
                    uniqueLogins.add(extLogin);
                }
                // Get Candidate
                Candidate candidate;
                try {
                    if (simpleExtSource) {
                        // retrieve data about subjects from ext source based on ext. login
                        candidate = getPerunBl().getExtSourcesManagerBl().getCandidate(sess, source, extLogin);
                    } else {
                        // retrieve data about subjects from subjects we already have locally
                        candidate = getPerunBl().getExtSourcesManagerBl().getCandidate(sess, s, source, extLogin);
                    }
                } catch (ExtSourceNotExistsException e) {
                    throw new ConsistencyErrorException("Getting candidate from non-existing extSource " + source, e);
                } catch (CandidateNotExistsException e) {
                    throw new ConsistencyErrorException("findSubjects returned that candidate, but getCandidate cannot find him using login " + extLogin, e);
                } catch (ExtSourceUnsupportedOperationException e) {
                    throw new InternalErrorException("extSource supports findSubjects but not getCandidate???", e);
                }
                try {
                    getPerunBl().getMembersManagerBl().getMemberByUserExtSources(sess, vo, candidate.getUserExtSources());
                    // Candidate is already a member of the VO, so do not add him to the list of candidates
                    continue;
                } catch (MemberNotExistsException e) {
                // This is OK
                }
                // Add candidate to the list of candidates
                log.debug("findCandidates: returning candidate: {}", candidate);
                candidates.add(candidate);
                numOfResults++;
                // Stop getting new members if the number of already retrieved members exceeded the maxNumOfResults
                if (maxNumOfResults > 0 && numOfResults >= maxNumOfResults) {
                    break;
                }
            }
            // Stop walking through next sources if the number of already retrieved members exceeded the maxNumOfResults
            if (maxNumOfResults > 0 && numOfResults >= maxNumOfResults) {
                break;
            }
        }
        log.debug("Returning {} potential members for vo {}", candidates.size(), vo);
        return candidates;
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ExtSourceApi(cz.metacentrum.perun.core.implApi.ExtSourceApi) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourceUnsupportedOperationException(cz.metacentrum.perun.core.api.exceptions.ExtSourceUnsupportedOperationException) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) Map(java.util.Map) ExtSourceSimpleApi(cz.metacentrum.perun.core.implApi.ExtSourceSimpleApi) HashSet(java.util.HashSet) CandidateNotExistsException(cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)

Example 2 with MemberNotExistsException

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

the class VOOT method isMemberOf.

/**
	 * Return groups that user is member of.
	 *
	 * @return                  groups that user is member of
	 * @throws VOOTException    if the can not read groups of user
	 */
private List<Group> isMemberOf() throws VOOTException {
    List<Group> groups = new ArrayList<Group>();
    List<Vo> vos = new ArrayList<Vo>();
    try {
        vos.addAll(perun.getUsersManagerBl().getVosWhereUserIsMember(session, user));
    } catch (InternalErrorException ex) {
        throw new VOOTException("internal_server_error");
    }
    try {
        for (Vo vo : vos) {
            Member member = perun.getMembersManagerBl().getMemberByUser(session, vo, user);
            groups.addAll(perun.getGroupsManagerBl().getAllMemberGroups(session, member));
        }
    } catch (InternalErrorException ex) {
        throw new VOOTException("internal_server_error");
    } catch (MemberNotExistsException ex) {
        throw new VOOTException("not_a_member");
    }
    return groups;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) ArrayList(java.util.ArrayList) Vo(cz.metacentrum.perun.core.api.Vo) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 3 with MemberNotExistsException

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

the class MembersManagerBlImpl method createMember.

// MAIN METHOD
@Override
public Member createMember(PerunSession sess, Vo vo, SpecificUserType specificUserType, Candidate candidate, List<Group> groups, List<String> overwriteUserAttributes) throws WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException {
    log.debug("Creating member for VO {} from candidate {}", vo, candidate);
    // Get the user
    User user = null;
    if (candidate.getUserExtSources() != null) {
        for (UserExtSource ues : candidate.getUserExtSources()) {
            // Check if the extSource exists
            ExtSource tmpExtSource = getPerunBl().getExtSourcesManagerBl().checkOrCreateExtSource(sess, ues.getExtSource().getName(), ues.getExtSource().getType());
            // Set the extSource ID
            ues.getExtSource().setId(tmpExtSource.getId());
            try {
                // Try to find the user by userExtSource
                user = getPerunBl().getUsersManagerBl().getUserByExtSourceNameAndExtLogin(sess, ues.getExtSource().getName(), ues.getLogin());
            } catch (UserExtSourceNotExistsException e) {
            // This is OK, non-existent userExtSource will be assigned later
            } catch (UserNotExistsException | ExtSourceNotExistsException e) {
            // Ignore, we are only checking if the user exists
            }
        }
    }
    // If user hasn't been found, then create him
    if (user == null) {
        user = new User();
        user.setFirstName(candidate.getFirstName());
        user.setLastName(candidate.getLastName());
        user.setMiddleName(candidate.getMiddleName());
        user.setTitleAfter(candidate.getTitleAfter());
        user.setTitleBefore(candidate.getTitleBefore());
        if (specificUserType.equals(SpecificUserType.SERVICE))
            user.setServiceUser(true);
        if (specificUserType.equals(SpecificUserType.SPONSORED))
            user.setSponsoredUser(true);
        // Store the user, this must be done in separate transaction
        user = getPerunBl().getUsersManagerBl().createUser(sess, user);
        log.debug("createMember: new user: {}", user);
    }
    // Assign missing userExtSource and update LoA
    if (candidate.getUserExtSources() != null) {
        for (UserExtSource userExtSource : candidate.getUserExtSources()) {
            try {
                UserExtSource currentUserExtSource = getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(sess, userExtSource.getExtSource(), userExtSource.getLogin());
                // Update LoA
                currentUserExtSource.setLoa(userExtSource.getLoa());
                getPerunBl().getUsersManagerBl().updateUserExtSource(sess, currentUserExtSource);
            } catch (UserExtSourceNotExistsException e) {
                // Create userExtSource
                try {
                    getPerunBl().getUsersManagerBl().addUserExtSource(sess, user, userExtSource);
                } catch (UserExtSourceExistsException e1) {
                    throw new ConsistencyErrorException("Adding userExtSource which already exists: " + userExtSource);
                }
            } catch (UserExtSourceExistsException e1) {
                throw new ConsistencyErrorException("Updating login of userExtSource to value which already exists: " + userExtSource);
            }
        }
    }
    try {
        Member member = getMemberByUser(sess, vo, user);
        throw new AlreadyMemberException(member);
    } catch (MemberNotExistsException IGNORE) {
    }
    // Create the member
    Member member = getMembersManagerImpl().createMember(sess, vo, user);
    getPerunBl().getAuditer().log(sess, new MemberCreated(member));
    // Create the member's attributes
    List<Attribute> membersAttributes = new ArrayList<>();
    List<Attribute> usersAttributesToMerge = new ArrayList<>();
    List<Attribute> usersAttributesToModify = new ArrayList<>();
    if (candidate.getAttributes() != null) {
        for (String attributeName : candidate.getAttributes().keySet()) {
            AttributeDefinition attributeDefinition;
            try {
                attributeDefinition = getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, attributeName);
            } catch (AttributeNotExistsException ex) {
                throw new InternalErrorException(ex);
            }
            Attribute attribute = new Attribute(attributeDefinition);
            attribute.setValue(getPerunBl().getAttributesManagerBl().stringToAttributeValue(candidate.getAttributes().get(attributeName), attribute.getType()));
            if (getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR_DEF) || getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR_OPT)) {
                // This is member's attribute
                membersAttributes.add(attribute);
            } else if (getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR_DEF) || getPerunBl().getAttributesManagerBl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR_OPT)) {
                if (overwriteUserAttributes != null && !overwriteUserAttributes.isEmpty() && overwriteUserAttributes.contains(attribute.getName())) {
                    usersAttributesToModify.add(attribute);
                } else {
                    usersAttributesToMerge.add(attribute);
                }
            }
        }
    }
    // Store the attributes
    try {
        // If empty, skip setting or merging empty arrays of attributes at all
        if (!membersAttributes.isEmpty())
            getPerunBl().getAttributesManagerBl().setAttributes(sess, member, membersAttributes);
        if (!usersAttributesToMerge.isEmpty())
            getPerunBl().getAttributesManagerBl().mergeAttributesValues(sess, user, usersAttributesToMerge);
        if (!usersAttributesToModify.isEmpty())
            getPerunBl().getAttributesManagerBl().setAttributes(sess, user, usersAttributesToModify);
    } catch (WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    }
    // Set the initial membershipExpiration
    // Get user LOA
    String memberLoa = null;
    try {
        Attribute loa = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_VIRT + ":loa");
        memberLoa = Integer.toString((Integer) loa.getValue());
    } catch (AttributeNotExistsException e) {
    // user has no loa defined - if required by VO, it will be stopped in checking method later
    } catch (WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    }
    // Check if user can be member
    this.canBeMemberInternal(sess, vo, user, memberLoa, true);
    // set initial membership expiration
    this.extendMembership(sess, member);
    insertToMemberGroup(sess, member, vo);
    // Add member also to all groups in list
    if (groups != null && !groups.isEmpty()) {
        for (Group group : groups) {
            try {
                perunBl.getGroupsManagerBl().addMember(sess, group, member);
            } catch (GroupNotExistsException e) {
                throw new ConsistencyErrorException(e);
            }
        }
    }
    return member;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) ParentGroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.ParentGroupNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) MemberCreated(cz.metacentrum.perun.audit.events.MembersManagerEvents.MemberCreated) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 4 with MemberNotExistsException

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

the class EventServiceResolverImpl method resolveEvent.

// ----- methods -------------------------------------
@Override
public Map<Facility, Set<Service>> resolveEvent(AuditEvent event) throws InvalidEventMessageException, ServiceNotExistsException, PrivilegeException {
    log.info("Event - I am going to process event: {}", event);
    Map<Facility, Set<Service>> result = new HashMap<Facility, Set<Service>>();
    if (event instanceof EngineIgnoreEvent) {
        log.info("Event ignored {} facilities will be returned", result.size());
        return result;
    }
    // GET All Beans (only PerunBeans) from message
    List<PerunBean> listOfBeans = new ArrayList<PerunBean>();
    listOfBeans = AuditParser.parseLog(event.getMessage());
    // Prepare variables
    AttributeDefinition attributeDefinition = null;
    Facility facility = null;
    Resource resource = null;
    Group group = null;
    User user = null;
    Member member = null;
    Service service = null;
    Host host = null;
    // TODO: What about more than 1 resources, or more than 1 facilities etc. ?
    for (PerunBean pb : listOfBeans) {
        if (pb instanceof AttributeDefinition) {
            attributeDefinition = (AttributeDefinition) pb;
        } else if (pb instanceof Facility) {
            facility = (Facility) pb;
        } else if (pb instanceof Resource) {
            resource = (Resource) pb;
        } else if (pb instanceof Group) {
            group = (Group) pb;
        } else if (pb instanceof User) {
            user = (User) pb;
        } else if (pb instanceof Member) {
            member = (Member) pb;
        } else if (pb instanceof Service) {
            service = (Service) pb;
        } else if (pb instanceof Host) {
            host = (Host) pb;
        }
    }
    // If there is any attribute, so create AttributeDefinition
    if (attributeDefinition != null) {
        log.debug("Attribute found in event. {}.", attributeDefinition);
    }
    List<Facility> facilitiesResolvedFromEvent = new ArrayList<Facility>();
    List<Resource> resourcesResolvedFromEvent = new ArrayList<Resource>();
    List<Service> servicesResolvedFromEvent = new ArrayList<Service>();
    if (perunSession == null) {
        perunSession = perun.getPerunSession(new PerunPrincipal(dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), dispatcherProperties.getProperty("perun.principal.extSourceType")), new PerunClient());
    }
    // Try to find FACILITY in event
    if (facility != null) {
        try {
            log.debug("Facility found in event. {}.", facility);
            facilitiesResolvedFromEvent.add(facility);
            resourcesResolvedFromEvent.addAll(perun.getFacilitiesManager().getAssignedResources(perunSession, facility));
        } catch (FacilityNotExistsException ex) {
            log.warn("Non-existing facility found while resolving event. id={}", facility.getId());
        }
    } else {
        // Try to find RESOURCE in event
        if (resource != null) {
            resourcesResolvedFromEvent.add(resource);
        } else {
            // Try to find GROUP in event
            if (group != null) {
                try {
                    resourcesResolvedFromEvent = perun.getResourcesManager().getAssignedResources(perunSession, group);
                } catch (GroupNotExistsException ex) {
                    log.warn("Non-existing group found while resolving event. id={}", group.getId());
                }
            } else {
                // try to find USER in event
                if (user != null) {
                    try {
                        resourcesResolvedFromEvent = perun.getUsersManager().getAllowedResources(perunSession, user);
                    } catch (UserNotExistsException ex) {
                        log.warn("Non-existing user found while resolving event. id={}", user.getId());
                    }
                } else {
                    // try to find MEMBER in event
                    if (member != null) {
                        try {
                            resourcesResolvedFromEvent = perun.getResourcesManager().getAllowedResources(perunSession, member);
                        } catch (MemberNotExistsException ex) {
                            log.warn("Non-existing member found while resolving event. id={}", member.getId());
                        }
                    } else {
                        // try to find HOST in event
                        if (host != null) {
                            try {
                                log.debug("Host found in event.id= {}.", host.getId());
                                facility = perun.getFacilitiesManager().getFacilityForHost(perunSession, host);
                                facilitiesResolvedFromEvent.add(facility);
                                resourcesResolvedFromEvent.addAll(perun.getFacilitiesManager().getAssignedResources(perunSession, facility));
                            } catch (FacilityNotExistsException ex) {
                                log.warn("Host on non-existing facility found while resolving event. Host id={}", host.getId());
                            } catch (HostNotExistsException ex) {
                                log.warn("Non-existing host found while resolving event. id={}", host.getId());
                            }
                        } else {
                            log.warn("No match found for this event. Event={}", event);
                        }
                    }
                }
            }
        }
    }
    // TODO resolve more than one service
    if (service != null) {
        servicesResolvedFromEvent.add(service);
    }
    for (Resource r : resourcesResolvedFromEvent) {
        Facility facilityResolvedFromEvent;
        List<Service> servicesResolvedFromResource;
        try {
            facilityResolvedFromEvent = perun.getResourcesManager().getFacility(perunSession, r);
            servicesResolvedFromResource = perun.getResourcesManager().getAssignedServices(perunSession, r);
            // process only services resolved from event if any
            if (!servicesResolvedFromEvent.isEmpty())
                servicesResolvedFromResource.retainAll(servicesResolvedFromEvent);
        } catch (ResourceNotExistsException ex) {
            log.error("Non-existing resource found while resolving event. Resource={}", r);
            // skip to next resource
            continue;
        }
        for (Service s : servicesResolvedFromResource) {
            if (attributeDefinition != null) {
                // remove from future processing services
                // which don't require the found attribute
                // TODO (CHECKME) This method can raise
                // ServiceNotExistsException. Is it ok? Or it must be
                // catch?
                List<AttributeDefinition> serviceRequiredAttributes = perun.getAttributesManager().getRequiredAttributesDefinition(perunSession, s);
                if (!serviceRequiredAttributes.contains(attributeDefinition))
                    continue;
            }
            if (!result.containsKey(facilityResolvedFromEvent)) {
                Set<Service> servicesToPut = new HashSet<Service>();
                servicesToPut.add(s);
                result.put(facilityResolvedFromEvent, servicesToPut);
            } else {
                result.get(facilityResolvedFromEvent).add(s);
            }
        }
    }
    log.info("{} facilities will be returned", result.size());
    return result;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) HashSet(java.util.HashSet) Set(java.util.Set) User(cz.metacentrum.perun.core.api.User) HashMap(java.util.HashMap) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) HostNotExistsException(cz.metacentrum.perun.core.api.exceptions.HostNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) Service(cz.metacentrum.perun.core.api.Service) Host(cz.metacentrum.perun.core.api.Host) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) EngineIgnoreEvent(cz.metacentrum.perun.audit.events.EngineIgnoreEvent) PerunBean(cz.metacentrum.perun.core.api.PerunBean) PerunClient(cz.metacentrum.perun.core.api.PerunClient) Facility(cz.metacentrum.perun.core.api.Facility)

Example 5 with MemberNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException 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)

Aggregations

MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)36 Member (cz.metacentrum.perun.core.api.Member)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)22 ArrayList (java.util.ArrayList)21 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)14 User (cz.metacentrum.perun.core.api.User)12 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)11 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)10 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)10 Attribute (cz.metacentrum.perun.core.api.Attribute)9 Group (cz.metacentrum.perun.core.api.Group)9 HashSet (java.util.HashSet)9 RichUser (cz.metacentrum.perun.core.api.RichUser)8 Vo (cz.metacentrum.perun.core.api.Vo)8 Map (java.util.Map)8 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)7 ExtSource (cz.metacentrum.perun.core.api.ExtSource)7 RichMember (cz.metacentrum.perun.core.api.RichMember)7 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)7 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)7