use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class GroupsManagerBlImpl method removeDirectMember.
private void removeDirectMember(PerunSession sess, Group group, Member member) throws NotGroupMemberException, GroupNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException {
lockGroupMembership(group, Collections.singletonList(member));
Map<Integer, Map<Integer, MemberGroupStatus>> previousStatuses = getPreviousStatuses(sess, group, List.of(member));
member.setSourceGroupId(group.getId());
getGroupsManagerImpl().removeMember(sess, group, member);
if (this.getGroupsManagerImpl().isGroupMember(sess, group, member)) {
getPerunBl().getAuditer().log(sess, new DirectMemberRemovedFromGroup(member, group));
// If member was indirect in group before, we don't need to change anything in other groups
return;
} else {
notifyMemberRemovalFromGroup(sess, group, member);
// remove all member-group attributes because member is not part of group any more
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member, group);
} catch (MemberGroupMismatchException e) {
throw new InternalErrorException(e);
}
getPerunBl().getAuditer().log(sess, new MemberRemovedFromGroupTotally(member, group));
}
// check all relations with this group and call removeRelationMembers to reflect changes of removing member from group
List<Integer> relations = groupsManagerImpl.getResultGroupsIds(sess, group.getId());
for (Integer groupId : relations) {
removeRelationMembers(sess, groupsManagerImpl.getGroupById(sess, groupId), Collections.singletonList(member), group.getId());
}
if (!VosManager.MEMBERS_GROUP.equals(group.getName())) {
recalculateMemberGroupStatusRecursively(sess, member, group, previousStatuses);
}
if (!getGroupsManagerImpl().isGroupMember(sess, group, member)) {
addMemberToGroupsFromTriggerAttribute(sess, group, member);
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class GroupsManagerBlImpl method reactivateMember.
@Override
public void reactivateMember(PerunSession sess, Member member, Group group) throws MemberNotExistsException {
// only direct membership has own status and expiration, indirect membership get it's status and expiration from origin group
if (!isDirectGroupMember(sess, group, member))
throw new MemberNotExistsException("Member does not belong to this group");
validateMemberInGroup(sess, member, group);
// Get current membershipExpiration date attribute
Attribute membershipExpirationAttribute = getMemberExpiration(sess, member, group);
// Set new value of the membershipExpiration for the member
membershipExpirationAttribute.setValue(null);
try {
getPerunBl().getAttributesManagerBl().setAttribute(sess, member, group, membershipExpirationAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException("Wrong value: " + membershipExpirationAttribute.getValue(), e);
} catch (WrongReferenceAttributeValueException | WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
} catch (MemberGroupMismatchException e) {
throw new ConsistencyErrorException(e);
}
try {
extendMembershipInGroup(sess, member, group);
} catch (ExtendMembershipException ex) {
// This exception should not be thrown for null membershipExpiration attribute
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class GroupsManagerBlImpl method extendMembershipInGroup.
private void extendMembershipInGroup(PerunSession sess, Member member, Group group, boolean setValue) throws ExtendMembershipException {
Attribute membershipExpirationRulesAttribute = getMembershipExpirationRulesAttribute(sess, group);
if (membershipExpirationRulesAttribute == null) {
return;
}
LinkedHashMap<String, String> membershipExpirationRules = membershipExpirationRulesAttribute.valueAsMap();
LocalDate localDate = LocalDate.now();
// Get current membershipExpiration date
Attribute membershipExpirationAttribute = getMemberExpiration(sess, member, group);
checkLoaForExpiration(sess, membershipExpirationRules, membershipExpirationAttribute, member);
String period = null;
// Default extension
if (membershipExpirationRules.get(AbstractMembershipExpirationRulesModule.membershipPeriodKeyName) != null) {
period = membershipExpirationRules.get(AbstractMembershipExpirationRulesModule.membershipPeriodKeyName);
}
String loaPeriod = getLoaPeriod(sess, member, membershipExpirationRules, membershipExpirationAttribute);
if (loaPeriod != null) {
period = loaPeriod;
}
// Do we extend for x months or for static date?
if (period != null) {
if (period.startsWith("+")) {
localDate = extendForMonths(localDate, period, membershipExpirationRules, membershipExpirationAttribute, member, group);
} else {
// We will extend to particular date
localDate = extendForStaticDate(localDate, period, membershipExpirationRules, membershipExpirationAttribute, member, group);
}
}
if (setValue) {
// Set new value of the membershipExpiration for the member
membershipExpirationAttribute.setValue(localDate.toString());
try {
getPerunBl().getAttributesManagerBl().setAttribute(sess, member, group, membershipExpirationAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException("Wrong value: " + membershipExpirationAttribute.getValue(), e);
} catch (WrongReferenceAttributeValueException | WrongAttributeAssignmentException | MemberGroupMismatchException e) {
throw new InternalErrorException(e);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class GroupsManagerBlImpl method getRichGroupsWithAttributesAssignedToResource.
@Override
public List<RichGroup> getRichGroupsWithAttributesAssignedToResource(PerunSession sess, Member member, Resource resource, List<String> attrNames) {
List<Group> assignedGroups = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
assignedGroups.retainAll(perunBl.getGroupsManagerBl().getAllMemberGroups(sess, member));
try {
return this.convertGroupsToRichGroupsWithAttributes(sess, member, resource, assignedGroups, attrNames);
} catch (GroupResourceMismatchException | MemberGroupMismatchException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class ServicesManagerBlImpl method getData.
private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, Group group, Map<Member, ServiceAttributes> memberAttributes, boolean filterExpiredMembers) {
ServiceAttributes groupServiceAttributes = new ServiceAttributes();
try {
// add group and group_resource attributes
groupServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource, group, true));
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
ServiceAttributes groupsMembersElement = new ServiceAttributes();
// Invalid and disabled are not allowed here
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
if (filterExpiredMembers) {
List<Member> membersToRemove = new ArrayList<>();
for (Member member : members) {
if (member.getGroupStatus() == MemberGroupStatus.EXPIRED) {
membersToRemove.add(member);
}
}
members.removeAll(membersToRemove);
}
for (Member member : members) {
// append also member_group attributes for each member in a group
// rest of member/user attributes was passed in a param if present
ServiceAttributes tempAttrs = new ServiceAttributes();
if (memberAttributes.get(member) != null) {
tempAttrs.addAttributes(memberAttributes.get(member).getAttributes());
}
try {
tempAttrs.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, member, group));
} catch (MemberGroupMismatchException e) {
throw new InternalErrorException(e);
}
groupsMembersElement.addChildElement(tempAttrs);
}
// Services expect members to be second child element, so we create empty ServiceAttributes where subgroups used to be.
groupServiceAttributes.addChildElement(new ServiceAttributes());
groupServiceAttributes.addChildElement(groupsMembersElement);
return groupServiceAttributes;
}
Aggregations