Search in sources :

Example 46 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

public boolean setAttributeWithoutCheck(PerunSession sess, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = true;
    if (isVirtAttribute(sess, attribute)) {
        //TODO
        throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute instead.");
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, group, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, group);
        getAttributesManagerImpl().changedAttributeHook(sess, group, attribute);
    }
    return changed;
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 47 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

public boolean removeAttributeWithoutCheck(PerunSession sess, Resource resource, Member member, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
    getAttributesManagerImpl().checkNamespace(sess, attribute, NS_MEMBER_RESOURCE_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, resource, member, attribute);
    if (changed) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, resource, member, 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);
        }
        getPerunBl().getAuditer().log(sess, "{} removed for {} and {}", attribute, resource, member);
    }
    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) 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 48 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

public boolean setAttributeWithoutCheck(PerunSession sess, Host host, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_HOST_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = true;
    if (isVirtAttribute(sess, attribute)) {
        //TODO
        throw new InternalErrorException("Virtual attribute " + attribute + " can't be set this way yet. Please set physical attribute.");
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, host, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, host);
    //TODO this method not existed yet!
    //getAttributesManagerImpl().changedAttributeHook(sess, host, attribute);
    }
    return changed;
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 49 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, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<Attribute> attributes = getAttributes(sess, user);
    getAttributesManagerImpl().removeAllAttributes(sess, user);
    getPerunBl().getAuditer().log(sess, "All attributes removed for {}", user);
    for (Attribute attribute : attributes) attribute.setValue(null);
    try {
        checkAttributesValue(sess, user, attributes);
        this.checkAttributesDependencies(sess, user, null, attributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    }
    for (Attribute attribute : attributes) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, 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) 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 50 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, Member member, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (!(workWithUserAttributes)) {
        removeAttributes(sess, resource, member, attributes);
    } else {
        List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
        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(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, resource, member, attribute))
                        attributesToCheck.add(attribute);
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
                    if (removeAttributeWithoutCheck(sess, facility, user, 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, resource, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
        this.checkAttributesDependencies(sess, resource, 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) Facility(cz.metacentrum.perun.core.api.Facility)

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