Search in sources :

Example 71 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class AttributesManagerBlImpl method removeAllAttributes.

@Override
public void removeAllAttributes(PerunSession sess, Group group) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<Attribute> attributes = getAttributes(sess, group);
    if (getAttributesManagerImpl().removeAllAttributes(sess, group)) {
        getPerunBl().getAuditer().log(sess, new AllAttributesRemovedForGroup(group));
    }
    log.info("{} removed all attributes from group {}.", sess.getLogId(), group.getId());
    for (Attribute attribute : attributes) attribute.setValue(null);
    try {
        checkAttributesSemantics(sess, group, attributes);
        checkAttributesDependencies(sess, group, attributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    }
    for (Attribute attribute : attributes) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, group, new Attribute(attribute));
        } catch (WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) AllAttributesRemovedForGroup(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForGroup) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 72 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.
 * That means, returns all MemberResource rich attributes for the given resource and for those members that can
 * access the given resource and are allowed.
 * Each rich attribute is returned only once.
 *
 * @param sess     session
 * @param resource resource
 * @param attrDef  type of attribute that will be returned
 * @return List of RichAttribute
 */
private List<RichAttribute> getMemberResourceAttributes(PerunSession sess, Resource resource, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberResourceMismatchException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    List<Member> members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    for (Member memberElement : members) {
        if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, memberElement)) {
            Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, resource, attrDef.getName());
            listOfRichAttributes.add(new RichAttribute<>(resource, memberElement, attribute));
        }
    }
    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)

Example 73 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class AttributesManagerBlImpl method removeAttribute.

@Override
public void removeAttribute(PerunSession sess, User user, AttributeDefinition attribute) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (removeAttributeWithoutCheck(sess, user, attribute)) {
        checkAttributeSemantics(sess, user, new Attribute(attribute));
        checkAttributeDependencies(sess, new RichAttribute<>(user, null, new Attribute(attribute)));
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute)

Example 74 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 member and group.
 * That means, returns all MemberGroup rich attributes for the given member and group.
 * If the member is not allowed, an empty list is returned.
 * Each rich attribute is returned only once.
 *
 * @param sess    session
 * @param member  member
 * @param group   group
 * @param attrDef type of attribute that will be returned
 * @return List of RichAttribute
 */
private List<RichAttribute> getMemberGroupAttributes(PerunSession sess, Member member, Group group, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberGroupMismatchException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
        Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, group, attrDef.getName());
        listOfRichAttributes.add(new RichAttribute<>(member, group, attribute));
    }
    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)

Example 75 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class AttributesManagerBlImpl method getEntitylessAttributes.

/**
 * Returns all entityless rich attributes for the given key.
 * Each rich attribute is returned only once.
 *
 * @param sess    session
 * @param key     key
 * @param attrDef type of attribute that will be returned
 * @return List of RichAttribute
 */
private List<RichAttribute> getEntitylessAttributes(PerunSession sess, String key, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, key, attrDef.getName());
    listOfRichAttributes.add(new RichAttribute<>(key, null, 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)

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