Search in sources :

Example 61 with WrongReferenceAttributeValueException

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

the class AttributesManagerBlImpl method removeAllAttributes.

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

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

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

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

the class AttributesManagerBlImpl method removeAllAttributes.

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

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

the class AttributesManagerBlImpl method doTheMagic.

public void doTheMagic(PerunSession sess, Member member, boolean trueMagic) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
    for (Resource resource : resources) {
        Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
        List<Attribute> requiredAttributes = getResourceRequiredAttributes(sess, resource, facility, resource, user, member);
        boolean allOk = false;
        AttributeDefinition lastWrongAttribute = null;
        int safetyCounter = 0;
        do {
            try {
                setRequiredAttributes(sess, facility, resource, user, member, requiredAttributes);
                allOk = true;
            } catch (AttributeNotExistsException ex) {
                throw new ConsistencyErrorException(ex);
            } catch (WrongAttributeAssignmentException ex) {
                throw new ConsistencyErrorException(ex);
            } catch (WrongAttributeValueException ex) {
                if (!trueMagic)
                    throw ex;
                AttributeDefinition wrongAttributeDefinition = ex.getAttribute();
                if (wrongAttributeDefinition == null)
                    throw new ConsistencyErrorException("WrongAttributeValueException doesn't have set the wrong attribute.", ex);
                if (wrongAttributeDefinition.equals(lastWrongAttribute))
                    throw new WrongAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
                lastWrongAttribute = wrongAttributeDefinition;
                findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null);
            } catch (WrongReferenceAttributeValueException ex) {
                if (!trueMagic)
                    throw ex;
                AttributeDefinition wrongAttributeDefinition = ex.getReferenceAttribute();
                if (wrongAttributeDefinition == null)
                    throw new ConsistencyErrorException("WrongReferenceAttributeValueException doesn't have set reference attribute.", ex);
                if (wrongAttributeDefinition.equals(lastWrongAttribute))
                    throw new WrongReferenceAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
                lastWrongAttribute = wrongAttributeDefinition;
                if (!findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null)) {
                    //this attribute can't be fixed here
                    throw ex;
                }
            }
            safetyCounter++;
            if (safetyCounter == 50)
                throw new InternalErrorException("Method doTheMagic possibly stays in infinite loop.");
        } while (trueMagic && !allOk);
    }
}
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) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 65 with WrongReferenceAttributeValueException

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

the class AttributesManagerBlImpl method removeAllAttributes.

public void removeAllAttributes(PerunSession sess, Facility facility, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<Attribute> attributes = getAttributes(sess, facility, user);
    //remove all non-virtual attributes
    getAttributesManagerImpl().removeAllAttributes(sess, facility, user);
    //remove all virtual attributes
    List<Attribute> virtualAttributes = getVirtualAttributes(sess, facility, user);
    for (Attribute attribute : virtualAttributes) {
        getAttributesManagerImpl().removeVirtualAttribute(sess, facility, user, attribute);
    }
    attributes.addAll(virtualAttributes);
    getPerunBl().getAuditer().log(sess, "All attributes removed for {} and {}", facility, user);
    for (Attribute attribute : attributes) attribute.setValue(null);
    try {
        checkAttributesValue(sess, facility, user, attributes);
        this.checkAttributesDependencies(sess, facility, user, attributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    }
    for (Attribute attribute : attributes) {
        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) 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)

Aggregations

WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)109 Attribute (cz.metacentrum.perun.core.api.Attribute)101 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)70 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)64 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)62 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)51 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 Resource (cz.metacentrum.perun.core.api.Resource)13 ArrayList (java.util.ArrayList)13 Facility (cz.metacentrum.perun.core.api.Facility)12 Matcher (java.util.regex.Matcher)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 BigDecimal (java.math.BigDecimal)6 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 List (java.util.List)5 Pattern (java.util.regex.Pattern)5 Pair (cz.metacentrum.perun.core.api.Pair)3 LinkedHashMap (java.util.LinkedHashMap)3