Search in sources :

Example 91 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

@Override
public boolean setAttributeWithoutCheck(PerunSession sess, Member member, Group group, Attribute attribute, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = true;
    if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_GROUP_ATTR)) {
        if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
            changed = getAttributesManagerImpl().setVirtualAttribute(sess, member, group, attribute);
        } else {
            changed = getAttributesManagerImpl().setAttribute(sess, member, group, attribute);
            if (changed) {
                getPerunBl().getAuditer().log(sess, "{} set for {} and {}.", attribute, member, group);
                getAttributesManagerImpl().changedAttributeHook(sess, member, group, attribute);
            }
        }
    } else if (workWithUserAttributes) {
        if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
            User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
            if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
                changed = getAttributesManagerImpl().setVirtualAttribute(sess, user, attribute);
            } else {
                changed = setAttributeWithoutCheck(sess, user, attribute);
            }
        } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
            if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
                changed = getAttributesManagerImpl().setVirtualAttribute(sess, member, attribute);
            } else {
                changed = setAttributeWithoutCheck(sess, member, attribute);
            }
        } else {
            throw new WrongAttributeAssignmentException(attribute);
        }
    } else {
        throw new WrongAttributeAssignmentException(attribute);
    }
    return changed;
}
Also used : User(cz.metacentrum.perun.core.api.User) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)

Example 92 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method checkAttributesDependencies.

private void checkAttributesDependencies(PerunSession sess, Resource resource, Group group, List<Attribute> attributes, boolean workWithGroupAttributes) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
    if (workWithGroupAttributes) {
        List<Attribute> groupAttributes = new ArrayList<Attribute>();
        List<Attribute> groupResourceAttributes = new ArrayList<Attribute>();
        for (Attribute attr : attributes) {
            if (getAttributesManagerImpl().isFromNamespace(sess, attr, NS_GROUP_RESOURCE_ATTR)) {
                groupResourceAttributes.add(attr);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attr, NS_GROUP_ATTR)) {
                groupAttributes.add(attr);
            } else {
                throw new WrongAttributeAssignmentException(attr);
            }
        }
        checkAttributesDependencies(sess, resource, group, groupResourceAttributes);
        checkAttributesDependencies(sess, group, null, groupAttributes);
    } else {
        checkAttributesDependencies(sess, resource, group, attributes);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList)

Example 93 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributes.

public void setAttributes(PerunSession sess, Facility facility, Resource resource, User user, Member member, List<Attribute> attributes) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
    // clasification of attributes to attributes to remove and attributes to set
    List<Attribute> attributesToRemove = new ArrayList<Attribute>();
    List<Attribute> attributesToSet = new ArrayList<Attribute>();
    for (Attribute attribute : attributes) {
        if (attribute.getValue() == null) {
            attributesToRemove.add(attribute);
        } else {
            attributesToSet.add(attribute);
        }
    }
    removeAttributes(sess, facility, resource, user, member, attributesToRemove);
    for (Attribute attribute : attributesToSet) {
        //skip core attributes
        if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
            if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                setAttributeWithoutCheck(sess, resource, member, attribute, false);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
                setAttributeWithoutCheck(sess, facility, user, attribute);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
                setAttributeWithoutCheck(sess, user, attribute);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
                setAttributeWithoutCheck(sess, member, attribute);
            } else {
                throw new WrongAttributeAssignmentException(attribute);
            }
        }
    }
    //if checkAttributesValue fails it causes rollback so no attribute will be stored
    checkAttributesValue(sess, facility, resource, user, member, attributesToSet);
    this.checkAttributesDependencies(sess, resource, member, user, facility, attributesToSet);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList)

Example 94 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, Vo vo, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, NS_VO_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, vo, attribute);
    if (changed) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, vo, 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, vo);
    }
    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 95 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setRequiredAttributes.

public void setRequiredAttributes(PerunSession sess, Facility facility, Resource resource, User user, Member member, List<Attribute> attributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeValueException {
    //fill attributes and get back only those which were really filled with new value
    List<Attribute> filledAttributes = this.fillAttributes(sess, facility, resource, user, member, attributes, true);
    //Remove all filledAttributes from all attributes list
    Iterator<Attribute> iterAttr = attributes.iterator();
    while (iterAttr.hasNext()) {
        Attribute attributeFromAllAttrs = iterAttr.next();
        for (Attribute attributeFromFillAttrs : filledAttributes) {
            if (attributeFromAllAttrs.getName().equals(attributeFromFillAttrs.getName())) {
                iterAttr.remove();
                break;
            }
        }
    }
    //Set all filledAttributes withoutCheck
    for (Attribute attribute : filledAttributes) {
        //skip core attributes
        if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
            if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                this.setAttributeWithoutCheck(sess, resource, member, attribute, false);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
                this.setAttributeWithoutCheck(sess, facility, user, attribute);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
                this.setAttributeWithoutCheck(sess, user, attribute);
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
                this.setAttributeWithoutCheck(sess, member, attribute);
            } else {
                throw new WrongAttributeAssignmentException(attribute);
            }
        }
    }
    //Join all attributes and filled attributes together
    attributes.addAll(filledAttributes);
    //refresh all virtual attributes with new value
    for (Attribute attr : attributes) {
        if (this.isVirtAttribute(sess, attr)) {
            if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                attr.setValue(this.getAttribute(sess, resource, member, attr.getName()).getValue());
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_USER_FACILITY_ATTR)) {
                attr.setValue(this.getAttribute(sess, facility, user, attr.getName()).getValue());
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_USER_ATTR)) {
                attr.setValue(this.getAttribute(sess, user, attr.getName()).getValue());
            } else if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_MEMBER_ATTR)) {
                attr.setValue(this.getAttribute(sess, member, attr.getName()).getValue());
            } else {
                throw new WrongAttributeAssignmentException(attr);
            }
        }
    }
    //Check all attributes
    checkAttributesValue(sess, facility, resource, user, member, attributes);
    //Check all attributes dependencies
    this.checkAttributesDependencies(sess, resource, member, user, facility, attributes);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)

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