Search in sources :

Example 31 with AttributeDefinition

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

the class urn_perun_resource_attribute_def_def_defaultDataQuota method getAttributeDefinition.

@Override
public AttributeDefinition getAttributeDefinition() {
    AttributeDefinition attr = new AttributeDefinition();
    attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_DEF);
    attr.setFriendlyName("defaultDataQuota");
    attr.setDisplayName("Default data quota");
    attr.setType(String.class.getName());
    attr.setDescription("Soft quota including units (M, G, T, ...), G is default.");
    return attr;
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 32 with AttributeDefinition

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

the class AttributesManagerBlImpl method getEntitylessAttributesWithKeys.

@Override
public Map<String, Attribute> getEntitylessAttributesWithKeys(PerunSession sess, String attrName) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    AttributeDefinition definition = getAttributeDefinition(sess, attrName);
    List<String> keys = getEntitylessKeys(sess, definition);
    return getEntitylessAttributesWithKeys(sess, attrName, keys);
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 33 with AttributeDefinition

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

the class AttributesManagerBlImpl method removeAttributes.

private void removeAttributes(PerunSession sess, Resource resource, Member member, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, MemberResourceMismatchException {
    if (!(workWithUserAttributes)) {
        removeAttributes(sess, member, resource, attributes);
    } else {
        List<AttributeDefinition> attributesToCheck = new ArrayList<>();
        for (AttributeDefinition attribute : attributes) {
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
                User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
                if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, member, resource, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, facility, user, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_USER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, user, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_MEMBER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, member, attribute))
                        attributesToCheck.add(attribute);
                } else {
                    throw new WrongAttributeAssignmentException(attribute);
                }
            }
        }
        checkAttributesSemantics(sess, member, resource, attributesFromDefinitions(attributesToCheck), true);
        checkAttributesDependencies(sess, member, resource, attributesFromDefinitions(attributesToCheck), true);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) AllUserFacilityAttributesRemovedForFacilitiesAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllUserFacilityAttributesRemovedForFacilitiesAndUser) AttributeRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacilityAndUser) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) AllAttributesRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForFacilityAndUser) AttributeSetForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacilityAndUser) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AttributeRemovedForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility) Facility(cz.metacentrum.perun.core.api.Facility) AttributeSetForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility)

Example 34 with AttributeDefinition

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

private boolean removeAttributeWithoutCheck(PerunSession sess, UserExtSource ues, AttributeDefinition attribute) throws WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_UES_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, ues, attribute);
    if (changed) {
        getAttributesManagerImpl().changedAttributeHook(sess, ues, new Attribute(attribute));
        log.info("{} removed attribute {} from user external source {}.", sess.getLogId(), attribute.getName(), ues.getId());
        getPerunBl().getAuditer().log(sess, new AttributeRemovedForUes(new AttributeDefinition(attribute), ues));
    }
    return changed;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeRemovedForUes(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUes) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 35 with AttributeDefinition

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

the class AttributesManagerBlImpl method removeAttributes.

@Override
public void removeAttributes(PerunSession sess, Resource resource, Group group, List<? extends AttributeDefinition> attributes, boolean workWithGroupAttributes) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
    if (!workWithGroupAttributes) {
        removeAttributes(sess, resource, group, attributes);
    } else {
        List<AttributeDefinition> attributesToCheck = new ArrayList<>();
        for (AttributeDefinition attribute : attributes) {
            // skip core attributes
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, resource, group, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_GROUP_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, group, attribute))
                        attributesToCheck.add(attribute);
                } else {
                    throw new WrongAttributeAssignmentException(attribute);
                }
            }
        }
        checkAttributesSemantics(sess, resource, group, attributesFromDefinitions(attributesToCheck), true);
        checkAttributesDependencies(sess, group, resource, attributesFromDefinitions(attributesToCheck), true);
    }
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Aggregations

AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)764 Attribute (cz.metacentrum.perun.core.api.Attribute)311 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)171 ArrayList (java.util.ArrayList)111 Test (org.junit.Test)99 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)79 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)59 LinkedHashMap (java.util.LinkedHashMap)59 User (cz.metacentrum.perun.core.api.User)58 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)56 HashMap (java.util.HashMap)42 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)40 Facility (cz.metacentrum.perun.core.api.Facility)38 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)37 Resource (cz.metacentrum.perun.core.api.Resource)28 Member (cz.metacentrum.perun.core.api.Member)25 Group (cz.metacentrum.perun.core.api.Group)24 Vo (cz.metacentrum.perun.core.api.Vo)23 HashSet (java.util.HashSet)23 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)20