Search in sources :

Example 66 with WrongAttributeValueException

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

// s workWithUserAttr.
public boolean removeAttributeWithoutCheck(PerunSession sess, Member member, Group group, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, NS_MEMBER_GROUP_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, member, group, attribute);
    if (changed) {
        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);
        }
        getPerunBl().getAuditer().log(sess, "{} removed for {} and {}", attribute, member, group);
    }
    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 67 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, 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 68 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, 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 69 with WrongAttributeValueException

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

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

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