use of cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException in project perun by CESNET.
the class GroupsManagerBlImpl method removeFormerMemberWhileSynchronization.
/**
* Remove former member from group (if he is not listed in ExtSource).
*
* If this is membersGroup (of some Vo) try to disableMember, if not possible then delete him.
* If this is regular group (of some Vo) remove him and if this group is also
* his last authoritative group, disable or delete him also in the Vo.
*
* This method runs in separate transaction.
*
* @param sess perun session
* @param group to be synchronized
* @param memberToRemove member to be removed from Group
*
* @throws GroupNotExistsException if group does not exist
*/
public void removeFormerMemberWhileSynchronization(PerunSession sess, Group group, RichMember memberToRemove, boolean isAuthoritative) throws GroupNotExistsException {
// Member is missing in the external group, so remove him from the perun group
try {
// members group
if (group.getName().equals(VosManager.MEMBERS_GROUP)) {
// If the group is members group, the member must be disabled as a member of VO
removeMemberFromMembersGroup(sess, group, memberToRemove);
// not members group
} else {
// If Yes = deleteMember (from Vo), if No = only removeMember
if (isAuthoritative) {
removeMemberFromAuthoritativeGroup(sess, group, memberToRemove);
} else {
getPerunBl().getGroupsManagerBl().removeMember(sess, group, memberToRemove);
log.info("Group synchronization {}: Member id {} removed.", group, memberToRemove.getId());
}
}
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("Trying to remove non-existing user");
} catch (MemberAlreadyRemovedException ex) {
// Member was probably removed before starting of synchronization removing process, log it and skip this member
log.debug("Member {} was removed from group {} before removing process. Skip this member.", memberToRemove, group);
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException in project perun by CESNET.
the class MembersManagerBlImpl method moveMembership.
@Override
public void moveMembership(PerunSession sess, Vo vo, User sourceUser, User targetUser) throws MemberNotExistsException, AlreadyMemberException, ExtendMembershipException {
Member sourceMember = this.getMemberByUserId(sess, vo, sourceUser.getId());
List<Group> directGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, sourceMember);
List<Group> synchronizedGroups = new ArrayList<>();
try {
for (Group group : directGroups) {
Attribute attrSynchronizeEnabled = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, getPerunBl().getGroupsManager().GROUPSYNCHROENABLED_ATTRNAME);
if ("true".equals(attrSynchronizeEnabled.getValue())) {
synchronizedGroups.add(group);
}
}
} catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
throw new InternalErrorException(e);
}
Member targetMember;
try {
// create targetMember and add him to all direct groups that are not synchronized
directGroups.removeAll(synchronizedGroups);
targetMember = this.createMember(sess, vo, targetUser, directGroups);
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
}
// add 'members' group to directGroups to move its member-group attributes too
try {
directGroups.add(getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP));
} catch (GroupNotExistsException e) {
throw new InternalErrorException(e);
}
moveMembersAttributes(sess, vo, sourceMember, targetMember, directGroups);
// first validate member to prevent MemberNotValidYetException later
try {
this.validateMember(sess, targetMember);
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
}
if (sourceMember.getStatus() != Status.VALID) {
try {
this.setStatus(sess, targetMember, sourceMember.getStatus());
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException | MemberNotValidYetException e) {
throw new InternalErrorException(e);
}
}
getMembersManagerImpl().moveMembersApplications(sess, sourceMember, targetMember);
moveMembersSponsorships(sess, vo, sourceUser, targetUser, sourceMember, targetMember);
moveMembersBans(sess, sourceMember, targetMember);
try {
this.deleteMember(sess, sourceMember);
} catch (MemberAlreadyRemovedException e) {
log.warn("Trying to delete already deleted member {}. Exception: {}", sourceMember, e);
}
}
Aggregations