Search in sources :

Example 36 with WrongAttributeValueException

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

public boolean removeAttributeWithoutCheck(PerunSession sess, Facility facility, User user, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, NS_USER_FACILITY_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = false;
    if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
        changed = getAttributesManagerImpl().removeVirtualAttribute(sess, facility, user, attribute);
    } else {
        changed = getAttributesManagerImpl().removeAttribute(sess, facility, user, attribute);
    }
    if (changed) {
        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);
        }
        getPerunBl().getAuditer().log(sess, "{} removed for {} and {}", attribute, facility, user);
    }
    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 37 with WrongAttributeValueException

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

the class AttributesManagerBlImpl method removeAllAttributes.

public void removeAllAttributes(PerunSession sess, Member member) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<Attribute> attributes = getAttributes(sess, member);
    getAttributesManagerImpl().removeAllAttributes(sess, member);
    getPerunBl().getAuditer().log(sess, "All attributes removed for {}", member);
    for (Attribute attribute : attributes) attribute.setValue(null);
    try {
        checkAttributesValue(sess, member, attributes);
        this.checkAttributesDependencies(sess, member, null, attributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    }
    for (Attribute attribute : attributes) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, 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);
        }
    }
}
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 38 with WrongAttributeValueException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

public boolean setAttributeWithoutCheck(PerunSession sess, Member member, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR);
    boolean changed = true;
    if (isVirtAttribute(sess, attribute)) {
        //TODO better exception here
        try {
            return getAttributesManagerImpl().setVirtualAttribute(sess, member, attribute);
        } catch (WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
    //FIXME update "changed" variable
    } else if (isCoreAttribute(sess, attribute)) {
        //TODO better exception
        try {
            setCoreAttributeWithoutCheck(sess, member, attribute);
        } catch (WrongReferenceAttributeValueException ex) {
            throw new InternalErrorException(ex);
        } catch (WrongAttributeValueException ex) {
            throw new InternalErrorException(ex);
        }
        //FIXME check if attribute is acctualy changed
        changed = true;
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, member, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, member);
        getAttributesManagerImpl().changedAttributeHook(sess, member, attribute);
    }
    return changed;
}
Also used : 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 39 with WrongAttributeValueException

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

public boolean removeAttributeWithoutCheck(PerunSession sess, Facility facility, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, NS_FACILITY_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, facility, attribute);
    if (changed) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, facility, 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 {}", attribute, facility);
    }
    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 40 with WrongAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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)

Aggregations

WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)135 Attribute (cz.metacentrum.perun.core.api.Attribute)100 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)82 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)75 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)66 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)54 Matcher (java.util.regex.Matcher)31 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 ArrayList (java.util.ArrayList)17 LinkedHashMap (java.util.LinkedHashMap)16 Facility (cz.metacentrum.perun.core.api.Facility)14 Map (java.util.Map)14 Resource (cz.metacentrum.perun.core.api.Resource)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 Pattern (java.util.regex.Pattern)8 BigDecimal (java.math.BigDecimal)7 List (java.util.List)7 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5