use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getMemberGroupAttributes.
/**
* Returns all relevant MemberGroup RichAttributes for given user and facility.
* That means, returns all MemberGroup rich attributes for members that belong to the given user and are allowed
* and those groups that can access the given facility.
* Each rich attribute is returned only once.
*
* @param sess session
* @param user user
* @param facility facility
* @param attrDef type of attribute that will be returned
* @return List of RichAttribute
*/
private List<RichAttribute> getMemberGroupAttributes(PerunSession sess, User user, Facility facility, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberGroupMismatchException {
List<RichAttribute> listOfRichAttributes = new ArrayList<>();
// get all groups from facility
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
// get all groups from user
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
Set<Group> groupsFromMembers = new HashSet<>();
for (Member memberElement : membersFromUser) {
groupsFromMembers.addAll(getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement));
}
// retain of groups
groupsFromMembers.retainAll(groupsFromFacility);
List<Group> retainedGroups = new ArrayList<>(groupsFromMembers);
// all possible groups
for (Group groupElement : retainedGroups) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, groupElement);
membersFromGroup.retainAll(membersFromUser);
// all possibilities
for (Member memberElement : membersFromGroup) {
if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, memberElement)) {
Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute<>(memberElement, groupElement, attribute));
}
}
}
listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
return listOfRichAttributes;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getMemberResourceAttributes.
/**
* Returns all relevant MemberResource RichAttributes for given group and resource.
* That means, returns all MemberResource rich attributes for the given resource and groups that can access this
* resource via theirs allowed users.
* Each rich attribute is returned only once.
*
* @param sess session
* @param group group
* @param resource resource
* @param attrDef type of attribute that will be returned
* @return List of RichAttribute
*/
private List<RichAttribute> getMemberResourceAttributes(PerunSession sess, Group group, Resource resource, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberResourceMismatchException {
List<RichAttribute> listOfRichAttributes = new ArrayList<>();
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
membersFromGroup.retainAll(membersFromResource);
membersFromGroup = new ArrayList<>(new HashSet<>(membersFromGroup));
for (Member memberElement : membersFromGroup) {
Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, resource, attrDef.getName());
listOfRichAttributes.add(new RichAttribute<>(resource, memberElement, attribute));
}
listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
return listOfRichAttributes;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributes.
@Override
public void setAttributes(PerunSession sess, User user, List<Attribute> attributes) throws WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
// classification of attributes to attributes to remove and attributes to set
List<Attribute> attributesToRemove = new ArrayList<>();
List<Attribute> attributesToSet = new ArrayList<>();
convertEmptyAttrValueToNull(attributes);
for (Attribute attribute : attributes) {
if (attribute.getValue() == null) {
attributesToRemove.add(attribute);
} else {
attributesToSet.add(attribute);
}
}
removeAttributes(sess, user, attributesToRemove);
// if checkAttributesSyntax fails it causes rollback so no attribute will be stored
checkAttributesSyntax(sess, user, attributesToSet);
// fist we have to store attributes into DB because checkAttributesSemantics can be preformed only on stored attributes.
for (Attribute attribute : attributesToSet) {
// skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (isVirtAttribute(sess, attribute)) {
throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute.");
} else {
setAttributeWithoutCheck(sess, user, attribute);
}
}
}
// if checkAttributesSemantics fails it causes rollback so no attribute will be stored
checkAttributesSemantics(sess, user, attributesToSet);
checkAttributesDependencies(sess, user, attributesToSet);
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getMemberResourceAttributes.
/**
* Returns all relevant MemberResource RichAttributes for given resource and member.
* That means, returns all MemberResource rich attributes for the given member and resource.
* If the given member is not allowed, returns an empty list.
* Each rich attribute is returned only once.
*
* @param sess session
* @param member member
* @param resource resource
* @param attrDef type of attribute that will be returned
* @return List of RichAttribute
*/
private List<RichAttribute> getMemberResourceAttributes(PerunSession sess, Member member, Resource resource, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberResourceMismatchException {
List<RichAttribute> listOfRichAttributes = new ArrayList<>();
if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, resource, attrDef.getName());
listOfRichAttributes.add(new RichAttribute<>(resource, member, attribute));
}
listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
return listOfRichAttributes;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getEntitylessAttributeForUpdate.
@Override
public Attribute getEntitylessAttributeForUpdate(PerunSession sess, String key, String attrName) throws AttributeNotExistsException {
AttributeDefinition attrDef = this.getAttributeDefinition(sess, attrName);
Attribute attr = new Attribute(attrDef);
String value = getAttributesManagerImpl().getEntitylessAttrValueForUpdate(sess, attrDef.getId(), key);
if (value != null) {
attr.setValue(BeansUtils.stringToAttributeValue(value, attr.getType()));
}
return attr;
}
Aggregations