Search in sources :

Example 66 with Attribute

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;
}
Also used : AllAttributesRemovedForMemberAndGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMemberAndGroup) AttributeRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForGroup) AllAttributesRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup) AttributeSetForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForGroup) Group(cz.metacentrum.perun.core.api.Group) AttributeSetForMemberAndGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMemberAndGroup) AttributeRemovedForMemberAndGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMemberAndGroup) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeSetForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResourceAndMember) AllAttributesRemovedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResourceAndMember) Member(cz.metacentrum.perun.core.api.Member) AttributeSetForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMember) AllAttributesRemovedForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMember) AttributeRemovedForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMember) AttributeRemovedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResourceAndMember) HashSet(java.util.HashSet)

Example 67 with Attribute

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;
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeSetForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResourceAndMember) AllAttributesRemovedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResourceAndMember) Member(cz.metacentrum.perun.core.api.Member) AttributeSetForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMember) AllAttributesRemovedForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMember) AttributeRemovedForMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMember) AttributeRemovedForResourceAndMember(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResourceAndMember) HashSet(java.util.HashSet)

Example 68 with Attribute

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);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 69 with Attribute

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;
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 70 with Attribute

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;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1689 Test (org.junit.Test)615 ArrayList (java.util.ArrayList)492 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)489 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)478 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)313 User (cz.metacentrum.perun.core.api.User)301 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)280 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)231 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)221 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)218 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)197 Facility (cz.metacentrum.perun.core.api.Facility)190 Resource (cz.metacentrum.perun.core.api.Resource)187 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)180 List (java.util.List)177 LinkedHashMap (java.util.LinkedHashMap)158 Before (org.junit.Before)156 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)145 Method (java.lang.reflect.Method)140