use of cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException in project perun by CESNET.
the class GroupsManagerBlImpl method getGroupMemberById.
@Override
public Member getGroupMemberById(PerunSession sess, Group group, int memberId) throws NotGroupMemberException {
List<Member> members = getGroupsManagerImpl().getGroupMembersById(sess, group, memberId);
if (members.isEmpty())
throw new NotGroupMemberException("Member with ID=" + memberId + " is not member of " + group + " or doesn't exists at all.");
List<Member> filteredMembers = this.filterMembersByMembershipTypeInGroup(members);
if (filteredMembers.size() == 0)
throw new InternalErrorException("Filtering DIRECT/INDIRECT members resulted in empty members list.");
if (filteredMembers.size() > 1)
throw new ConsistencyErrorException("Filtering DIRECT/INDIRECT members resulted with >1 members with same ID.");
return filteredMembers.get(0);
}
use of cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException in project perun by CESNET.
the class GroupsManagerBlImpl method removeGroupUnion.
@Override
public void removeGroupUnion(PerunSession sess, Group resultGroup, Group operandGroup, boolean parentFlag) throws GroupRelationDoesNotExist, GroupRelationCannotBeRemoved, GroupNotExistsException {
if (!groupsManagerImpl.isOneWayRelationBetweenGroups(resultGroup, operandGroup)) {
throw new GroupRelationDoesNotExist("Union does not exist between result group " + resultGroup + " and operand group" + operandGroup + ".");
}
Map<Integer, Map<Integer, MemberGroupStatus>> previousStatuses = getPreviousStatuses(sess, operandGroup, getGroupMembers(sess, resultGroup));
if (parentFlag || groupsManagerImpl.isRelationRemovable(sess, resultGroup, operandGroup)) {
try {
removeRelationMembers(sess, resultGroup, getGroupMembers(sess, operandGroup), operandGroup.getId());
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException("Removing relation members failed. Cause: {}", ex);
} catch (NotGroupMemberException ex) {
throw new ConsistencyErrorException("Database inconsistency. Cause: {}", ex);
}
} else {
throw new GroupRelationCannotBeRemoved("Union between result group " + resultGroup + " and operand group" + operandGroup + " cannot be removed, because it's part of the hierarchical structure of the groups.");
}
groupsManagerImpl.removeGroupUnion(sess, resultGroup, operandGroup);
// recalculates statuses of members in result group
for (Member member : getGroupMembers(sess, resultGroup)) {
recalculateMemberGroupStatusRecursively(sess, member, resultGroup, previousStatuses);
}
}
use of cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException 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.NotGroupMemberException in project perun by CESNET.
the class BBMRICollections method approveApplication.
/**
* Find groups representing collections by input. Groups are looked for in subgroups
* of group the module is assigned to. Add user as a member to the groups.
*
* @param session who approves the application
* @param app application
* @return unchanged application
* @throws PerunException in case of internal error in Perun
*/
@Override
public Application approveApplication(PerunSession session, Application app) throws VoNotExistsException, UserNotExistsException, PrivilegeException, MemberNotExistsException, RegistrarException, GroupNotExistsException, AttributeNotExistsException, WrongAttributeAssignmentException, ExternallyManagedException, WrongAttributeValueException, WrongReferenceAttributeValueException, NotGroupMemberException {
// get perun and beans from session
PerunBl perun = (PerunBl) session.getPerun();
Vo vo = app.getVo();
User user = app.getUser();
Member member = perun.getMembersManagerBl().getMemberByUser(session, vo, user);
// get the field of application with the collections
Set<String> collectionIDsInApplication = getCollectionIDsFromApplication(session, app);
// get map of collection IDs to group from Perun
String directoryGroupName = this.getDirectoryGroupNameFromApplication(session, app);
Group directoryGroup;
try {
directoryGroup = perun.getGroupsManager().getGroupByName(session, vo, directoryGroupName);
} catch (GroupNotExistsException e) {
throw new InternalErrorException("Target group does not exist");
}
Map<String, Group> collectionIDsToGroupsMap = getCollectionIDsToGroupsMap(session, perun, directoryGroup);
// add user to all groups from the field on application
for (String collectionID : collectionIDsInApplication) {
Group collection = collectionIDsToGroupsMap.get(collectionID);
if (collection == null) {
log.debug("There are no groups for collectionID: {}", collectionID);
} else {
try {
perun.getGroupsManager().addMember(session, collection, member);
} catch (AlreadyMemberException ex) {
// ignore
}
}
}
try {
perun.getGroupsManager().removeMember(session, app.getGroup(), member);
} catch (MemberNotExistsException | NotGroupMemberException e) {
// we can ignore these exceptions
}
return app;
}
use of cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException in project perun by CESNET.
the class MembersManagerBlImpl method deleteMember.
@Override
public void deleteMember(PerunSession sess, Member member) throws MemberAlreadyRemovedException {
Vo vo = this.getMemberVo(sess, member);
// Remove member from all groups
List<Group> memberGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, member);
for (Group group : memberGroups) {
// Member must be removed from the members group using separate method
if (group.getName().equals(VosManager.MEMBERS_GROUP))
continue;
try {
getPerunBl().getGroupsManagerBl().removeMember(sess, group, member);
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("getMemberGroups return group where the member is not member", e);
} catch (GroupNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
// Remove member from the VO members group
try {
Group g = getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP);
try {
getPerunBl().getGroupsManagerBl().removeMemberFromMembersOrAdministratorsGroup(sess, g, member);
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("Member is not in the \"members\" group." + member + " " + g, e);
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
}
} catch (GroupNotExistsException e) {
throw new InternalErrorException(e);
}
// Remove member's attributes (namespaces: member and resource-member)
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member);
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resource : resources) {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member, resource);
}
} catch (AttributeValueException ex) {
throw new ConsistencyErrorException("Member is removed from all groups. There are no required attribute for this member. Member's attributes can be removed without problem.", ex);
} catch (MemberResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
removeAllMemberBans(sess, member);
// Remove possible links to member's sponsors
membersManagerImpl.deleteSponsorLinks(sess, member);
membersManagerImpl.rejectAllMemberOpenApplications(sess, member);
// Remove member from the DB
getMembersManagerImpl().deleteMember(sess, member);
getPerunBl().getAuditer().log(sess, new MemberDeleted(member));
}
Aggregations