Search in sources :

Example 41 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAttributes.

@Override
public void removeAttributes(PerunSession sess, Member member, Group group, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (!workWithUserAttributes) {
        getAttributesManagerImpl().checkNamespace(sess, attributes, NS_MEMBER_GROUP_ATTR);
        List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
        for (AttributeDefinition attribute : attributes) {
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                if (removeAttributeWithoutCheck(sess, member, group, attribute))
                    attributesToCheck.add(attribute);
            }
        }
        checkAttributesValue(sess, member, group, attributesFromDefinitions(attributesToCheck));
        this.checkAttributesDependencies(sess, member, group, attributesFromDefinitions(attributesToCheck));
    } else {
        List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
        for (AttributeDefinition attribute : attributes) {
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
                if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_GROUP_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, member, group, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, user, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, member, attribute))
                        attributesToCheck.add(attribute);
                } else {
                    throw new WrongAttributeAssignmentException(attribute);
                }
            }
        }
        checkAttributesValue(sess, member, group, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
        this.checkAttributesDependencies(sess, member, group, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 42 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAllUserFacilityAttributes.

public void removeAllUserFacilityAttributes(PerunSession sess, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<RichAttribute<User, Facility>> userFacilitiesAttributes = getAttributesManagerImpl().getAllUserFacilityRichAttributes(sess, user);
    //remove all non-virtual attributes
    getAttributesManagerImpl().removeAllUserFacilityAttributes(sess, user);
    getPerunBl().getAuditer().log(sess, "All non-virtual user-facility attributes removed for all facilities and {}", user);
    for (RichAttribute<User, Facility> richAttribute : userFacilitiesAttributes) {
        try {
            checkAttributeValue(sess, richAttribute.getSecondaryHolder(), richAttribute.getPrimaryHolder(), new Attribute(richAttribute.getAttribute()));
            this.checkAttributeDependencies(sess, richAttribute);
        } catch (WrongAttributeAssignmentException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    for (RichAttribute<User, Facility> attribute : userFacilitiesAttributes) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, attribute.getSecondaryHolder(), attribute.getPrimaryHolder(), new Attribute(attribute.getAttribute()));
        } catch (WrongAttributeValueException ex) {
            //TODO better exception here
            throw new InternalErrorException(ex);
        } catch (WrongReferenceAttributeValueException ex) {
            //TODO better exception here
            throw new InternalErrorException(ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) 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) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 43 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAllAttributes.

public void removeAllAttributes(PerunSession sess, Facility facility, boolean removeAlsoUserFacilityAttributes) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    removeAllAttributes(sess, facility);
    if (removeAlsoUserFacilityAttributes) {
        List<Attribute> userFacilityAttributes = getUserFacilityAttributesForAnyUser(sess, facility);
        getAttributesManagerImpl().removeAllUserFacilityAttributesForAnyUser(sess, facility);
        getPerunBl().getAuditer().log(sess, "All user-facility attributes removed for {} for any user.", facility);
        for (Attribute attribute : userFacilityAttributes) attribute.setValue(null);
        List<User> facilityUsers = perunBl.getFacilitiesManagerBl().getAllowedUsers(sess, facility);
        for (User user : facilityUsers) {
            try {
                checkAttributesValue(sess, facility, user, userFacilityAttributes);
                this.checkAttributesDependencies(sess, facility, user, userFacilityAttributes);
            } catch (WrongAttributeAssignmentException ex) {
                throw new ConsistencyErrorException(ex);
            }
            for (Attribute attribute : userFacilityAttributes) {
                try {
                    getAttributesManagerImpl().changedAttributeHook(sess, facility, user, new Attribute(attribute));
                } catch (WrongAttributeValueException ex) {
                    //TODO better exception here
                    throw new InternalErrorException(ex);
                } catch (WrongReferenceAttributeValueException ex) {
                    //TODO better exception here
                    throw new InternalErrorException(ex);
                }
            }
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) 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) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 44 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAttributes.

public void removeAttributes(PerunSession sess, Member member, boolean workWithUserAttributes, List<? extends AttributeDefinition> attributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (!workWithUserAttributes) {
        getAttributesManagerImpl().checkNamespace(sess, attributes, NS_MEMBER_ATTR);
        List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
        for (AttributeDefinition attribute : attributes) {
            //skip core attributes
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                if (removeAttributeWithoutCheck(sess, member, attribute))
                    attributesToCheck.add(attribute);
            }
        }
        this.checkAttributesValue(sess, member, attributesFromDefinitions(attributesToCheck));
        this.checkAttributesDependencies(sess, member, null, attributesFromDefinitions(attributesToCheck));
    } else {
        User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
        List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
        for (AttributeDefinition attribute : attributes) {
            //skip core attributes
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, member, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, user, attribute))
                        attributesToCheck.add(attribute);
                } else {
                    throw new WrongAttributeAssignmentException(attribute);
                }
            }
        }
        this.checkAttributesValue(sess, member, attributesFromDefinitions(attributesToCheck), true);
        this.checkAttributesDependencies(sess, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition)

Example 45 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAttributes.

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

Aggregations

WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)127 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)97 Attribute (cz.metacentrum.perun.core.api.Attribute)95 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)61 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)59 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)55 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)52 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)42 User (cz.metacentrum.perun.core.api.User)31 ArrayList (java.util.ArrayList)31 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)14 Facility (cz.metacentrum.perun.core.api.Facility)14 LinkedHashMap (java.util.LinkedHashMap)11 Member (cz.metacentrum.perun.core.api.Member)10 Map (java.util.Map)9 Group (cz.metacentrum.perun.core.api.Group)8 List (java.util.List)8 Resource (cz.metacentrum.perun.core.api.Resource)7 Vo (cz.metacentrum.perun.core.api.Vo)6 HashMap (java.util.HashMap)6