use of cz.metacentrum.perun.core.api.AttributeDefinition in project perun by CESNET.
the class MembersManagerBlImpl method getRichMembersWithAttributesByNames.
@Override
public List<RichMember> getRichMembersWithAttributesByNames(PerunSession sess, Vo vo, List<String> attrsNames) throws AttributeNotExistsException {
List<Member> members = new ArrayList<>(perunBl.getMembersManagerBl().getMembers(sess, vo));
List<RichMember> richMembers = this.convertMembersToRichMembers(sess, members);
List<AttributeDefinition> attrsDef = new ArrayList<>();
for (String atrrName : attrsNames) {
AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, atrrName);
attrsDef.add(attrDef);
}
return this.convertMembersToRichMembersWithAttributes(sess, richMembers, attrsDef);
}
use of cz.metacentrum.perun.core.api.AttributeDefinition in project perun by CESNET.
the class MembersManagerBlImpl method sponsorMember.
@Override
public Member sponsorMember(PerunSession session, Member sponsoredMember, User sponsor, LocalDate validityTo) throws MemberNotSponsoredException, AlreadySponsorException, UserNotInRoleException {
// check that sponsoring user has role SPONSOR for the VO
Vo vo = getMemberVo(session, sponsoredMember);
if (!getPerunBl().getVosManagerBl().isUserInRoleForVo(session, sponsor, Role.SPONSOR, vo, true)) {
throw new UserNotInRoleException("user " + sponsor.getId() + " is not in role SPONSOR for VO " + vo.getId());
}
if (!sponsoredMember.isSponsored()) {
throw new MemberNotSponsoredException("member " + sponsoredMember.getId() + " is not marked as sponsored");
}
// check whether the user is already sponsor
List<User> sponsors = getPerunBl().getUsersManagerBl().getSponsors(session, sponsoredMember);
if (sponsors.stream().map(PerunBean::getId).anyMatch(id -> id == sponsor.getId())) {
throw new AlreadySponsorException("member " + sponsoredMember.getId() + " is already sponsored by user " + sponsor.getId());
}
// add the sponsor
getMembersManagerImpl().addSponsor(session, sponsoredMember, sponsor, validityTo);
// remove expiration and validate member
try {
AttributeDefinition expiration = getPerunBl().getAttributesManagerBl().getAttributeDefinition(session, EXPIRATION);
getPerunBl().getAttributesManagerBl().removeAttribute(session, sponsoredMember, expiration);
} catch (WrongAttributeAssignmentException | AttributeNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException("cannot remove expiration date for sponsored member " + sponsoredMember.getId(), ex);
}
try {
validateMember(session, sponsoredMember);
} catch (WrongReferenceAttributeValueException | WrongAttributeValueException ex) {
throw new InternalErrorException("cannot validate sponsored member " + sponsoredMember.getId(), ex);
}
getPerunBl().getAuditer().log(session, new SponsorshipEstablished(sponsoredMember, sponsor, validityTo));
return sponsoredMember;
}
use of cz.metacentrum.perun.core.api.AttributeDefinition in project perun by CESNET.
the class MembersManagerBlImpl method convertMembersToRichMembersWithAttributes.
/**
* Adds userAttributes and memberAttributes to rich members.
* Specifically adds attributes that are associated with the members and the resource. Attributes are also limited by the list of attributes definitions.
* Adds member and member-resource attributes to memberAttributes and user and user-facility attributes to userAttributes.
* The method returns list of rich members with userAttributes and memberAttributes filled.
*
* @param sess
* @param richMembers
* @param resource
* @param attrsDef
* @return list of rich members with userAttributes and memberAttributes filled
* @throws InternalErrorException
* @throws WrongAttributeAssignmentException
*/
@Override
public List<RichMember> convertMembersToRichMembersWithAttributes(PerunSession sess, List<RichMember> richMembers, Resource resource, List<AttributeDefinition> attrsDef) throws MemberResourceMismatchException {
List<String> attrNames = new ArrayList<>();
for (AttributeDefinition attributeDefinition : attrsDef) {
attrNames.add(attributeDefinition.getName());
}
for (RichMember richMember : richMembers) {
List<Attribute> userAttributes = new ArrayList<>();
List<Attribute> memberAttributes = new ArrayList<>();
List<Attribute> attributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, richMember, resource, attrNames, true);
for (Attribute attribute : attributes) {
if (attribute.getName().startsWith(AttributesManager.NS_USER_ATTR))
userAttributes.add(attribute);
else if (attribute.getName().startsWith(AttributesManager.NS_USER_FACILITY_ATTR))
userAttributes.add(attribute);
else if (attribute.getName().startsWith(AttributesManager.NS_MEMBER_ATTR))
memberAttributes.add(attribute);
else if (attribute.getName().startsWith(AttributesManager.NS_MEMBER_RESOURCE_ATTR))
memberAttributes.add(attribute);
else {
throw new InternalErrorException(attribute + " is not from user or member namespace (member-resource, user-facility included)!");
}
}
richMember.setUserAttributes(userAttributes);
richMember.setMemberAttributes(memberAttributes);
}
return richMembers;
}
use of cz.metacentrum.perun.core.api.AttributeDefinition in project perun by CESNET.
the class MembersManagerBlImpl method convertMembersToRichMembersWithAttributes.
/**
* Adds userAttributes and memberAttributes to rich members.
* Attributes are limited by the list of attributes definitions.
* The method returns list of rich members with userAttributes and memberAttributes filled.
*
* @param sess
* @param richMembers
* @param attrsDef
* @return list of rich members with userAttributes and memberAttributes filled
* @throws InternalErrorException
*/
@Override
public List<RichMember> convertMembersToRichMembersWithAttributes(PerunSession sess, List<RichMember> richMembers, List<AttributeDefinition> attrsDef) {
List<AttributeDefinition> usersAttributesDef = new ArrayList<>();
List<AttributeDefinition> membersAttributesDef = new ArrayList<>();
for (AttributeDefinition attrd : attrsDef) {
if (attrd.getName().startsWith(AttributesManager.NS_USER_ATTR))
usersAttributesDef.add(attrd);
else if (attrd.getName().startsWith(AttributesManager.NS_MEMBER_ATTR))
membersAttributesDef.add(attrd);
}
for (RichMember richMember : richMembers) {
List<String> userAttrNames = new ArrayList<>();
for (AttributeDefinition ad : usersAttributesDef) {
userAttrNames.add(ad.getName());
}
List<Attribute> userAttributes = new ArrayList<>(getPerunBl().getAttributesManagerBl().getAttributes(sess, richMember.getUser(), userAttrNames));
List<String> memberAttrNames = new ArrayList<>();
for (AttributeDefinition ad : membersAttributesDef) {
memberAttrNames.add(ad.getName());
}
List<Attribute> memberAttributes = new ArrayList<>(getPerunBl().getAttributesManagerBl().getAttributes(sess, richMember, memberAttrNames));
richMember.setUserAttributes(userAttributes);
richMember.setMemberAttributes(memberAttributes);
}
return richMembers;
}
use of cz.metacentrum.perun.core.api.AttributeDefinition in project perun by CESNET.
the class SearcherBlImpl method getFacilities.
@Override
public List<Facility> getFacilities(PerunSession sess, Map<String, String> attributesWithSearchingValues) throws AttributeNotExistsException, WrongAttributeAssignmentException {
if (attributesWithSearchingValues == null || attributesWithSearchingValues.isEmpty()) {
return perunBl.getFacilitiesManagerBl().getFacilities(sess);
}
Map<Attribute, String> mapOfAttrsWithValues = new HashMap<>();
Map<AttributeDefinition, String> mapOfCoreAttributesWithValues = new HashMap<>();
for (String name : attributesWithSearchingValues.keySet()) {
if (name == null || name.equals("")) {
throw new AttributeNotExistsException("There is no attribute with specified name!");
}
AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, name);
if (getPerunBl().getAttributesManagerBl().isCoreAttribute(sess, attrDef)) {
mapOfCoreAttributesWithValues.put(attrDef, attributesWithSearchingValues.get(name));
} else {
mapOfAttrsWithValues.put(new Attribute(attrDef), attributesWithSearchingValues.get(name));
}
}
List<Facility> facilitiesFromCoreAttributes = getFacilitiesForCoreAttributesByMapOfAttributes(sess, mapOfCoreAttributesWithValues);
List<Facility> facilitiesFromAttributes = getSearcherImpl().getFacilities(sess, mapOfAttrsWithValues);
facilitiesFromCoreAttributes.retainAll(facilitiesFromAttributes);
return facilitiesFromCoreAttributes;
}
Aggregations